Skip to main content

Mojo function

reduce

reduce[reduce_fn: fn[acc_type: DType, dtype: DType, width: Int](SIMD[acc_type, width], SIMD[dtype, width]) capturing -> SIMD[acc_type, width], dtype: DType](src: Span[Scalar[dtype], origin], init: Scalar[dtype]) -> Scalar[dtype]

Computes a custom reduction of buffer elements.

Parameters:

  • ​reduce_fn (fn[acc_type: DType, dtype: DType, width: Int](SIMD[acc_type, width], SIMD[dtype, width]) capturing -> SIMD[acc_type, width]): The lambda implementing the reduction.
  • ​dtype (DType): The dtype of the input.

Args:

  • ​src (Span): The input buffer.
  • ​init (Scalar): The initial value to use in accumulator.

Returns:

Scalar: The computed reduction value.

Raises:

If the operation fails.

Was this page helpful?