diff -r e5fab0125a8e -r 672aec2e1acd src/norms.rs --- a/src/norms.rs Thu Dec 26 12:35:53 2024 -0500 +++ b/src/norms.rs Tue Dec 24 00:24:10 2024 -0500 @@ -7,6 +7,7 @@ use crate::types::*; use crate::euclidean::*; use crate::mapping::{Mapping, Space, Instance}; +use crate::operator_arithmetic::{Constant, Weighted}; // // Abstract norms @@ -50,6 +51,8 @@ pub struct L21; impl NormExponent for L21 {} +impl NormExponent for Weighted {} + /// Norms for pairs (a, b). ‖(a,b)‖ = ‖(‖a‖_A, ‖b‖_B)‖_J /// For use with [`crate::direct_product::Pair`] #[derive(Copy,Debug,Clone,Serialize,Eq,PartialEq)] @@ -176,6 +179,20 @@ } } +impl Norm> for D +where + F : Float, + D : Norm, + C : Constant, + E : NormExponent, +{ + fn norm(&self, e : Weighted) -> F { + let v = e.weight.value(); + assert!(v > F::ZERO); + v * self.norm(e.base_fn) + } +} + // impl> Norm for Vec { // fn norm(&self, _l21 : L21) -> F { // self.iter().map(|e| e.norm(L2)).sum() @@ -266,6 +283,29 @@ } } +impl HasDualExponent for Weighted { + type DualExp = Weighted; + fn dual_exponent(&self) -> Self::DualExp { + Weighted { + weight : C::Type::ONE / self.weight.value(), + base_fn : self.base_fn.dual_exponent() + } + } +} +impl Projection> for T +where + T : Projection, + F : Float, + C : Constant, + E : NormExponent, +{ + fn proj_ball(self, ρ : F, q : Weighted) -> Self { + self.proj_ball(ρ / q.weight.value(), q.base_fn) + } + fn proj_ball_mut(&mut self, ρ : F, q : Weighted) { + self.proj_ball_mut(ρ / q.weight.value(), q.base_fn) + } +} \ No newline at end of file