src/norms.rs

branch
dev
changeset 64
4f6ca107ccb1
parent 63
f7b87d84864d
child 70
672aec2e1acd
child 80
f802ddbabcfc
--- a/src/norms.rs	Sun Dec 22 14:54:46 2024 -0500
+++ b/src/norms.rs	Sun Dec 22 15:30:34 2024 -0500
@@ -104,9 +104,9 @@
 }
 
 /// Trait for distances with respect to a norm.
-pub trait Dist<F : Num, Exponent : NormExponent> : Norm<F, Exponent> {
+pub trait Dist<F : Num, Exponent : NormExponent> : Norm<F, Exponent> + Space {
     /// Calculate the distance
-    fn dist(&self, other : &Self, _p : Exponent) -> F;
+    fn dist<I : Instance<Self>>(&self, other : I, _p : Exponent) -> F;
 }
 
 /// Trait for Euclidean projections to the `Exponent`-[`Norm`]-ball.
@@ -171,22 +171,22 @@
 }
 
 impl<F : Float, E : Euclidean<F>> Dist<F, HuberL1<F>> for E {
-    fn dist(&self, other : &Self, huber : HuberL1<F>) -> F {
+    fn dist<I : Instance<Self>>(&self, other : I, huber : HuberL1<F>) -> F {
         huber.apply(self.dist2_squared(other))
     }
 }
 
-impl<F : Float, E : Norm<F, L2>> Norm<F, L21> for Vec<E> {
-    fn norm(&self, _l21 : L21) -> F {
-        self.iter().map(|e| e.norm(L2)).sum()
-    }
-}
+// impl<F : Float, E : Norm<F, L2>> Norm<F, L21> for Vec<E> {
+//     fn norm(&self, _l21 : L21) -> F {
+//         self.iter().map(|e| e.norm(L2)).sum()
+//     }
+// }
 
-impl<F : Float, E : Dist<F, L2>> Dist<F, L21> for Vec<E> {
-    fn dist(&self, other : &Self, _l21 : L21) -> F {
-        self.iter().zip(other.iter()).map(|(e, g)| e.dist(g, L2)).sum()
-    }
-}
+// impl<F : Float, E : Dist<F, L2>> Dist<F, L21> for Vec<E> {
+//     fn dist<I : Instance<Self>>(&self, other : I, _l21 : L21) -> F {
+//         self.iter().zip(other.iter()).map(|(e, g)| e.dist(g, L2)).sum()
+//     }
+// }
 
 impl<E, F, Domain> Mapping<Domain> for NormMapping<F, E>
 where

mercurial