weighted_sum_simd

Function weighted_sum_simd 

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

SIMD-accelerated weighted sum

Computes sum(values * weights).

§Arguments

  • values - Values array
  • weights - Weights array (same length as values)

§Returns

Weighted sum

§Examples

use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::elementwise::weighted_sum_simd;

let values = array![10.0_f64, 20.0, 30.0];
let weights = array![0.2_f64, 0.3, 0.5];
let ws = weighted_sum_simd::<f64>(&values.view(), &weights.view());
// 10*0.2 + 20*0.3 + 30*0.5 = 2 + 6 + 15 = 23
assert!((ws - 23.0).abs() < 1e-10);

§Use Cases

  • Portfolio valuation
  • Weighted regression
  • Attention mechanism scores
  • Signal filtering