Fri, 05 Sep 2025 00:16:08 -0500
strides alt
| src/euclidean/wrap.rs | file | annotate | diff | comparison | revisions | |
| src/nalgebra_support.rs | file | annotate | diff | comparison | revisions |
--- a/src/euclidean/wrap.rs Wed Sep 03 22:05:33 2025 -0500 +++ b/src/euclidean/wrap.rs Fri Sep 05 00:16:08 2025 -0500 @@ -124,6 +124,7 @@ // $crate::wrap!(imp<> do $type); // }; ($F:ty; $type:ty where $($qual:tt)*) => { + $crate::wrap!(impl_unary $type, std::ops::Neg, neg where $($qual)*); $crate::wrap!(impl_binary $type, std::ops::Add, add where $($qual)*); $crate::wrap!(impl_binary $type, std::ops::Sub, sub where $($qual)*); @@ -140,14 +141,14 @@ impl<$($qual)*> $crate::norms::Norm<$crate::norms::L2, $F> for $type { fn norm(&self, p : $crate::norms::L2) -> $F { - self.get_view().norm(p) + $crate::norms::Norm::norm(&self.get_view(), p) } } impl<$($qual)*> $crate::norms::Dist<$crate::norms::L2, $F> for $type { fn dist<I: $crate::instance::Instance<Self>>(&self, other : I, p : $crate::norms::L2) -> $F { - other.eval_decompose(|x| self.get_view().dist(p, x)) + other.eval_ref(|x| self.get_view().dist(x, p)) } } @@ -163,7 +164,7 @@ type DualSpace = Self; fn dual_origin(&self) -> Self { - self.similar_origin(self) + $crate::linops::VectorSpace::similar_origin(self) } } @@ -231,7 +232,7 @@ fn copy_from<I: $crate::instance::Instance<Self>>(&mut self, x: I) { x.eval_decompose(|v| { - self.get_view_mut().copy_from(v.get_view()) + self.get_view_mut().copy_from(&v.get_view()) }) } @@ -248,7 +249,7 @@ } impl<$($qual)*> $crate::instance::Space for $type { - type Decomp = <<Self as $crate::euclidean::wrap::Wrapped>::Unwrapped as $crate::instance::Space>::Decomp; + type Decomp = $crate::instance::BasicDecomposition; type Principal = Self; } };
--- a/src/nalgebra_support.rs Wed Sep 03 22:05:33 2025 -0500 +++ b/src/nalgebra_support.rs Fri Sep 05 00:16:08 2025 -0500 @@ -17,9 +17,9 @@ use nalgebra::base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; use nalgebra::base::dimension::*; use nalgebra::{ - ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, MatrixView, OMatrix, - OVector, RawStorage, RealField, Scalar, SimdComplexField, Storage, StorageMut, UniformNorm, - Vector, U1, + ArrayStorage, ClosedAddAssign, ClosedMulAssign, DefaultAllocator, Dim, LpNorm, Matrix, + MatrixView, OMatrix, OVector, RawStorage, RealField, Scalar, SimdComplexField, Storage, + StorageMut, UniformNorm, VecStorage, Vector, ViewStorage, ViewStorageMut, U1, }; use num_traits::identities::{One, Zero}; use std::ops::Mul; @@ -60,10 +60,7 @@ } trait StridesOk<E, N, M = U1, S = <DefaultAllocator as Allocator<N, M>>::Buffer<E>>: - DimEq<Dyn, S::RStride> - + DimEq<Dyn, S::CStride> - + DimEq<Dyn, <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::RStride> - + DimEq<Dyn, <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::CStride> + DimEq<Dyn, S::RStride> + DimEq<Dyn, S::CStride> where S: RawStorage<E, N, M>, E: Scalar, @@ -73,25 +70,47 @@ { } -impl<S, E, N, M> StridesOk<E, N, M, S> for ShapeConstraint +impl<E, M> StridesOk<E, Dyn, M, VecStorage<E, Dyn, M>> for ShapeConstraint where - ShapeConstraint: DimEq<Dyn, S::RStride> - + DimEq<Dyn, S::CStride> - + DimEq< - Dyn, - <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::RStride, - > + DimEq< - Dyn, - <<DefaultAllocator as Allocator<N, M>>::Buffer<E> as RawStorage<E, N, M>>::CStride, - >, - S: Storage<E, N, M>, + M: Dim, E: Scalar, - N: Dim, - M: Dim, - DefaultAllocator: Allocator<N, M>, + DefaultAllocator: Allocator<Dyn, M>, +{ +} + +impl<E, const N: usize, const M: usize> StridesOk<E, Const<N>, Const<M>, ArrayStorage<E, N, M>> + for ShapeConstraint +where + E: Scalar, { } +macro_rules! strides_ok { + ($R:ty, $C:ty where $($qual:tt)*) => { + impl<'a, E, N, M, $($qual)*> StridesOk<E, N, M, ViewStorage<'a, E, N, M, $R, $C>> for ShapeConstraint + where + N: Dim, + M: Dim, + E: Scalar, + DefaultAllocator: Allocator<N, M>, + { + } + impl<'a, E, N, M, $($qual)*> StridesOk<E, N, M, ViewStorageMut<'a, E, N, M, $R, $C>> for ShapeConstraint + where + N: Dim, + M: Dim, + E: Scalar, + DefaultAllocator: Allocator<N, M>, + { + } + }; +} + +strides_ok!(Dyn, Dyn where ); +strides_ok!(Dyn, Const<C> where const C : usize); +strides_ok!(Const<R>, Dyn where const R : usize); +strides_ok!(Const<R>, Const<C> where const R : usize, const C : usize); + impl<SM, N, M, E> Space for Matrix<E, N, M, SM> where SM: Storage<E, N, M>, @@ -99,7 +118,7 @@ M: Dim, E: Scalar + Zero + One + Copy, DefaultAllocator: Allocator<N, M>, - ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, N, M>, + ShapeConstraint: StridesOk<E, N, M>, { type Principal = OMatrix<E, N, M>; type Decomp = MatrixDecomposition; @@ -115,7 +134,7 @@ K: Dim, E: Scalar + Zero + One + Copy, DefaultAllocator: Allocator<M, K>, - ShapeConstraint: StridesOk<E, M, K, S> + StridesOk<E, M, K>, + ShapeConstraint: StridesOk<E, M, K>, { type Decomposition<'b> = MyCow<'b, OMatrix<E, M, K>> @@ -143,7 +162,7 @@ K: Dim, E: Scalar + Zero + One + Copy, DefaultAllocator: Allocator<M, K>, - ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, + ShapeConstraint: StridesOk<E, M, K, S2> + StridesOk<E, M, K>, { #[inline] fn eval_ref<'b, R>( @@ -188,7 +207,7 @@ K: Dim, E: Scalar + Zero + One + Copy, DefaultAllocator: Allocator<M, K>, - ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, + ShapeConstraint: StridesOk<E, M, K, S2> + StridesOk<E, M, K>, { fn eval_ref<'b, R>( &'b self, @@ -231,7 +250,7 @@ K: Dim, E: Scalar + Zero + One + Copy, DefaultAllocator: Allocator<M, K>, - ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K>, + ShapeConstraint: StridesOk<E, M, K>, { #[inline] fn eval_ref<'b, R>( @@ -275,7 +294,7 @@ K: Dim, E: Scalar + Zero + One + Copy + ClosedMulAssign + ClosedAddAssign, DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, - ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K> + StridesOk<E, N, K>, + ShapeConstraint: StridesOk<E, M, K> + StridesOk<E, N, K>, { type Codomain = OMatrix<E, N, K>; @@ -293,7 +312,7 @@ K: Dim, E: Scalar + Zero + One + Copy + ClosedMulAssign + ClosedAddAssign, DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, - ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K> + StridesOk<E, N, K>, + ShapeConstraint: StridesOk<E, M, K> + StridesOk<E, N, K>, { } @@ -306,7 +325,7 @@ K: Dim, E: Scalar + Zero + One + Float, DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, - ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, N, K, SV2> + StridesOk<E, M, K>, + ShapeConstraint: StridesOk<E, M, K> + StridesOk<E, N, K>, { #[inline] fn gemv<I: Instance<OMatrix<E, M, K>>>( @@ -328,7 +347,7 @@ N: Dim, E: Scalar + Zero + One + Float, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, + ShapeConstraint: StridesOk<E, M, N>, { type Field = E; type PrincipalV = OMatrix<E, M, N>; @@ -348,7 +367,7 @@ N: Dim, E: Scalar + Zero + One + Float, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, SM> + StridesOk<E, M, N, SV1>, + ShapeConstraint: StridesOk<E, M, N>, { #[inline] fn axpy<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, α: E, x: I, β: E) { @@ -393,7 +412,7 @@ M: Dim, E: Scalar + Zero + One + Float + RealField, DefaultAllocator: Allocator<M>, - ShapeConstraint: StridesOk<E, M, U1, SM>, + ShapeConstraint: StridesOk<E, M>, { #[inline] fn proj_ball(self, ρ: E, exp: Linfinity) -> <Self as Space>::Principal { @@ -409,7 +428,7 @@ M: Dim, E: Scalar + Zero + One + Copy + Float + RealField, DefaultAllocator: Allocator<M>, - ShapeConstraint: StridesOk<E, M, U1, SM>, + ShapeConstraint: StridesOk<E, M>, { #[inline] fn proj_ball_mut(&mut self, ρ: E, _: Linfinity) { @@ -426,8 +445,7 @@ K: Dim, E: Scalar + Zero + One + Copy + SimdComplexField, DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, - ShapeConstraint: - StridesOk<E, N, M, SM> + StridesOk<E, N, K> + StridesOk<E, M, N> + StridesOk<E, M, K>, + ShapeConstraint: StridesOk<E, N, K> + StridesOk<E, M, K>, { type AdjointCodomain = OMatrix<E, M, K>; type Adjoint<'a> @@ -471,7 +489,7 @@ S: Storage<E, M, N>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, + ShapeConstraint: StridesOk<E, M, N>, { type PrincipalE = OMatrix<E, M, N>; @@ -497,7 +515,7 @@ S: Storage<E, M>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M>, - ShapeConstraint: StridesOk<E, M, U1, S>, + ShapeConstraint: StridesOk<E, M>, { #[inline] fn origin() -> OVector<E, M> { @@ -513,7 +531,7 @@ S: Storage<E, M, N>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, + ShapeConstraint: StridesOk<E, M, N>, { type NormExp = L2; @@ -535,7 +553,7 @@ S: Storage<E, M, N>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, + ShapeConstraint: StridesOk<E, M, N>, { type DualSpace = OMatrix<E, M, N>; @@ -551,7 +569,6 @@ S: Storage<E, M>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M>, - ShapeConstraint: StridesOk<E, M, U1, S>, { #[inline] fn norm(&self, _: L1) -> E { @@ -565,7 +582,7 @@ S: Storage<E, M>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M>, - ShapeConstraint: StridesOk<E, M, U1, S>, + ShapeConstraint: StridesOk<E, M>, { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> E { @@ -580,7 +597,6 @@ S: Storage<E, M, N>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, { #[inline] fn norm(&self, _: L2) -> E { @@ -595,7 +611,7 @@ S: Storage<E, M, N>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, + ShapeConstraint: StridesOk<E, M, N>, { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: L2) -> E { @@ -610,7 +626,6 @@ S: Storage<E, M, N>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, { #[inline] fn norm(&self, _: Linfinity) -> E { @@ -625,7 +640,7 @@ S: Storage<E, M, N>, E: Float + Scalar + Zero + One + RealField, DefaultAllocator: Allocator<M, N>, - ShapeConstraint: StridesOk<E, M, N, S>, + ShapeConstraint: StridesOk<E, M, N>, { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> E {