Thu, 01 May 2025 02:13:44 -0500
reduce restriction
|
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 | |
| 115 | 42 | macro_rules! impl_unary { |
| 43 | ($trait:ident, $fn:ident) => { | |
| 44 | impl<A, B> $trait for Pair<A, B> | |
| 45 | where | |
| 46 | A: $trait, | |
| 47 | B: $trait, | |
| 48 | { | |
| 49 | type Output = Pair<A::Output, B::Output>; | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
50 | fn $fn(self) -> Self::Output { |
| 115 | 51 | let Pair(a, b) = self; |
| 52 | Pair(a.$fn(), b.$fn()) | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
53 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | } |
| 115 | 55 | |
| 56 | impl<'a, A, B> $trait for &'a Pair<A, B> | |
| 57 | where | |
| 58 | &'a A: $trait, | |
| 59 | &'a B: $trait, | |
| 60 | { | |
| 61 | type Output = Pair<<&'a A as $trait>::Output, <&'a B as $trait>::Output>; | |
| 62 | fn $fn(self) -> Self::Output { | |
| 63 | let Pair(ref a, ref b) = self; | |
| 64 | Pair(a.$fn(), b.$fn()) | |
| 65 | } | |
| 66 | } | |
| 67 | }; | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
68 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
69 | |
| 115 | 70 | impl_unary!(Neg, neg); |
| 71 | ||
| 116 | 72 | macro_rules! impl_binary { |
| 73 | ($trait:ident, $fn:ident) => { | |
| 74 | impl<A, B, C, D> $trait<Pair<C, D>> for Pair<A, B> | |
| 75 | where | |
| 76 | A: $trait<C>, | |
| 77 | B: $trait<D>, | |
| 78 | { | |
| 79 | type Output = Pair<A::Output, B::Output>; | |
| 80 | fn $fn(self, Pair(c, d): Pair<C, D>) -> Self::Output { | |
| 81 | let Pair(a, b) = self; | |
| 82 | Pair(a.$fn(c), b.$fn(d)) | |
| 83 | } | |
| 84 | } | |
| 85 | ||
| 86 | impl<'a, A, B, C, D> $trait<Pair<C, D>> for &'a Pair<A, B> | |
| 87 | where | |
| 88 | &'a A: $trait<C>, | |
| 89 | &'a B: $trait<D>, | |
| 90 | { | |
| 91 | type Output = Pair<<&'a A as $trait<C>>::Output, <&'a B as $trait<D>>::Output>; | |
| 92 | fn $fn(self, Pair(c, d): Pair<C, D>) -> Self::Output { | |
| 93 | let Pair(ref a, ref b) = self; | |
| 94 | Pair(a.$fn(c), b.$fn(d)) | |
| 95 | } | |
| 96 | } | |
| 97 | ||
| 98 | impl<'a, 'b, A, B, C, D> $trait<&'b Pair<C, D>> for &'a Pair<A, B> | |
| 99 | where | |
| 100 | &'a A: $trait<&'b C>, | |
| 101 | &'a B: $trait<&'b D>, | |
| 102 | { | |
| 103 | type Output = Pair<<&'a A as $trait<&'b C>>::Output, <&'a B as $trait<&'b D>>::Output>; | |
| 104 | fn $fn(self, Pair(ref c, ref d): &'b Pair<C, D>) -> Self::Output { | |
| 105 | let Pair(ref a, ref b) = self; | |
| 106 | Pair(a.$fn(c), b.$fn(d)) | |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | impl<'b, A, B, C, D> $trait<&'b Pair<C, D>> for Pair<A, B> | |
| 111 | where | |
| 112 | A: $trait<&'b C>, | |
| 113 | B: $trait<&'b D>, | |
| 114 | { | |
| 115 | type Output = Pair<<A as $trait<&'b C>>::Output, <B as $trait<&'b D>>::Output>; | |
| 116 | fn $fn(self, Pair(ref c, ref d): &'b Pair<C, D>) -> Self::Output { | |
| 117 | let Pair(a, b) = self; | |
| 118 | Pair(a.$fn(c), b.$fn(d)) | |
| 119 | } | |
| 120 | } | |
| 121 | }; | |
| 122 | } | |
| 123 | ||
| 118 | 124 | impl_binary!(Add, add); |
| 125 | impl_binary!(Sub, sub); | |
| 126 | ||
| 119 | 127 | macro_rules! impl_scalar { |
| 120 | 128 | ($trait:ident, $fn:ident) => { |
| 129 | impl<A, B, F: Num> $trait<F> for Pair<A, B> | |
| 119 | 130 | where |
| 120 | 131 | A: $trait<F>, |
| 132 | B: $trait<F>, | |
| 119 | 133 | { |
| 134 | type Output = Pair<A::Output, B::Output>; | |
| 120 | 135 | fn $fn(self, t: F) -> Self::Output { |
| 119 | 136 | let Pair(a, b) = self; |
| 137 | Pair(a.$fn(t), b.$fn(t)) | |
| 138 | } | |
| 139 | } | |
| 140 | ||
| 120 | 141 | impl<'a, A, B, F: Num> $trait<F> for &'a Pair<A, B> |
| 119 | 142 | where |
| 120 | 143 | &'a A: $trait<F>, |
| 144 | &'a B: $trait<F>, | |
| 119 | 145 | { |
| 120 | 146 | type Output = Pair<<&'a A as $trait<F>>::Output, <&'a B as $trait<F>>::Output>; |
| 147 | fn $fn(self, t: F) -> Self::Output { | |
| 119 | 148 | let Pair(ref a, ref b) = self; |
| 149 | Pair(a.$fn(t), b.$fn(t)) | |
| 150 | } | |
| 151 | } | |
| 152 | ||
| 153 | // impl<'a, 'b, A, B> $trait<&'b $F> for &'a Pair<A, B> | |
| 154 | // where | |
| 155 | // &'a A: $trait<&'b $F>, | |
| 156 | // &'a B: $trait<&'b $F>, | |
| 157 | // { | |
| 158 | // type Output = | |
| 159 | // Pair<<&'a A as $trait<&'b $F>>::Output, <&'a B as $trait<&'b $F>>::Output>; | |
| 160 | // fn $fn(self, t: &'b $F) -> Self::Output { | |
| 161 | // let Pair(ref a, ref b) = self; | |
| 162 | // Pair(a.$fn(t), b.$fn(t)) | |
| 163 | // } | |
| 164 | // } | |
| 165 | ||
| 166 | // impl<'b, A, B> $trait<&'b $F> for Pair<A, B> | |
| 167 | // where | |
| 168 | // A: $trait<&'b $F>, | |
| 169 | // B: $trait<&'b $F>, | |
| 170 | // { | |
| 171 | // type Output = Pair<<A as $trait<&'b $F>>::Output, <B as $trait<&'b $F>>::Output>; | |
| 172 | // fn $fn(self, t: &'b $F) -> Self::Output { | |
| 173 | // let Pair(a, b) = self; | |
| 174 | // Pair(a.$fn(t), b.$fn(t)) | |
| 175 | // } | |
| 176 | // } | |
| 177 | }; | |
| 178 | } | |
| 179 | ||
| 120 | 180 | impl_scalar!(Mul, mul); |
| 181 | //impl_scalar!(Mul, mul, f64); | |
| 182 | impl_scalar!(Sub, sub); | |
| 183 | //impl_scalar!(Sub, sub, f64); | |
| 119 | 184 | |
| 185 | macro_rules! impl_scalar_lhs { | |
| 186 | ($trait:ident, $fn:ident, $F:ty) => { | |
| 187 | impl<A, B> $trait<Pair<A, B>> for $F | |
| 188 | where | |
| 189 | $F: $trait<A> + $trait<B>, | |
| 190 | { | |
| 191 | type Output = Pair<<$F as $trait<A>>::Output, <$F as $trait<B>>::Output>; | |
| 192 | fn $fn(self, Pair(a, b): Pair<A, B>) -> Self::Output { | |
| 193 | Pair(self.$fn(a), self.$fn(b)) | |
| 194 | } | |
| 195 | } | |
| 196 | ||
| 197 | // Compiler overflow: | |
| 198 | // | |
| 199 | // impl<'a, A, B> $trait<&'a Pair<A, B>> for $F | |
| 200 | // where | |
| 201 | // $F: $trait<&'a A> + $trait<&'a B>, | |
| 202 | // { | |
| 203 | // type Output = Pair<<$F as $trait<&'a A>>::Output, <$F as $trait<&'a B>>::Output>; | |
| 204 | // fn $fn(self, Pair(a, b): &'a Pair<A, B>) -> Self::Output { | |
| 205 | // Pair(self.$fn(a), self.$fn(b)) | |
| 206 | // } | |
| 207 | // } | |
| 208 | }; | |
| 209 | } | |
| 210 | ||
| 211 | impl_scalar_lhs!(Mul, mul, f32); | |
| 212 | impl_scalar_lhs!(Mul, mul, f64); | |
| 213 | ||
| 117 | 214 | macro_rules! impl_binary_mut { |
| 215 | ($trait:ident, $fn:ident) => { | |
| 216 | impl<'a, A, B, C, D> $trait<Pair<C, D>> for Pair<A, B> | |
| 217 | where | |
| 218 | A: $trait<C>, | |
| 219 | B: $trait<D>, | |
| 220 | { | |
| 221 | fn $fn(&mut self, Pair(c, d): Pair<C, D>) { | |
| 222 | let Pair(ref mut a, ref mut b) = self; | |
| 223 | a.$fn(c); | |
| 224 | b.$fn(d); | |
| 225 | } | |
| 226 | } | |
| 227 | ||
| 228 | impl<'a, 'b, A, B, C, D> $trait<&'b Pair<C, D>> for Pair<A, B> | |
| 229 | where | |
| 230 | A: $trait<&'b C>, | |
| 231 | B: $trait<&'b D>, | |
| 232 | { | |
| 233 | fn $fn(&mut self, Pair(ref c, ref d): &'b Pair<C, D>) { | |
| 234 | let Pair(ref mut a, ref mut b) = self; | |
| 235 | a.$fn(c); | |
| 236 | b.$fn(d); | |
| 237 | } | |
| 238 | } | |
| 239 | }; | |
| 240 | } | |
| 241 | ||
| 242 | impl_binary_mut!(AddAssign, add_assign); | |
| 243 | impl_binary_mut!(SubAssign, sub_assign); | |
| 116 | 244 | |
| 118 | 245 | macro_rules! impl_scalar_mut { |
| 119 | 246 | ($trait:ident, $fn:ident, $F:ty) => { |
| 247 | impl<'a, A, B> $trait<$F> for Pair<A, B> | |
| 118 | 248 | where |
| 119 | 249 | A: $trait<$F>, |
| 250 | B: $trait<$F>, | |
| 118 | 251 | { |
| 119 | 252 | fn $fn(&mut self, t: $F) { |
| 118 | 253 | let Pair(ref mut a, ref mut b) = self; |
| 254 | a.$fn(t); | |
| 255 | b.$fn(t); | |
| 256 | } | |
| 257 | } | |
| 258 | }; | |
| 259 | } | |
| 260 | ||
| 119 | 261 | impl_scalar_mut!(MulAssign, mul_assign, f32); |
| 262 | impl_scalar_mut!(MulAssign, mul_assign, f64); | |
| 263 | impl_scalar_mut!(DivAssign, div_assign, f32); | |
| 264 | impl_scalar_mut!(DivAssign, div_assign, f64); | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
265 | |
| 119 | 266 | /// We only support 'closed' `Euclidean` `Pair`s, as more general ones cause |
| 267 | /// compiler overflows. | |
| 118 | 268 | impl<A, B, F: Float> Euclidean<F> for Pair<A, B> |
| 269 | where | |
| 270 | A: Euclidean<F>, | |
| 271 | B: Euclidean<F>, | |
| 272 | //Pair<A, B>: Euclidean<F>, | |
| 273 | Self: Sized | |
| 274 | + Mul<F, Output = Pair<A, B>> | |
| 275 | + MulAssign<F> | |
| 276 | + Div<F, Output = Pair<A, B>> | |
| 277 | + DivAssign<F> | |
| 278 | + Add<Self, Output = Pair<A, B>> | |
| 279 | + Sub<Self, Output = Pair<A, B>> | |
| 280 | + for<'b> Add<&'b Self, Output = Pair<A, B>> | |
| 281 | + for<'b> Sub<&'b Self, Output = Pair<A, B>> | |
| 282 | + AddAssign<Self> | |
| 283 | + for<'b> AddAssign<&'b Self> | |
| 284 | + SubAssign<Self> | |
| 285 | + for<'b> SubAssign<&'b Self> | |
| 286 | + Neg<Output = Pair<A, B>>, | |
| 287 | { | |
| 288 | type Output = Pair<A, B>; | |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
289 | |
| 118 | 290 | fn dot<I: Instance<Self>>(&self, other: I) -> F { |
| 291 | let Pair(u, v) = other.decompose(); | |
| 292 | self.0.dot(u) + self.1.dot(v) | |
| 293 | } | |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
294 | |
| 118 | 295 | fn norm2_squared(&self) -> F { |
| 296 | self.0.norm2_squared() + self.1.norm2_squared() | |
| 297 | } | |
| 298 | ||
| 299 | fn dist2_squared<I: Instance<Self>>(&self, other: I) -> F { | |
| 300 | let Pair(u, v) = other.decompose(); | |
| 301 | self.0.dist2_squared(u) + self.1.dist2_squared(v) | |
| 302 | } | |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
303 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
304 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
305 | 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
|
306 | where |
| 94 | 307 | U: Space, |
| 308 | V: Space, | |
| 309 | A: AXPY<F, U>, | |
| 310 | B: AXPY<F, V>, | |
| 311 | F: Num, | |
| 312 | Self: MulAssign<F>, | |
| 313 | Pair<A, B>: MulAssign<F>, | |
| 314 | 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
|
315 | { |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
316 | type Owned = Pair<A::Owned, B::Owned>; |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
317 | |
| 94 | 318 | 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
|
319 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
320 | self.0.axpy(α, u, β); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
321 | self.1.axpy(α, v, β); |
|
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 | |
| 94 | 324 | 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
|
325 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
326 | self.0.copy_from(u); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
327 | self.1.copy_from(v); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
328 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
329 | |
| 94 | 330 | 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
|
331 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
332 | self.0.scale_from(α, u); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
333 | self.1.scale_from(α, v); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
334 | } |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
335 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
336 | /// Return a similar zero as `self`. |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
337 | fn similar_origin(&self) -> Self::Owned { |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
338 | 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
|
339 | } |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
340 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
341 | /// Set self to zero. |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
342 | fn set_zero(&mut self) { |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
343 | self.0.set_zero(); |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
344 | self.1.set_zero(); |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
345 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
346 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
347 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
348 | /// [`Decomposition`] for working with [`Pair`]s. |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
349 | #[derive(Copy, Clone, Debug)] |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
350 | pub struct PairDecomposition<D, Q>(D, Q); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
351 | |
| 94 | 352 | 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
|
353 | type Decomp = PairDecomposition<A::Decomp, B::Decomp>; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
354 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
355 | |
| 94 | 356 | 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
|
357 | where |
| 94 | 358 | A: Space, |
| 359 | B: Space, | |
| 360 | D: Decomposition<A>, | |
| 361 | Q: Decomposition<B>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
362 | { |
| 94 | 363 | type Decomposition<'b> |
| 364 | = Pair<D::Decomposition<'b>, Q::Decomposition<'b>> | |
| 365 | where | |
| 366 | Pair<A, B>: 'b; | |
| 367 | type Reference<'b> | |
| 368 | = Pair<D::Reference<'b>, Q::Reference<'b>> | |
| 369 | where | |
| 370 | Pair<A, B>: 'b; | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
371 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
372 | #[inline] |
| 94 | 373 | 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
|
374 | Pair(D::lift(u), Q::lift(v)) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
375 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
376 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
377 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
378 | 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
|
379 | where |
| 94 | 380 | A: Space, |
| 381 | B: Space, | |
| 382 | D: Decomposition<A>, | |
| 383 | Q: Decomposition<B>, | |
| 384 | U: Instance<A, D>, | |
| 385 | V: Instance<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
386 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
387 | #[inline] |
| 94 | 388 | fn decompose<'b>( |
| 389 | self, | |
| 390 | ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b> | |
| 391 | where | |
| 392 | Self: 'b, | |
| 393 | Pair<A, B>: 'b, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
394 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
395 | Pair(self.0.decompose(), self.1.decompose()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
396 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
397 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
398 | #[inline] |
| 94 | 399 | fn ref_instance( |
| 400 | &self, | |
| 401 | ) -> <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
|
402 | 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
|
403 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
404 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
405 | #[inline] |
| 94 | 406 | fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
| 407 | where | |
| 408 | Self: 'b, | |
| 409 | { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
410 | 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
|
411 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
412 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
413 | #[inline] |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
414 | fn own(self) -> Pair<A, B> { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
415 | Pair(self.0.own(), self.1.own()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
416 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
417 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
418 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
419 | 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
|
420 | where |
| 94 | 421 | A: Space, |
| 422 | B: Space, | |
| 423 | D: Decomposition<A>, | |
| 424 | Q: Decomposition<B>, | |
| 425 | U: Instance<A, D>, | |
| 426 | V: Instance<B, Q>, | |
| 427 | &'a U: Instance<A, D>, | |
| 428 | &'a V: Instance<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
429 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
430 | #[inline] |
| 94 | 431 | fn decompose<'b>( |
| 432 | self, | |
| 433 | ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b> | |
| 434 | where | |
| 435 | Self: 'b, | |
| 436 | Pair<A, B>: 'b, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
437 | { |
| 94 | 438 | Pair( |
| 439 | D::lift(self.0.ref_instance()), | |
| 440 | Q::lift(self.1.ref_instance()), | |
| 441 | ) | |
|
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 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
444 | #[inline] |
| 94 | 445 | fn ref_instance( |
| 446 | &self, | |
| 447 | ) -> <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
|
448 | 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
|
449 | } |
|
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 | #[inline] |
| 94 | 452 | fn cow<'b>(self) -> MyCow<'b, Pair<A, B>> |
| 453 | where | |
| 454 | Self: 'b, | |
| 455 | { | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
456 | MyCow::Owned(self.own()) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
457 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
458 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
459 | #[inline] |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
460 | fn own(self) -> Pair<A, B> { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
461 | let Pair(ref u, ref v) = self; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
462 | Pair(u.own(), v.own()) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
463 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
464 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
465 | |
| 94 | 466 | 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
|
467 | where |
| 94 | 468 | A: Space, |
| 469 | B: Space, | |
| 470 | D: DecompositionMut<A>, | |
| 471 | Q: DecompositionMut<B>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
472 | { |
| 94 | 473 | type ReferenceMut<'b> |
| 474 | = Pair<D::ReferenceMut<'b>, Q::ReferenceMut<'b>> | |
| 475 | where | |
| 476 | Pair<A, B>: 'b; | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
477 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
478 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
479 | 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
|
480 | where |
| 94 | 481 | A: Space, |
| 482 | B: Space, | |
| 483 | D: DecompositionMut<A>, | |
| 484 | Q: DecompositionMut<B>, | |
| 485 | U: InstanceMut<A, D>, | |
| 486 | V: InstanceMut<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
487 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
488 | #[inline] |
| 94 | 489 | fn ref_instance_mut( |
| 490 | &mut self, | |
| 491 | ) -> <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
|
492 | 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
|
493 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
494 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
495 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
496 | 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
|
497 | where |
| 94 | 498 | A: Space, |
| 499 | B: Space, | |
| 500 | D: DecompositionMut<A>, | |
| 501 | Q: DecompositionMut<B>, | |
| 502 | U: InstanceMut<A, D>, | |
| 503 | V: InstanceMut<B, Q>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
504 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
505 | #[inline] |
| 94 | 506 | fn ref_instance_mut( |
| 507 | &mut self, | |
| 508 | ) -> <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
|
509 | 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
|
510 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
511 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
512 | |
| 94 | 513 | 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
|
514 | where |
| 94 | 515 | F: Num, |
| 516 | ExpA: NormExponent, | |
| 517 | ExpB: NormExponent, | |
| 518 | ExpJ: NormExponent, | |
| 519 | A: Norm<F, ExpA>, | |
| 520 | B: Norm<F, ExpB>, | |
| 521 | Loc<F, 2>: Norm<F, ExpJ>, | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
522 | { |
| 94 | 523 | 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
|
524 | 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
|
525 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
526 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
527 | |
| 94 | 528 | 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
|
529 | where |
| 94 | 530 | A: Normed<F>, |
| 531 | B: Normed<F>, | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
532 | { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
533 | type NormExp = PairNorm<A::NormExp, B::NormExp, L2>; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
534 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
535 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
536 | fn norm_exponent(&self) -> Self::NormExp { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
537 | 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
|
538 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
539 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
540 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
541 | fn is_zero(&self) -> bool { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
542 | self.0.is_zero() && self.1.is_zero() |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
543 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
544 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
545 | |
| 94 | 546 | 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
|
547 | where |
| 94 | 548 | A: HasDual<F>, |
| 549 | B: HasDual<F>, | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
550 | { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
551 | type DualSpace = Pair<A::DualSpace, B::DualSpace>; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
552 | } |