diff -r edb95d2b83cc -r d2acaaddd9af src/loc.rs --- a/src/loc.rs Sun Nov 10 09:02:57 2024 -0500 +++ b/src/loc.rs Tue Dec 31 09:12:43 2024 -0500 @@ -6,6 +6,7 @@ use std::ops::{Add,Sub,AddAssign,SubAssign,Mul,Div,MulAssign,DivAssign,Neg,Index,IndexMut}; use std::slice::{Iter,IterMut}; use std::fmt::{Display, Formatter}; +use std::borrow::Borrow; use crate::types::{Float,Num,SignedNum}; use crate::maputil::{FixedLength,FixedLengthMut,map1,map2,map1_mut,map2_mut}; use crate::euclidean::*; @@ -23,6 +24,10 @@ pub [F; N] ); +impl HasScalarField for Loc { + type Field = F; +} + impl Display for Loc{ // Required method fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { @@ -393,7 +398,7 @@ macro_rules! domination { ($norm:ident, $dominates:ident) => { - impl Dominated> for $norm { + impl Dominated<$dominates, Loc> for $norm { #[inline] fn norm_factor(&self, _p : $dominates) -> F { F::ONE @@ -405,7 +410,7 @@ } }; ($norm:ident, $dominates:ident, $fn:path) => { - impl Dominated> for $norm { + impl Dominated<$dominates, Loc> for $norm { #[inline] fn norm_factor(&self, _p : $dominates) -> F { $fn(F::cast_from(N)) @@ -426,18 +431,18 @@ domination!(Linfinity, L2); domination!(L2, L1); -impl Dot,F> for Loc { +impl>, const N : usize> Dot for Loc { /// This implementation is not stabilised as it's meant to be used for very small vectors. /// Use [`nalgebra`] for larger vectors. #[inline] - fn dot(&self, other : &Loc) -> F { + fn dot(&self, other : T) -> F { self.0.iter() - .zip(other.0.iter()) + .zip(other.borrow().0.iter()) .fold(F::ZERO, |m, (&v, &w)| m + v * w) } } -impl Euclidean for Loc { +impl Euclidean for Loc { type Output = Self; #[inline] @@ -483,24 +488,24 @@ pub const ORIGIN : Self = Loc([F::ZERO; N]); } -impl StaticEuclidean for Loc { +impl StaticEuclidean for Loc { #[inline] fn origin() -> Self { Self::ORIGIN } } -impl Norm for Loc { +impl Norm for Loc { #[inline] fn norm(&self, _ : L2) -> F { self.norm2() } } -impl Dist for Loc { +impl Dist for Loc { #[inline] fn dist(&self, other : &Self, _ : L2) -> F { self.dist2(other) } } -impl Norm for Loc { +impl Norm for Loc { /// This implementation is not stabilised as it's meant to be used for very small vectors. /// Use [`nalgebra`] for larger vectors. #[inline] @@ -509,7 +514,7 @@ } } -impl Dist for Loc { +impl Dist for Loc { #[inline] fn dist(&self, other : &Self, _ : L1) -> F { self.iter() @@ -518,14 +523,14 @@ } } -impl Projection for Loc { +impl Projection for Loc { #[inline] fn proj_ball_mut(&mut self, ρ : F, _ : Linfinity) { self.iter_mut().for_each(|v| *v = num_traits::clamp(*v, -ρ, ρ)) } } -impl Norm for Loc { +impl Norm for Loc { /// This implementation is not stabilised as it's meant to be used for very small vectors. /// Use [`nalgebra`] for larger vectors. #[inline] @@ -534,7 +539,7 @@ } } -impl Dist for Loc { +impl Dist for Loc { #[inline] fn dist(&self, other : &Self, _ : Linfinity) -> F { self.iter() @@ -572,19 +577,18 @@ } } -impl AXPY> for Loc { - +impl<'a, T : Borrow>, F : Num, const N : usize> AXPY for Loc { #[inline] - fn axpy(&mut self, α : F, x : &Loc, β : F) { + fn axpy(&mut self, α : F, x : T, β : F) { if β == F::ZERO { - map2_mut(self, x, |yi, xi| { *yi = α * (*xi) }) + map2_mut(self, x.borrow(), |yi, xi| { *yi = α * (*xi) }) } else { - map2_mut(self, x, |yi, xi| { *yi = β * (*yi) + α * (*xi) }) + map2_mut(self, x.borrow(), |yi, xi| { *yi = β * (*yi) + α * (*xi) }) } } #[inline] - fn copy_from(&mut self, x : &Loc) { - map2_mut(self, x, |yi, xi| *yi = *xi ) + fn copy_from(&mut self, x : T) { + map2_mut(self, x.borrow(), |yi, xi| *yi = *xi ) } }