# HG changeset patch # User Tuomo Valkonen # Date 1745893957 18000 # Node ID aead46a1976741dd909536a6c5e30b9e69df0d29 # Parent 997961aa6eeeb146666f9455e2b3284a06cc7d62 LipschitzDifferentiableImpl diff -r 997961aa6eee -r aead46a19767 src/mapping.rs --- 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; } + +/// Helper trait for implementing [`Lipschitz`] for mappings that implement [`DifferentiableImpl`]. +pub trait LipschitzDifferentiableImpl: DifferentiableImpl { + type FloatType: Float; + + /// Compute the lipschitz factor of the derivative of `f`. + fn diff_lipschitz_factor(&self, seminorm: M) -> Option; +} + +impl<'b, M, X, A> Lipschitz for Differential<'b, X, A> +where + X: Space, + A: LipschitzDifferentiableImpl + Clone, +{ + type FloatType = A::FloatType; + + fn lipschitz_factor(&self, seminorm: M) -> Option { + (*self.g).diff_lipschitz_factor(seminorm) + } +} diff -r 997961aa6eee -r aead46a19767 src/mapping/quadratic.rs --- 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 for Differential<'b, X, Quadratic<'a, F, X, A>> +impl<'a, F, X, ExpX, A> LipschitzDifferentiableImpl for Quadratic<'a, F, X, A> where F: Float, X: Space + Clone + Norm, ExpX: NormExponent, A: Clone + BoundedLinear, + Self: DifferentiableImpl, { type FloatType = F; - fn lipschitz_factor(&self, seminorm: ExpX) -> Option { - Some((*self.g).opA.opnorm_bound(seminorm, L2).powi(2)) + fn diff_lipschitz_factor(&self, seminorm: ExpX) -> Option { + Some(self.opA.opnorm_bound(seminorm, L2).powi(2)) } }