1use rayon::prelude::*; 2 3pub trait Vector { 4 fn l2_norm(&self) -> f64; 5} 6 7impl Vector for [f64] { 8 fn l2_norm(&self) -> f64 { 9 self.into_par_iter() 10 .map(|xi| xi.powi(2)) 11 .sum::<f64>() 12 .sqrt() 13 } 14}