# HG changeset patch # User Tuomo Valkonen # Date 1666728340 -10800 # Node ID d80b87b8acd08e71cabdfad7ad0429934b12ab95 # Parent 59dc4c5883f4dcc743b4f7f797a2290825a7eab5 Added NormExponent trait for exponents of norms diff -r 59dc4c5883f4 -r d80b87b8acd0 src/norms.rs --- a/src/norms.rs Sat Oct 22 14:40:28 2022 +0300 +++ b/src/norms.rs Tue Oct 25 23:05:40 2022 +0300 @@ -10,22 +10,32 @@ // Abstract norms // +/// An exponent for norms. +/// +// Just a collection of desirabl attributes for a marker type +pub trait NormExponent : Copy + Send + Sync + 'static {} + + /// Exponent type for the 1-[`Norm`]. #[derive(Copy,Debug,Clone,Serialize,Eq,PartialEq)] pub struct L1; +impl NormExponent for L1 {} /// Exponent type for the 2-[`Norm`]. #[derive(Copy,Debug,Clone,Serialize,Eq,PartialEq)] pub struct L2; +impl NormExponent for L2 {} /// Exponent type for the ∞-[`Norm`]. #[derive(Copy,Debug,Clone,Serialize,Eq,PartialEq)] pub struct Linfinity; +impl NormExponent for Linfinity {} /// Exponent type for 2,1-[`Norm`]. /// (1-norm over a domain Ω, 2-norm of a vector at each point of the domain.) #[derive(Copy,Debug,Clone,Serialize,Eq,PartialEq)] pub struct L21; +impl NormExponent for L21 {} /// A Huber/Moreau–Yosida smoothed [`L1`] norm. (Not a norm itself.) /// @@ -33,6 +43,7 @@ /// values more smoothing. Behaviour with γ < 0 is undefined. #[derive(Copy,Debug,Clone,Serialize,Eq,PartialEq)] pub struct HuberL1(pub F); +impl NormExponent for HuberL1 {} /// A Huber/Moreau–Yosida smoothed [`L21`] norm. (Not a norm itself.) /// @@ -40,6 +51,8 @@ /// values more smoothing. Behaviour with γ < 0 is undefined. #[derive(Copy,Debug,Clone,Serialize,Eq,PartialEq)] pub struct HuberL21(pub F); +impl NormExponent for HuberL21 {} + /// A normed space (type) with exponent or other type `Exponent` for the norm. /// @@ -51,14 +64,14 @@ /// /// println!("{}, {} {}", x.norm(L1), x.norm(L2), x.norm(Linfinity)) /// ``` -pub trait Norm { +pub trait Norm { /// Calculate the norm. fn norm(&self, _p : Exponent) -> F; } /// Indicates that the `Self`-[`Norm`] is dominated by the `Exponent`-`Norm` on the space /// `Elem` with the corresponding field `F`. -pub trait Dominated { +pub trait Dominated { /// Indicates the factor $c$ for the inequality $‖x‖ ≤ C ‖x‖_p$. fn norm_factor(&self, p : Exponent) -> F; /// Given a norm-value $‖x‖_p$, calculates $C‖x‖_p$ such that $‖x‖ ≤ C‖x‖_p$ @@ -69,7 +82,7 @@ } /// Trait for distances with respect to a norm. -pub trait Dist : Norm { +pub trait Dist : Norm { /// Calculate the distance fn dist(&self, other : &Self, _p : Exponent) -> F; } @@ -84,7 +97,8 @@ /// /// println!("{:?}, {:?}", x.proj_ball(1.0, L2), x.proj_ball(0.5, Linfinity)); /// ``` -pub trait Projection : Norm + Euclidean where F : Float { +pub trait Projection : Norm + Euclidean +where F : Float { /// Projection of `self` to the `q`-norm-ball of radius ρ. fn proj_ball(mut self, ρ : F, q : Exponent) -> Self { self.proj_ball_mut(ρ, q);