src/operator_arithmetic.rs

branch
dev
changeset 133
2b13f8a0c8ba
parent 128
f75bf34adda0
child 137
d5dfcb6abcf5
child 150
c4e394a9c84c
equal deleted inserted replaced
132:89371dc4d637 133:2b13f8a0c8ba
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 }

mercurial