dual_origin dev

Mon, 12 May 2025 23:29:17 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 12 May 2025 23:29:17 -0500
branch
dev
changeset 138
593912dc3293
parent 133
2b13f8a0c8ba
child 139
f78885441218

dual_origin

src/direct_product.rs file | annotate | diff | comparison | revisions
src/loc.rs file | annotate | diff | comparison | revisions
src/nalgebra_support.rs file | annotate | diff | comparison | revisions
src/norms.rs file | annotate | diff | comparison | revisions
--- a/src/direct_product.rs	Mon May 12 20:40:14 2025 -0500
+++ b/src/direct_product.rs	Mon May 12 23:29:17 2025 -0500
@@ -561,4 +561,8 @@
     B: HasDual<F>,
 {
     type DualSpace = Pair<A::DualSpace, B::DualSpace>;
+
+    fn dual_origin(&self) -> <Self::DualSpace as AXPY>::Owned {
+        Pair(self.0.dual_origin(), self.1.dual_origin())
+    }
 }
--- a/src/loc.rs	Mon May 12 20:40:14 2025 -0500
+++ b/src/loc.rs	Mon May 12 23:29:17 2025 -0500
@@ -595,6 +595,10 @@
 
 impl<F: Float, const N: usize> HasDual<F> for Loc<N, F> {
     type DualSpace = Self;
+
+    fn dual_origin(&self) -> Self::DualSpace {
+        self.similar_origin()
+    }
 }
 
 impl<F: Float, const N: usize> Norm<L2, F> for Loc<N, F> {
--- a/src/nalgebra_support.rs	Mon May 12 20:40:14 2025 -0500
+++ b/src/nalgebra_support.rs	Mon May 12 23:29:17 2025 -0500
@@ -275,12 +275,16 @@
 impl<E, M, S> HasDual<E> for Vector<E, M, S>
 where
     M: Dim,
-    S: Storage<E, M> + Clone,
+    S: StorageMut<E, M> + Clone,
     E: Float + Scalar + Zero + One + RealField,
     DefaultAllocator: Allocator<M>,
 {
     // TODO: Doesn't work with different storage formats.
-    type DualSpace = Self;
+    type DualSpace = Vector<E, M, S>;
+
+    fn dual_origin(&self) -> OVector<E, M> {
+        OVector::zeros_generic(M::from_usize(self.len()), Const)
+    }
 }
 
 impl<E, M, S> Norm<L1, E> for Vector<E, M, S>
--- a/src/norms.rs	Mon May 12 20:40:14 2025 -0500
+++ b/src/norms.rs	Mon May 12 23:29:17 2025 -0500
@@ -3,6 +3,7 @@
 */
 
 use crate::euclidean::*;
+use crate::linops::AXPY;
 use crate::mapping::{Instance, Mapping, Space};
 use crate::types::*;
 use serde::{Deserialize, Serialize};
@@ -231,8 +232,10 @@
     }
 }
 
-pub trait HasDual<F: Num = f64>: Normed<F> {
-    type DualSpace: Normed<F>;
+pub trait HasDual<F: Num = f64>: Normed<F> + AXPY<Field = F> {
+    type DualSpace: Normed<F> + AXPY<Field = F>;
+
+    fn dual_origin(&self) -> <Self::DualSpace as AXPY>::Owned;
 }
 
 /// Automatically implemented trait for reflexive spaces

mercurial