Mojo function
clamp(val: Int, lower_bound: Int, upper_bound: Int) -> Int
Clamps the integer value vector to be in a certain range.
Args:
- val (
Int): The value to clamp. - lower_bound (
Int): Minimum of the range to clamp to. - upper_bound (
Int): Maximum of the range to clamp to.
Returns:
Int: An integer clamped to be within lower_bound and upper_bound.
clamp(val: Scalar[DType.uint], lower_bound: Scalar[DType.uint], upper_bound: Scalar[DType.uint]) -> Scalar[DType.uint]
Clamps the integer value vector to be in a certain range.
Args:
- val (
Scalar): The value to clamp. - lower_bound (
Scalar): Minimum of the range to clamp to. - upper_bound (
Scalar): Maximum of the range to clamp to.
Returns:
Scalar: An integer clamped to be within lower_bound and upper_bound.
clamp[dtype: DType, width: Int, //](val: SIMD[dtype, width], lower_bound: SIMD[dtype, width], upper_bound: SIMD[dtype, width]) -> SIMD[dtype, width]
Clamps the values in a SIMD vector to be in a certain range.
Clamp cuts values in the input SIMD vector off at the upper bound and
lower bound values. For example, SIMD vector [0, 1, 2, 3] clamped to
a lower bound of 1 and an upper bound of 2 would return [1, 1, 2, 2].
Parameters:
- dtype (
DType): Thedtypeof the input and output SIMD vector. - width (
Int): The width of the input and output SIMD vector.
Args:
- val (
SIMD): The value to clamp. - lower_bound (
SIMD): Minimum of the range to clamp to. - upper_bound (
SIMD): Maximum of the range to clamp to.
Returns:
SIMD: A SIMD vector containing x clamped to be within lower_bound and
upper_bound.