diff -r d8305c9b6fdf -r f7b87d84864d src/euclidean.rs --- a/src/euclidean.rs Sat Dec 21 23:32:20 2024 -0500 +++ b/src/euclidean.rs Sun Dec 22 14:54:46 2024 -0500 @@ -4,38 +4,35 @@ use std::ops::{Mul, MulAssign, Div, DivAssign, Add, Sub, AddAssign, SubAssign, Neg}; use crate::types::*; -use crate::mapping::Space; - -/// Space (type) with a defined dot product. -/// -/// `U` is the space of the multiplier, and `F` the space of scalars. -/// Since `U` ≠ `Self`, this trait can also implement dual products. -pub trait Dot { - fn dot(&self, other : &U) -> F; -} +use crate::instance::Instance; +use crate::norms::{HasDual, Reflexive}; /// Space (type) with Euclidean and vector space structure /// /// The type should implement vector space operations (addition, subtraction, scalar /// multiplication and scalar division) along with their assignment versions, as well -/// as the [`Dot`] product with respect to `Self`. -pub trait Euclidean : Space + Dot - + Mul>::Output> + MulAssign - + Div>::Output> + DivAssign - + Add>::Output> - + Sub>::Output> - + for<'b> Add<&'b Self, Output=>::Output> - + for<'b> Sub<&'b Self, Output=>::Output> - + AddAssign + for<'b> AddAssign<&'b Self> - + SubAssign + for<'b> SubAssign<&'b Self> - + Neg>::Output> { +/// as an inner product. +pub trait Euclidean : HasDual + Reflexive + + Mul>::Output> + MulAssign + + Div>::Output> + DivAssign + + Add>::Output> + + Sub>::Output> + + for<'b> Add<&'b Self, Output=>::Output> + + for<'b> Sub<&'b Self, Output=>::Output> + + AddAssign + for<'b> AddAssign<&'b Self> + + SubAssign + for<'b> SubAssign<&'b Self> + + Neg>::Output> +{ type Output : Euclidean; + // Inner product + fn dot>(&self, other : I) -> F; + /// Calculate the square of the 2-norm, $\frac{1}{2}\\|x\\|_2^2$, where `self` is $x$. - #[inline] - fn norm2_squared(&self) -> F { - self.dot(self) - } + /// + /// This is not automatically implemented to avoid imposing + /// `for <'a> &'a Self : Instance` trait bound bloat. + fn norm2_squared(&self) -> F; /// Calculate the square of the 2-norm divided by 2, $\frac{1}{2}\\|x\\|_2^2$, /// where `self` is $x$.