Skip to main content

pairwise_sum

Function pairwise_sum 

Source
pub fn pairwise_sum<T>(data: &[T], identity: T) -> T
where T: Copy + Add<Output = T>,
Expand description

Pairwise summation of a slice.

Uses an iterative carry-merge algorithm with O(ε log N) error bound, matching NumPy’s summation accuracy. Data is processed in 128-element base chunks, then merged pairwise using a small stack (like binary carry addition). Zero recursion overhead — stack depth is at most ceil(log2(N/128)) + 1 ≈ 20 entries.