Skip to main content

reduce_axis

Function reduce_axis 

Source
pub fn reduce_axis<T: Copy + Send + Sync, Op: ElementOp<T>, M, R, U>(
    src: &StridedView<'_, T, Op>,
    axis: usize,
    map_fn: M,
    reduce_fn: R,
    init: U,
    exec: Exec<'_>,
) -> Result<StridedArray<U>>
where M: Fn(T) -> U + Sync, R: Fn(U, U) -> U + Sync, U: Clone + Send + Sync,
Expand description

Reduce along a single axis, returning a new StridedArray.

This allocates a column-major output and delegates to reduce_axis_into.

Every output folds init once and then its reduced elements. When the reduced axis has unit stride those elements are folded with the lane scheme of reduce, so reduce_fn must be associative and commutative. When the leading kept axis has unit stride, a block of adjacent outputs is accumulated one contiguous source column at a time, which keeps the left to right order per output. Outputs are split across the budget of exec once the number of source elements read exceeds the threading threshold; each output is computed by one task, so the result does not depend on the budget.

§Errors

Returns StridedError::InvalidAxis when axis >= src.ndim(), and StridedError::OffsetOverflow when the source element count cannot be represented in usize. The destination layout is built here, so the destination-shape errors of reduce_axis_into cannot occur.

§Panics

Panics when the kept source extents cannot be described in isize, which an empty source extent hides from the element-count check: reducing axis 0 of a [0, usize::MAX] source builds the output strides with col_major_strides, which panics instead of reporting an error.