src/direct_product.rs

branch
dev
changeset 129
d2994e34a5f5
parent 124
6aa955ad8122
child 130
0a689881b0f1
equal deleted inserted replaced
128:f75bf34adda0 129:d2994e34a5f5
242 242
243 impl_binary_mut!(AddAssign, add_assign); 243 impl_binary_mut!(AddAssign, add_assign);
244 impl_binary_mut!(SubAssign, sub_assign); 244 impl_binary_mut!(SubAssign, sub_assign);
245 245
246 macro_rules! impl_scalar_mut { 246 macro_rules! impl_scalar_mut {
247 ($trait:ident, $fn:ident, $F:ty) => { 247 ($trait:ident, $fn:ident) => {
248 impl<'a, A, B> $trait<$F> for Pair<A, B> 248 impl<'a, A, B, F: Num> $trait<F> for Pair<A, B>
249 where 249 where
250 A: $trait<$F>, 250 A: $trait<F>,
251 B: $trait<$F>, 251 B: $trait<F>,
252 { 252 {
253 fn $fn(&mut self, t: $F) { 253 fn $fn(&mut self, t: F) {
254 let Pair(ref mut a, ref mut b) = self; 254 let Pair(ref mut a, ref mut b) = self;
255 a.$fn(t); 255 a.$fn(t);
256 b.$fn(t); 256 b.$fn(t);
257 } 257 }
258 } 258 }
259 }; 259 };
260 } 260 }
261 261
262 impl_scalar_mut!(MulAssign, mul_assign, f32); 262 impl_scalar_mut!(MulAssign, mul_assign);
263 impl_scalar_mut!(MulAssign, mul_assign, f64); 263 impl_scalar_mut!(DivAssign, div_assign);
264 impl_scalar_mut!(DivAssign, div_assign, f32);
265 impl_scalar_mut!(DivAssign, div_assign, f64);
266 264
267 /// We only support 'closed' `Euclidean` `Pair`s, as more general ones cause 265 /// We only support 'closed' `Euclidean` `Pair`s, as more general ones cause
268 /// compiler overflows. 266 /// compiler overflows.
269 impl<A, B, F: Float> Euclidean<F> for Pair<A, B> 267 impl<A, B, F: Float> Euclidean<F> for Pair<A, B>
270 where 268 where
301 let Pair(u, v) = other.decompose(); 299 let Pair(u, v) = other.decompose();
302 self.0.dist2_squared(u) + self.1.dist2_squared(v) 300 self.0.dist2_squared(u) + self.1.dist2_squared(v)
303 } 301 }
304 } 302 }
305 303
306 impl<F, A, B, U, V> AXPY<F, Pair<U, V>> for Pair<A, B> 304 impl<F, A, B, U, V> AXPY<Pair<U, V>> for Pair<A, B>
307 where 305 where
308 U: Space, 306 U: Space,
309 V: Space, 307 V: Space,
310 A: AXPY<F, U>, 308 A: AXPY<U, Field = F>,
311 B: AXPY<F, V>, 309 B: AXPY<V, Field = F>,
312 F: Num, 310 F: Num,
313 Self: MulAssign<F>, 311 Self: MulAssign<F>,
314 Pair<A, B>: MulAssign<F>, 312 Pair<A, B>: MulAssign<F>,
315 Pair<A::Owned, B::Owned>: AXPY<F, Pair<U, V>>, 313 //A::Owned: MulAssign<F>,
316 { 314 //B::Owned: MulAssign<F>,
315 //Pair<A::Owned, B::Owned>: AXPY<Pair<U, V>, Field = F>,
316 {
317 type Field = F;
317 type Owned = Pair<A::Owned, B::Owned>; 318 type Owned = Pair<A::Owned, B::Owned>;
318 319
319 fn axpy<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I, β: F) { 320 fn axpy<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I, β: F) {
320 let Pair(u, v) = x.decompose(); 321 let Pair(u, v) = x.decompose();
321 self.0.axpy(α, u, β); 322 self.0.axpy(α, u, β);

mercurial