Sat, 21 Dec 2024 14:27:14 -0500
Try to use HasDual with adjoints. Problem with nalgebra Instances.
0 | 1 | /*! |
2 | Abstract linear operators. | |
3 | */ | |
4 | ||
5 | use numeric_literals::replace_float_literals; | |
6 | use std::marker::PhantomData; | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
7 | use serde::Serialize; |
0 | 8 | use crate::types::*; |
61 | 9 | pub use crate::mapping::{Mapping, Space, Composition}; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
10 | use crate::direct_product::Pair; |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
11 | use crate::instance::Instance; |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
12 | use crate::norms::{NormExponent, PairNorm, L1, L2, Linfinity, Norm, HasDual}; |
0 | 13 | |
14 | /// Trait for linear operators on `X`. | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
15 | pub trait Linear<X : Space> : Mapping<X> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
16 | { } |
0 | 17 | |
18 | /// Efficient in-place summation. | |
19 | #[replace_float_literals(F::cast_from(literal))] | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
20 | pub trait AXPY<F, X = Self> : Space |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
21 | where |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
22 | F : Num, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
23 | X : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
24 | { |
0 | 25 | /// Computes `y = βy + αx`, where `y` is `Self`. |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
26 | fn axpy<I : Instance<X>>(&mut self, α : F, x : I, β : F); |
0 | 27 | |
28 | /// Copies `x` to `self`. | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
29 | fn copy_from<I : Instance<X>>(&mut self, x : I) { |
0 | 30 | self.axpy(1.0, x, 0.0) |
31 | } | |
32 | ||
5 | 33 | /// Computes `y = αx`, where `y` is `Self`. |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
34 | fn scale_from<I : Instance<X>>(&mut self, α : F, x : I) { |
0 | 35 | self.axpy(α, x, 0.0) |
36 | } | |
37 | } | |
38 | ||
39 | /// Efficient in-place application for [`Linear`] operators. | |
40 | #[replace_float_literals(F::cast_from(literal))] | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
41 | pub trait GEMV<F : Num, X : Space, Y = <Self as Mapping<X>>::Codomain> : Linear<X> { |
5 | 42 | /// Computes `y = αAx + βy`, where `A` is `Self`. |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
43 | fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F); |
0 | 44 | |
5 | 45 | /// Computes `y = Ax`, where `A` is `Self` |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
46 | fn apply_mut<I : Instance<X>>(&self, y : &mut Y, x : I){ |
0 | 47 | self.gemv(y, 1.0, x, 0.0) |
48 | } | |
49 | ||
5 | 50 | /// Computes `y += Ax`, where `A` is `Self` |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
51 | fn apply_add<I : Instance<X>>(&self, y : &mut Y, x : I){ |
0 | 52 | self.gemv(y, 1.0, x, 1.0) |
53 | } | |
54 | } | |
55 | ||
56 | ||
57 | /// Bounded linear operators | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
58 | pub trait BoundedLinear<X, XExp, CodExp, F = f64> : Linear<X> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
59 | where |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
60 | F : Num, |
61 | 61 | X : Space + Norm<F, XExp>, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
62 | XExp : NormExponent, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
63 | CodExp : NormExponent |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
64 | { |
0 | 65 | /// A bound on the operator norm $\|A\|$ for the linear operator $A$=`self`. |
66 | /// This is not expected to be the norm, just any bound on it that can be | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
67 | /// reasonably implemented. The [`NormExponent`] `xexp` indicates the norm |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
68 | /// in `X`, and `codexp` in the codomain. |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
69 | fn opnorm_bound(&self, xexp : XExp, codexp : CodExp) -> F; |
0 | 70 | } |
71 | ||
5 | 72 | // Linear operator application into mutable target. The [`AsRef`] bound |
73 | // is used to guarantee compatibility with `Yʹ` and `Self::Codomain`; | |
74 | // the former is assumed to be e.g. a view into the latter. | |
0 | 75 | |
76 | /*impl<X,Y,T> Fn(&X) -> Y for T where T : Linear<X,Codomain=Y> { | |
77 | fn call(&self, x : &X) -> Y { | |
78 | self.apply(x) | |
79 | } | |
80 | }*/ | |
81 | ||
5 | 82 | /// Trait for forming the adjoint operator of `Self`. |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
83 | pub trait Adjointable<X, F : Float = f64> : Linear<X> |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
84 | where |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
85 | X : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
86 | Self::Codomain : HasDual<F>, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
87 | { |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
88 | type AdjointCodomain : Instance<X::DualSpace>; |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
89 | type Adjoint<'a> : Linear< |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
90 | <Self::Codomain as HasDual<F>>::DualSpace, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
91 | Codomain=Self::AdjointCodomain, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
92 | > where Self : 'a; |
0 | 93 | |
94 | /// Form the adjoint operator of `self`. | |
95 | fn adjoint(&self) -> Self::Adjoint<'_>; | |
96 | } | |
97 | ||
5 | 98 | /// Trait for forming a preadjoint of an operator. |
99 | /// | |
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
100 | /// For an operator $A$ this is an operator $A\_\*$ |
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
101 | /// such that its adjoint $(A\_\*)^\*=A$. The space `X` is the domain of the `Self` |
0 | 102 | /// operator. The space `Ypre` is the predual of its codomain, and should be the |
103 | /// domain of the adjointed operator. `Self::Preadjoint` should be | |
104 | /// [`Adjointable`]`<'a,Ypre,X>`. | |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
105 | /// |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
106 | /// We do not set further restrictions on the spacds, to allow preadjointing when `X` |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
107 | /// is on the dual space of `Ypre`, but a subset of it. |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
108 | pub trait Preadjointable<X : Space, Ypre : Space> : Linear<X> |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
109 | //where |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
110 | // Ypre : HasDual<F, DualSpace=Self::Codomain>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
111 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
112 | type PreadjointCodomain : Space; |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
113 | type Preadjoint<'a> : Linear<Ypre, Codomain=Self::PreadjointCodomain> where Self : 'a; |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
114 | |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
115 | /// Form the adjoint operator of `self`. |
0 | 116 | fn preadjoint(&self) -> Self::Preadjoint<'_>; |
117 | } | |
118 | ||
119 | ||
120 | /// The identity operator | |
121 | #[derive(Clone,Copy,Debug,Serialize,Eq,PartialEq)] | |
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
122 | pub struct IdOp<X> (PhantomData<X>); |
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
123 | |
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
124 | impl<X> IdOp<X> { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
125 | pub fn new() -> IdOp<X> { IdOp(PhantomData) } |
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
126 | } |
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
127 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
128 | impl<X : Clone + Space> Mapping<X> for IdOp<X> { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
129 | type Codomain = X; |
0 | 130 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
131 | fn apply<I : Instance<X>>(&self, x : I) -> X { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
132 | x.own() |
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
133 | } |
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
134 | } |
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
135 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
136 | impl<X : Clone + Space> Linear<X> for IdOp<X> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
137 | { } |
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
138 | |
0 | 139 | #[replace_float_literals(F::cast_from(literal))] |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
140 | impl<F : Num, X, Y> GEMV<F, X, Y> for IdOp<X> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
141 | where |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
142 | Y : AXPY<F, X>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
143 | X : Clone + Space |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
144 | { |
0 | 145 | // Computes `y = αAx + βy`, where `A` is `Self`. |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
146 | fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F) { |
0 | 147 | y.axpy(α, x, β) |
148 | } | |
149 | ||
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
150 | fn apply_mut<I : Instance<X>>(&self, y : &mut Y, x : I){ |
0 | 151 | y.copy_from(x); |
152 | } | |
153 | } | |
154 | ||
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
155 | impl<F, X, E> BoundedLinear<X, E, E, F> for IdOp<X> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
156 | where |
61 | 157 | X : Space + Clone + Norm<F, E>, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
158 | F : Num, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
159 | E : NormExponent |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
160 | { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
161 | fn opnorm_bound(&self, _xexp : E, _codexp : E) -> F { F::ONE } |
0 | 162 | } |
163 | ||
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
164 | impl<X : Clone + HasDual<F, DualSpace=X>, F : Float> Adjointable<X, F> for IdOp<X> { |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
165 | type AdjointCodomain = X; |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
166 | type Adjoint<'a> = IdOp<X::DualSpace> where X : 'a; |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
167 | |
0 | 168 | fn adjoint(&self) -> Self::Adjoint<'_> { IdOp::new() } |
169 | } | |
170 | ||
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
171 | impl<X : Clone + Space> Preadjointable<X, X> for IdOp<X> { |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
172 | type PreadjointCodomain = X; |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
173 | type Preadjoint<'a> = IdOp<X> where X : 'a; |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
174 | |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
175 | fn preadjoint(&self) -> Self::Preadjoint<'_> { IdOp::new() } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
176 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
177 | |
61 | 178 | |
179 | impl<S, T, E, X> Linear<X> for Composition<S, T, E> | |
180 | where | |
181 | X : Space, | |
182 | T : Linear<X>, | |
183 | S : Linear<T::Codomain> | |
184 | { } | |
185 | ||
186 | impl<F, S, T, E, X, Y> GEMV<F, X, Y> for Composition<S, T, E> | |
187 | where | |
188 | F : Num, | |
189 | X : Space, | |
190 | T : Linear<X>, | |
191 | S : GEMV<F, T::Codomain, Y>, | |
192 | { | |
193 | fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F) { | |
194 | self.outer.gemv(y, α, self.inner.apply(x), β) | |
195 | } | |
196 | ||
197 | /// Computes `y = Ax`, where `A` is `Self` | |
198 | fn apply_mut<I : Instance<X>>(&self, y : &mut Y, x : I){ | |
199 | self.outer.apply_mut(y, self.inner.apply(x)) | |
200 | } | |
201 | ||
202 | /// Computes `y += Ax`, where `A` is `Self` | |
203 | fn apply_add<I : Instance<X>>(&self, y : &mut Y, x : I){ | |
204 | self.outer.apply_add(y, self.inner.apply(x)) | |
205 | } | |
206 | } | |
207 | ||
208 | impl<F, S, T, X, Z, Xexp, Yexp, Zexp> BoundedLinear<X, Xexp, Yexp, F> for Composition<S, T, Zexp> | |
209 | where | |
210 | F : Num, | |
211 | X : Space + Norm<F, Xexp>, | |
212 | Z : Space + Norm<F, Zexp>, | |
213 | Xexp : NormExponent, | |
214 | Yexp : NormExponent, | |
215 | Zexp : NormExponent, | |
216 | T : BoundedLinear<X, Xexp, Zexp, F, Codomain=Z>, | |
217 | S : BoundedLinear<Z, Zexp, Yexp, F>, | |
218 | { | |
219 | fn opnorm_bound(&self, xexp : Xexp, yexp : Yexp) -> F { | |
220 | let zexp = self.intermediate_norm_exponent; | |
221 | self.outer.opnorm_bound(zexp, yexp) * self.inner.opnorm_bound(xexp, zexp) | |
222 | } | |
223 | } | |
224 | ||
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
225 | /// “Row operator” $(S, T)$; $(S, T)(x, y)=Sx + Ty$. |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
226 | pub struct RowOp<S, T>(pub S, pub T); |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
227 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
228 | use std::ops::Add; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
229 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
230 | impl<A, B, S, T> Mapping<Pair<A, B>> for RowOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
231 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
232 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
233 | B : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
234 | S : Mapping<A>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
235 | T : Mapping<B>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
236 | S::Codomain : Add<T::Codomain>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
237 | <S::Codomain as Add<T::Codomain>>::Output : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
238 | |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
239 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
240 | type Codomain = <S::Codomain as Add<T::Codomain>>::Output; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
241 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
242 | fn apply<I : Instance<Pair<A, B>>>(&self, x : I) -> Self::Codomain { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
243 | let Pair(a, b) = x.decompose(); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
244 | self.0.apply(a) + self.1.apply(b) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
245 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
246 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
247 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
248 | impl<A, B, S, T> Linear<Pair<A, B>> for RowOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
249 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
250 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
251 | B : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
252 | S : Linear<A>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
253 | T : Linear<B>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
254 | S::Codomain : Add<T::Codomain>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
255 | <S::Codomain as Add<T::Codomain>>::Output : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
256 | { } |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
257 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
258 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
259 | impl<'b, F, S, T, Y, U, V> GEMV<F, Pair<U, V>, Y> for RowOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
260 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
261 | U : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
262 | V : Space, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
263 | S : GEMV<F, U, Y>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
264 | T : GEMV<F, V, Y>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
265 | F : Num, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
266 | Self : Linear<Pair<U, V>, Codomain=Y> |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
267 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
268 | fn gemv<I : Instance<Pair<U, V>>>(&self, y : &mut Y, α : F, x : I, β : F) { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
269 | let Pair(u, v) = x.decompose(); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
270 | self.0.gemv(y, α, u, β); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
271 | self.1.gemv(y, α, v, F::ONE); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
272 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
273 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
274 | fn apply_mut<I : Instance<Pair<U, V>>>(&self, y : &mut Y, x : I) { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
275 | let Pair(u, v) = x.decompose(); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
276 | self.0.apply_mut(y, u); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
277 | self.1.apply_mut(y, v); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
278 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
279 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
280 | /// Computes `y += Ax`, where `A` is `Self` |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
281 | fn apply_add<I : Instance<Pair<U, V>>>(&self, y : &mut Y, x : I) { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
282 | let Pair(u, v) = x.decompose(); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
283 | self.0.apply_add(y, u); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
284 | self.1.apply_add(y, v); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
285 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
286 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
287 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
288 | /// “Column operator” $(S; T)$; $(S; T)x=(Sx, Tx)$. |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
289 | pub struct ColOp<S, T>(pub S, pub T); |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
290 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
291 | impl<A, S, T> Mapping<A> for ColOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
292 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
293 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
294 | S : Mapping<A>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
295 | T : Mapping<A>, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
296 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
297 | type Codomain = Pair<S::Codomain, T::Codomain>; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
298 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
299 | fn apply<I : Instance<A>>(&self, a : I) -> Self::Codomain { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
300 | Pair(self.0.apply(a.ref_instance()), self.1.apply(a)) |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
301 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
302 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
303 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
304 | impl<A, S, T> Linear<A> for ColOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
305 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
306 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
307 | S : Mapping<A>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
308 | T : Mapping<A>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
309 | { } |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
310 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
311 | impl<F, S, T, A, B, X> GEMV<F, X, Pair<A, B>> for ColOp<S, T> |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
312 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
313 | X : Space, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
314 | S : GEMV<F, X, A>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
315 | T : GEMV<F, X, B>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
316 | F : Num, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
317 | Self : Linear<X, Codomain=Pair<A, B>> |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
318 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
319 | fn gemv<I : Instance<X>>(&self, y : &mut Pair<A, B>, α : F, x : I, β : F) { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
320 | self.0.gemv(&mut y.0, α, x.ref_instance(), β); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
321 | self.1.gemv(&mut y.1, α, x, β); |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
322 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
323 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
324 | fn apply_mut<I : Instance<X>>(&self, y : &mut Pair<A, B>, x : I){ |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
325 | self.0.apply_mut(&mut y.0, x.ref_instance()); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
326 | self.1.apply_mut(&mut y.1, x); |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
327 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
328 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
329 | /// Computes `y += Ax`, where `A` is `Self` |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
330 | fn apply_add<I : Instance<X>>(&self, y : &mut Pair<A, B>, x : I){ |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
331 | self.0.apply_add(&mut y.0, x.ref_instance()); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
332 | self.1.apply_add(&mut y.1, x); |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
333 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
334 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
335 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
336 | |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
337 | impl<F, A, B, Yʹ, S, T> Adjointable<Pair<A, B>, F> for RowOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
338 | where |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
339 | F : Float, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
340 | A : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
341 | B : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
342 | S : Adjointable<A, F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
343 | T : Adjointable<B, F>, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
344 | Yʹ : Space, |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
345 | S :: Codomain : HasDual<F, DualSpace=Yʹ>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
346 | T :: Codomain : HasDual<F, DualSpace=Yʹ>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
347 | S::Codomain : Add<T::Codomain>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
348 | <S::Codomain as Add<T::Codomain>>::Output : HasDual<F, DualSpace=Yʹ>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
349 | Self::Codomain : HasDual<F, DualSpace=Yʹ>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
350 | //Self : Linear<Pair<A, B>>, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
351 | // for<'a> ColOp<S::Adjoint<'a>, T::Adjoint<'a>> : Linear< |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
352 | // Yʹ, |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
353 | // //Codomain=Pair<S::AdjointCodomain, T::AdjointCodomain> |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
354 | // >, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
355 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
356 | type AdjointCodomain = Pair<S::AdjointCodomain, T::AdjointCodomain>; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
357 | type Adjoint<'a> = ColOp<S::Adjoint<'a>, T::Adjoint<'a>> where Self : 'a; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
358 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
359 | fn adjoint(&self) -> Self::Adjoint<'_> { |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
360 | ColOp(self.0.adjoint(), self.1.adjoint()) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
361 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
362 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
363 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
364 | impl<A, B, Yʹ, S, T> Preadjointable<Pair<A,B>, Yʹ> for RowOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
365 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
366 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
367 | B : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
368 | Yʹ : Space, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
369 | S : Preadjointable<A, Yʹ>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
370 | T : Preadjointable<B, Yʹ>, |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
371 | S::Codomain : Add<T::Codomain>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
372 | <S::Codomain as Add<T::Codomain>>::Output : Space, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
373 | //Self : Linear<Pair<A, B>, Codomain=Y>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
374 | //for<'a> ColOp<S::Preadjoint<'a>, T::Preadjoint<'a>> : Adjointable<Yʹ, F>, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
375 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
376 | type PreadjointCodomain = Pair<S::PreadjointCodomain, T::PreadjointCodomain>; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
377 | type Preadjoint<'a> = ColOp<S::Preadjoint<'a>, T::Preadjoint<'a>> where Self : 'a; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
378 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
379 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
380 | ColOp(self.0.preadjoint(), self.1.preadjoint()) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
381 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
382 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
383 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
384 | |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
385 | impl<F, A, Aʹ, S, T> Adjointable<A, F> for ColOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
386 | where |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
387 | F : Float, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
388 | A : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
389 | S : Adjointable<A, F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
390 | T : Adjointable<A, F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
391 | T::Codomain : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
392 | S::Codomain : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
393 | Aʹ : Space + Instance<A::DualSpace>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
394 | <S as Adjointable<A, F>>::AdjointCodomain : Add<<T as Adjointable<A, F>>::AdjointCodomain, Output=Aʹ>, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
395 | // for<'a> RowOp<S::Adjoint<'a>, T::Adjoint<'a>> : Linear< |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
396 | // Pair<<T::Codomain as HasDual<F>>::DualSpace, <S::Codomain as HasDual<F>>::DualSpace>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
397 | // Codomain=Aʹ |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
398 | // >, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
399 | { |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
400 | type AdjointCodomain = Aʹ; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
401 | type Adjoint<'a> = RowOp<S::Adjoint<'a>, T::Adjoint<'a>> where Self : 'a; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
402 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
403 | fn adjoint(&self) -> Self::Adjoint<'_> { |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
404 | RowOp(self.0.adjoint(), self.1.adjoint()) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
405 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
406 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
407 | |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
408 | impl<A, Aʹ, Xʹ, Yʹ, S, T> Preadjointable<A,Pair<Xʹ,Yʹ>> for ColOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
409 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
410 | A : Space, |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
411 | Aʹ : Space, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
412 | Xʹ : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
413 | Yʹ : Space, |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
414 | S : Preadjointable<A, Xʹ, PreadjointCodomain=Aʹ>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
415 | T : Preadjointable<A, Yʹ, PreadjointCodomain=Aʹ>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
416 | Aʹ : ClosedAdd, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
417 | //for<'a> RowOp<S::Preadjoint<'a>, T::Preadjoint<'a>> : Adjointable<Pair<Xʹ,Yʹ>, F>, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
418 | { |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
419 | type PreadjointCodomain = Aʹ; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
420 | type Preadjoint<'a> = RowOp<S::Preadjoint<'a>, T::Preadjoint<'a>> where Self : 'a; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
421 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
422 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
423 | RowOp(self.0.preadjoint(), self.1.preadjoint()) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
424 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
425 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
426 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
427 | /// Diagonal operator |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
428 | pub struct DiagOp<S, T>(pub S, pub T); |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
429 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
430 | impl<A, B, S, T> Mapping<Pair<A, B>> for DiagOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
431 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
432 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
433 | B : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
434 | S : Mapping<A>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
435 | T : Mapping<B>, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
436 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
437 | type Codomain = Pair<S::Codomain, T::Codomain>; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
438 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
439 | fn apply<I : Instance<Pair<A, B>>>(&self, x : I) -> Self::Codomain { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
440 | let Pair(a, b) = x.decompose(); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
441 | Pair(self.0.apply(a), self.1.apply(b)) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
442 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
443 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
444 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
445 | impl<A, B, S, T> Linear<Pair<A, B>> for DiagOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
446 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
447 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
448 | B : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
449 | S : Linear<A>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
450 | T : Linear<B>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
451 | { } |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
452 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
453 | impl<F, S, T, A, B, U, V> GEMV<F, Pair<U, V>, Pair<A, B>> for DiagOp<S, T> |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
454 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
455 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
456 | B : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
457 | U : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
458 | V : Space, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
459 | S : GEMV<F, U, A>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
460 | T : GEMV<F, V, B>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
461 | F : Num, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
462 | Self : Linear<Pair<U, V>, Codomain=Pair<A, B>>, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
463 | { |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
464 | fn gemv<I : Instance<Pair<U, V>>>(&self, y : &mut Pair<A, B>, α : F, x : I, β : F) { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
465 | let Pair(u, v) = x.decompose(); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
466 | self.0.gemv(&mut y.0, α, u, β); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
467 | self.1.gemv(&mut y.1, α, v, β); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
468 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
469 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
470 | fn apply_mut<I : Instance<Pair<U, V>>>(&self, y : &mut Pair<A, B>, x : I){ |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
471 | let Pair(u, v) = x.decompose(); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
472 | self.0.apply_mut(&mut y.0, u); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
473 | self.1.apply_mut(&mut y.1, v); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
474 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
475 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
476 | /// Computes `y += Ax`, where `A` is `Self` |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
477 | fn apply_add<I : Instance<Pair<U, V>>>(&self, y : &mut Pair<A, B>, x : I){ |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
478 | let Pair(u, v) = x.decompose(); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
479 | self.0.apply_add(&mut y.0, u); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
480 | self.1.apply_add(&mut y.1, v); |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
481 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
482 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
483 | |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
484 | impl<F, A, B, S, T> Adjointable<Pair<A,B>, F> for DiagOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
485 | where |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
486 | F: Float, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
487 | A : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
488 | B : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
489 | S : Adjointable<A, F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
490 | T : Adjointable<B, F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
491 | T::Codomain : HasDual<F>, |
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
492 | S::Codomain : HasDual<F>, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
493 | { |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
494 | type AdjointCodomain = Pair<S::AdjointCodomain, T::AdjointCodomain>; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
495 | type Adjoint<'a> = DiagOp<S::Adjoint<'a>, T::Adjoint<'a>> where Self : 'a; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
496 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
497 | fn adjoint(&self) -> Self::Adjoint<'_> { |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
498 | DiagOp(self.0.adjoint(), self.1.adjoint()) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
499 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
500 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
501 | |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
502 | impl<A, B, Xʹ, Yʹ, S, T> Preadjointable<Pair<A,B>, Pair<Xʹ,Yʹ>> for DiagOp<S, T> |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
503 | where |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
504 | A : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
505 | B : Space, |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
506 | Xʹ : Space, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
507 | Yʹ : Space, |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
508 | S : Preadjointable<A, Xʹ>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
509 | T : Preadjointable<B, Yʹ>, |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
510 | { |
78
cebedc4a8331
Try to use HasDual with adjoints. Problem with nalgebra Instances.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
511 | type PreadjointCodomain = Pair<S::PreadjointCodomain, T::PreadjointCodomain>; |
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
512 | type Preadjoint<'a> = DiagOp<S::Preadjoint<'a>, T::Preadjoint<'a>> where Self : 'a; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
513 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
514 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
515 | DiagOp(self.0.preadjoint(), self.1.preadjoint()) |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
516 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
517 | } |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
518 | |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
519 | /// Block operator |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
520 | pub type BlockOp<S11, S12, S21, S22> = ColOp<RowOp<S11, S12>, RowOp<S21, S22>>; |
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
521 | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
522 | |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
523 | macro_rules! pairnorm { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
524 | ($expj:ty) => { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
525 | impl<F, A, B, S, T, ExpA, ExpB, ExpR> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
526 | BoundedLinear<Pair<A, B>, PairNorm<ExpA, ExpB, $expj>, ExpR, F> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
527 | for RowOp<S, T> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
528 | where |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
529 | F : Float, |
61 | 530 | A : Space + Norm<F, ExpA>, |
531 | B : Space + Norm<F, ExpB>, | |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
532 | S : BoundedLinear<A, ExpA, ExpR, F>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
533 | T : BoundedLinear<B, ExpB, ExpR, F>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
534 | S::Codomain : Add<T::Codomain>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
535 | <S::Codomain as Add<T::Codomain>>::Output : Space, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
536 | ExpA : NormExponent, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
537 | ExpB : NormExponent, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
538 | ExpR : NormExponent, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
539 | { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
540 | fn opnorm_bound( |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
541 | &self, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
542 | PairNorm(expa, expb, _) : PairNorm<ExpA, ExpB, $expj>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
543 | expr : ExpR |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
544 | ) -> F { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
545 | // An application of the triangle inequality bounds the norm by the maximum |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
546 | // of the individual norms. A simple observation shows this to be exact. |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
547 | let na = self.0.opnorm_bound(expa, expr); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
548 | let nb = self.1.opnorm_bound(expb, expr); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
549 | na.max(nb) |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
550 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
551 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
552 | |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
553 | impl<F, A, S, T, ExpA, ExpS, ExpT> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
554 | BoundedLinear<A, ExpA, PairNorm<ExpS, ExpT, $expj>, F> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
555 | for ColOp<S, T> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
556 | where |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
557 | F : Float, |
61 | 558 | A : Space + Norm<F, ExpA>, |
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
559 | S : BoundedLinear<A, ExpA, ExpS, F>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
560 | T : BoundedLinear<A, ExpA, ExpT, F>, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
561 | ExpA : NormExponent, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
562 | ExpS : NormExponent, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
563 | ExpT : NormExponent, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
564 | { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
565 | fn opnorm_bound( |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
566 | &self, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
567 | expa : ExpA, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
568 | PairNorm(exps, expt, _) : PairNorm<ExpS, ExpT, $expj> |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
569 | ) -> F { |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
570 | // This is based on the rule for RowOp and ‖A^*‖ = ‖A‖, hence, |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
571 | // for A=[S; T], ‖A‖=‖[S^*, T^*]‖ ≤ max{‖S^*‖, ‖T^*‖} = max{‖S‖, ‖T‖} |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
572 | let ns = self.0.opnorm_bound(expa, exps); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
573 | let nt = self.1.opnorm_bound(expa, expt); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
574 | ns.max(nt) |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
575 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
576 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
577 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
578 | } |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
579 | |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
580 | pairnorm!(L1); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
581 | pairnorm!(L2); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
582 | pairnorm!(Linfinity); |
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
583 |