src/nalgebra_support.rs

branch
dev
changeset 170
221728aeeb7e
parent 169
114ecdf63ce5
child 171
fa8df5a14486
--- a/src/nalgebra_support.rs	Wed Sep 03 19:37:15 2025 -0500
+++ b/src/nalgebra_support.rs	Wed Sep 03 19:55:05 2025 -0500
@@ -146,6 +146,19 @@
     ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>,
 {
     #[inline]
+    fn either<'b, R>(
+        self,
+        f: impl FnOnce(OMatrix<E, M, K>) -> R,
+        _g: impl FnOnce(MatrixView<'b, E, M, K, Dyn, Dyn>) -> R,
+    ) -> R
+    where
+        Self: 'b,
+    {
+        // TODO: should not turn non-owned matrices into owned
+        f(self.into_owned())
+    }
+
+    #[inline]
     fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R
     where
         Self: 'b,
@@ -190,6 +203,18 @@
     DefaultAllocator: Allocator<M, K>,
     ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>,
 {
+    #[inline]
+    fn either<'b, R>(
+        self,
+        _f: impl FnOnce(OMatrix<E, M, K>) -> R,
+        g: impl FnOnce(MatrixView<'b, E, M, K, Dyn, Dyn>) -> R,
+    ) -> R
+    where
+        Self: 'b,
+    {
+        g(self.as_view())
+    }
+
     fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R
     where
         Self: 'b,

mercurial