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