Mon, 28 Apr 2025 23:16:56 -0500
Add generic scalar right multiplication for Pair
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | /*! |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | Direct products of the form $A \times B$. |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | TODO: This could be easily much more generic if `derive_more` could derive arithmetic |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | operations on references. |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | */ |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
8 | use crate::euclidean::Euclidean; |
| 94 | 9 | use crate::instance::{Decomposition, DecompositionMut, Instance, InstanceMut, MyCow}; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
10 | use crate::linops::AXPY; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
11 | use crate::loc::Loc; |
| 94 | 12 | use crate::mapping::Space; |
| 13 | use crate::norms::{HasDual, Norm, NormExponent, Normed, PairNorm, L2}; | |
| 14 | use crate::types::{Float, Num}; | |
| 15 | use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; | |
| 16 | use serde::{Deserialize, Serialize}; | |
| 17 | use std::clone::Clone; | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | |
| 94 | 19 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] |
| 20 | pub struct Pair<A, B>(pub A, pub B); | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | |
| 94 | 22 | impl<A, B> Pair<A, B> { |
| 23 | pub fn new(a: A, b: B) -> Pair<A, B> { | |
| 24 | Pair(a, b) | |
| 25 | } | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | |
| 94 | 28 | impl<A, B> From<(A, B)> for Pair<A, B> { |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | #[inline] |
| 94 | 30 | fn from((a, b): (A, B)) -> Pair<A, B> { |
| 31 | Pair(a, b) | |
| 32 | } | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
33 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
34 | |
| 94 | 35 | impl<A, B> From<Pair<A, B>> for (A, B) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
36 | #[inline] |
| 94 | 37 | fn from(Pair(a, b): Pair<A, B>) -> (A, B) { |
| 38 | (a, b) | |
| 39 | } | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | macro_rules! impl_binop { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
43 | (($a : ty, $b : ty), $trait : ident, $fn : ident, $refl:ident, $refr:ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
44 | impl_binop!(@doit: $a, $b, $trait, $fn; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
45 | maybe_lifetime!($refl, &'l Pair<$a,$b>), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
46 | (maybe_lifetime!($refl, &'l $a), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
47 | maybe_lifetime!($refl, &'l $b)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
48 | maybe_lifetime!($refr, &'r Pair<Ai,Bi>), |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
49 | (maybe_lifetime!($refr, &'r Ai), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
50 | maybe_lifetime!($refr, &'r Bi)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
51 | $refl, $refr); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
52 | }; |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
53 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
54 | (@doit: $a:ty, $b:ty, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
55 | $trait:ident, $fn:ident; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | $self:ty, ($aself:ty, $bself:ty); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | $in:ty, ($ain:ty, $bin:ty); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
58 | $refl:ident, $refr:ident) => { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
59 | impl<'l, 'r, Ai, Bi> $trait<$in> |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | for $self |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
61 | where $aself: $trait<$ain>, |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
62 | $bself: $trait<$bin> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
63 | type Output = Pair<<$aself as $trait<$ain>>::Output, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
64 | <$bself as $trait<$bin>>::Output>; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
65 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
66 | #[inline] |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
67 | fn $fn(self, y : $in) -> Self::Output { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
68 | Pair(maybe_ref!($refl, self.0).$fn(maybe_ref!($refr, y.0)), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
69 | maybe_ref!($refl, self.1).$fn(maybe_ref!($refr, y.1))) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
71 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
72 | }; |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
73 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
74 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
75 | macro_rules! impl_assignop { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
76 | (($a : ty, $b : ty), $trait : ident, $fn : ident, $refr:ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
77 | impl_assignop!(@doit: $a, $b, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
78 | $trait, $fn; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
79 | maybe_lifetime!($refr, &'r Pair<Ai,Bi>), |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
80 | (maybe_lifetime!($refr, &'r Ai), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
81 | maybe_lifetime!($refr, &'r Bi)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
82 | $refr); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
83 | }; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
84 | (@doit: $a : ty, $b : ty, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
85 | $trait:ident, $fn:ident; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | $in:ty, ($ain:ty, $bin:ty); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | $refr:ident) => { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
88 | impl<'r, Ai, Bi> $trait<$in> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
89 | for Pair<$a,$b> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
90 | where $a: $trait<$ain>, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
91 | $b: $trait<$bin> { |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
92 | #[inline] |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
93 | fn $fn(&mut self, y : $in) -> () { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
94 | self.0.$fn(maybe_ref!($refr, y.0)); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
95 | self.1.$fn(maybe_ref!($refr, y.1)); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
96 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
97 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
98 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
99 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
100 | |
|
103
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
101 | // macro_rules! impl_scalarop { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
102 | // (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
103 | // impl_scalarop!(@doit: $field, |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
104 | // $trait, $fn; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
105 | // maybe_lifetime!($refl, &'l Pair<$a,$b>), |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
106 | // (maybe_lifetime!($refl, &'l $a), |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
107 | // maybe_lifetime!($refl, &'l $b)); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
108 | // $refl); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
109 | // }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
110 | // (@doit: $field : ty, |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
111 | // $trait:ident, $fn:ident; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
112 | // $self:ty, ($aself:ty, $bself:ty); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
113 | // $refl:ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
114 | // // Scalar as Rhs |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
115 | // impl<'l> $trait<$field> |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
116 | // for $self |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
117 | // where $aself: $trait<$field>, |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
118 | // $bself: $trait<$field> { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
119 | // type Output = Pair<<$aself as $trait<$field>>::Output, |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
120 | // <$bself as $trait<$field>>::Output>; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
121 | // #[inline] |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
122 | // fn $fn(self, a : $field) -> Self::Output { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
123 | // Pair(maybe_ref!($refl, self.0).$fn(a), |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
124 | // maybe_ref!($refl, self.1).$fn(a)) |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
125 | // } |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
126 | // } |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
127 | // } |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
128 | // } |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
129 | // |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
130 | |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
131 | macro_rules! impl_scalarop_gen { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
132 | ($field : ty, $trait : ident, $fn : ident, $refl:ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
133 | impl_scalarop_gen!(@doit: $field, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
134 | $trait, $fn; |
|
103
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
135 | maybe_lifetime!($refl, &'l Pair<A,B>), |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
136 | (maybe_lifetime!($refl, &'l A), |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
137 | maybe_lifetime!($refl, &'l B)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
138 | $refl); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
139 | }; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
140 | (@doit: $field : ty, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
141 | $trait:ident, $fn:ident; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
142 | $self:ty, ($aself:ty, $bself:ty); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
143 | $refl:ident) => { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
144 | // Scalar as Rhs |
|
103
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
145 | impl<'l, A, B> $trait<$field> |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
146 | for $self |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
147 | where $aself: $trait<$field>, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
148 | $bself: $trait<$field> { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
149 | type Output = Pair<<$aself as $trait<$field>>::Output, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
150 | <$bself as $trait<$field>>::Output>; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
151 | #[inline] |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
152 | fn $fn(self, a : $field) -> Self::Output { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
153 | Pair(maybe_ref!($refl, self.0).$fn(a), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
154 | maybe_ref!($refl, self.1).$fn(a)) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
155 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
156 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
157 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
158 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
159 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
160 | // Not used due to compiler overflow |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
161 | #[allow(unused_macros)] |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
162 | macro_rules! impl_scalarlhs_op { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
163 | (($a : ty, $b : ty), $field : ty, $trait:ident, $fn:ident, $refr:ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
164 | impl_scalarlhs_op!(@doit: $trait, $fn, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
165 | maybe_lifetime!($refr, &'r Pair<$a,$b>), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
166 | (maybe_lifetime!($refr, &'r $a), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
167 | maybe_lifetime!($refr, &'r $b)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
168 | $refr, $field); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
169 | }; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
170 | (@doit: $trait:ident, $fn:ident, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
171 | $in:ty, ($ain:ty, $bin:ty); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
172 | $refr:ident, $field:ty) => { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
173 | impl<'r> $trait<$in> |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
174 | for $field |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
175 | where $field : $trait<$ain> |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
176 | + $trait<$bin> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
177 | type Output = Pair<<$field as $trait<$ain>>::Output, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
178 | <$field as $trait<$bin>>::Output>; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
179 | #[inline] |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
180 | fn $fn(self, x : $in) -> Self::Output { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
181 | Pair(self.$fn(maybe_ref!($refr, x.0)), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
182 | self.$fn(maybe_ref!($refr, x.1))) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
183 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
184 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
185 | }; |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
186 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
187 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
188 | macro_rules! impl_scalar_assignop { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
189 | (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => { |
| 94 | 190 | impl<'r> $trait<$field> for Pair<$a, $b> |
| 191 | where | |
| 192 | $a: $trait<$field>, | |
| 193 | $b: $trait<$field>, | |
| 194 | { | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
195 | #[inline] |
| 94 | 196 | fn $fn(&mut self, a: $field) -> () { |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
197 | self.0.$fn(a); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
198 | self.1.$fn(a); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
199 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
200 | } |
| 94 | 201 | }; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
202 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
203 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
204 | macro_rules! impl_unaryop { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
205 | (($a : ty, $b : ty), $trait:ident, $fn:ident, $refl:ident) => { |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
206 | impl_unaryop!(@doit: $trait, $fn; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
207 | maybe_lifetime!($refl, &'l Pair<$a,$b>), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
208 | (maybe_lifetime!($refl, &'l $a), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
209 | maybe_lifetime!($refl, &'l $b)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
210 | $refl); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
211 | }; |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
212 | (@doit: $trait:ident, $fn:ident; |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
213 | $self:ty, ($aself:ty, $bself:ty); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
214 | $refl : ident) => { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
215 | impl<'l> $trait |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
216 | for $self |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
217 | where $aself: $trait, |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
218 | $bself: $trait { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
219 | type Output = Pair<<$aself as $trait>::Output, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
220 | <$bself as $trait>::Output>; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
221 | #[inline] |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
222 | fn $fn(self) -> Self::Output { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
223 | Pair(maybe_ref!($refl, self.0).$fn(), |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
224 | maybe_ref!($refl, self.1).$fn()) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
225 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
226 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
227 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
228 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
229 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
230 | #[macro_export] |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
231 | macro_rules! impl_pair_vectorspace_ops { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
232 | (($a:ty, $b:ty), $field:ty) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
233 | impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
234 | impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
235 | impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
236 | impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); |
|
103
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
237 | // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
238 | // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div); |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
239 | // Compiler overflow |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
240 | // $( |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
241 | // impl_pair_vectorspace_ops!(@scalar_lhs, ($a, $b), $field, $impl_scalarlhs_op, Mul, mul); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
242 | // )* |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
243 | impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, MulAssign, mul_assign); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
244 | impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, DivAssign, div_assign); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
245 | impl_pair_vectorspace_ops!(@unary, ($a, $b), Neg, neg); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
246 | }; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
247 | (@binary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
248 | impl_binop!(($a, $b), $trait, $fn, ref, ref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
249 | impl_binop!(($a, $b), $trait, $fn, ref, noref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
250 | impl_binop!(($a, $b), $trait, $fn, noref, ref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
251 | impl_binop!(($a, $b), $trait, $fn, noref, noref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
252 | }; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
253 | (@assign, ($a : ty, $b : ty), $trait : ident, $fn :ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
254 | impl_assignop!(($a, $b), $trait, $fn, ref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
255 | impl_assignop!(($a, $b), $trait, $fn, noref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
256 | }; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
257 | (@scalar, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn :ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
258 | impl_scalarop!(($a, $b), $field, $trait, $fn, ref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
259 | impl_scalarop!(($a, $b), $field, $trait, $fn, noref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
260 | }; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
261 | (@scalar_lhs, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
262 | impl_scalarlhs_op!(($a, $b), $field, $trait, $fn, ref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
263 | impl_scalarlhs_op!(($a, $b), $field, $trait, $fn, noref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
264 | }; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
265 | (@scalar_assign, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
266 | impl_scalar_assignop!(($a, $b), $field, $trait, $fn); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
267 | }; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
268 | (@unary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
269 | impl_unaryop!(($a, $b), $trait, $fn, ref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
270 | impl_unaryop!(($a, $b), $trait, $fn, noref); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
271 | }; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
272 | } |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
273 | |
|
103
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
274 | // TODO: add what we can here. |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
275 | #[macro_export] |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
276 | macro_rules! impl_pair_vectorspace_ops_gen { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
277 | ($field:ty) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
278 | // impl_pair_vectorspace_ops_gen!(@binary, Add, add); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
279 | // impl_pair_vectorspace_ops_gen!(@binary, Sub, sub); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
280 | // impl_pair_vectorspace_ops_gen!(@assign, AddAssign, add_assign); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
281 | // impl_pair_vectorspace_ops_gen!(@assign, SubAssign, sub_assign); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
282 | impl_pair_vectorspace_ops_gen!(@scalar, $field, Mul, mul); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
283 | impl_pair_vectorspace_ops_gen!(@scalar, $field, Div, div); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
284 | // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, MulAssign, mul_assign); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
285 | // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, DivAssign, div_assign); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
286 | // impl_pair_vectorspace_ops_gen!(@unary, Neg, neg); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
287 | }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
288 | // (@binary, $trait : ident, $fn : ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
289 | // impl_binop_gen!(($a, $b), $trait, $fn, ref, ref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
290 | // impl_binop_gen!(($a, $b), $trait, $fn, ref, noref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
291 | // impl_binop_gen!(($a, $b), $trait, $fn, noref, ref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
292 | // impl_binop_gen!(($a, $b), $trait, $fn, noref, noref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
293 | // }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
294 | // (@assign, $trait : ident, $fn :ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
295 | // impl_assignop_gen!(($a, $b), $trait, $fn, ref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
296 | // impl_assignop_gen!(($a, $b), $trait, $fn, noref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
297 | // }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
298 | (@scalar, $field : ty, $trait : ident, $fn :ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
299 | impl_scalarop_gen!($field, $trait, $fn, ref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
300 | impl_scalarop_gen!($field, $trait, $fn, noref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
301 | }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
302 | // (@scalar_lhs, $field : ty, $trait : ident, $fn : ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
303 | // impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, ref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
304 | // impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, noref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
305 | // }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
306 | // (@scalar_assign, $field : ty, $trait : ident, $fn : ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
307 | // impl_scalar_assignop_gen!(($a, $b), $field, $trait, $fn); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
308 | // }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
309 | // (@unary, $trait : ident, $fn : ident) => { |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
310 | // impl_unaryop_gen!(($a, $b), $trait, $fn, ref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
311 | // impl_unaryop_gen!(($a, $b), $trait, $fn, noref); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
312 | // }; |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
313 | } |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
314 | |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
315 | impl_pair_vectorspace_ops_gen!(f32); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
316 | impl_pair_vectorspace_ops_gen!(f64); |
|
e98e1da2530d
Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
317 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
318 | impl_pair_vectorspace_ops!((f32, f32), f32); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
319 | impl_pair_vectorspace_ops!((f64, f64), f64); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
320 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
321 | type PairOutput<F, A, B> = Pair<<A as Euclidean<F>>::Output, <B as Euclidean<F>>::Output>; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
322 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
323 | impl<A, B, F> Euclidean<F> for Pair<A, B> |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
324 | where |
| 94 | 325 | A: Euclidean<F>, |
| 326 | B: Euclidean<F>, | |
| 327 | F: Float, | |
| 328 | PairOutput<F, A, B>: Euclidean<F>, | |
| 329 | Self: Sized | |
| 330 | + Mul<F, Output = PairOutput<F, A, B>> | |
| 331 | + MulAssign<F> | |
| 332 | + Div<F, Output = PairOutput<F, A, B>> | |
| 333 | + DivAssign<F> | |
| 334 | + Add<Self, Output = PairOutput<F, A, B>> | |
| 335 | + Sub<Self, Output = PairOutput<F, A, B>> | |
| 336 | + for<'b> Add<&'b Self, Output = PairOutput<F, A, B>> | |
| 337 | + for<'b> Sub<&'b Self, Output = PairOutput<F, A, B>> | |
| 338 | + AddAssign<Self> | |
| 339 | + for<'b> AddAssign<&'b Self> | |
| 340 | + SubAssign<Self> | |
| 341 | + for<'b> SubAssign<&'b Self> | |
| 342 | + Neg<Output = PairOutput<F, A, B>>, | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
343 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
344 | type Output = PairOutput<F, A, B>; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
345 | |
| 94 | 346 | fn dot<I: Instance<Self>>(&self, other: I) -> F { |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
347 | let Pair(u, v) = other.decompose(); |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
348 | self.0.dot(u) + self.1.dot(v) |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
349 | } |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
350 | |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
351 | fn norm2_squared(&self) -> F { |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
352 | self.0.norm2_squared() + self.1.norm2_squared() |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
353 | } |
|
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
354 | |
| 94 | 355 | fn dist2_squared<I: Instance<Self>>(&self, other: I) -> F { |
|
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
356 | let Pair(u, v) = other.decompose(); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
357 | self.0.dist2_squared(u) + self.1.dist2_squared(v) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
358 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
359 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
360 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
361 | impl<F, A, B, U, V> AXPY<F, Pair<U, V>> for Pair<A, B> |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
362 | where |
| 94 | 363 | U: Space, |
| 364 | V: Space, | |
| 365 | A: AXPY<F, U>, | |
| 366 | B: AXPY<F, V>, | |
| 367 | F: Num, | |
| 368 | Self: MulAssign<F>, | |
| 369 | Pair<A, B>: MulAssign<F>, | |
| 370 | Pair<A::Owned, B::Owned>: AXPY<F, Pair<U, V>>, | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
371 | { |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
372 | type Owned = Pair<A::Owned, B::Owned>; |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
373 | |
| 94 | 374 | fn axpy<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I, β: F) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
375 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
376 | self.0.axpy(α, u, β); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
377 | self.1.axpy(α, v, β); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
378 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
379 | |
| 94 | 380 | fn copy_from<I: Instance<Pair<U, V>>>(&mut self, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
381 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
382 | self.0.copy_from(u); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
383 | self.1.copy_from(v); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
384 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
385 | |
| 94 | 386 | fn scale_from<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
387 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
388 | self.0.scale_from(α, u); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
389 | self.1.scale_from(α, v); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
390 | } |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
391 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
392 | /// Return a similar zero as `self`. |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
393 | fn similar_origin(&self) -> Self::Owned { |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
394 | Pair(self.0.similar_origin(), self.1.similar_origin()) |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
395 | } |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
396 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
397 | /// Set self to zero. |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
398 | fn set_zero(&mut self) { |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
399 | self.0.set_zero(); |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
400 | self.1.set_zero(); |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
401 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
402 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
403 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
404 | /// [`Decomposition`] for working with [`Pair`]s. |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
405 | #[derive(Copy, Clone, Debug)] |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
406 | pub struct PairDecomposition<D, Q>(D, Q); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
407 | |
| 94 | 408 | impl<A: Space, B: Space> Space for Pair<A, B> { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
409 | type Decomp = PairDecomposition<A::Decomp, B::Decomp>; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
410 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
411 | |
| 94 | 412 | impl<A, B, D, Q> Decomposition<Pair<A, B>> for PairDecomposition<D, Q> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
413 | where |
| 94 | 414 | A: Space, |
| 415 | B: Space, | |
| 416 | D: Decomposition<A>, | |
| 417 | Q: Decomposition<B>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
418 | { |
| 94 | 419 | type Decomposition<'b> |
| 420 | = Pair<D::Decomposition<'b>, Q::Decomposition<'b>> | |
| 421 | where | |
| 422 | Pair<A, B>: 'b; | |
| 423 | type Reference<'b> | |
| 424 | = Pair<D::Reference<'b>, Q::Reference<'b>> | |
| 425 | where | |
| 426 | Pair<A, B>: 'b; | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
427 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
428 | #[inline] |
| 94 | 429 | fn lift<'b>(Pair(u, v): Self::Reference<'b>) -> Self::Decomposition<'b> { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
430 | Pair(D::lift(u), Q::lift(v)) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
431 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
432 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
433 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
434 | impl<A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
435 | where |
| 94 | 436 | A: Space, |
| 437 | B: Space, | |
| 438 | D: Decomposition<A>, | |
| 439 | Q: Decomposition<B>, | |
| 440 | U: Instance<A, D>, | |
| 441 | V: Instance<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
442 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
443 | #[inline] |
| 94 | 444 | fn decompose<'b>( |
| 445 | self, | |
| 446 | ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b> | |
| 447 | where | |
| 448 | Self: 'b, | |
| 449 | Pair<A, B>: 'b, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
450 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
451 | Pair(self.0.decompose(), self.1.decompose()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
452 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
453 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
454 | #[inline] |
| 94 | 455 | fn ref_instance( |
| 456 | &self, | |
| 457 | ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Reference<'_> { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
458 | Pair(self.0.ref_instance(), self.1.ref_instance()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
459 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
460 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
461 | #[inline] |
| 94 | 462 | fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
| 463 | where | |
| 464 | Self: 'b, | |
| 465 | { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
466 | MyCow::Owned(Pair(self.0.own(), self.1.own())) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
467 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
468 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
469 | #[inline] |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
470 | fn own(self) -> Pair<A, B> { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
471 | Pair(self.0.own(), self.1.own()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
472 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
473 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
474 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
475 | impl<'a, A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for &'a Pair<U, V> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
476 | where |
| 94 | 477 | A: Space, |
| 478 | B: Space, | |
| 479 | D: Decomposition<A>, | |
| 480 | Q: Decomposition<B>, | |
| 481 | U: Instance<A, D>, | |
| 482 | V: Instance<B, Q>, | |
| 483 | &'a U: Instance<A, D>, | |
| 484 | &'a V: Instance<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
485 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
486 | #[inline] |
| 94 | 487 | fn decompose<'b>( |
| 488 | self, | |
| 489 | ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b> | |
| 490 | where | |
| 491 | Self: 'b, | |
| 492 | Pair<A, B>: 'b, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
493 | { |
| 94 | 494 | Pair( |
| 495 | D::lift(self.0.ref_instance()), | |
| 496 | Q::lift(self.1.ref_instance()), | |
| 497 | ) | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
498 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
499 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
500 | #[inline] |
| 94 | 501 | fn ref_instance( |
| 502 | &self, | |
| 503 | ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Reference<'_> { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
504 | Pair(self.0.ref_instance(), self.1.ref_instance()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
505 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
506 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
507 | #[inline] |
| 94 | 508 | fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
| 509 | where | |
| 510 | Self: 'b, | |
| 511 | { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
512 | MyCow::Owned(self.own()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
513 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
514 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
515 | #[inline] |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
516 | fn own(self) -> Pair<A, B> { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
517 | let Pair(ref u, ref v) = self; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
518 | Pair(u.own(), v.own()) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
519 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
520 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
521 | |
| 94 | 522 | impl<A, B, D, Q> DecompositionMut<Pair<A, B>> for PairDecomposition<D, Q> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
523 | where |
| 94 | 524 | A: Space, |
| 525 | B: Space, | |
| 526 | D: DecompositionMut<A>, | |
| 527 | Q: DecompositionMut<B>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
528 | { |
| 94 | 529 | type ReferenceMut<'b> |
| 530 | = Pair<D::ReferenceMut<'b>, Q::ReferenceMut<'b>> | |
| 531 | where | |
| 532 | Pair<A, B>: 'b; | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
533 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
534 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
535 | impl<A, B, U, V, D, Q> InstanceMut<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
536 | where |
| 94 | 537 | A: Space, |
| 538 | B: Space, | |
| 539 | D: DecompositionMut<A>, | |
| 540 | Q: DecompositionMut<B>, | |
| 541 | U: InstanceMut<A, D>, | |
| 542 | V: InstanceMut<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
543 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
544 | #[inline] |
| 94 | 545 | fn ref_instance_mut( |
| 546 | &mut self, | |
| 547 | ) -> <PairDecomposition<D, Q> as DecompositionMut<Pair<A, B>>>::ReferenceMut<'_> { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
548 | Pair(self.0.ref_instance_mut(), self.1.ref_instance_mut()) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
549 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
550 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
551 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
552 | impl<'a, A, B, U, V, D, Q> InstanceMut<Pair<A, B>, PairDecomposition<D, Q>> for &'a mut Pair<U, V> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
553 | where |
| 94 | 554 | A: Space, |
| 555 | B: Space, | |
| 556 | D: DecompositionMut<A>, | |
| 557 | Q: DecompositionMut<B>, | |
| 558 | U: InstanceMut<A, D>, | |
| 559 | V: InstanceMut<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
560 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
561 | #[inline] |
| 94 | 562 | fn ref_instance_mut( |
| 563 | &mut self, | |
| 564 | ) -> <PairDecomposition<D, Q> as DecompositionMut<Pair<A, B>>>::ReferenceMut<'_> { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
565 | Pair(self.0.ref_instance_mut(), self.1.ref_instance_mut()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
566 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
567 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
568 | |
| 94 | 569 | impl<F, A, B, ExpA, ExpB, ExpJ> Norm<F, PairNorm<ExpA, ExpB, ExpJ>> for Pair<A, B> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
570 | where |
| 94 | 571 | F: Num, |
| 572 | ExpA: NormExponent, | |
| 573 | ExpB: NormExponent, | |
| 574 | ExpJ: NormExponent, | |
| 575 | A: Norm<F, ExpA>, | |
| 576 | B: Norm<F, ExpB>, | |
| 577 | Loc<F, 2>: Norm<F, ExpJ>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
578 | { |
| 94 | 579 | fn norm(&self, PairNorm(expa, expb, expj): PairNorm<ExpA, ExpB, ExpJ>) -> F { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
580 | Loc([self.0.norm(expa), self.1.norm(expb)]).norm(expj) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
581 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
582 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
583 | |
| 94 | 584 | impl<F: Float, A, B> Normed<F> for Pair<A, B> |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
585 | where |
| 94 | 586 | A: Normed<F>, |
| 587 | B: Normed<F>, | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
588 | { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
589 | type NormExp = PairNorm<A::NormExp, B::NormExp, L2>; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
590 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
591 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
592 | fn norm_exponent(&self) -> Self::NormExp { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
593 | PairNorm(self.0.norm_exponent(), self.1.norm_exponent(), L2) |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
594 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
595 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
596 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
597 | fn is_zero(&self) -> bool { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
598 | self.0.is_zero() && self.1.is_zero() |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
599 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
600 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
601 | |
| 94 | 602 | impl<F: Float, A, B> HasDual<F> for Pair<A, B> |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
603 | where |
| 94 | 604 | A: HasDual<F>, |
| 605 | B: HasDual<F>, | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
606 | { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
607 | type DualSpace = Pair<A::DualSpace, B::DualSpace>; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
608 | } |