LipschitzDifferentiableImpl dev

Mon, 28 Apr 2025 21:32:37 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 28 Apr 2025 21:32:37 -0500
branch
dev
changeset 102
aead46a19767
parent 101
997961aa6eee
child 103
e98e1da2530d

LipschitzDifferentiableImpl

src/mapping.rs file | annotate | diff | comparison | revisions
src/mapping/quadratic.rs file | annotate | diff | comparison | revisions
--- a/src/mapping.rs	Mon Apr 28 16:52:15 2025 -0500
+++ b/src/mapping.rs	Mon Apr 28 21:32:37 2025 -0500
@@ -294,3 +294,23 @@
     /// Returns the Lipschitz factor of `self` with respect to the (semi)norm `D`.
     fn lipschitz_factor(&self, seminorm: M) -> Option<Self::FloatType>;
 }
+
+/// Helper trait for implementing [`Lipschitz`] for mappings that implement [`DifferentiableImpl`].
+pub trait LipschitzDifferentiableImpl<X: Space, M>: DifferentiableImpl<X> {
+    type FloatType: Float;
+
+    /// Compute the lipschitz factor of the derivative of `f`.
+    fn diff_lipschitz_factor(&self, seminorm: M) -> Option<Self::FloatType>;
+}
+
+impl<'b, M, X, A> Lipschitz<M> for Differential<'b, X, A>
+where
+    X: Space,
+    A: LipschitzDifferentiableImpl<X, M> + Clone,
+{
+    type FloatType = A::FloatType;
+
+    fn lipschitz_factor(&self, seminorm: M) -> Option<Self::FloatType> {
+        (*self.g).diff_lipschitz_factor(seminorm)
+    }
+}
--- a/src/mapping/quadratic.rs	Mon Apr 28 16:52:15 2025 -0500
+++ b/src/mapping/quadratic.rs	Mon Apr 28 21:32:37 2025 -0500
@@ -5,7 +5,7 @@
 
 #![allow(non_snake_case)]
 
-use super::{DifferentiableImpl, Differential, Lipschitz, Mapping};
+use super::{DifferentiableImpl, LipschitzDifferentiableImpl, Mapping};
 use crate::convex::ConvexMapping;
 use crate::euclidean::Euclidean;
 use crate::instance::{Instance, Space};
@@ -83,16 +83,17 @@
     }
 }
 
-impl<'a, 'b, F, X, ExpX, A> Lipschitz<ExpX> for Differential<'b, X, Quadratic<'a, F, X, A>>
+impl<'a, F, X, ExpX, A> LipschitzDifferentiableImpl<X, ExpX> for Quadratic<'a, F, X, A>
 where
     F: Float,
     X: Space + Clone + Norm<F, ExpX>,
     ExpX: NormExponent,
     A: Clone + BoundedLinear<X, ExpX, L2, F>,
+    Self: DifferentiableImpl<X>,
 {
     type FloatType = F;
 
-    fn lipschitz_factor(&self, seminorm: ExpX) -> Option<F> {
-        Some((*self.g).opA.opnorm_bound(seminorm, L2).powi(2))
+    fn diff_lipschitz_factor(&self, seminorm: ExpX) -> Option<F> {
+        Some(self.opA.opnorm_bound(seminorm, L2).powi(2))
     }
 }

mercurial