For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo function
reduce
def reduce[dtype: DType, ReduceFnType: def[acc_type: DType, dtype: DType, width: SIMDLength](SIMD[acc_type, width], SIMD[dtype, width]) -> SIMD[acc_type, width] & RegisterPassable & ImplicitlyCopyable, //](src: Span[Scalar[dtype]], init: Scalar[dtype], reduce_fn: ReduceFnType) -> Scalar[dtype]
Computes a custom reduction of buffer elements.
Parameters:
- dtype (
DType): The dtype of the input. - ReduceFnType (
def[acc_type: DType, dtype: DType, width: SIMDLength](SIMD[acc_type, width], SIMD[dtype, width]) -> SIMD[acc_type, width]&RegisterPassable&ImplicitlyCopyable): The type ofreduce_fn(inferred).
Args:
- src (
Span[Scalar[dtype]]): The input buffer. - init (
Scalar[dtype]): The initial value to use in accumulator. - reduce_fn (
ReduceFnType): The lambda implementing the reduction.
Returns:
Scalar[dtype]: The computed reduction value.
Raises:
If the operation fails.