diff -r 1a38447a89fa -r 9226980e45a7 src/nalgebra_support.rs --- a/src/nalgebra_support.rs Sat Dec 14 09:31:27 2024 -0500 +++ b/src/nalgebra_support.rs Tue Dec 31 08:30:02 2024 -0500 @@ -23,51 +23,49 @@ use num_traits::identities::{Zero, One}; use crate::linops::*; use crate::euclidean::*; +use crate::mapping::{Space, BasicDecomposition}; use crate::types::Float; use crate::norms::*; +use crate::instance::Instance; -impl Apply> for Matrix -where SM: Storage, SV: Storage, - N : Dim, M : Dim, K : Dim, E : Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, - DefaultAllocator : Allocator, - DefaultAllocator : Allocator, - DefaultAllocator : Allocator, - DefaultAllocator : Allocator { - type Output = OMatrix; - - #[inline] - fn apply(&self, x : Matrix) -> Self::Output { - self.mul(x) - } +impl Space for Matrix +where + SM: Storage + Clone, + N : Dim, M : Dim, E : Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, + DefaultAllocator : Allocator, +{ + type Decomp = BasicDecomposition; } -impl<'a, SM,SV,N,M,K,E> Apply<&'a Matrix> for Matrix -where SM: Storage, SV: Storage, - N : Dim, M : Dim, K : Dim, E : Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, - DefaultAllocator : Allocator, - DefaultAllocator : Allocator, - DefaultAllocator : Allocator, - DefaultAllocator : Allocator { - type Output = OMatrix; - - #[inline] - fn apply(&self, x : &'a Matrix) -> Self::Output { - self.mul(x) - } -} - -impl<'a, SM,SV,N,M,K,E> Linear> for Matrix -where SM: Storage, SV: Storage, +impl Mapping> for Matrix +where SM: Storage, SV: Storage + Clone, N : Dim, M : Dim, K : Dim, E : Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, DefaultAllocator : Allocator, DefaultAllocator : Allocator, DefaultAllocator : Allocator, DefaultAllocator : Allocator { type Codomain = OMatrix; + + #[inline] + fn apply>>( + &self, x : I + ) -> Self::Codomain { + x.either(|owned| self.mul(owned), |refr| self.mul(refr)) + } +} + + +impl<'a, SM,SV,N,M,K,E> Linear> for Matrix +where SM: Storage, SV: Storage + Clone, + N : Dim, M : Dim, K : Dim, E : Scalar + Zero + One + ClosedAddAssign + ClosedMulAssign, + DefaultAllocator : Allocator, + DefaultAllocator : Allocator, + DefaultAllocator : Allocator, + DefaultAllocator : Allocator { } impl GEMV, Matrix> for Matrix -where SM: Storage, SV1: Storage, SV2: StorageMut, +where SM: Storage, SV1: Storage + Clone, SV2: StorageMut, N : Dim, M : Dim, K : Dim, E : Scalar + Zero + One + Float, DefaultAllocator : Allocator, DefaultAllocator : Allocator, @@ -75,34 +73,36 @@ DefaultAllocator : Allocator { #[inline] - fn gemv(&self, y : &mut Matrix, α : E, x : &Matrix, β : E) { - Matrix::gemm(y, α, self, x, β) + fn gemv>>( + &self, y : &mut Matrix, α : E, x : I, β : E + ) { + x.eval(|x̃| Matrix::gemm(y, α, self, x̃, β)) } #[inline] - fn apply_mut<'a>(&self, y : &mut Matrix, x : &Matrix) { - self.mul_to(x, y) + fn apply_mut<'a, I : Instance>>(&self, y : &mut Matrix, x : I) { + x.eval(|x̃| self.mul_to(x̃, y)) } } impl AXPY> for Vector -where SM: StorageMut, SV1: Storage, +where SM: StorageMut + Clone, SV1: Storage + Clone, M : Dim, E : Scalar + Zero + One + Float, DefaultAllocator : Allocator { #[inline] - fn axpy(&mut self, α : E, x : &Vector, β : E) { - Matrix::axpy(self, α, x, β) + fn axpy>>(&mut self, α : E, x : I, β : E) { + x.eval(|x̃| Matrix::axpy(self, α, x̃, β)) } #[inline] - fn copy_from(&mut self, y : &Vector) { - Matrix::copy_from(self, y) + fn copy_from>>(&mut self, y : I) { + y.eval(|ỹ| Matrix::copy_from(self, ỹ)) } } impl Projection for Vector -where SM: StorageMut, +where SM: StorageMut + Clone, M : Dim, E : Scalar + Zero + One + Float + RealField, DefaultAllocator : Allocator { #[inline] @@ -111,9 +111,9 @@ } } -impl<'own,SV1,SV2,SM,N,M,K,E> Adjointable,Matrix> +impl<'own,SV1,SV2,SM,N,M,K,E> Adjointable, Matrix> for Matrix -where SM: Storage, SV1: Storage, SV2: Storage, +where SM: Storage, SV1: Storage + Clone, SV2: Storage + Clone, N : Dim, M : Dim, K : Dim, E : Scalar + Zero + One + SimdComplexField, DefaultAllocator : Allocator, DefaultAllocator : Allocator, @@ -170,7 +170,7 @@ impl Euclidean for Vector where M : Dim, - S : StorageMut, + S : StorageMut + Clone, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator { @@ -195,7 +195,7 @@ impl StaticEuclidean for Vector where M : DimName, - S : StorageMut, + S : StorageMut + Clone, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator {