| 4 TODO: This could be easily much more generic if `derive_more` could derive arithmetic |
4 TODO: This could be easily much more generic if `derive_more` could derive arithmetic |
| 5 operations on references. |
5 operations on references. |
| 6 */ |
6 */ |
| 7 |
7 |
| 8 use crate::euclidean::Euclidean; |
8 use crate::euclidean::Euclidean; |
| 9 use crate::instance::{Decomposition, DecompositionMut, Instance, InstanceMut, MyCow}; |
9 use crate::instance::{ |
| |
10 Decomposition, DecompositionMut, Instance, InstanceMut, Instantiated, MyCow, |
| |
11 }; |
| 10 use crate::linops::AXPY; |
12 use crate::linops::AXPY; |
| 11 use crate::loc::Loc; |
13 use crate::loc::Loc; |
| 12 use crate::mapping::Space; |
14 use crate::mapping::Space; |
| 13 use crate::norms::{HasDual, Norm, NormExponent, Normed, PairNorm, L2}; |
15 use crate::norms::{HasDual, Norm, NormExponent, Normed, PairNorm, L2}; |
| 14 use crate::types::{Float, Num}; |
16 use crate::types::{Float, Num}; |
| 365 = Pair<D::Decomposition<'b>, Q::Decomposition<'b>> |
367 = Pair<D::Decomposition<'b>, Q::Decomposition<'b>> |
| 366 where |
368 where |
| 367 Pair<A, B>: 'b; |
369 Pair<A, B>: 'b; |
| 368 } |
370 } |
| 369 |
371 |
| |
372 impl<A, B, U, V, D, Q> Instantiated<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V> |
| |
373 where |
| |
374 A: Space, |
| |
375 B: Space, |
| |
376 U: Instantiated<A, D>, |
| |
377 V: Instantiated<B, Q>, |
| |
378 D: Decomposition<A>, |
| |
379 Q: Decomposition<B>, |
| |
380 { |
| |
381 type RefInstance<'b> |
| |
382 = Pair<U::RefInstance<'b>, V::RefInstance<'b>> |
| |
383 where |
| |
384 Self: 'b; |
| |
385 |
| |
386 fn ref_inst(&self) -> Self::RefInstance<'_> { |
| |
387 Pair(self.0.ref_inst(), self.1.ref_inst()) |
| |
388 } |
| |
389 } |
| |
390 |
| 370 impl<A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V> |
391 impl<A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V> |
| 371 where |
392 where |
| 372 A: Space, |
393 A: Space, |
| 373 B: Space, |
394 B: Space, |
| 374 D: Decomposition<A>, |
395 D: Decomposition<A>, |
| 375 Q: Decomposition<B>, |
396 Q: Decomposition<B>, |
| 376 U: Instance<A, D>, |
397 U: Instance<A, D>, |
| 377 V: Instance<B, Q>, |
398 V: Instance<B, Q>, |
| 378 { |
399 { |
| |
400 type Instantiated = Pair<U::Instantiated, V::Instantiated>; |
| |
401 |
| |
402 fn instantiate(self) -> Self::Instantiated { |
| |
403 Pair(self.0.instantiate(), self.1.instantiate()) |
| |
404 } |
| |
405 |
| 379 fn eval_decompose<'b, R>( |
406 fn eval_decompose<'b, R>( |
| 380 self, |
407 self, |
| 381 f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, |
408 f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, |
| 382 ) -> R |
409 ) -> R |
| 383 where |
410 where |
| 423 U: Instance<A, D>, |
450 U: Instance<A, D>, |
| 424 V: Instance<B, Q>, |
451 V: Instance<B, Q>, |
| 425 &'a U: Instance<A, D>, |
452 &'a U: Instance<A, D>, |
| 426 &'a V: Instance<B, Q>, |
453 &'a V: Instance<B, Q>, |
| 427 { |
454 { |
| |
455 type Instantiated = |
| |
456 Pair<<&'a U as Instance<A, D>>::Instantiated, <&'a V as Instance<B, Q>>::Instantiated>; |
| |
457 |
| |
458 fn instantiate(self) -> Self::Instantiated { |
| |
459 let &Pair(ref u, ref v) = self; |
| |
460 Pair(u.instantiate(), v.instantiate()) |
| |
461 } |
| |
462 |
| 428 fn eval_decompose<'b, R>( |
463 fn eval_decompose<'b, R>( |
| 429 self, |
464 self, |
| 430 f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, |
465 f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, |
| 431 ) -> R |
466 ) -> R |
| 432 where |
467 where |