src/nalgebra_support.rs

branch
dev
changeset 156
adf3c425c7a9
parent 151
402d717bb5c0
child 157
2ac69af65636
--- a/src/nalgebra_support.rs	Tue Sep 02 00:05:29 2025 -0500
+++ b/src/nalgebra_support.rs	Tue Sep 02 00:09:46 2025 -0500
@@ -9,17 +9,16 @@
 */
 
 use crate::euclidean::*;
-use crate::instance::{Instance, Ownable};
+use crate::instance::{Decomposition, Instance, Ownable, Space};
 use crate::linops::*;
-use crate::mapping::{BasicDecomposition, Space};
 use crate::norms::*;
 use crate::types::Float;
 use nalgebra::base::allocator::Allocator;
 use nalgebra::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
 use nalgebra::base::dimension::*;
 use nalgebra::{
-    ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, OMatrix, OVector,
-    RealField, Scalar, SimdComplexField, Storage, StorageMut, UniformNorm, Vector,
+    ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, MatrixView, OMatrix,
+    OVector, RealField, Scalar, SimdComplexField, Storage, StorageMut, UniformNorm, Vector,
 };
 use num_traits::identities::{One, Zero};
 use std::ops::Mul;
@@ -54,7 +53,68 @@
     DefaultAllocator: Allocator<N, M>,
 {
     type OwnedSpace = OMatrix<E, N, M>;
-    type Decomp = BasicDecomposition;
+    type Decomp = MatrixDecomposition;
+}
+
+#[derive(Copy, Clone, Debug)]
+pub struct MatrixDecomposition;
+
+impl<E, M, K, S> Decomposition<Matrix<E, M, K, S>> for MatrixDecomposition
+where
+    S: Storage<E, M, K>,
+    M: Dim,
+    K: Dim,
+    E: Scalar + Zero + One,
+    DefaultAllocator: Allocator<M, K>,
+{
+    type OwnedInstance = OMatrix<E, M, K>;
+
+    type Decomposition<'b>
+        = OMatrix<E, M, K>
+    where
+        Matrix<E, M, K, S>: 'b;
+    type Reference<'b>
+        = &'b MatrixView<'b, E, M, K, Dyn, Dyn>
+    where
+        Matrix<E, M, K, S>: 'b;
+
+    #[inline]
+    fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b> {
+        r.into_owned()
+    }
+}
+
+impl<SM, SV, M, K, E> Instance<Matrix<E, M, K, SM>> for Matrix<E, M, K, SV>
+where
+    SM: Storage<E, M, K>,
+    SV: Storage<E, M, K>,
+    M: Dim,
+    K: Dim,
+    E: Scalar + Zero + One,
+    DefaultAllocator: Allocator<M, K>,
+{
+    fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R
+    where
+        Self: 'b,
+    {
+        f(self.into_owned())
+    }
+
+    fn eval_ref_decompose<'b, R>(
+        &'b self,
+        f: impl FnOnce(&'b MatrixView<'b, E, M, K, Dyn, Dyn>) -> R,
+    ) -> R
+    where
+        Self: 'b,
+        Matrix<E, M, K, SM>: 'b,
+    {
+        f(&self.as_view::<M, K, Dyn, Dyn>())
+    }
+
+    #[inline]
+    fn own(self) -> OMatrix<E, M, K> {
+        self.into_owned()
+    }
 }
 
 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM>

mercurial