1 /*! |
1 /*! |
2 Implementation of scaling of functions on a manifold by a scalar. |
2 Implementation of scaling of functions on a manifold by a scalar. |
3 */ |
3 */ |
4 |
4 |
5 use alg_tools::mapping::Apply; |
5 use alg_tools::mapping::{Mapping, Instance}; |
6 use crate::manifold::ManifoldPoint; |
6 use crate::manifold::ManifoldPoint; |
7 use crate::fb::{Grad, Desc, Prox}; |
7 use crate::fb::{Grad, Desc, Prox}; |
8 |
8 |
9 /// Structure for a function of type `G`, scaled by a scalar. |
9 /// Structure for a function of type `G`, scaled by a scalar. |
10 pub struct Scaled<G> { |
10 pub struct Scaled<G> { |
20 pub fn new(α : f64, g : G) -> Self { |
20 pub fn new(α : f64, g : G) -> Self { |
21 Scaled{ α, g } |
21 Scaled{ α, g } |
22 } |
22 } |
23 } |
23 } |
24 |
24 |
25 impl<M, G : Apply<M, Output=f64>> Apply<M> for Scaled< G> { |
25 impl<M, G : Mapping<M, Codomain=f64>> Mapping<M> for Scaled< G> { |
26 type Output = f64; |
26 type Codomain = f64; |
27 |
27 |
28 fn apply(&self, x : M) -> Self::Output { |
28 fn apply<I : Instance<M>>(&self, x : I) -> Self::Codomain { |
29 self.g.apply(x) * self.α |
29 self.g.apply(x) * self.α |
30 } |
30 } |
31 } |
31 } |
32 |
32 |
33 impl<M : ManifoldPoint, G : Desc<M>> Desc<M> for Scaled<G> { |
33 impl<M : ManifoldPoint, G : Desc<M>> Desc<M> for Scaled<G> { |