pub fn normalize(vector: &mut [f32])Expand description
Normalizes a vector to unit length (L2 norm = 1).
This operation modifies the vector in-place, scaling all components so that the resulting vector has a magnitude of 1.0.
§Arguments
vector- Mutable reference to the vector to normalize
§Behavior
- If the vector has zero magnitude, it remains unchanged
- Empty vectors remain unchanged
§Performance
This function performs two passes over the data (magnitude calculation and scaling). For better performance when normalizing many vectors, consider batching or using SIMD operations.
§Examples
use foxstash_core::vector::ops::normalize;
let mut v = vec![3.0, 4.0];
normalize(&mut v);
assert!((v[0] - 0.6).abs() < 1e-6);
assert!((v[1] - 0.8).abs() < 1e-6);