use core::ops::{Add, Index, Mul, Sub};
use num_traits::Float;
pub trait Point:
Add<Self, Output = Self> + Sub<Self, Output = Self> + Mul<Self::Scalar, Output = Self> + Copy
{
type Scalar: Float;
const DIM: usize;
}
pub trait PointIndex: Point + Index<usize, Output = Self::Scalar> {}
impl<T> PointIndex for T where T: Point + Index<usize, Output = Self::Scalar> {}
pub trait PointDot: PointIndex {
fn dot(&self, other: &Self) -> Self::Scalar {
let mut sum = <Self::Scalar as num_traits::NumCast>::from(0.0).unwrap();
for i in 0..Self::DIM {
sum = sum + self[i] * other[i];
}
sum
}
}
impl<T> PointDot for T where T: PointIndex {}
pub trait PointNorm: PointDot {
fn squared_norm(&self) -> Self::Scalar {
self.dot(self)
}
}
impl<T> PointNorm for T where T: PointDot {}