Missing Norm222 traits dev

Thu, 01 May 2025 00:01:15 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 01 May 2025 00:01:15 -0500
branch
dev
changeset 112
ed8124f1af1d
parent 111
e1455e48bd2b
child 113
d97fcf22a61c

Missing Norm222 traits

src/convex.rs file | annotate | diff | comparison | revisions
--- 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<Domain: Euclidean<F>, F: Float> Mapping<Domain> for Norm222<F> {
+impl<X: Euclidean<F>, F: Float> Mapping<X> for Norm222<F> {
     type Codomain = F;
 
     /// Compute the value of `self` at `x`.
-    fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain {
+    fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain {
         x.eval(|z| z.norm2_squared() / F::TWO)
     }
 }
 
-impl<Domain: Euclidean<F>, F: Float> ConvexMapping<Domain, F> for Norm222<F> {
+impl<X: Euclidean<F>, F: Float> ConvexMapping<X, F> for Norm222<F> {
     fn factor_of_strong_convexity(&self) -> F {
         F::ONE
     }
 }
 
-impl<Domain: Euclidean<F>, F: Float> Conjugable<Domain, F> for Norm222<F> {
+impl<X: Euclidean<F>, F: Float> Conjugable<X, F> for Norm222<F> {
     type Conjugate<'a>
         = Self
     where
@@ -369,7 +370,7 @@
     }
 }
 
-impl<Domain: Euclidean<F>, F: Float> Preconjugable<Domain, Domain, F> for Norm222<F> {
+impl<X: Euclidean<F>, F: Float> Preconjugable<X, X, F> for Norm222<F> {
     type Preconjugate<'a>
         = Self
     where
@@ -381,10 +382,10 @@
     }
 }
 
-impl<Domain, F> Prox<Domain> for Norm222<F>
+impl<X, F> Prox<X> for Norm222<F>
 where
     F: Float,
-    Domain: Euclidean<F, Output = Domain>,
+    X: Euclidean<F, Output = X>,
 {
     type Prox<'a>
         = Scaled<F>
@@ -395,3 +396,27 @@
         Scaled(F::ONE / (F::ONE + τ))
     }
 }
+
+impl<X, F> DifferentiableImpl<X> for Norm222<F>
+where
+    F: Float,
+    X: Euclidean<F, Output = X>,
+{
+    type Derivative = X;
+
+    fn differential_impl<I: Instance<X>>(&self, x: I) -> X {
+        x.own()
+    }
+}
+
+impl<X, F> LipschitzDifferentiableImpl<X, L2> for Norm222<F>
+where
+    F: Float,
+    X: Euclidean<F, Output = X>,
+{
+    type FloatType = F;
+
+    fn diff_lipschitz_factor(&self, _: L2) -> DynResult<Self::FloatType> {
+        Ok(F::ONE)
+    }
+}

mercurial