| 1 /*! |
1 /*! |
| 2 Arithmetic of [`Mapping`]s. |
2 Arithmetic of [`Mapping`]s. |
| 3 */ |
3 */ |
| 4 |
4 |
| 5 use serde::Serialize; |
5 use serde::{Serialize, Deserialize}; |
| 6 use crate::types::*; |
6 use crate::types::*; |
| 7 use crate::instance::{Space, Instance}; |
7 use crate::instance::{Space, Instance}; |
| 8 use crate::mapping::{Mapping, DifferentiableImpl, DifferentiableMapping}; |
8 use crate::mapping::{Mapping, DifferentiableImpl, DifferentiableMapping}; |
| 9 |
9 |
| 10 /// A trait for encoding constant [`Float`] values |
10 /// A trait for encoding constant [`Float`] values |
| 20 #[inline] |
20 #[inline] |
| 21 fn value(&self) -> F { *self } |
21 fn value(&self) -> F { *self } |
| 22 } |
22 } |
| 23 |
23 |
| 24 /// Weighting of a [`Mapping`] by scalar multiplication. |
24 /// Weighting of a [`Mapping`] by scalar multiplication. |
| 25 #[derive(Copy,Clone,Debug,Serialize)] |
25 #[derive(Copy,Clone,Debug,Serialize,Deserialize)] |
| 26 pub struct Weighted<T, C : Constant> { |
26 pub struct Weighted<T, C : Constant> { |
| 27 /// The weight |
27 /// The weight |
| 28 pub weight : C, |
28 pub weight : C, |
| 29 /// The base [`Mapping`] being weighted. |
29 /// The base [`Mapping`] being weighted. |
| 30 pub base_fn : T, |
30 pub base_fn : T, |
| 71 self.base_fn.differential(x) * self.weight.value() |
71 self.base_fn.differential(x) * self.weight.value() |
| 72 } |
72 } |
| 73 } |
73 } |
| 74 |
74 |
| 75 /// A sum of [`Mapping`]s. |
75 /// A sum of [`Mapping`]s. |
| 76 #[derive(Serialize, Debug, Clone)] |
76 #[derive(Debug, Clone, Serialize, Deserialize)] |
| 77 pub struct MappingSum<M>(Vec<M>); |
77 pub struct MappingSum<M>(Vec<M>); |
| 78 |
78 |
| 79 impl< M> MappingSum<M> { |
79 impl< M> MappingSum<M> { |
| 80 /// Construct from an iterator. |
80 /// Construct from an iterator. |
| 81 pub fn new<I : IntoIterator<Item = M>>(iter : I) -> Self { |
81 pub fn new<I : IntoIterator<Item = M>>(iter : I) -> Self { |