# HG changeset patch # User Tuomo Valkonen # Date 1745993185 18000 # Node ID 943c6b3b941494041044ea98ef69ece378b51ede # Parent 6be459f08b66b242eec5a81e0a1a8b776d8a3f5d More Normed usage diff -r 6be459f08b66 -r 943c6b3b9414 src/convex.rs --- a/src/convex.rs Wed Apr 30 00:48:56 2025 -0500 +++ b/src/convex.rs Wed Apr 30 01:06:25 2025 -0500 @@ -16,10 +16,8 @@ /// /// TODO: should constrain `Mapping::Codomain` to implement a partial order, /// but this makes everything complicated with little benefit. -pub trait ConvexMapping: Mapping { - /// Returns (a lower estimate of) the factor of strong convexity. - /// - /// TODO: should include a specification of the respective norm. +pub trait ConvexMapping, F: Num = f64>: Mapping { + /// Returns (a lower estimate of) the factor of strong convexity in the norm of `Domain`. fn factor_of_strong_convexity(&self) -> F { F::ZERO } @@ -43,7 +41,7 @@ /// but a `Preconjugable` mapping has to be convex. pub trait Preconjugable: ConvexMapping where - Domain: Space, + Domain: Normed, Predual: HasDual, { type Preconjugate<'a>: Mapping @@ -90,7 +88,7 @@ impl ConvexMapping for NormMapping where - Domain: Space, + Domain: Normed, E: NormExponent, F: Float, Self: Mapping, @@ -116,7 +114,7 @@ impl ConvexMapping for NormConstraint where - Domain: Space, + Domain: Normed, E: NormExponent, F: Float, Self: Mapping, @@ -127,7 +125,7 @@ where E: HasDualExponent, F: Float, - Domain: HasDual + Norm + Space, + Domain: HasDual + Norm + Normed, >::DualSpace: Norm, { type Conjugate<'a> @@ -209,7 +207,7 @@ impl Mapping for NormProjection where - Domain: Space + Projection, + Domain: Normed + Projection, F: Float, E: NormExponent, { @@ -239,7 +237,7 @@ } } -impl ConvexMapping for Zero {} +impl, F: Float> ConvexMapping for Zero {} impl, F: Float> Conjugable for Zero { type Conjugate<'a> @@ -255,7 +253,7 @@ impl Preconjugable for Zero where - Domain: Space, + Domain: Normed, Predual: HasDual, { type Preconjugate<'a> diff -r 6be459f08b66 -r 943c6b3b9414 src/mapping/dataterm.rs --- a/src/mapping/dataterm.rs Wed Apr 30 00:48:56 2025 -0500 +++ b/src/mapping/dataterm.rs Wed Apr 30 01:06:25 2025 -0500 @@ -5,11 +5,11 @@ #![allow(non_snake_case)] -use super::{DifferentiableImpl, DifferentiableMapping, /*LipschitzDifferentiableImpl,*/ Mapping,}; +use super::{DifferentiableImpl, DifferentiableMapping, LipschitzDifferentiableImpl, Mapping}; use crate::convex::ConvexMapping; use crate::instance::{Instance, Space}; -use crate::linops::{/*BoundedLinear,*/ Linear, Preadjointable}; -//use crate::norms::{Norm, NormExponent, L2}; +use crate::linops::{BoundedLinear, Linear, Preadjointable}; +use crate::norms::{Normed, L2}; use crate::types::Float; use std::ops::Sub; //use serde::{Deserialize, Serialize}; @@ -72,10 +72,10 @@ impl ConvexMapping for DataTerm where F: Float, - X: Space, + X: Normed, A: Linear, G: ConvexMapping, - A::Codomain: for<'a> Sub<&'a A::Codomain, Output = A::Codomain>, + A::Codomain: Normed + for<'a> Sub<&'a A::Codomain, Output = A::Codomain>, { } @@ -103,22 +103,18 @@ } } -/* -impl<'a, F, X, ExpX, Y, ExpY, A, G> LipschitzDifferentiableImpl for DataTerm +impl<'a, F, X, Y, A, G> LipschitzDifferentiableImpl for DataTerm where F: Float, - X: Space + Clone + Norm, - Y: Space + Norm, - ExpX: NormExponent, - ExpY: NormExponent, - A: Clone + BoundedLinear, - G: Mapping + LipschitzDifferentiableImpl, + X: Normed + Clone, + Y: Normed, + A: Clone + BoundedLinear, + G: Mapping + LipschitzDifferentiableImpl, Self: DifferentiableImpl, { type FloatType = F; - fn diff_lipschitz_factor(&self, seminorm: ExpX) -> Option { + fn diff_lipschitz_factor(&self, seminorm: X::NormExp) -> Option { Some(self.opA.opnorm_bound(seminorm, L2).powi(2)) } } -*/ diff -r 6be459f08b66 -r 943c6b3b9414 src/mapping/quadratic.rs --- a/src/mapping/quadratic.rs Wed Apr 30 00:48:56 2025 -0500 +++ b/src/mapping/quadratic.rs Wed Apr 30 01:06:25 2025 -0500 @@ -10,7 +10,7 @@ use crate::euclidean::Euclidean; use crate::instance::{Instance, Space}; use crate::linops::{BoundedLinear, Linear, Preadjointable}; -use crate::norms::{Norm, NormExponent, L2}; +use crate::norms::{Norm, NormExponent, Normed, L2}; use crate::types::Float; use std::marker::PhantomData; @@ -59,7 +59,7 @@ } } -impl<'a, F: Float, X: Space, A: Linear> ConvexMapping for Quadratic<'a, F, X, A> where +impl<'a, F: Float, X: Normed, A: Linear> ConvexMapping for Quadratic<'a, F, X, A> where A::Codomain: Euclidean { } diff -r 6be459f08b66 -r 943c6b3b9414 src/norms.rs --- a/src/norms.rs Wed Apr 30 00:48:56 2025 -0500 +++ b/src/norms.rs Wed Apr 30 01:06:25 2025 -0500 @@ -176,13 +176,13 @@ } } -impl> Norm> for E { +impl + Normed> Norm> for E { fn norm(&self, huber: HuberL1) -> F { huber.apply(self.norm2_squared()) } } -impl> Dist> for E { +impl + Normed> Dist> for E { fn dist>(&self, other: I, huber: HuberL1) -> F { huber.apply(self.dist2_squared(other)) }