Apply clamp.
(
ctx: Any,
tensor: torch.Tensor,
min: float | None,
max: float | None,
pushback: float,
)
| 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. |
nothing calls this directly
no outgoing calls
no test coverage detected