oneflow.clamp_max

oneflow.clamp_max()

Clamp all elements in input which are greater than max to max and return a resulting tensor:

\[y_i = \min(max, x_i)\]

If input is of type FloatTensor or DoubleTensor, args max must be real numbers, otherwise they should be integers.

Parameters
  • input (Tensor) – the input tensor.

  • max (Number) – upper-bound of the range to be clamped to.

  • out (Tensor, optional) – the output tensor.

For example:

>>> import oneflow as flow
>>> input = flow.Tensor([0.2, 0.6, -1.5, -0.3])
>>> output = flow.clamp_max(input, max=-0.5)
>>> output
tensor([-0.5000, -0.5000, -1.5000, -0.5000], dtype=oneflow.float32)

>>> input = flow.Tensor([0.2, 0.6, -1.5, -0.3])
>>> output = flow.clamp_max(input, max=-2)
>>> output
tensor([-2., -2., -2., -2.], dtype=oneflow.float32)

>>> input = flow.Tensor([0.2, 0.6, -1.5, -0.3])
>>> output = flow.clamp_max(input, max=1)
>>> output
tensor([ 0.2000,  0.6000, -1.5000, -0.3000], dtype=oneflow.float32)