Skip to main content



clamp[type: DType, simd_width: Int](x: SIMD[type, simd_width], lower_bound: SIMD[type, simd_width], upper_bound: SIMD[type, simd_width]) -> SIMD[$0, $1]

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].


  • type (DType): DType of the input SIMD vectors.
  • simd_width (Int): Width of the input SIMD vectors.


  • x (SIMD[type, simd_width]): SIMD vector to perform the clamp operation on.
  • lower_bound (SIMD[type, simd_width]): Minimum of the range to clamp to.
  • upper_bound (SIMD[type, simd_width]): Maximum of the range to clamp to.


A new SIMD vector containing x clamped to be within lower_bound and upper_bound.