--- a/src/nalgebra_support.rs Tue Dec 31 08:30:02 2024 -0500 +++ b/src/nalgebra_support.rs Tue Dec 31 09:02:55 2024 -0500 @@ -101,6 +101,20 @@ } } +/* Implemented automatically as Euclidean. +impl<SM,M,E> Projection<E, L2> for Vector<E,M,SM> +where SM: StorageMut<E,M> + Clone, + M : Dim, E : Scalar + Zero + One + Float + RealField, + DefaultAllocator : Allocator<M> { + #[inline] + fn proj_ball_mut(&mut self, ρ : E, _ : L2) { + let n = self.norm(L2); + if n > ρ { + self.iter_mut().for_each(|v| *v *= ρ/n) + } + } +}*/ + impl<SM,M,E> Projection<E, Linfinity> for Vector<E,M,SM> where SM: StorageMut<E,M> + Clone, M : Dim, E : Scalar + Zero + One + Float + RealField, @@ -205,10 +219,41 @@ } } +/// The default norm for `Vector` is [`L2`]. +impl<E,M,S> Normed<E> +for Vector<E,M,S> +where M : Dim, + S : Storage<E,M> + Clone, + E : Float + Scalar + Zero + One + RealField, + DefaultAllocator : Allocator<M> { + + type NormExp = L2; + + #[inline] + fn norm_exponent(&self) -> Self::NormExp { + L2 + } + + #[inline] + fn is_zero(&self) -> bool { + Vector::<E,M,S>::norm_squared(self) == E::ZERO + } +} + +impl<E,M,S> HasDual<E> +for Vector<E,M,S> +where M : Dim, + S : Storage<E,M> + Clone, + E : Float + Scalar + Zero + One + RealField, + DefaultAllocator : Allocator<M> { + // TODO: Doesn't work with different storage formats. + type DualSpace = Self; +} + impl<E,M,S> Norm<E, L1> for Vector<E,M,S> where M : Dim, - S : StorageMut<E,M>, + S : Storage<E,M>, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator<M> { @@ -221,7 +266,7 @@ impl<E,M,S> Dist<E, L1> for Vector<E,M,S> where M : Dim, - S : StorageMut<E,M>, + S : Storage<E,M>, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator<M> { #[inline] @@ -233,7 +278,7 @@ impl<E,M,S> Norm<E, L2> for Vector<E,M,S> where M : Dim, - S : StorageMut<E,M>, + S : Storage<E,M>, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator<M> { @@ -246,7 +291,7 @@ impl<E,M,S> Dist<E, L2> for Vector<E,M,S> where M : Dim, - S : StorageMut<E,M>, + S : Storage<E,M>, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator<M> { #[inline] @@ -258,7 +303,7 @@ impl<E,M,S> Norm<E, Linfinity> for Vector<E,M,S> where M : Dim, - S : StorageMut<E,M>, + S : Storage<E,M>, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator<M> { @@ -271,7 +316,7 @@ impl<E,M,S> Dist<E, Linfinity> for Vector<E,M,S> where M : Dim, - S : StorageMut<E,M>, + S : Storage<E,M>, E : Float + Scalar + Zero + One + RealField, DefaultAllocator : Allocator<M> { #[inline]