diff -r ad68dacabe4f -r 84923812d220 src/scaled.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/scaled.rs Wed Nov 06 10:15:38 2024 -0500 @@ -0,0 +1,46 @@ +/*! +Implementation of scaling of functions on a manifold by a scalar. +*/ + +use alg_tools::mapping::Apply; +use crate::manifold::ManifoldPoint; +use crate::fb::{Grad, Desc, Prox}; + +/// Structure for a function of type `G`, scaled by a scalar. +pub struct Scaled { + α : f64, + g : G, +} + +impl Scaled { + #[allow(dead_code)] + pub fn new(α : f64, g : G) -> Self { + Scaled{ α, g } + } +} + +impl> Apply for Scaled< G> { + type Output = f64; + + fn apply(&self, x : M) -> Self::Output { + self.g.apply(x) * self.α + } +} + +impl> Desc for Scaled { + fn desc(&self, τ : f64, x : M) -> M { + self.g.desc(τ * self.α, x) + } +} + +impl> Grad for Scaled { + fn grad(&self, x : &M) -> M::Tangent { + self.g.grad(x) * self.α + } +} + +impl> Prox for Scaled { + fn prox(&self, τ : f64, x : M) -> M { + self.g.prox(τ * self.α, x) + } +} \ No newline at end of file