# HG changeset patch # User Tuomo Valkonen # Date 1746106833 18000 # Node ID 495448cca603576ff48a3fc827e515bc0313589a # Parent fc7d923ff6e7133450b85280a2dbada205e9b2ef remove quadratic diff -r fc7d923ff6e7 -r 495448cca603 src/mapping.rs --- a/src/mapping.rs Thu May 01 02:28:28 2025 -0500 +++ b/src/mapping.rs Thu May 01 08:40:33 2025 -0500 @@ -314,8 +314,6 @@ } } -mod quadratic; -pub use quadratic::Quadratic; mod dataterm; pub use dataterm::DataTerm; diff -r fc7d923ff6e7 -r 495448cca603 src/mapping/quadratic.rs --- a/src/mapping/quadratic.rs Thu May 01 02:28:28 2025 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/*! -Quadratic functions of the form $\frac{1}{2}\|Ax-b\|_2^2$ for an operator $A$ -to a [`Euclidean`] space. -*/ - -#![allow(non_snake_case)] - -use super::{DifferentiableImpl, LipschitzDifferentiableImpl, Mapping}; -use crate::convex::ConvexMapping; -use crate::error::DynResult; -use crate::euclidean::Euclidean; -use crate::instance::{Instance, Space}; -use crate::linops::{BoundedLinear, Linear, Preadjointable}; -use crate::norms::{Norm, NormExponent, Normed, L2}; -use crate::types::Float; -use std::marker::PhantomData; - -/// Functions of the form $\frac{1}{2}\|Ax-b\|_2^2$ for an operator $A$ -/// to a [`Euclidean`] space. -#[derive(Clone, Copy)] -pub struct Quadratic<'a, F: Float, Domain: Space, A: Mapping> { - opA: &'a A, - b: &'a >::Codomain, - _phantoms: PhantomData, -} - -#[allow(non_snake_case)] -impl<'a, F: Float, Domain: Space, A: Mapping> Quadratic<'a, F, Domain, A> { - pub fn new(opA: &'a A, b: &'a A::Codomain) -> Self { - Quadratic { - opA, - b, - _phantoms: PhantomData, - } - } - - pub fn operator(&self) -> &'a A { - self.opA - } - - pub fn data(&self) -> &'a >::Codomain { - self.b - } -} - -//+ AdjointProductBoundedBy, P, FloatType = F>, - -impl<'a, F: Float, X: Space, A: Mapping> Mapping for Quadratic<'a, F, X, A> -where - A::Codomain: Euclidean, -{ - type Codomain = F; - - fn apply>(&self, x: I) -> F { - // TODO: possibly (if at all more effcient) use GEMV once generalised - // to not require preallocation. However, Rust should be pretty efficient - // at not doing preallocations or anything here, as the result of self.opA.apply() - // can be consumed, so maybe GEMV is no use. - (self.opA.apply(x) - self.b).norm2_squared() / F::TWO - } -} - -impl<'a, F: Float, X: Normed, A: Linear> ConvexMapping for Quadratic<'a, F, X, A> where - A::Codomain: Euclidean -{ -} - -impl<'a, F, X, A> DifferentiableImpl for Quadratic<'a, F, X, A> -where - F: Float, - X: Space, - >::Codomain: Euclidean, - A: Linear + Preadjointable, - <>::Codomain as Euclidean>::Output: Instance<>::Codomain>, -{ - type Derivative = A::PreadjointCodomain; - - fn differential_impl>(&self, x: I) -> Self::Derivative { - // TODO: possibly (if at all more effcient) use GEMV once generalised - // to not require preallocation. However, Rust should be pretty efficient - // at not doing preallocations or anything here, as the result of self.opA.apply() - // can be consumed, so maybe GEMV is no use. - self.opA.preadjoint().apply(self.opA.apply(x) - self.b) - } -} - -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 diff_lipschitz_factor(&self, seminorm: ExpX) -> DynResult { - Ok(self.opA.opnorm_bound(seminorm, L2)?.powi(2)) - } -}