diff -r c5f70e767511 -r f802ddbabcfc src/convex.rs --- a/src/convex.rs Tue Dec 31 08:48:50 2024 -0500 +++ b/src/convex.rs Mon Dec 23 23:27:45 2024 -0500 @@ -4,9 +4,9 @@ use std::marker::PhantomData; use crate::types::*; -use crate::mapping::{Mapping, Space}; +use crate::mapping::{Mapping, Space, ArithmeticTrue}; use crate::linops::IdOp; -use crate::instance::{Instance, InstanceMut, DecompositionMut}; +use crate::instance::{Instance, InstanceMut, DecompositionMut,}; use crate::norms::*; /// Trait for convex mappings. Has no features, just serves as a constraint @@ -85,6 +85,7 @@ E : NormExponent, { type Codomain = F; + type ArithmeticOptIn = ArithmeticTrue; fn apply>(&self, d : I) -> F { if d.eval(|x| x.norm(self.0.exponent)) <= F::ONE { @@ -118,6 +119,53 @@ } } +impl Prox for NormConjugate +where + Domain : Space + Norm, + E : NormExponent, + F : Float, + NormProjection : Mapping, +{ + type Prox<'a> = NormProjection where Self : 'a; + + #[inline] + fn prox_mapping(&self, τ : Self::Codomain) -> Self::Prox<'_> { + NormProjection{ α : τ, exponent : self.0.exponent } + } +} + +pub struct NormProjection { + α : F, + exponent : E, +} + +/* +impl Mapping for NormProjection +where + Domain : Space + Euclidean + std::ops::MulAssign, + F : Float, +{ + type Codomain = Domain; + + fn apply>(&self, d : I) -> Domain { + d.own().proj_ball2(self.α) + } +} +*/ + +impl Mapping for NormProjection +where + Domain : Space + Projection + std::ops::MulAssign, + F : Float, + E : NormExponent, +{ + type Codomain = Domain; + type ArithmeticOptIn = ArithmeticTrue; + + fn apply>(&self, d : I) -> Domain { + d.own().proj_ball(self.α, self.exponent) + } +} /// The zero mapping pub struct Zero(PhantomData<(Domain, F)>); @@ -130,6 +178,7 @@ impl Mapping for Zero { type Codomain = F; + type ArithmeticOptIn = ArithmeticTrue; /// Compute the value of `self` at `x`. fn apply>(&self, _x : I) -> Self::Codomain { @@ -183,6 +232,7 @@ impl, F : Float> Mapping for ZeroIndicator { type Codomain = F; + type ArithmeticOptIn = ArithmeticTrue; /// Compute the value of `self` at `x`. fn apply>(&self, x : I) -> Self::Codomain {