sum_simd

Function sum_simd 

Source
pub fn sum_simd<F>(x: &ArrayView1<'_, F>) -> F
where F: Float + SimdUnifiedOps,
Expand description

Compute sum of a 1D array with SIMD acceleration.

This function uses SIMD operations when beneficial for performance, providing significant speedups for large arrays on supported platforms (AVX2, NEON).

§Arguments

  • x - Input 1D array

§Returns

  • The sum of all elements in the array (0 for empty array)

§Performance

  • f32: ~2-3x faster than scalar for arrays > 1000 elements
  • f64: ~2-3x faster than scalar for arrays > 1000 elements

§Examples

use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::reduction::sum_simd;

let x = array![1.0f64, 2.0, 3.0, 4.0, 5.0];
let sum = sum_simd(&x.view());
assert_eq!(sum, 15.0);