Skip to contents

Clamps every element of operand to the range [min_val, max_val], i.e. max(min_val, min(operand, max_val)).

Usage

prim_clamp(min_val, operand, max_val)

Arguments

min_val

(arrayish)
Minimum value. Must be scalar or the same shape as operand.

operand

(arrayish)
Arrayish value of any data type.

max_val

(arrayish)
Maximum value. Must be scalar or the same shape as operand.

Value

arrayish
Has the same data type and shape as operand. It is ambiguous if the input is ambiguous.

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to stablehlo::hlo_clamp().

See also

Examples

x <- nv_array(c(-1, 0.5, 2))
prim_clamp(nv_scalar(0), x, nv_scalar(1))
#> AnvlArray
#>  0.0000
#>  0.5000
#>  1.0000
#> [ CPUf32{3} ]