diff -r 402d717bb5c0 -r dab30b331f49 src/nalgebra_support.rs --- 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 Space for Matrix @@ -54,7 +68,61 @@ DefaultAllocator: Allocator, { type OwnedSpace = OMatrix; - type Decomp = BasicDecomposition; + type Decomp = MatrixDecomposition; +} + +#[derive(Copy, Clone, Debug)] +pub struct MatrixDecomposition; + +impl Decomposition> for MatrixDecomposition +where + S: Storage, + M: Dim, + K: Dim, + E: Scalar + Zero + One, + DefaultAllocator: Allocator, +{ + type Decomposition<'b> + = OMatrix + where + Matrix: 'b; + type Reference<'b> + = &'b MatrixView<'b, E, M, K, Dyn, Dyn> + where + Matrix: 'b; + + #[inline] + fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b> { + r.into_owned() + } +} + +impl Instance> for Matrix +where + SM: Storage, + SV: Storage, + M: Dim, + K: Dim, + E: Scalar + Zero + One, + DefaultAllocator: Allocator, +{ + fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix) -> 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: 'b, + { + f(&self.as_view::()) + } } impl Mapping> for Matrix