# HG changeset patch # User Tuomo Valkonen # Date 1746075675 18000 # Node ID ed8124f1af1da7edb01f09a6515272cbc083b417 # Parent e1455e48bd2b023331cfc1e3b0f3f06e7b1aa4d4 Missing Norm222 traits diff -r e1455e48bd2b -r ed8124f1af1d src/convex.rs --- a/src/convex.rs Wed Apr 30 23:57:17 2025 -0500 +++ b/src/convex.rs Thu May 01 00:01:15 2025 -0500 @@ -2,10 +2,11 @@ Some convex analysis basics */ +use crate::error::DynResult; use crate::euclidean::Euclidean; use crate::instance::{DecompositionMut, Instance, InstanceMut}; use crate::linops::{IdOp, Scaled}; -use crate::mapping::{Mapping, Space}; +use crate::mapping::{DifferentiableImpl, LipschitzDifferentiableImpl, Mapping, Space}; use crate::norms::*; use crate::operator_arithmetic::{Constant, Weighted}; use crate::types::*; @@ -342,22 +343,22 @@ } } -impl, F: Float> Mapping for Norm222 { +impl, F: Float> Mapping for Norm222 { type Codomain = F; /// Compute the value of `self` at `x`. - fn apply>(&self, x: I) -> Self::Codomain { + fn apply>(&self, x: I) -> Self::Codomain { x.eval(|z| z.norm2_squared() / F::TWO) } } -impl, F: Float> ConvexMapping for Norm222 { +impl, F: Float> ConvexMapping for Norm222 { fn factor_of_strong_convexity(&self) -> F { F::ONE } } -impl, F: Float> Conjugable for Norm222 { +impl, F: Float> Conjugable for Norm222 { type Conjugate<'a> = Self where @@ -369,7 +370,7 @@ } } -impl, F: Float> Preconjugable for Norm222 { +impl, F: Float> Preconjugable for Norm222 { type Preconjugate<'a> = Self where @@ -381,10 +382,10 @@ } } -impl Prox for Norm222 +impl Prox for Norm222 where F: Float, - Domain: Euclidean, + X: Euclidean, { type Prox<'a> = Scaled @@ -395,3 +396,27 @@ Scaled(F::ONE / (F::ONE + τ)) } } + +impl DifferentiableImpl for Norm222 +where + F: Float, + X: Euclidean, +{ + type Derivative = X; + + fn differential_impl>(&self, x: I) -> X { + x.own() + } +} + +impl LipschitzDifferentiableImpl for Norm222 +where + F: Float, + X: Euclidean, +{ + type FloatType = F; + + fn diff_lipschitz_factor(&self, _: L2) -> DynResult { + Ok(F::ONE) + } +}