Tue, 31 Dec 2024 23:49:09 -0500
simplify
src/direct_product.rs | file | annotate | diff | comparison | revisions | |
src/linops.rs | file | annotate | diff | comparison | revisions | |
src/loc.rs | file | annotate | diff | comparison | revisions | |
src/nalgebra_support.rs | file | annotate | diff | comparison | revisions |
--- a/src/direct_product.rs Tue Dec 31 23:34:47 2024 -0500 +++ b/src/direct_product.rs Tue Dec 31 23:49:09 2024 -0500 @@ -282,12 +282,9 @@ F : Num, Self : MulAssign<F>, Pair<A, B> : MulAssign<F>, - Pair<A::Owned, B::Owned> : AXPY<F, Pair<U, V>>, { - type Owned = Pair<A::Owned, B::Owned>; - - fn add_mul<I : Instance<Pair<U,V>>>(self, α : F, x : I, β : F) -> Self::Owned { + fn add_mul<I : Instance<Pair<U,V>>>(self, α : F, x : I, β : F) -> Pair<U, V> { let Pair(u, v) = x.decompose(); Pair(self.0.add_mul(α, u, β), self.1.add_mul(α, v, β)) } @@ -311,7 +308,7 @@ } /// Return a similar zero as `self`. - fn similar_origin(&self) -> Self::Owned { + fn similar_origin(&self) -> Pair<U, V> { Pair(self.0.similar_origin(), self.1.similar_origin()) }
--- a/src/linops.rs Tue Dec 31 23:34:47 2024 -0500 +++ b/src/linops.rs Tue Dec 31 23:49:09 2024 -0500 @@ -22,10 +22,8 @@ F : Num, X : Space, { - type Owned : AXPY<F, X>; - /// Computes `βy + αx`, where `y` is `Self`. - fn add_mul<I : Instance<X>>(self, α : F, x : I, β : F) -> Self::Owned ; + fn add_mul<I : Instance<X>>(self, α : F, x : I, β : F) -> X; /// Computes `y = βy + αx`, where `y` is `Self`. fn axpy<I : Instance<X>>(&mut self, α : F, x : I, β : F); @@ -41,7 +39,7 @@ } /// Return a similar zero as `self`. - fn similar_origin(&self) -> Self::Owned; + fn similar_origin(&self) -> X; /// Set self to zero. fn set_zero(&mut self); @@ -49,10 +47,12 @@ /// Efficient in-place application for [`Linear`] operators. #[replace_float_literals(F::cast_from(literal))] -pub trait GEMV<F : Num, X : Space, Y : AXPY<F> = <Self as Mapping<X>>::Codomain> : Linear<X> { +pub trait GEMV<F : Num, X : Space, Y : AXPY<F> = <Self as Mapping<X>>::Codomain> + : Linear<X, Codomain=Y> +{ /// Computes `αAx + βy`, where `A` is `Self`. - fn apply_add_mul<I : Instance<X>>(&self, y : Y, α : F, x : I, β : F) -> Y::Owned { + fn apply_add_mul<I : Instance<X>>(&self, y : Y, α : F, x : I, β : F) -> Y { y.add_mul(α, self.apply(x), β) }
--- a/src/loc.rs Tue Dec 31 23:34:47 2024 -0500 +++ b/src/loc.rs Tue Dec 31 23:49:09 2024 -0500 @@ -706,8 +706,6 @@ impl<F : Float, const N : usize> Linear<Loc<F, N>> for Loc<F, N> { } impl<F : Float, const N : usize> AXPY<F, Loc<F, N>> for Loc<F, N> { - type Owned = Self; - #[inline] fn add_mul<I : Instance<Loc<F, N>>>(mut self, α : F, x : I, β : F) -> Self { self.axpy(α, x, β); @@ -731,7 +729,7 @@ } #[inline] - fn similar_origin(&self) -> Self::Owned { + fn similar_origin(&self) -> Self { Self::ORIGIN }
--- a/src/nalgebra_support.rs Tue Dec 31 23:34:47 2024 -0500 +++ b/src/nalgebra_support.rs Tue Dec 31 23:49:09 2024 -0500 @@ -63,8 +63,9 @@ DefaultAllocator : Allocator<M,N> { } -impl<SM,SV1,SV2,N,M,K,E> GEMV<E, Matrix<E,M,K,SV1>, Matrix<E,N,K,SV2>> for Matrix<E,N,M,SM> -where SM: Storage<E,N,M>, SV1: Storage<E,M,K> + Clone, SV2: StorageMut<E,N,K>, +impl<SM,SV1,N,M,K,E> GEMV<E, Matrix<E,M,K,SV1>> for Matrix<E,N,M,SM> +where SM: Storage<E,N,M>, SV1: Storage<E,M,K> + Clone, + OMatrix<E, N, K> : AXPY<E>, N : Dim, M : Dim, K : Dim, E : Scalar + Zero + One + Float, DefaultAllocator : Allocator<N,K>, DefaultAllocator : Allocator<M,K>, @@ -73,37 +74,36 @@ #[inline] fn gemv<I : Instance<Matrix<E,M,K,SV1>>>( - &self, y : &mut Matrix<E,N,K,SV2>, α : E, x : I, β : E + &self, y : &mut OMatrix<E,N,K>, α : E, x : I, β : E ) { x.eval(|x̃| Matrix::gemm(y, α, self, x̃, β)) } #[inline] - fn apply_mut<'a, I : Instance<Matrix<E,M,K,SV1>>>(&self, y : &mut Matrix<E,N,K,SV2>, x : I) { + fn apply_mut<'a, I : Instance<Matrix<E,M,K,SV1>>>(&self, y : &mut OMatrix<E,N,K>, x : I) { x.eval(|x̃| self.mul_to(x̃, y)) } } -impl<SM,SV1,M,E> AXPY<E, Vector<E,M,SV1>> for Vector<E,M,SM> -where SM: StorageMut<E,M> + Clone, SV1: Storage<E,M> + Clone, +impl<SM,M,E> AXPY<E, OVector<E, M>> for Vector<E,M,SM> +where SM: StorageMut<E,M> + Clone, M : Dim, E : Scalar + Zero + One + Float, DefaultAllocator : Allocator<M> { - type Owned = OVector<E, M>; #[inline] - fn add_mul<I : Instance<Vector<E,M,SV1>>>(self, α : E, x : I, β : E) -> Self::Owned { + fn add_mul<I : Instance<OVector<E, M>>>(self, α : E, x : I, β : E) -> OVector<E, M> { let mut owned = self.into_owned(); x.eval(|x̃| Matrix::axpy(&mut owned, α, x̃, β)); owned } #[inline] - fn axpy<I : Instance<Vector<E,M,SV1>>>(&mut self, α : E, x : I, β : E) { + fn axpy<I : Instance<OVector<E, M>>>(&mut self, α : E, x : I, β : E) { x.eval(|x̃| Matrix::axpy(self, α, x̃, β)) } #[inline] - fn copy_from<I : Instance<Vector<E,M,SV1>>>(&mut self, y : I) { + fn copy_from<I : Instance<OVector<E, M>>>(&mut self, y : I) { y.eval(|ỹ| Matrix::copy_from(self, ỹ)) } @@ -113,7 +113,7 @@ } #[inline] - fn similar_origin(&self) -> Self::Owned { + fn similar_origin(&self) -> OVector<E, M> { OVector::zeros_generic(M::from_usize(self.len()), Const) } }