src/direct_product.rs

branch
dev
changeset 187
76c77e49581a
parent 182
71fa6d3df947
child 189
14193146d8f2
equal deleted inserted replaced
186:afe04e6b4a5b 187:76c77e49581a
8 use crate::euclidean::Euclidean; 8 use crate::euclidean::Euclidean;
9 use crate::instance::{Decomposition, DecompositionMut, Instance, InstanceMut, MyCow, Ownable}; 9 use crate::instance::{Decomposition, DecompositionMut, Instance, InstanceMut, MyCow, Ownable};
10 use crate::linops::{VectorSpace, AXPY}; 10 use crate::linops::{VectorSpace, AXPY};
11 use crate::loc::Loc; 11 use crate::loc::Loc;
12 use crate::mapping::Space; 12 use crate::mapping::Space;
13 use crate::norms::{HasDual, Norm, NormExponent, Normed, PairNorm, L2}; 13 use crate::norms::{Dist, HasDual, Norm, NormExponent, Normed, PairNorm, L2};
14 use crate::types::{Float, Num}; 14 use crate::types::{Float, Num};
15 use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; 15 use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
16 use serde::{Deserialize, Serialize}; 16 use serde::{Deserialize, Serialize};
17 use std::clone::Clone; 17 use std::clone::Clone;
18 18
566 fn norm(&self, PairNorm(expa, expb, expj): PairNorm<ExpA, ExpB, ExpJ>) -> F { 566 fn norm(&self, PairNorm(expa, expb, expj): PairNorm<ExpA, ExpB, ExpJ>) -> F {
567 Loc([self.0.norm(expa), self.1.norm(expb)]).norm(expj) 567 Loc([self.0.norm(expa), self.1.norm(expb)]).norm(expj)
568 } 568 }
569 } 569 }
570 570
571 impl<F, A, B, ExpA, ExpB, ExpJ> Dist<PairNorm<ExpA, ExpB, ExpJ>, F> for Pair<A, B>
572 where
573 F: Num,
574 ExpA: NormExponent,
575 ExpB: NormExponent,
576 ExpJ: NormExponent,
577 A: Dist<ExpA, F>,
578 B: Dist<ExpB, F>,
579 Loc<2, F>: Norm<ExpJ, F>,
580 {
581 fn dist<I: Instance<Self>>(
582 &self,
583 x: I,
584 PairNorm(expa, expb, expj): PairNorm<ExpA, ExpB, ExpJ>,
585 ) -> F {
586 x.eval_decompose(|Pair(x1, x2)| {
587 Loc([self.0.dist(x1, expa), self.1.dist(x2, expb)]).norm(expj)
588 })
589 }
590 }
591
592 impl<F, A, B> Norm<L2, F> for Pair<A, B>
593 where
594 F: Num,
595 A: Norm<L2, F>,
596 B: Norm<L2, F>,
597 Loc<2, F>: Norm<L2, F>,
598 {
599 fn norm(&self, _: L2) -> F {
600 Loc([self.0.norm(L2), self.1.norm(L2)]).norm(L2)
601 }
602 }
603
604 impl<F, A, B> Dist<L2, F> for Pair<A, B>
605 where
606 F: Num,
607 A: Dist<L2, F>,
608 B: Dist<L2, F>,
609 Loc<2, F>: Norm<L2, F>,
610 {
611 fn dist<I: Instance<Self>>(&self, x: I, _: L2) -> F {
612 x.eval_decompose(|Pair(x1, x2)| Loc([self.0.dist(x1, L2), self.1.dist(x2, L2)]).norm(L2))
613 }
614 }
615
571 impl<F: Float, A, B> Normed<F> for Pair<A, B> 616 impl<F: Float, A, B> Normed<F> for Pair<A, B>
572 where 617 where
573 A: Normed<F>, 618 A: Normed<F>,
574 B: Normed<F>, 619 B: Normed<F>,
575 { 620 {

mercurial