# HG changeset patch # User Tuomo Valkonen # Date 1756789786 18000 # Node ID adf3c425c7a9e68b3bd31fdd6011d82ddfe0ab0b # Parent 45d03cf92c23ee5abdc78c44142e05a9b281a274 sketc diff -r 45d03cf92c23 -r adf3c425c7a9 src/nalgebra_support.rs --- 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, { 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 OwnedInstance = OMatrix; + + 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::()) + } + + #[inline] + fn own(self) -> OMatrix { + self.into_owned() + } } impl Mapping> for Matrix