| 283 + SubAssign<Self> |
283 + SubAssign<Self> |
| 284 + for<'b> SubAssign<&'b Self> |
284 + for<'b> SubAssign<&'b Self> |
| 285 + Neg<Output = <Self as AXPY>::Owned>, |
285 + Neg<Output = <Self as AXPY>::Owned>, |
| 286 { |
286 { |
| 287 fn dot<I: Instance<Self>>(&self, other: I) -> F { |
287 fn dot<I: Instance<Self>>(&self, other: I) -> F { |
| 288 let Pair(u, v) = other.decompose(); |
288 other.eval_decompose(|Pair(u, v)| self.0.dot(u) + self.1.dot(v)) |
| 289 self.0.dot(u) + self.1.dot(v) |
|
| 290 } |
289 } |
| 291 |
290 |
| 292 fn norm2_squared(&self) -> F { |
291 fn norm2_squared(&self) -> F { |
| 293 self.0.norm2_squared() + self.1.norm2_squared() |
292 self.0.norm2_squared() + self.1.norm2_squared() |
| 294 } |
293 } |
| 295 |
294 |
| 296 fn dist2_squared<I: Instance<Self>>(&self, other: I) -> F { |
295 fn dist2_squared<I: Instance<Self>>(&self, other: I) -> F { |
| 297 let Pair(u, v) = other.decompose(); |
296 other.eval_decompose(|Pair(u, v)| self.0.dist2_squared(u) + self.1.dist2_squared(v)) |
| 298 self.0.dist2_squared(u) + self.1.dist2_squared(v) |
|
| 299 } |
297 } |
| 300 } |
298 } |
| 301 |
299 |
| 302 impl<F, A, B, U, V> AXPY<Pair<U, V>> for Pair<A, B> |
300 impl<F, A, B, U, V> AXPY<Pair<U, V>> for Pair<A, B> |
| 303 where |
301 where |
| 314 { |
312 { |
| 315 type Field = F; |
313 type Field = F; |
| 316 type Owned = Pair<A::Owned, B::Owned>; |
314 type Owned = Pair<A::Owned, B::Owned>; |
| 317 |
315 |
| 318 fn axpy<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I, β: F) { |
316 fn axpy<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I, β: F) { |
| 319 let Pair(u, v) = x.decompose(); |
317 x.eval_decompose(|Pair(u, v)| { |
| 320 self.0.axpy(α, u, β); |
318 self.0.axpy(α, u, β); |
| 321 self.1.axpy(α, v, β); |
319 self.1.axpy(α, v, β); |
| |
320 }) |
| 322 } |
321 } |
| 323 |
322 |
| 324 fn copy_from<I: Instance<Pair<U, V>>>(&mut self, x: I) { |
323 fn copy_from<I: Instance<Pair<U, V>>>(&mut self, x: I) { |
| 325 let Pair(u, v) = x.decompose(); |
324 x.eval_decompose(|Pair(u, v)| { |
| 326 self.0.copy_from(u); |
325 self.0.copy_from(u); |
| 327 self.1.copy_from(v); |
326 self.1.copy_from(v); |
| |
327 }) |
| 328 } |
328 } |
| 329 |
329 |
| 330 fn scale_from<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I) { |
330 fn scale_from<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I) { |
| 331 let Pair(u, v) = x.decompose(); |
331 x.eval_decompose(|Pair(u, v)| { |
| 332 self.0.scale_from(α, u); |
332 self.0.scale_from(α, u); |
| 333 self.1.scale_from(α, v); |
333 self.1.scale_from(α, v); |
| |
334 }) |
| 334 } |
335 } |
| 335 |
336 |
| 336 /// Return a similar zero as `self`. |
337 /// Return a similar zero as `self`. |
| 337 fn similar_origin(&self) -> Self::Owned { |
338 fn similar_origin(&self) -> Self::Owned { |
| 338 Pair(self.0.similar_origin(), self.1.similar_origin()) |
339 Pair(self.0.similar_origin(), self.1.similar_origin()) |
| 382 D: Decomposition<A>, |
383 D: Decomposition<A>, |
| 383 Q: Decomposition<B>, |
384 Q: Decomposition<B>, |
| 384 U: Instance<A, D>, |
385 U: Instance<A, D>, |
| 385 V: Instance<B, Q>, |
386 V: Instance<B, Q>, |
| 386 { |
387 { |
| 387 #[inline] |
388 fn eval_decompose<'b, R>( |
| 388 fn decompose<'b>( |
|
| 389 self, |
389 self, |
| 390 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b> |
390 f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, |
| 391 where |
391 ) -> R |
| |
392 where |
| |
393 Pair<A, B>: 'b, |
| 392 Self: 'b, |
394 Self: 'b, |
| |
395 { |
| |
396 self.0 |
| |
397 .eval_decompose(|a| self.1.eval_decompose(|b| f(Pair(a, b)))) |
| |
398 } |
| |
399 |
| |
400 fn eval_ref_decompose<'b, R>( |
| |
401 &'b self, |
| |
402 f: impl FnOnce(Pair<D::Reference<'b>, Q::Reference<'b>>) -> R, |
| |
403 ) -> R |
| |
404 where |
| 393 Pair<A, B>: 'b, |
405 Pair<A, B>: 'b, |
| |
406 Self: 'b, |
| 394 { |
407 { |
| 395 Pair(self.0.decompose(), self.1.decompose()) |
408 self.0 |
| 396 } |
409 .eval_ref_decompose(|a| self.1.eval_ref_decompose(|b| f(Pair(a, b)))) |
| 397 |
|
| 398 #[inline] |
|
| 399 fn ref_instance( |
|
| 400 &self, |
|
| 401 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Reference<'_> { |
|
| 402 Pair(self.0.ref_instance(), self.1.ref_instance()) |
|
| 403 } |
410 } |
| 404 |
411 |
| 405 #[inline] |
412 #[inline] |
| 406 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
413 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
| 407 where |
414 where |
| 425 U: Instance<A, D>, |
432 U: Instance<A, D>, |
| 426 V: Instance<B, Q>, |
433 V: Instance<B, Q>, |
| 427 &'a U: Instance<A, D>, |
434 &'a U: Instance<A, D>, |
| 428 &'a V: Instance<B, Q>, |
435 &'a V: Instance<B, Q>, |
| 429 { |
436 { |
| 430 #[inline] |
437 fn eval_decompose<'b, R>( |
| 431 fn decompose<'b>( |
|
| 432 self, |
438 self, |
| 433 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b> |
439 f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, |
| 434 where |
440 ) -> R |
| |
441 where |
| |
442 Pair<A, B>: 'b, |
| 435 Self: 'b, |
443 Self: 'b, |
| |
444 { |
| |
445 self.0.eval_ref_decompose(|a| { |
| |
446 self.1 |
| |
447 .eval_ref_decompose(|b| f(Pair(D::lift(a), Q::lift(b)))) |
| |
448 }) |
| |
449 } |
| |
450 |
| |
451 fn eval_ref_decompose<'b, R>( |
| |
452 &'b self, |
| |
453 f: impl FnOnce(Pair<D::Reference<'b>, Q::Reference<'b>>) -> R, |
| |
454 ) -> R |
| |
455 where |
| 436 Pair<A, B>: 'b, |
456 Pair<A, B>: 'b, |
| |
457 Self: 'b, |
| 437 { |
458 { |
| 438 Pair( |
459 self.0 |
| 439 D::lift(self.0.ref_instance()), |
460 .eval_ref_decompose(|a| self.1.eval_ref_decompose(|b| f(Pair(a, b)))) |
| 440 Q::lift(self.1.ref_instance()), |
|
| 441 ) |
|
| 442 } |
|
| 443 |
|
| 444 #[inline] |
|
| 445 fn ref_instance( |
|
| 446 &self, |
|
| 447 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Reference<'_> { |
|
| 448 Pair(self.0.ref_instance(), self.1.ref_instance()) |
|
| 449 } |
461 } |
| 450 |
462 |
| 451 #[inline] |
463 #[inline] |
| 452 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
464 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
| 453 where |
465 where |