src/direct_product.rs

branch
dev
changeset 63
f7b87d84864d
parent 62
d8305c9b6fdf
child 64
4f6ca107ccb1
--- a/src/direct_product.rs	Sat Dec 21 23:32:20 2024 -0500
+++ b/src/direct_product.rs	Sun Dec 22 14:54:46 2024 -0500
@@ -10,7 +10,7 @@
 use serde::{Serialize, Deserialize};
 use crate::types::{Num, Float};
 use crate::{maybe_lifetime, maybe_ref};
-use crate::euclidean::{Dot, Euclidean};
+use crate::euclidean::Euclidean;
 use crate::instance::{Instance, InstanceMut, Decomposition, DecompositionMut, MyCow};
 use crate::mapping::Space;
 use crate::linops::AXPY;
@@ -237,18 +237,6 @@
 impl_pair_vectorspace_ops!((f32, f32), f32);
 impl_pair_vectorspace_ops!((f64, f64), f64);
 
-impl<A, B, U, V, F> Dot<Pair<U, V>, F> for Pair<A, B>
-where
-    A : Dot<U, F>,
-    B : Dot<V, F>,
-    F : Num
-{
-
-    fn dot(&self, Pair(ref u, ref v) : &Pair<U, V>) -> F {
-        self.0.dot(u) + self.1.dot(v)
-    }
-}
-
 type PairOutput<F, A, B> = Pair<<A as Euclidean<F>>::Output, <B as Euclidean<F>>::Output>;
 
 impl<A, B, F> Euclidean<F> for Pair<A, B>
@@ -257,7 +245,7 @@
     B : Euclidean<F>,
     F : Float,
     PairOutput<F, A, B> : Euclidean<F>,
-    Self : Sized + Dot<Self,F>
+    Self : Sized
           + Mul<F, Output=PairOutput<F, A, B>> + MulAssign<F>
           + Div<F, Output=PairOutput<F, A, B>> + DivAssign<F>
           + Add<Self, Output=PairOutput<F, A, B>>
@@ -270,6 +258,15 @@
 {
     type Output = PairOutput<F, 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)
+    }
+
+    fn norm2_squared(&self) -> F {
+        self.0.norm2_squared() + self.1.norm2_squared()
+    }
+
     fn dist2_squared(&self, Pair(ref u, ref v) : &Self) -> F {
         self.0.dist2_squared(u) + self.1.dist2_squared(v)
     }

mercurial