--- a/src/nalgebra_support.rs Mon Sep 01 20:55:34 2025 -0500 +++ b/src/nalgebra_support.rs Mon Sep 01 23:03:27 2025 -0500 @@ -9,17 +9,17 @@ */ use crate::euclidean::*; -use crate::instance::{Instance, Ownable}; +use crate::instance::{Decomposition, EitherDecomp, Instance, MyCow, Ownable}; use crate::linops::*; -use crate::mapping::{BasicDecomposition, Space}; +use crate::mapping::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; @@ -43,6 +43,20 @@ fn clone_owned(&self) -> Self::OwnedVariant { Matrix::clone_owned(self) } + + fn owned_cow<'b>(self) -> MyCow<'b, Self::OwnedVariant> + where + Self: 'b, + { + EitherDecomp::Owned(self.into_owned()) + } + + fn ref_owned_cow<'b>(&'b self) -> MyCow<'b, Self::OwnedVariant> + where + Self: 'b, + { + EitherDecomp::Owned(self.into_owned()) + } } impl<SM, N, M, E> Space for Matrix<E, N, M, SM> @@ -54,7 +68,61 @@ 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 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>()) + } } impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM>