| 97 M::Codomain: std::iter::Sum + Clone, |
97 M::Codomain: std::iter::Sum + Clone, |
| 98 { |
98 { |
| 99 type Codomain = M::Codomain; |
99 type Codomain = M::Codomain; |
| 100 |
100 |
| 101 fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain { |
101 fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain { |
| 102 let xr = x.ref_instance(); |
102 x.eval_ref_decompose(|xr| self.0.iter().map(|c| c.apply(xr)).sum()) |
| 103 self.0.iter().map(|c| c.apply(xr)).sum() |
|
| 104 } |
103 } |
| 105 } |
104 } |
| 106 |
105 |
| 107 impl<Domain, M> DifferentiableImpl<Domain> for MappingSum<M> |
106 impl<Domain, M> DifferentiableImpl<Domain> for MappingSum<M> |
| 108 where |
107 where |
| 111 M::DerivativeDomain: std::iter::Sum, |
110 M::DerivativeDomain: std::iter::Sum, |
| 112 { |
111 { |
| 113 type Derivative = M::DerivativeDomain; |
112 type Derivative = M::DerivativeDomain; |
| 114 |
113 |
| 115 fn differential_impl<I: Instance<Domain>>(&self, x: I) -> Self::Derivative { |
114 fn differential_impl<I: Instance<Domain>>(&self, x: I) -> Self::Derivative { |
| 116 let xr = x.ref_instance(); |
115 x.eval_ref_decompose(|xr| self.0.iter().map(|c| c.differential(xr)).sum()) |
| 117 self.0.iter().map(|c| c.differential(xr)).sum() |
|
| 118 } |
116 } |
| 119 } |
117 } |