Skip to main content

sum

Function sum 

Source
pub fn sum<T: Copy + Zero + Add<Output = T> + Send + Sync + MaybeSimdOps, Op: ElementOp<T>>(
    src: &StridedView<'_, T, Op>,
    exec: Exec<'_>,
) -> Result<T>
Expand description

Sum all elements: sum(src).

§Evaluation order

The result is independent of the pool when the call runs with a serial token (Exec::serial) or a budget of one. With a larger budget a contiguous identity operand above the threading threshold is summed per task and the partial sums are combined in a tree, so the result is repeatable for a fixed budget but can differ between budgets.

Neither path is a strict left to right sum: a contiguous run is folded with independent SIMD or scalar lanes (see reduce for the lane scheme of the generic path). The last bits can therefore differ from a naive loop, and no bitwise equality across machines or target features is guaranteed.

For a deterministic accumulation of f32 data in f64, use zip_reduce with an f64 map and a 0.0f64 init.

§Allocation

At rank ≤ INLINE_RANK the view metadata and the traversal plan are stored inline, so a call performs no heap allocation.