src/loc.rs

branch
dev
changeset 59
9226980e45a7
parent 52
c70b575d22b6
child 60
848ecc05becf
--- a/src/loc.rs	Sat Dec 14 09:31:27 2024 -0500
+++ b/src/loc.rs	Tue Dec 31 08:30:02 2024 -0500
@@ -10,9 +10,12 @@
 use crate::maputil::{FixedLength,FixedLengthMut,map1,map2,map1_mut,map2_mut};
 use crate::euclidean::*;
 use crate::norms::*;
-use crate::linops::AXPY;
+use crate::linops::{AXPY, Mapping, Linear};
+use crate::instance::{Instance, BasicDecomposition};
+use crate::mapping::Space;
 use serde::ser::{Serialize, Serializer, SerializeSeq};
 
+
 /// A container type for (short) `N`-dimensional vectors of element type `F`.
 ///
 /// Supports basic operations of an [`Euclidean`] space, several [`Norm`]s, and
@@ -657,19 +660,35 @@
     }
 }
 
+
+impl<F : Num, const N : usize> Space for Loc<F, N> {
+    type Decomp = BasicDecomposition;
+}
+
+impl<F : Num, const N : usize> Mapping<Loc<F, N>> for Loc<F, N> {
+    type Codomain = F;
+
+    fn apply<I : Instance<Loc<F, N>>>(&self, x : I) -> Self::Codomain {
+        x.eval(|x̃| self.dot(x̃))
+    }
+}
+
+impl<F : Num, const N : usize> Linear<Loc<F, N>> for Loc<F, N> { }
+
 impl<F : Num, const N : usize> AXPY<F, Loc<F, N>> for Loc<F, N> {
-
     #[inline]
-    fn axpy(&mut self, α : F, x : &Loc<F, N>, β : F) {
-        if β == F::ZERO {
-            map2_mut(self, x, |yi, xi| { *yi = α * (*xi) })
-        } else {
-            map2_mut(self, x, |yi, xi| { *yi = β * (*yi) + α * (*xi) })
-        }
+    fn axpy<I : Instance<Loc<F, N>>>(&mut self, α : F, x : I, β : F) {
+        x.eval(|x̃| {
+            if β == F::ZERO {
+                map2_mut(self, x̃, |yi, xi| { *yi = α * (*xi) })
+            } else {
+                map2_mut(self, x̃, |yi, xi| { *yi = β * (*yi) + α * (*xi) })
+            }
+        })
     }
 
     #[inline]
-    fn copy_from(&mut self, x : &Loc<F, N>) {
-        map2_mut(self, x, |yi, xi| *yi = *xi )
+    fn copy_from<I : Instance<Loc<F, N>>>(&mut self, x : I) {
+        x.eval(|x̃| map2_mut(self, x̃, |yi, xi| *yi = *xi ))
     }
 }

mercurial