Skip to main content

normalize

Function normalize 

Source
pub fn normalize(v: &[f32]) -> Vec<f32>
Expand description

Normalize a vector to unit length.

Returns a zero vector if the input has zero magnitude.

ยงExample

use liteforge::rag::normalize;

let v = vec![3.0, 4.0];
let n = normalize(&v);
assert!((n[0] - 0.6).abs() < 0.001);
assert!((n[1] - 0.8).abs() < 0.001);