src/direct_product.rs

Mon, 12 May 2025 15:42:48 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 12 May 2025 15:42:48 -0500
branch
dev
changeset 129
d2994e34a5f5
parent 124
6aa955ad8122
child 130
0a689881b0f1
permissions
-rw-r--r--

Simplify ZeroOp to SimpleZeroOp, only from X to X. Add Prox for ZeroIndicator. Move F parameter to AXPY::Field.

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

mercurial