normalize_simd

Function normalize_simd 

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

SIMD-accelerated L2 normalization

Normalizes the vector to unit length: x / ||x||₂

§Arguments

  • a - Input array

§Returns

Unit-normalized array (or zero if input is zero)

§Examples

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

let x = array![3.0_f64, 4.0];
let result = normalize_simd::<f64>(&x.view());
// ||result|| = 1
let norm = (result[0]*result[0] + result[1]*result[1]).sqrt();
assert!((norm - 1.0).abs() < 1e-10);
// x/5 = [0.6, 0.8]
assert!((result[0] - 0.6).abs() < 1e-10);
assert!((result[1] - 0.8).abs() < 1e-10);

§Use Cases

  • Unit vector computation
  • Cosine similarity preparation
  • Gradient normalization
  • Direction extraction