src/mapping.rs

branch
dev
changeset 110
a1278320be26
parent 105
103aa137fcb2
child 122
495448cca603
equal deleted inserted replaced
109:943c6b3b9414 110:a1278320be26
1 /*! 1 /*!
2 Traits for mathematical functions. 2 Traits for mathematical functions.
3 */ 3 */
4 4
5 use crate::error::DynResult;
5 pub use crate::instance::{BasicDecomposition, Decomposition, Instance, Space}; 6 pub use crate::instance::{BasicDecomposition, Decomposition, Instance, Space};
6 use crate::loc::Loc; 7 use crate::loc::Loc;
7 use crate::norms::{Norm, NormExponent}; 8 use crate::norms::{Norm, NormExponent};
8 use crate::operator_arithmetic::{Constant, Weighted}; 9 use crate::operator_arithmetic::{Constant, Weighted};
9 use crate::types::{ClosedMul, Float, Num}; 10 use crate::types::{ClosedMul, Float, Num};
322 pub trait Lipschitz<M> { 323 pub trait Lipschitz<M> {
323 /// The type of floats 324 /// The type of floats
324 type FloatType: Float; 325 type FloatType: Float;
325 326
326 /// Returns the Lipschitz factor of `self` with respect to the (semi)norm `D`. 327 /// Returns the Lipschitz factor of `self` with respect to the (semi)norm `D`.
327 fn lipschitz_factor(&self, seminorm: M) -> Option<Self::FloatType>; 328 fn lipschitz_factor(&self, seminorm: M) -> DynResult<Self::FloatType>;
328 } 329 }
329 330
330 /// Helper trait for implementing [`Lipschitz`] for mappings that implement [`DifferentiableImpl`]. 331 /// Helper trait for implementing [`Lipschitz`] for mappings that implement [`DifferentiableImpl`].
331 pub trait LipschitzDifferentiableImpl<X: Space, M>: DifferentiableImpl<X> { 332 pub trait LipschitzDifferentiableImpl<X: Space, M>: DifferentiableImpl<X> {
332 type FloatType: Float; 333 type FloatType: Float;
333 334
334 /// Compute the lipschitz factor of the derivative of `f`. 335 /// Compute the lipschitz factor of the derivative of `f`.
335 fn diff_lipschitz_factor(&self, seminorm: M) -> Option<Self::FloatType>; 336 fn diff_lipschitz_factor(&self, seminorm: M) -> DynResult<Self::FloatType>;
336 } 337 }
337 338
338 impl<'b, M, X, A> Lipschitz<M> for Differential<'b, X, A> 339 impl<'b, M, X, A> Lipschitz<M> for Differential<'b, X, A>
339 where 340 where
340 X: Space, 341 X: Space,
341 A: LipschitzDifferentiableImpl<X, M> + Clone, 342 A: LipschitzDifferentiableImpl<X, M> + Clone,
342 { 343 {
343 type FloatType = A::FloatType; 344 type FloatType = A::FloatType;
344 345
345 fn lipschitz_factor(&self, seminorm: M) -> Option<Self::FloatType> { 346 fn lipschitz_factor(&self, seminorm: M) -> DynResult<Self::FloatType> {
346 (*self.g).diff_lipschitz_factor(seminorm) 347 (*self.g).diff_lipschitz_factor(seminorm)
347 } 348 }
348 } 349 }

mercurial