Mon, 12 May 2025 19:30:41 -0500
Make Euclidean depend on AXPY
| src/convex.rs | file | annotate | diff | comparison | revisions | |
| src/direct_product.rs | file | annotate | diff | comparison | revisions | |
| src/euclidean.rs | file | annotate | diff | comparison | revisions | |
| src/loc.rs | file | annotate | diff | comparison | revisions | |
| src/nalgebra_support.rs | file | annotate | diff | comparison | revisions |
--- a/src/convex.rs Mon May 12 16:28:50 2025 -0500 +++ b/src/convex.rs Mon May 12 19:30:41 2025 -0500 @@ -401,7 +401,7 @@ impl<X, F> Prox<X> for Norm222<F> where F: Float, - X: Euclidean<F, Output = X>, + X: Euclidean<F, Owned = X>, { type Prox<'a> = Scaled<F> @@ -416,7 +416,7 @@ impl<X, F> DifferentiableImpl<X> for Norm222<F> where F: Float, - X: Euclidean<F, Output = X>, + X: Euclidean<F, Owned = X>, { type Derivative = X; @@ -428,7 +428,7 @@ impl<X, F> LipschitzDifferentiableImpl<X, L2> for Norm222<F> where F: Float, - X: Euclidean<F, Output = X>, + X: Euclidean<F, Owned = X>, { type FloatType = F;
--- a/src/direct_product.rs Mon May 12 16:28:50 2025 -0500 +++ b/src/direct_product.rs Mon May 12 19:30:41 2025 -0500 @@ -270,22 +270,20 @@ B: Euclidean<F>, //Pair<A, B>: Euclidean<F>, Self: Sized - + Mul<F, Output = Pair<A, B>> + + Mul<F, Output = <Self as AXPY>::Owned> + MulAssign<F> - + Div<F, Output = Pair<A, B>> + + Div<F, Output = <Self as AXPY>::Owned> + DivAssign<F> - + Add<Self, Output = Pair<A, B>> - + Sub<Self, Output = Pair<A, B>> - + for<'b> Add<&'b Self, Output = Pair<A, B>> - + for<'b> Sub<&'b Self, Output = Pair<A, B>> + + Add<Self, Output = <Self as AXPY>::Owned> + + Sub<Self, Output = <Self as AXPY>::Owned> + + for<'b> Add<&'b Self, Output = <Self as AXPY>::Owned> + + for<'b> Sub<&'b Self, Output = <Self as AXPY>::Owned> + AddAssign<Self> + for<'b> AddAssign<&'b Self> + SubAssign<Self> + for<'b> SubAssign<&'b Self> - + Neg<Output = Pair<A, B>>, + + Neg<Output = <Self as AXPY>::Owned>, { - type Output = Pair<A, B>; - fn dot<I: Instance<Self>>(&self, other: I) -> F { let Pair(u, v) = other.decompose(); self.0.dot(u) + self.1.dot(v)
--- a/src/euclidean.rs Mon May 12 16:28:50 2025 -0500 +++ b/src/euclidean.rs Mon May 12 19:30:41 2025 -0500 @@ -3,34 +3,27 @@ */ use crate::instance::Instance; +use crate::linops::AXPY; use crate::norms::{HasDual, Reflexive}; use crate::types::*; -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; +use std::ops::{Add, AddAssign, Sub, SubAssign}; /// 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 an inner product. +// TODO: remove F parameter, use AXPY::Field pub trait Euclidean<F: Float = f64>: HasDual<F, DualSpace = Self> + + AXPY<Field = F> + Reflexive<F> - + Mul<F, Output = <Self as Euclidean<F>>::Output> - + MulAssign<F> - + Div<F, Output = <Self as Euclidean<F>>::Output> - + DivAssign<F> - + Add<Self, Output = <Self as Euclidean<F>>::Output> - + Sub<Self, Output = <Self as Euclidean<F>>::Output> - + for<'b> Add<&'b Self, Output = <Self as Euclidean<F>>::Output> - + for<'b> Sub<&'b Self, Output = <Self as Euclidean<F>>::Output> - + AddAssign<Self> + // TODO: move the following to AXPY + + for<'b> Add<&'b Self, Output = <Self as AXPY>::Owned> + + for<'b> Sub<&'b Self, Output = <Self as AXPY>::Owned> + for<'b> AddAssign<&'b Self> - + SubAssign<Self> + for<'b> SubAssign<&'b Self> - + Neg<Output = <Self as Euclidean<F>>::Output> { - type Output: Euclidean<F>; - // Inner product fn dot<I: Instance<Self>>(&self, other: I) -> F; @@ -82,5 +75,5 @@ /// Trait for [`Euclidean`] spaces with dimensions known at compile time. pub trait StaticEuclidean<F: Float = f64>: Euclidean<F> { /// Returns the origin - fn origin() -> <Self as Euclidean<F>>::Output; + fn origin() -> <Self as AXPY>::Owned; }
--- a/src/loc.rs Mon May 12 16:28:50 2025 -0500 +++ b/src/loc.rs Mon May 12 19:30:41 2025 -0500 @@ -433,8 +433,6 @@ domination!(L2, L1); impl<F: Float, const N: usize> Euclidean<F> for Loc<N, F> { - type Output = Self; - /// This implementation is not stabilised as it's meant to be used for very small vectors. /// Use [`nalgebra`] for larger vectors. #[inline]
--- a/src/nalgebra_support.rs Mon May 12 16:28:50 2025 -0500 +++ b/src/nalgebra_support.rs Mon May 12 19:30:41 2025 -0500 @@ -222,8 +222,6 @@ E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M>, { - type Output = OVector<E, M>; - #[inline] fn dot<I: Instance<Self>>(&self, other: I) -> E { Vector::<E, M, S>::dot(self, other.ref_instance())