IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

reduce

reduce[reduce_fn: def[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]], init: Scalar[dtype]) -> Scalar[dtype]

Computes a custom reduction of buffer elements.

Parameters:

  • reduce_fn (def[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:

Returns:

Scalar[dtype]: The computed reduction value.

Raises:

If the operation fails.