Skip to main content

simd_sum

Function simd_sum 

Source
pub fn simd_sum(data: &[f64]) -> f64
Expand description

Computes the sum of a slice with multi-tier SIMD acceleration and Kahan (compensated) summation for numerical stability.

On x86_64: runtime-detects AVX-512F → AVX2+FMA → SSE2 (baseline). On aarch64: uses NEON intrinsics. Elsewhere: portable 4-wide scalar ILP unroll.

Each tier maintains per-lane compensation vectors that track accumulated rounding error, dramatically reducing the O(n·ε²) error of naive pairwise summation to O(ε) regardless of input length.

§Examples

use chronix_analytics::compute::simd_sum;
assert!((simd_sum(&[1.0, 2.0, 3.0, 4.0]) - 10.0).abs() < 1e-10);
assert_eq!(simd_sum(&[]), 0.0);