Skip to main content

reduce_axis_into

Function reduce_axis_into 

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

Reduce along a single axis into caller-owned storage.

dest must have the source’s shape with axis removed, or any single-element destination for a full reduction, and an injective layout. Every destination element is written: an empty reduced axis fills each output with init.

§Errors

Returns StridedError::InvalidAxis for axis >= src.ndim(), StridedError::RankMismatch / StridedError::ShapeMismatch for a destination shape that is not the reduced source shape, StridedError::NonInjectiveOutputLayout for an overlapping destination, and StridedError::OffsetOverflow for unrepresentable sizes.

§Examples

use strided_basic::{reduce_axis_into, Exec, StridedArray};
let mut out = StridedArray::<f64>::col_major(&[3]);
reduce_axis_into(&mut out.view_mut(), &src.view(), 0, |x| x, |a, b| a + b, 0.0, Exec::serial()).unwrap();
assert_eq!(out.get(&[0]), 1.0);

Validation runs here; reduce_axis_into_impl is the shared kernel. The array-returning wrapper owns a fresh column-major destination and calls the kernel directly, so the common path does not re-validate.