Clip#

API#

class warp_nn.modules.operators.Clip(
min_val: float | None = None,
max_val: float | None = None,
*,
requires_grad: bool = True,
)[source]#

Bases: Module

Element-wise clipping (clamping) of the input values into the interval [min_val, max_val].

\[\text{Clip}(x) = \min(\text{max\_val}, \max(x, \text{min\_val}))\]

When min_val is greater than max_val, all the values are set to max_val.

PyTorch’s Hardtanh(min_val, max_val) is equivalent to Clip(min_val, max_val).

Parameters:
  • min_val – The lower bound of the interval. If None, the values are not bounded below.

  • max_val – The upper bound of the interval. If None, the values are not bounded above.

  • requires_grad – Whether the cached output arrays of the module require gradients.

__call__(input: array) → array[source]#

Forward pass of the operation.

Parameters:

input – The input array, with up to 3 dimensions.

Returns:

The output array, with same shape as the input array.

Raises:

TypeError – If the input array’s data type or number of dimensions is not supported.

property max_val: float | None[source]#

The upper bound of the interval.

property min_val: float | None[source]#

The lower bound of the interval.