1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use ndarray::prelude::*; use ndarray::LinalgScalar; use num_traits::float::Float; pub trait Vector { type Scalar; fn norm(&self) -> Self::Scalar; } impl<A: Float + LinalgScalar> Vector for Array<A, Ix> { type Scalar = A; fn norm(&self) -> Self::Scalar { self.dot(&self).sqrt() } }