MCPcopy Create free account
hub / github.com/apple/ml-sharp / forward

Method forward

src/sharp/utils/math.py:110–125  ·  view source on GitHub ↗

Apply clamp.

(
        ctx: Any,
        tensor: torch.Tensor,
        min: float | None,
        max: float | None,
        pushback: float,
    )

Source from the content-addressed store, hash-verified

108
109 @staticmethod
110 def forward(
111 ctx: Any,
112 tensor: torch.Tensor,
113 min: float | None,
114 max: float | None,
115 pushback: float,
116 ) -> torch.Tensor:
117 """Apply clamp."""
118 if min is not None and max is not None and min >= max:
119 raise ValueError("Only min < max is supported.")
120
121 ctx.save_for_backward(tensor)
122 ctx.min = min
123 ctx.max = max
124 ctx.pushback = pushback
125 return torch.clamp(tensor, min=min, max=max)
126
127 @staticmethod
128 def backward( # type: ignore[override] # Deal with buggy torch annotations.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected