src/direct_product.rs

Thu, 01 May 2025 02:13:44 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 01 May 2025 02:13:44 -0500
branch
dev
changeset 120
07e487685b29
parent 119
cc0c6a8d0933
child 121
fc7d923ff6e7
permissions
-rw-r--r--

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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
12 use crate::mapping::Space;
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
13 use crate::norms::{HasDual, Norm, NormExponent, Normed, PairNorm, L2};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
14 use crate::types::{Float, Num};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
15 use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
16 use serde::{Deserialize, Serialize};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
17 use std::clone::Clone;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
19 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
22 impl<A, B> Pair<A, B> {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
23 pub fn new(a: A, b: B) -> Pair<A, B> {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
24 Pair(a, b)
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
30 fn from((a, b): (A, B)) -> Pair<A, B> {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
31 Pair(a, b)
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
37 fn from(Pair(a, b): Pair<A, B>) -> (A, B) {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
38 (a, b)
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
42 macro_rules! impl_unary {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
43 ($trait:ident, $fn:ident) => {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
44 impl<A, B> $trait for Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
45 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
46 A: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
47 B: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
48 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
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
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
51 let Pair(a, b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
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
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
55
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
56 impl<'a, A, B> $trait for &'a Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
57 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
58 &'a A: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
59 &'a B: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
60 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
61 type Output = Pair<<&'a A as $trait>::Output, <&'a B as $trait>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
62 fn $fn(self) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
63 let Pair(ref a, ref b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
64 Pair(a.$fn(), b.$fn())
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
65 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
66 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
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
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
70 impl_unary!(Neg, neg);
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
71
116
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
72 macro_rules! impl_binary {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
73 ($trait:ident, $fn:ident) => {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
74 impl<A, B, C, D> $trait<Pair<C, D>> for Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
75 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
76 A: $trait<C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
77 B: $trait<D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
78 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
79 type Output = Pair<A::Output, B::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
80 fn $fn(self, Pair(c, d): Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
81 let Pair(a, b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
82 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
83 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
84 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
85
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
86 impl<'a, A, B, C, D> $trait<Pair<C, D>> for &'a Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
87 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
88 &'a A: $trait<C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
89 &'a B: $trait<D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
90 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
91 type Output = Pair<<&'a A as $trait<C>>::Output, <&'a B as $trait<D>>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
92 fn $fn(self, Pair(c, d): Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
93 let Pair(ref a, ref b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
94 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
95 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
96 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
97
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
98 impl<'a, 'b, A, B, C, D> $trait<&'b Pair<C, D>> for &'a Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
99 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
100 &'a A: $trait<&'b C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
101 &'a B: $trait<&'b D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
102 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
103 type Output = Pair<<&'a A as $trait<&'b C>>::Output, <&'a B as $trait<&'b D>>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
104 fn $fn(self, Pair(ref c, ref d): &'b Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
105 let Pair(ref a, ref b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
106 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
107 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
108 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
109
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
110 impl<'b, A, B, C, D> $trait<&'b Pair<C, D>> for Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
111 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
112 A: $trait<&'b C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
113 B: $trait<&'b D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
114 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
115 type Output = Pair<<A as $trait<&'b C>>::Output, <B as $trait<&'b D>>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
116 fn $fn(self, Pair(ref c, ref d): &'b Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
117 let Pair(a, b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
118 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
119 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
120 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
121 };
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
122 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
123
118
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
124 impl_binary!(Add, add);
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
125 impl_binary!(Sub, sub);
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
126
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
127 macro_rules! impl_scalar {
120
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
128 ($trait:ident, $fn:ident) => {
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
129 impl<A, B, F: Num> $trait<F> for Pair<A, B>
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
130 where
120
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
131 A: $trait<F>,
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
132 B: $trait<F>,
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
133 {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
134 type Output = Pair<A::Output, B::Output>;
120
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
135 fn $fn(self, t: F) -> Self::Output {
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
136 let Pair(a, b) = self;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
137 Pair(a.$fn(t), b.$fn(t))
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
138 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
139 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
140
120
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
141 impl<'a, A, B, F: Num> $trait<F> for &'a Pair<A, B>
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
142 where
120
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
143 &'a A: $trait<F>,
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
144 &'a B: $trait<F>,
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
145 {
120
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
146 type Output = Pair<<&'a A as $trait<F>>::Output, <&'a B as $trait<F>>::Output>;
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
147 fn $fn(self, t: F) -> Self::Output {
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
148 let Pair(ref a, ref b) = self;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
149 Pair(a.$fn(t), b.$fn(t))
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
150 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
151 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
152
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
153 // impl<'a, 'b, A, B> $trait<&'b $F> for &'a Pair<A, B>
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
154 // where
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
155 // &'a A: $trait<&'b $F>,
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
156 // &'a B: $trait<&'b $F>,
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
157 // {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
158 // type Output =
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
159 // Pair<<&'a A as $trait<&'b $F>>::Output, <&'a B as $trait<&'b $F>>::Output>;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
160 // fn $fn(self, t: &'b $F) -> Self::Output {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
161 // let Pair(ref a, ref b) = self;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
162 // Pair(a.$fn(t), b.$fn(t))
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
163 // }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
164 // }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
165
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
166 // impl<'b, A, B> $trait<&'b $F> for Pair<A, B>
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
167 // where
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
168 // A: $trait<&'b $F>,
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
169 // B: $trait<&'b $F>,
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
170 // {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
171 // type Output = Pair<<A as $trait<&'b $F>>::Output, <B as $trait<&'b $F>>::Output>;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
172 // fn $fn(self, t: &'b $F) -> Self::Output {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
173 // let Pair(a, b) = self;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
174 // Pair(a.$fn(t), b.$fn(t))
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
175 // }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
176 // }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
177 };
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
178 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
179
120
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
180 impl_scalar!(Mul, mul);
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
181 //impl_scalar!(Mul, mul, f64);
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
182 impl_scalar!(Sub, sub);
07e487685b29 reduce restriction
Tuomo Valkonen <tuomov@iki.fi>
parents: 119
diff changeset
183 //impl_scalar!(Sub, sub, f64);
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
184
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
185 macro_rules! impl_scalar_lhs {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
186 ($trait:ident, $fn:ident, $F:ty) => {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
187 impl<A, B> $trait<Pair<A, B>> for $F
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
188 where
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
189 $F: $trait<A> + $trait<B>,
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
190 {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
191 type Output = Pair<<$F as $trait<A>>::Output, <$F as $trait<B>>::Output>;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
192 fn $fn(self, Pair(a, b): Pair<A, B>) -> Self::Output {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
193 Pair(self.$fn(a), self.$fn(b))
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
194 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
195 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
196
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
197 // Compiler overflow:
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
198 //
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
199 // impl<'a, A, B> $trait<&'a Pair<A, B>> for $F
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
200 // where
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
201 // $F: $trait<&'a A> + $trait<&'a B>,
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
202 // {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
203 // type Output = Pair<<$F as $trait<&'a A>>::Output, <$F as $trait<&'a B>>::Output>;
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
204 // fn $fn(self, Pair(a, b): &'a Pair<A, B>) -> Self::Output {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
205 // Pair(self.$fn(a), self.$fn(b))
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
206 // }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
207 // }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
208 };
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
209 }
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
210
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
211 impl_scalar_lhs!(Mul, mul, f32);
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
212 impl_scalar_lhs!(Mul, mul, f64);
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
213
117
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
214 macro_rules! impl_binary_mut {
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
215 ($trait:ident, $fn:ident) => {
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
216 impl<'a, A, B, C, D> $trait<Pair<C, D>> for Pair<A, B>
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
217 where
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
218 A: $trait<C>,
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
219 B: $trait<D>,
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
220 {
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
221 fn $fn(&mut self, Pair(c, d): Pair<C, D>) {
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
222 let Pair(ref mut a, ref mut b) = self;
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
223 a.$fn(c);
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
224 b.$fn(d);
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
225 }
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
226 }
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
227
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
228 impl<'a, 'b, A, B, C, D> $trait<&'b Pair<C, D>> for Pair<A, B>
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
229 where
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
230 A: $trait<&'b C>,
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
231 B: $trait<&'b D>,
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
232 {
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
233 fn $fn(&mut self, Pair(ref c, ref d): &'b Pair<C, D>) {
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
234 let Pair(ref mut a, ref mut b) = self;
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
235 a.$fn(c);
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
236 b.$fn(d);
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
237 }
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
238 }
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
239 };
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
240 }
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
241
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
242 impl_binary_mut!(AddAssign, add_assign);
9b782aa6b452 binops_mut
Tuomo Valkonen <tuomov@iki.fi>
parents: 116
diff changeset
243 impl_binary_mut!(SubAssign, sub_assign);
116
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
244
118
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
245 macro_rules! impl_scalar_mut {
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
246 ($trait:ident, $fn:ident, $F:ty) => {
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
247 impl<'a, A, B> $trait<$F> for Pair<A, B>
118
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
248 where
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
249 A: $trait<$F>,
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
250 B: $trait<$F>,
118
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
251 {
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
252 fn $fn(&mut self, t: $F) {
118
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
253 let Pair(ref mut a, ref mut b) = self;
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
254 a.$fn(t);
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
255 b.$fn(t);
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
256 }
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
257 }
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
258 };
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
259 }
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
260
119
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
261 impl_scalar_mut!(MulAssign, mul_assign, f32);
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
262 impl_scalar_mut!(MulAssign, mul_assign, f64);
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
263 impl_scalar_mut!(DivAssign, div_assign, f32);
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
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
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
266 /// We only support 'closed' `Euclidean` `Pair`s, as more general ones cause
cc0c6a8d0933 simplify
Tuomo Valkonen <tuomov@iki.fi>
parents: 118
diff changeset
267 /// compiler overflows.
118
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
268 impl<A, B, F: Float> Euclidean<F> for Pair<A, B>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
269 where
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
270 A: Euclidean<F>,
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
271 B: Euclidean<F>,
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
272 //Pair<A, B>: Euclidean<F>,
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
273 Self: Sized
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
274 + Mul<F, Output = Pair<A, B>>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
275 + MulAssign<F>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
276 + Div<F, Output = Pair<A, B>>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
277 + DivAssign<F>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
278 + Add<Self, Output = Pair<A, B>>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
279 + Sub<Self, Output = Pair<A, B>>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
280 + for<'b> Add<&'b Self, Output = Pair<A, B>>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
281 + for<'b> Sub<&'b Self, Output = Pair<A, B>>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
282 + AddAssign<Self>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
283 + for<'b> AddAssign<&'b Self>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
284 + SubAssign<Self>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
285 + for<'b> SubAssign<&'b Self>
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
286 + Neg<Output = Pair<A, B>>,
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
287 {
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
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
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
290 fn dot<I: Instance<Self>>(&self, other: I) -> F {
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
291 let Pair(u, v) = other.decompose();
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
292 self.0.dot(u) + self.1.dot(v)
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
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
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
295 fn norm2_squared(&self) -> F {
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
296 self.0.norm2_squared() + self.1.norm2_squared()
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
297 }
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
298
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
299 fn dist2_squared<I: Instance<Self>>(&self, other: I) -> F {
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
300 let Pair(u, v) = other.decompose();
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
301 self.0.dist2_squared(u) + self.1.dist2_squared(v)
0fabd0b5914c restrict
Tuomo Valkonen <tuomov@iki.fi>
parents: 117
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
307 U: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
308 V: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
309 A: AXPY<F, U>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
310 B: AXPY<F, V>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
311 F: Num,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
312 Self: MulAssign<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
313 Pair<A, B>: MulAssign<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
358 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
359 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
360 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
361 Q: Decomposition<B>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
362 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
363 type Decomposition<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
364 = Pair<D::Decomposition<'b>, Q::Decomposition<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
365 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
366 Pair<A, B>: 'b;
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
367 type Reference<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
368 = Pair<D::Reference<'b>, Q::Reference<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
369 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
380 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
381 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
382 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
383 Q: Decomposition<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
384 U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
388 fn decompose<'b>(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
389 self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
390 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
391 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
392 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
399 fn ref_instance(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
400 &self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
406 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
407 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
408 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
421 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
422 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
423 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
424 Q: Decomposition<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
425 U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
426 V: Instance<B, Q>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
427 &'a U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
431 fn decompose<'b>(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
432 self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
433 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
434 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
435 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
436 Pair<A, B>: 'b,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
437 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
438 Pair(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
439 D::lift(self.0.ref_instance()),
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
440 Q::lift(self.1.ref_instance()),
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
445 fn ref_instance(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
446 &self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
452 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
453 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
454 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
468 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
469 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
470 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
471 Q: DecompositionMut<B>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
472 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
473 type ReferenceMut<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
474 = Pair<D::ReferenceMut<'b>, Q::ReferenceMut<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
475 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
481 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
482 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
483 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
484 Q: DecompositionMut<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
485 U: InstanceMut<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
489 fn ref_instance_mut(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
490 &mut self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
498 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
499 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
500 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
501 Q: DecompositionMut<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
502 U: InstanceMut<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
506 fn ref_instance_mut(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
507 &mut self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
515 F: Num,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
516 ExpA: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
517 ExpB: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
518 ExpJ: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
519 A: Norm<F, ExpA>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
520 B: Norm<F, ExpB>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
530 A: Normed<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
548 A: HasDual<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
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 }

mercurial