src/direct_product.rs

branch
dev
changeset 152
dab30b331f49
parent 151
402d717bb5c0
equal deleted inserted replaced
151:402d717bb5c0 152:dab30b331f49
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, Ownable}; 9 use crate::instance::{
10 Decomposition, DecompositionMut, EitherDecomp, Instance, InstanceMut, MyCow, Ownable,
11 };
10 use crate::linops::{VectorSpace, AXPY}; 12 use crate::linops::{VectorSpace, 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};
276 } 278 }
277 279
278 /// Returns an owned instance of a reference. 280 /// Returns an owned instance of a reference.
279 fn clone_owned(&self) -> Self::OwnedVariant { 281 fn clone_owned(&self) -> Self::OwnedVariant {
280 Pair(self.0.clone_owned(), self.1.clone_owned()) 282 Pair(self.0.clone_owned(), self.1.clone_owned())
283 }
284
285 fn owned_cow<'b>(self) -> MyCow<'b, Self::OwnedVariant> {
286 EitherDecomp::Owned(self.into_owned())
287 }
288
289 fn ref_owned_cow<'b>(&self) -> MyCow<'b, Self::OwnedVariant> {
290 EitherDecomp::Owned(self.into_owned())
281 } 291 }
282 } 292 }
283 293
284 /// We only support 'closed' `Euclidean` `Pair`s, as more general ones cause 294 /// We only support 'closed' `Euclidean` `Pair`s, as more general ones cause
285 /// compiler overflows. 295 /// compiler overflows.
437 Self: 'b, 447 Self: 'b,
438 { 448 {
439 self.0 449 self.0
440 .eval_ref_decompose(|a| self.1.eval_ref_decompose(|b| f(Pair(a, b)))) 450 .eval_ref_decompose(|a| self.1.eval_ref_decompose(|b| f(Pair(a, b))))
441 } 451 }
442
443 #[inline]
444 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
445 where
446 Self: 'b,
447 {
448 MyCow::Owned(Pair(self.0.own(), self.1.own()))
449 }
450
451 #[inline]
452 fn own(self) -> Pair<A, B> {
453 Pair(self.0.own(), self.1.own())
454 }
455 } 452 }
456 453
457 impl<'a, A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for &'a Pair<U, V> 454 impl<'a, A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for &'a Pair<U, V>
458 where 455 where
459 A: Space, 456 A: Space,
488 Self: 'b, 485 Self: 'b,
489 { 486 {
490 self.0 487 self.0
491 .eval_ref_decompose(|a| self.1.eval_ref_decompose(|b| f(Pair(a, b)))) 488 .eval_ref_decompose(|a| self.1.eval_ref_decompose(|b| f(Pair(a, b))))
492 } 489 }
493
494 #[inline]
495 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
496 where
497 Self: 'b,
498 {
499 MyCow::Owned(self.own())
500 }
501
502 #[inline]
503 fn own(self) -> Pair<A, B> {
504 let Pair(ref u, ref v) = self;
505 Pair(u.own(), v.own())
506 }
507 } 490 }
508 491
509 impl<A, B, D, Q> DecompositionMut<Pair<A, B>> for PairDecomposition<D, Q> 492 impl<A, B, D, Q> DecompositionMut<Pair<A, B>> for PairDecomposition<D, Q>
510 where 493 where
511 A: Space, 494 A: Space,

mercurial