Fri, 05 Sep 2025 01:09:21 -0500
Simplify nalgebra trait bounds further
| 0 | 1 | /*! |
| 2 | Abstract linear operators. | |
| 3 | */ | |
| 4 | ||
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
5 | use crate::direct_product::Pair; |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
6 | use crate::error::DynResult; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
7 | use crate::instance::Instance; |
| 150 | 8 | pub use crate::mapping::{ClosedSpace, Composition, DifferentiableImpl, Mapping, 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
|
9 | use crate::norms::{HasDual, Linfinity, Norm, NormExponent, PairNorm, L1, L2}; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
10 | use crate::types::*; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
11 | use numeric_literals::replace_float_literals; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
12 | use serde::Serialize; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
13 | use std::marker::PhantomData; |
| 130 | 14 | use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; |
| 0 | 15 | |
| 16 | /// Trait for linear operators on `X`. | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
17 | pub trait Linear<X: Space>: Mapping<X> {} |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
18 | |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
19 | // impl<X: Space, A: Linear<X>> DifferentiableImpl<X> for A { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
20 | // type Derivative = <Self as Mapping<X>>::Codomain; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
21 | |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
22 | // /// Compute the differential of `self` at `x`, consuming the input. |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
23 | // fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
24 | // self.apply(x) |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
25 | // } |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
26 | // } |
| 0 | 27 | |
| 150 | 28 | /// Vector spaces |
|
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
|
29 | #[replace_float_literals(Self::Field::cast_from(literal))] |
| 150 | 30 | pub trait VectorSpace: |
| 164 | 31 | Space<Principal = Self::PrincipalV> |
| 32 | + Mul<Self::Field, Output = Self::PrincipalV> | |
| 33 | + Div<Self::Field, Output = Self::PrincipalV> | |
| 34 | + Add<Self, Output = Self::PrincipalV> | |
| 35 | + Add<Self::PrincipalV, Output = Self::PrincipalV> | |
| 36 | + Sub<Self, Output = Self::PrincipalV> | |
| 37 | + Sub<Self::PrincipalV, Output = Self::PrincipalV> | |
| 130 | 38 | + Neg |
| 164 | 39 | + for<'b> Add<&'b Self, Output = <Self as VectorSpace>::PrincipalV> |
| 40 | + for<'b> Sub<&'b Self, Output = <Self as VectorSpace>::PrincipalV> | |
| 150 | 41 | { |
| 164 | 42 | /// Underlying scalar field |
| 150 | 43 | type Field: Num; |
| 164 | 44 | |
| 45 | /// Principal form of the space; always equal to [`Space::Principal`], but with | |
| 46 | /// more traits guaranteed. | |
|
177
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
47 | /// |
|
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
48 | /// `PrincipalV` is only assumed to be `AXPY` for itself, as [`AXPY`] |
|
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
49 | /// uses [`Instance`] to apply all other variants and avoid problems |
|
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
50 | /// of choosing multiple implementations of the trait. |
| 164 | 51 | type PrincipalV: ClosedSpace |
| 150 | 52 | + AXPY< |
|
177
b071a1b484f8
AXPY implementation reductions
Tuomo Valkonen <tuomov@iki.fi>
parents:
171
diff
changeset
|
53 | Self::PrincipalV, |
| 150 | 54 | Field = Self::Field, |
| 164 | 55 | PrincipalV = Self::PrincipalV, |
| 56 | OwnedVariant = Self::PrincipalV, | |
| 57 | Principal = Self::PrincipalV, | |
| 150 | 58 | >; |
| 59 | ||
| 60 | /// Return a similar zero as `self`. | |
| 164 | 61 | fn similar_origin(&self) -> Self::PrincipalV; |
| 150 | 62 | // { |
| 63 | // self.make_origin_generator().make_origin() | |
| 64 | // } | |
| 65 | ||
| 66 | /// Return a similar zero as `x`. | |
| 164 | 67 | fn similar_origin_inst<I: Instance<Self>>(x: I) -> Self::PrincipalV { |
| 150 | 68 | x.eval(|xr| xr.similar_origin()) |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | /// Efficient in-place summation. | |
| 73 | #[replace_float_literals(Self::Field::cast_from(literal))] | |
| 74 | pub trait AXPY<X = Self>: | |
| 75 | VectorSpace | |
| 76 | + MulAssign<Self::Field> | |
| 77 | + DivAssign<Self::Field> | |
| 78 | + AddAssign<Self> | |
| 164 | 79 | + AddAssign<Self::PrincipalV> |
| 150 | 80 | + SubAssign<Self> |
| 164 | 81 | + SubAssign<Self::PrincipalV> |
| 151 | 82 | + for<'b> AddAssign<&'b Self> |
| 83 | + for<'b> SubAssign<&'b Self> | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
84 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
85 | X: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
86 | { |
| 0 | 87 | /// Computes `y = βy + αx`, where `y` is `Self`. |
|
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
|
88 | fn axpy<I: Instance<X>>(&mut self, α: Self::Field, x: I, β: Self::Field); |
| 0 | 89 | |
| 90 | /// Copies `x` to `self`. | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
91 | fn copy_from<I: Instance<X>>(&mut self, x: I) { |
| 0 | 92 | self.axpy(1.0, x, 0.0) |
| 93 | } | |
| 94 | ||
| 5 | 95 | /// Computes `y = αx`, where `y` is `Self`. |
|
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
|
96 | fn scale_from<I: Instance<X>>(&mut self, α: Self::Field, x: I) { |
| 0 | 97 | self.axpy(α, x, 0.0) |
| 98 | } | |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
99 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
100 | /// Set self to zero. |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
101 | fn set_zero(&mut self); |
| 0 | 102 | } |
| 103 | ||
| 164 | 104 | pub trait ClosedVectorSpace: Instance<Self> + VectorSpace<PrincipalV = Self> {} |
| 105 | impl<X: Instance<X> + VectorSpace<PrincipalV = Self>> ClosedVectorSpace for X {} | |
| 151 | 106 | |
| 0 | 107 | /// Efficient in-place application for [`Linear`] operators. |
| 108 | #[replace_float_literals(F::cast_from(literal))] | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
109 | pub trait GEMV<F: Num, X: Space, Y = <Self as Mapping<X>>::Codomain>: Linear<X> { |
| 5 | 110 | /// Computes `y = αAx + βy`, where `A` is `Self`. |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
111 | fn gemv<I: Instance<X>>(&self, y: &mut Y, α: F, x: I, β: F); |
| 0 | 112 | |
| 67 | 113 | #[inline] |
| 5 | 114 | /// Computes `y = Ax`, where `A` is `Self` |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
115 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 0 | 116 | self.gemv(y, 1.0, x, 0.0) |
| 117 | } | |
| 118 | ||
| 67 | 119 | #[inline] |
| 5 | 120 | /// Computes `y += Ax`, where `A` is `Self` |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
121 | fn apply_add<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 0 | 122 | self.gemv(y, 1.0, x, 1.0) |
| 123 | } | |
| 124 | } | |
| 125 | ||
| 126 | /// Bounded linear operators | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
127 | pub trait BoundedLinear<X, XExp, CodExp, F = f64>: Linear<X> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
128 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
129 | F: Num, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
130 | X: Space + Norm<XExp, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
131 | XExp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
132 | CodExp: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
133 | { |
| 0 | 134 | /// A bound on the operator norm $\|A\|$ for the linear operator $A$=`self`. |
| 135 | /// 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
|
136 | /// reasonably implemented. The [`NormExponent`] `xexp` indicates the norm |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
137 | /// in `X`, and `codexp` in the codomain. |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
138 | /// |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
139 | /// This may fail with an error if the bound is for some reason incalculable. |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
140 | fn opnorm_bound(&self, xexp: XExp, codexp: CodExp) -> DynResult<F>; |
| 0 | 141 | } |
| 142 | ||
| 5 | 143 | // Linear operator application into mutable target. The [`AsRef`] bound |
| 144 | // is used to guarantee compatibility with `Yʹ` and `Self::Codomain`; | |
| 145 | // the former is assumed to be e.g. a view into the latter. | |
| 0 | 146 | |
| 147 | /*impl<X,Y,T> Fn(&X) -> Y for T where T : Linear<X,Codomain=Y> { | |
| 148 | fn call(&self, x : &X) -> Y { | |
| 149 | self.apply(x) | |
| 150 | } | |
| 151 | }*/ | |
| 152 | ||
| 5 | 153 | /// Trait for forming the adjoint operator of `Self`. |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
154 | pub trait Adjointable<X, Yʹ>: Linear<X> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
155 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
156 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
157 | Yʹ: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
158 | { |
| 151 | 159 | type AdjointCodomain: ClosedSpace; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
160 | type Adjoint<'a>: Linear<Yʹ, Codomain = Self::AdjointCodomain> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
161 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
162 | Self: 'a; |
| 0 | 163 | |
| 164 | /// Form the adjoint operator of `self`. | |
| 165 | fn adjoint(&self) -> Self::Adjoint<'_>; | |
| 166 | } | |
| 167 | ||
| 5 | 168 | /// Trait for forming a preadjoint of an operator. |
| 169 | /// | |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
170 | /// For an operator $A$ this is an operator $A\_\*$ |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
171 | /// such that its adjoint $(A\_\*)^\*=A$. The space `X` is the domain of the `Self` |
| 0 | 172 | /// operator. The space `Ypre` is the predual of its codomain, and should be the |
| 173 | /// domain of the adjointed operator. `Self::Preadjoint` should be | |
| 174 | /// [`Adjointable`]`<'a,Ypre,X>`. | |
|
65
9327d544ca0b
Reduce preadjointing constraints
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
175 | /// We do not make additional restrictions on `Self::Preadjoint` (in particular, it |
|
9327d544ca0b
Reduce preadjointing constraints
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
176 | /// does not have to be adjointable) to allow `X` to be a subspace yet the preadjoint |
|
9327d544ca0b
Reduce preadjointing constraints
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
177 | /// have the full space as the codomain, etc. |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
178 | pub trait Preadjointable<X: Space, Ypre: Space = <Self as Mapping<X>>::Codomain>: |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
179 | Linear<X> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
180 | { |
| 151 | 181 | type PreadjointCodomain: ClosedSpace; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
182 | type Preadjoint<'a>: Linear<Ypre, Codomain = Self::PreadjointCodomain> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
183 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
184 | Self: 'a; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
185 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
186 | /// Form the adjoint operator of `self`. |
| 0 | 187 | fn preadjoint(&self) -> Self::Preadjoint<'_>; |
| 188 | } | |
| 189 | ||
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
190 | /// Adjointable operators $A: X → Y$ between reflexive spaces $X$ and $Y$. |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
191 | pub trait SimplyAdjointable<X: Space>: Adjointable<X, <Self as Mapping<X>>::Codomain> {} |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
192 | impl<'a, X: Space, T> SimplyAdjointable<X> for T where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
193 | T: Adjointable<X, <Self as Mapping<X>>::Codomain> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
194 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
195 | } |
| 0 | 196 | |
| 197 | /// The identity operator | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
198 | #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)] |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
199 | pub struct IdOp<X>(PhantomData<X>); |
|
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
200 | |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
201 | impl<X> IdOp<X> { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
202 | pub fn new() -> IdOp<X> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
203 | IdOp(PhantomData) |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
204 | } |
|
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
205 | } |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
206 | |
| 150 | 207 | impl<X: Space> Mapping<X> for IdOp<X> { |
| 164 | 208 | type Codomain = X::Principal; |
| 0 | 209 | |
| 151 | 210 | fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { |
| 168 | 211 | 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
|
212 | } |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
213 | } |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
214 | |
| 150 | 215 | impl<X: Space> Linear<X> for IdOp<X> {} |
|
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
216 | |
| 0 | 217 | #[replace_float_literals(F::cast_from(literal))] |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
218 | impl<F: Num, X, Y> GEMV<F, X, Y> for IdOp<X> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
219 | 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
|
220 | Y: AXPY<X, Field = F>, |
| 150 | 221 | X: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
222 | { |
| 0 | 223 | // Computes `y = αAx + βy`, where `A` is `Self`. |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
224 | fn gemv<I: Instance<X>>(&self, y: &mut Y, α: F, x: I, β: F) { |
| 0 | 225 | y.axpy(α, x, β) |
| 226 | } | |
| 227 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
228 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 0 | 229 | y.copy_from(x); |
| 230 | } | |
| 231 | } | |
| 232 | ||
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
233 | 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
|
234 | where |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
235 | X: Space + Clone + Norm<E, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
236 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
237 | E: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
238 | { |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
239 | fn opnorm_bound(&self, _xexp: E, _codexp: E) -> DynResult<F> { |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
240 | Ok(F::ONE) |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
241 | } |
| 0 | 242 | } |
| 243 | ||
| 164 | 244 | impl<X: Clone + Space> Adjointable<X, X::Principal> for IdOp<X> { |
| 245 | type AdjointCodomain = X::Principal; | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
246 | type Adjoint<'a> |
| 164 | 247 | = IdOp<X::Principal> |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
248 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
249 | X: 'a; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
250 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
251 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
252 | IdOp::new() |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
253 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
254 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
255 | |
| 164 | 256 | impl<X: Clone + Space> Preadjointable<X, X::Principal> for IdOp<X> { |
| 257 | type PreadjointCodomain = X::Principal; | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
258 | type Preadjoint<'a> |
| 164 | 259 | = IdOp<X::Principal> |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
260 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
261 | X: 'a; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
262 | |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
263 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
264 | IdOp::new() |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
265 | } |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
266 | } |
| 61 | 267 | |
|
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
|
268 | /// The zero operator from a space to itself |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
269 | #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)] |
|
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
|
270 | pub struct SimpleZeroOp; |
| 66 | 271 | |
| 150 | 272 | impl<X: VectorSpace> Mapping<X> for SimpleZeroOp { |
| 164 | 273 | type Codomain = X::PrincipalV; |
| 66 | 274 | |
| 164 | 275 | fn apply<I: Instance<X>>(&self, x: I) -> X::PrincipalV { |
|
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
|
276 | X::similar_origin_inst(x) |
| 66 | 277 | } |
| 278 | } | |
| 279 | ||
| 150 | 280 | impl<X: VectorSpace> Linear<X> for SimpleZeroOp {} |
| 66 | 281 | |
| 282 | #[replace_float_literals(F::cast_from(literal))] | |
|
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
|
283 | impl<X, Y, F> GEMV<F, X, Y> for SimpleZeroOp |
| 66 | 284 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
285 | F: Num, |
|
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
|
286 | Y: AXPY<Field = F>, |
| 150 | 287 | X: VectorSpace<Field = F> + Instance<X>, |
| 66 | 288 | { |
| 289 | // Computes `y = αAx + βy`, where `A` is `Self`. | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
290 | fn gemv<I: Instance<X>>(&self, y: &mut Y, _α: F, _x: I, β: F) { |
| 66 | 291 | *y *= β; |
| 292 | } | |
| 293 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
294 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, _x: I) { |
| 66 | 295 | y.set_zero(); |
| 296 | } | |
| 297 | } | |
| 298 | ||
|
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
|
299 | impl<X, F, E1, E2> BoundedLinear<X, E1, E2, F> for SimpleZeroOp |
| 66 | 300 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
301 | F: Num, |
| 150 | 302 | X: VectorSpace<Field = F> + Norm<E1, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
303 | E1: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
304 | E2: NormExponent, |
| 66 | 305 | { |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
306 | fn opnorm_bound(&self, _xexp: E1, _codexp: E2) -> DynResult<F> { |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
307 | Ok(F::ZERO) |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
308 | } |
| 66 | 309 | } |
| 310 | ||
|
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
|
311 | impl<X, F> Adjointable<X, X::DualSpace> for SimpleZeroOp |
| 66 | 312 | 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
|
313 | F: Num, |
| 150 | 314 | X: VectorSpace<Field = F> + HasDual<F>, |
| 151 | 315 | X::DualSpace: ClosedVectorSpace, |
| 66 | 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 AdjointCodomain = X::DualSpace; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
318 | type Adjoint<'b> |
|
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
|
319 | = SimpleZeroOp |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
320 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
321 | Self: 'b; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
322 | // () means not (pre)adjointable. |
| 66 | 323 | |
| 324 | fn adjoint(&self) -> Self::Adjoint<'_> { | |
|
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
|
325 | SimpleZeroOp |
|
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
|
326 | } |
|
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
|
327 | } |
|
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
|
328 | |
| 150 | 329 | pub trait OriginGenerator<Y: VectorSpace> { |
| 140 | 330 | type Ref<'b>: OriginGenerator<Y> |
| 331 | where | |
| 332 | Self: 'b; | |
| 333 | ||
| 164 | 334 | fn origin(&self) -> Y::PrincipalV; |
| 140 | 335 | fn as_ref(&self) -> Self::Ref<'_>; |
| 336 | } | |
| 337 | ||
| 150 | 338 | impl<Y: VectorSpace> OriginGenerator<Y> for Y { |
| 140 | 339 | type Ref<'b> |
| 340 | = &'b Y | |
| 341 | where | |
| 342 | Self: 'b; | |
| 343 | ||
| 344 | #[inline] | |
| 164 | 345 | fn origin(&self) -> Y::PrincipalV { |
| 140 | 346 | return self.similar_origin(); |
| 347 | } | |
| 348 | ||
| 349 | #[inline] | |
| 350 | fn as_ref(&self) -> Self::Ref<'_> { | |
| 351 | self | |
| 352 | } | |
| 353 | } | |
| 354 | ||
| 150 | 355 | impl<'b, Y: VectorSpace> OriginGenerator<Y> for &'b Y { |
| 140 | 356 | type Ref<'c> |
| 357 | = Self | |
| 358 | where | |
| 359 | Self: 'c; | |
| 360 | ||
| 361 | #[inline] | |
| 164 | 362 | fn origin(&self) -> Y::PrincipalV { |
| 140 | 363 | return self.similar_origin(); |
| 364 | } | |
| 365 | ||
| 366 | #[inline] | |
| 367 | fn as_ref(&self) -> Self::Ref<'_> { | |
| 368 | self | |
| 369 | } | |
| 370 | } | |
| 371 | ||
| 139 | 372 | /// A zero operator that can be eitherh dualised or predualised (once). |
| 373 | /// This is achieved by storing an oppropriate zero. | |
| 150 | 374 | pub struct ZeroOp<X, Y: VectorSpace<Field = F>, OY: OriginGenerator<Y>, O, F: Float = f64> { |
| 140 | 375 | codomain_origin_generator: OY, |
| 376 | other_origin_generator: O, | |
| 139 | 377 | _phantoms: PhantomData<(X, Y, F)>, |
| 378 | } | |
| 379 | ||
| 140 | 380 | impl<X, Y, OY, F> ZeroOp<X, Y, OY, (), F> |
| 139 | 381 | where |
| 140 | 382 | OY: OriginGenerator<Y>, |
| 150 | 383 | X: VectorSpace<Field = F>, |
| 384 | Y: VectorSpace<Field = F>, | |
| 139 | 385 | F: Float, |
| 386 | { | |
| 140 | 387 | pub fn new(y_og: OY) -> Self { |
| 139 | 388 | ZeroOp { |
| 140 | 389 | codomain_origin_generator: y_og, |
| 390 | other_origin_generator: (), | |
| 139 | 391 | _phantoms: PhantomData, |
| 392 | } | |
| 393 | } | |
| 394 | } | |
| 395 | ||
| 140 | 396 | impl<X, Y, OY, OXprime, Xprime, Yprime, F> ZeroOp<X, Y, OY, OXprime, F> |
| 397 | where | |
| 398 | OY: OriginGenerator<Y>, | |
| 399 | OXprime: OriginGenerator<Xprime>, | |
| 400 | X: HasDual<F, DualSpace = Xprime>, | |
| 401 | Y: HasDual<F, DualSpace = Yprime>, | |
| 402 | F: Float, | |
| 164 | 403 | Xprime: VectorSpace<Field = F, PrincipalV = Xprime>, |
| 404 | Xprime::PrincipalV: AXPY<Field = F>, | |
| 140 | 405 | Yprime: Space + Instance<Yprime>, |
| 406 | { | |
| 407 | pub fn new_dualisable(y_og: OY, xprime_og: OXprime) -> Self { | |
| 408 | ZeroOp { | |
| 409 | codomain_origin_generator: y_og, | |
| 410 | other_origin_generator: xprime_og, | |
| 411 | _phantoms: PhantomData, | |
| 412 | } | |
| 413 | } | |
| 414 | } | |
| 415 | ||
| 416 | impl<X, Y, O, OY, F> Mapping<X> for ZeroOp<X, Y, OY, O, F> | |
| 139 | 417 | where |
| 150 | 418 | X: Space, |
| 419 | Y: VectorSpace<Field = F>, | |
| 139 | 420 | F: Float, |
| 140 | 421 | OY: OriginGenerator<Y>, |
| 139 | 422 | { |
| 164 | 423 | type Codomain = Y::PrincipalV; |
| 139 | 424 | |
| 164 | 425 | fn apply<I: Instance<X>>(&self, _x: I) -> Y::PrincipalV { |
| 140 | 426 | self.codomain_origin_generator.origin() |
| 139 | 427 | } |
| 428 | } | |
| 429 | ||
| 140 | 430 | impl<X, Y, OY, O, F> Linear<X> for ZeroOp<X, Y, OY, O, F> |
| 139 | 431 | where |
| 150 | 432 | X: Space, |
| 433 | Y: VectorSpace<Field = F>, | |
| 139 | 434 | F: Float, |
| 140 | 435 | OY: OriginGenerator<Y>, |
| 139 | 436 | { |
| 437 | } | |
| 438 | ||
| 439 | #[replace_float_literals(F::cast_from(literal))] | |
| 140 | 440 | impl<X, Y, OY, O, F> GEMV<F, X, Y> for ZeroOp<X, Y, OY, O, F> |
| 139 | 441 | where |
| 150 | 442 | X: Space, |
| 164 | 443 | Y: AXPY<Field = F, PrincipalV = Y>, |
| 139 | 444 | F: Float, |
| 140 | 445 | OY: OriginGenerator<Y>, |
| 139 | 446 | { |
| 447 | // Computes `y = αAx + βy`, where `A` is `Self`. | |
| 448 | fn gemv<I: Instance<X>>(&self, y: &mut Y, _α: F, _x: I, β: F) { | |
| 449 | *y *= β; | |
| 450 | } | |
| 451 | ||
| 452 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, _x: I) { | |
| 453 | y.set_zero(); | |
| 454 | } | |
| 455 | } | |
| 456 | ||
| 140 | 457 | impl<X, Y, OY, O, F, E1, E2> BoundedLinear<X, E1, E2, F> for ZeroOp<X, Y, OY, O, F> |
| 139 | 458 | where |
| 459 | X: Space + Instance<X> + Norm<E1, F>, | |
| 150 | 460 | Y: VectorSpace<Field = F>, |
| 164 | 461 | Y::PrincipalV: Clone, |
| 139 | 462 | F: Float, |
| 463 | E1: NormExponent, | |
| 464 | E2: NormExponent, | |
| 140 | 465 | OY: OriginGenerator<Y>, |
| 139 | 466 | { |
| 467 | fn opnorm_bound(&self, _xexp: E1, _codexp: E2) -> DynResult<F> { | |
| 468 | Ok(F::ZERO) | |
| 469 | } | |
| 470 | } | |
| 471 | ||
| 140 | 472 | impl<'b, X, Y, OY, OXprime, Xprime, Yprime, F> Adjointable<X, Yprime> |
| 473 | for ZeroOp<X, Y, OY, OXprime, F> | |
| 139 | 474 | where |
| 475 | X: HasDual<F, DualSpace = Xprime>, | |
| 476 | Y: HasDual<F, DualSpace = Yprime>, | |
| 477 | F: Float, | |
| 151 | 478 | Xprime: ClosedVectorSpace<Field = F>, |
| 479 | //Xprime::Owned: AXPY<Field = F>, | |
| 480 | Yprime: ClosedSpace, | |
| 140 | 481 | OY: OriginGenerator<Y>, |
| 482 | OXprime: OriginGenerator<X::DualSpace>, | |
| 139 | 483 | { |
| 484 | type AdjointCodomain = Xprime; | |
| 485 | type Adjoint<'c> | |
| 140 | 486 | = ZeroOp<Yprime, Xprime, OXprime::Ref<'c>, (), F> |
| 139 | 487 | where |
| 488 | Self: 'c; | |
| 489 | // () means not (pre)adjointable. | |
| 490 | ||
| 491 | fn adjoint(&self) -> Self::Adjoint<'_> { | |
| 492 | ZeroOp { | |
| 140 | 493 | codomain_origin_generator: self.other_origin_generator.as_ref(), |
| 494 | other_origin_generator: (), | |
|
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
|
495 | _phantoms: PhantomData, |
|
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
|
496 | } |
| 66 | 497 | } |
| 498 | } | |
| 499 | ||
| 61 | 500 | impl<S, T, E, X> Linear<X> for Composition<S, T, E> |
| 501 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
502 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
503 | T: Linear<X>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
504 | S: Linear<T::Codomain>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
505 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
506 | } |
| 61 | 507 | |
| 508 | impl<F, S, T, E, X, Y> GEMV<F, X, Y> for Composition<S, T, E> | |
| 509 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
510 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
511 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
512 | T: Linear<X>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
513 | S: GEMV<F, T::Codomain, Y>, |
| 61 | 514 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
515 | fn gemv<I: Instance<X>>(&self, y: &mut Y, α: F, x: I, β: F) { |
| 61 | 516 | self.outer.gemv(y, α, self.inner.apply(x), β) |
| 517 | } | |
| 518 | ||
| 519 | /// Computes `y = Ax`, where `A` is `Self` | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
520 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 61 | 521 | self.outer.apply_mut(y, self.inner.apply(x)) |
| 522 | } | |
| 523 | ||
| 524 | /// Computes `y += Ax`, where `A` is `Self` | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
525 | fn apply_add<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 61 | 526 | self.outer.apply_add(y, self.inner.apply(x)) |
| 527 | } | |
| 528 | } | |
| 529 | ||
| 530 | impl<F, S, T, X, Z, Xexp, Yexp, Zexp> BoundedLinear<X, Xexp, Yexp, F> for Composition<S, T, Zexp> | |
| 531 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
532 | F: Num, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
533 | X: Space + Norm<Xexp, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
534 | Z: Space + Norm<Zexp, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
535 | Xexp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
536 | Yexp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
537 | Zexp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
538 | T: BoundedLinear<X, Xexp, Zexp, F, Codomain = Z>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
539 | S: BoundedLinear<Z, Zexp, Yexp, F>, |
| 61 | 540 | { |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
541 | fn opnorm_bound(&self, xexp: Xexp, yexp: Yexp) -> DynResult<F> { |
| 61 | 542 | let zexp = self.intermediate_norm_exponent; |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
543 | Ok(self.outer.opnorm_bound(zexp, yexp)? * self.inner.opnorm_bound(xexp, zexp)?) |
| 61 | 544 | } |
| 545 | } | |
| 546 | ||
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
547 | /// “Row operator” $(S, T)$; $(S, T)(x, y)=Sx + Ty$. |
| 101 | 548 | #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)] |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
549 | 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
|
550 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
551 | 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
|
552 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
553 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
554 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
555 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
556 | T: Mapping<B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
557 | S::Codomain: Add<T::Codomain>, |
| 151 | 558 | <S::Codomain as Add<T::Codomain>>::Output: ClosedSpace, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
559 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
560 | 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
|
561 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
562 | fn apply<I: Instance<Pair<A, B>>>(&self, x: I) -> Self::Codomain { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
563 | x.eval_decompose(|Pair(a, b)| self.0.apply(a) + self.1.apply(b)) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
564 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
565 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
566 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
567 | 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
|
568 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
569 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
570 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
571 | S: Linear<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
572 | T: Linear<B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
573 | S::Codomain: Add<T::Codomain>, |
| 151 | 574 | <S::Codomain as Add<T::Codomain>>::Output: ClosedSpace, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
575 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
576 | } |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
577 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
578 | 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
|
579 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
580 | U: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
581 | V: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
582 | S: GEMV<F, U, Y>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
583 | T: GEMV<F, V, Y>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
584 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
585 | Self: Linear<Pair<U, V>, Codomain = Y>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
586 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
587 | fn gemv<I: Instance<Pair<U, V>>>(&self, y: &mut Y, α: F, x: I, β: F) { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
588 | x.eval_decompose(|Pair(u, v)| { |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
589 | self.0.gemv(y, α, u, β); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
590 | self.1.gemv(y, α, v, F::ONE); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
591 | }) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
592 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
593 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
594 | fn apply_mut<I: Instance<Pair<U, V>>>(&self, y: &mut Y, x: I) { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
595 | x.eval_decompose(|Pair(u, v)| { |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
596 | self.0.apply_mut(y, u); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
597 | self.1.apply_add(y, v); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
598 | }) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
599 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
600 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
601 | /// Computes `y += Ax`, where `A` is `Self` |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
602 | fn apply_add<I: Instance<Pair<U, V>>>(&self, y: &mut Y, x: I) { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
603 | x.eval_decompose(|Pair(u, v)| { |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
604 | self.0.apply_add(y, u); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
605 | self.1.apply_add(y, v); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
606 | }) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
607 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
608 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
609 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
610 | /// “Column operator” $(S; T)$; $(S; T)x=(Sx, Tx)$. |
| 101 | 611 | #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)] |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
612 | 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
|
613 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
614 | 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
|
615 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
616 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
617 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
618 | T: Mapping<A>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
619 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
620 | 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
|
621 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
622 | fn apply<I: Instance<A>>(&self, a: I) -> Self::Codomain { |
| 171 | 623 | Pair(a.eval_ref(|r| self.0.apply(r)), self.1.apply(a)) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
624 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
625 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
626 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
627 | 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
|
628 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
629 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
630 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
631 | T: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
632 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
633 | } |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
634 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
635 | 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
|
636 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
637 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
638 | S: GEMV<F, X, A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
639 | T: GEMV<F, X, B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
640 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
641 | Self: Linear<X, Codomain = Pair<A, B>>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
642 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
643 | fn gemv<I: Instance<X>>(&self, y: &mut Pair<A, B>, α: F, x: I, β: F) { |
| 171 | 644 | x.eval_ref(|r| self.0.gemv(&mut y.0, α, r, β)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
645 | self.1.gemv(&mut y.1, α, x, β); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
646 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
647 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
648 | fn apply_mut<I: Instance<X>>(&self, y: &mut Pair<A, B>, x: I) { |
| 171 | 649 | x.eval_ref(|r| self.0.apply_mut(&mut y.0, r)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
650 | 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
|
651 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
652 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
653 | /// Computes `y += Ax`, where `A` is `Self` |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
654 | fn apply_add<I: Instance<X>>(&self, y: &mut Pair<A, B>, x: I) { |
| 171 | 655 | x.eval_ref(|r| self.0.apply_add(&mut y.0, r)); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
656 | 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
|
657 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
658 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
659 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
660 | impl<A, B, Yʹ, S, T> Adjointable<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
|
661 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
662 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
663 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
664 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
665 | S: Adjointable<A, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
666 | T: Adjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
667 | Self: Linear<Pair<A, B>>, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
668 | // 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
|
669 | // Yʹ, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
670 | // Codomain=Pair<S::AdjointCodomain, T::AdjointCodomain> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
671 | // >, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
672 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
673 | type AdjointCodomain = Pair<S::AdjointCodomain, T::AdjointCodomain>; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
674 | type Adjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
675 | = ColOp<S::Adjoint<'a>, T::Adjoint<'a>> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
676 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
677 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
678 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
679 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
680 | ColOp(self.0.adjoint(), self.1.adjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
681 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
682 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
683 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
684 | 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
|
685 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
686 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
687 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
688 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
689 | S: Preadjointable<A, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
690 | T: Preadjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
691 | Self: Linear<Pair<A, B>>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
692 | for<'a> ColOp<S::Preadjoint<'a>, T::Preadjoint<'a>>: |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
693 | Linear<Yʹ, Codomain = Pair<S::PreadjointCodomain, T::PreadjointCodomain>>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
694 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
695 | type PreadjointCodomain = Pair<S::PreadjointCodomain, T::PreadjointCodomain>; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
696 | type Preadjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
697 | = ColOp<S::Preadjoint<'a>, T::Preadjoint<'a>> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
698 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
699 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
700 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
701 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
702 | ColOp(self.0.preadjoint(), self.1.preadjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
703 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
704 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
705 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
706 | impl<A, Xʹ, Yʹ, R, S, T> Adjointable<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
|
707 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
708 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
709 | Xʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
710 | Yʹ: Space, |
| 151 | 711 | R: ClosedSpace + ClosedAdd, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
712 | S: Adjointable<A, Xʹ, AdjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
713 | T: Adjointable<A, Yʹ, AdjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
714 | Self: Linear<A>, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
715 | // for<'a> RowOp<S::Adjoint<'a>, T::Adjoint<'a>> : Linear< |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
716 | // Pair<Xʹ,Yʹ>, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
717 | // Codomain=R, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
718 | // >, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
719 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
720 | type AdjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
721 | type Adjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
722 | = RowOp<S::Adjoint<'a>, T::Adjoint<'a>> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
723 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
724 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
725 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
726 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
727 | RowOp(self.0.adjoint(), self.1.adjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
728 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
729 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
730 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
731 | impl<A, Xʹ, Yʹ, R, 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
|
732 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
733 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
734 | Xʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
735 | Yʹ: Space, |
| 151 | 736 | R: ClosedSpace + ClosedAdd, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
737 | S: Preadjointable<A, Xʹ, PreadjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
738 | T: Preadjointable<A, Yʹ, PreadjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
739 | Self: Linear<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
740 | for<'a> RowOp<S::Preadjoint<'a>, T::Preadjoint<'a>>: Linear<Pair<Xʹ, Yʹ>, Codomain = R>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
741 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
742 | type PreadjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
743 | type Preadjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
744 | = RowOp<S::Preadjoint<'a>, T::Preadjoint<'a>> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
745 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
746 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
747 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
748 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
749 | RowOp(self.0.preadjoint(), self.1.preadjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
750 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
751 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
752 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
753 | /// Diagonal operator |
| 101 | 754 | #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)] |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
755 | 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
|
756 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
757 | 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
|
758 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
759 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
760 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
761 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
762 | T: Mapping<B>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
763 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
764 | 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
|
765 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
766 | fn apply<I: Instance<Pair<A, B>>>(&self, x: I) -> Self::Codomain { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
767 | x.eval_decompose(|Pair(a, b)| Pair(self.0.apply(a), self.1.apply(b))) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
768 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
769 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
770 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
771 | 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
|
772 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
773 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
774 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
775 | S: Linear<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
776 | T: Linear<B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
777 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
778 | } |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
779 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
780 | 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
|
781 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
782 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
783 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
784 | U: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
785 | V: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
786 | S: GEMV<F, U, A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
787 | T: GEMV<F, V, B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
788 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
789 | 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
|
790 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
791 | fn gemv<I: Instance<Pair<U, V>>>(&self, y: &mut Pair<A, B>, α: F, x: I, β: F) { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
792 | x.eval_decompose(|Pair(u, v)| { |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
793 | self.0.gemv(&mut y.0, α, u, β); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
794 | self.1.gemv(&mut y.1, α, v, β); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
795 | }) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
796 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
797 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
798 | fn apply_mut<I: Instance<Pair<U, V>>>(&self, y: &mut Pair<A, B>, x: I) { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
799 | x.eval_decompose(|Pair(u, v)| { |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
800 | self.0.apply_mut(&mut y.0, u); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
801 | self.1.apply_mut(&mut y.1, v); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
802 | }) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
803 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
804 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
805 | /// Computes `y += Ax`, where `A` is `Self` |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
806 | fn apply_add<I: Instance<Pair<U, V>>>(&self, y: &mut Pair<A, B>, x: I) { |
|
133
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
807 | x.eval_decompose(|Pair(u, v)| { |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
808 | self.0.apply_add(&mut y.0, u); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
809 | self.1.apply_add(&mut y.1, v); |
|
2b13f8a0c8ba
Replace Instance ref_instance and decompose by eval_* for flexibility
Tuomo Valkonen <tuomov@iki.fi>
parents:
130
diff
changeset
|
810 | }) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
811 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
812 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
813 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
814 | impl<A, B, Xʹ, Yʹ, R, S, T> Adjointable<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
|
815 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
816 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
817 | B: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
818 | Xʹ: Space, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
819 | Yʹ: Space, |
| 151 | 820 | R: ClosedSpace, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
821 | S: Adjointable<A, Xʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
822 | T: Adjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
823 | Self: Linear<Pair<A, B>>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
824 | for<'a> DiagOp<S::Adjoint<'a>, T::Adjoint<'a>>: Linear<Pair<Xʹ, Yʹ>, Codomain = R>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
825 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
826 | type AdjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
827 | type Adjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
828 | = DiagOp<S::Adjoint<'a>, T::Adjoint<'a>> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
829 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
830 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
831 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
832 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
833 | DiagOp(self.0.adjoint(), self.1.adjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
834 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
835 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
836 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
837 | impl<A, B, Xʹ, Yʹ, R, 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
|
838 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
839 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
840 | B: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
841 | Xʹ: Space, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
842 | Yʹ: Space, |
| 151 | 843 | R: ClosedSpace, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
844 | S: Preadjointable<A, Xʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
845 | T: Preadjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
846 | Self: Linear<Pair<A, B>>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
847 | for<'a> DiagOp<S::Preadjoint<'a>, T::Preadjoint<'a>>: Linear<Pair<Xʹ, Yʹ>, Codomain = R>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
848 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
849 | type PreadjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
850 | type Preadjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
851 | = DiagOp<S::Preadjoint<'a>, T::Preadjoint<'a>> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
852 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
853 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
854 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
855 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
856 | DiagOp(self.0.preadjoint(), self.1.preadjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
857 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
858 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
859 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
860 | /// Block operator |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
861 | 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
|
862 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
863 | macro_rules! pairnorm { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
864 | ($expj:ty) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
865 | impl<F, A, B, S, T, ExpA, ExpB, ExpR> |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
866 | BoundedLinear<Pair<A, B>, PairNorm<ExpA, ExpB, $expj>, ExpR, F> for RowOp<S, T> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
867 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
868 | F: Float, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
869 | A: Space + Norm<ExpA, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
870 | B: Space + Norm<ExpB, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
871 | S: BoundedLinear<A, ExpA, ExpR, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
872 | T: BoundedLinear<B, ExpB, ExpR, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
873 | S::Codomain: Add<T::Codomain>, |
| 151 | 874 | <S::Codomain as Add<T::Codomain>>::Output: ClosedSpace, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
875 | ExpA: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
876 | ExpB: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
877 | ExpR: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
878 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
879 | fn opnorm_bound( |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
880 | &self, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
881 | PairNorm(expa, expb, _): PairNorm<ExpA, ExpB, $expj>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
882 | expr: ExpR, |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
883 | ) -> DynResult<F> { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
884 | // 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
|
885 | // of the individual norms. A simple observation shows this to be exact. |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
886 | let na = self.0.opnorm_bound(expa, expr)?; |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
887 | let nb = self.1.opnorm_bound(expb, expr)?; |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
888 | Ok(na.max(nb)) |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
889 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
890 | } |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
891 | |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
892 | impl<F, A, S, T, ExpA, ExpS, ExpT> BoundedLinear<A, ExpA, PairNorm<ExpS, ExpT, $expj>, F> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
893 | for ColOp<S, T> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
894 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
895 | F: Float, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
896 | A: Space + Norm<ExpA, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
897 | S: BoundedLinear<A, ExpA, ExpS, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
898 | T: BoundedLinear<A, ExpA, ExpT, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
899 | ExpA: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
900 | ExpS: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
901 | ExpT: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
902 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
903 | fn opnorm_bound( |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
904 | &self, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
905 | expa: ExpA, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
906 | PairNorm(exps, expt, _): PairNorm<ExpS, ExpT, $expj>, |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
907 | ) -> DynResult<F> { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
908 | // 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
|
909 | // for A=[S; T], ‖A‖=‖[S^*, T^*]‖ ≤ max{‖S^*‖, ‖T^*‖} = max{‖S‖, ‖T‖} |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
910 | let ns = self.0.opnorm_bound(expa, exps)?; |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
911 | let nt = self.1.opnorm_bound(expa, expt)?; |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
912 | Ok(ns.max(nt)) |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
913 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
914 | } |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
915 | }; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
916 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
917 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
918 | pairnorm!(L1); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
919 | pairnorm!(L2); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
920 | pairnorm!(Linfinity); |
| 104 | 921 | |
| 922 | /// The simplest linear mapping, scaling by a scalar. | |
| 923 | /// | |
| 924 | /// TODO: redefined/replace [`Weighted`] by composition with [`Scaled`]. | |
| 925 | pub struct Scaled<F: Float>(pub F); | |
| 926 | ||
| 927 | impl<Domain, F> Mapping<Domain> for Scaled<F> | |
| 928 | where | |
| 929 | F: Float, | |
| 163 | 930 | Domain: Space, |
| 164 | 931 | Domain::Principal: Mul<F>, |
| 932 | <Domain::Principal as Mul<F>>::Output: ClosedSpace, | |
| 104 | 933 | { |
| 164 | 934 | type Codomain = <Domain::Principal as Mul<F>>::Output; |
| 104 | 935 | |
| 936 | /// Compute the value of `self` at `x`. | |
| 937 | fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain { | |
| 938 | x.own() * self.0 | |
| 939 | } | |
| 940 | } | |
| 941 | ||
| 942 | impl<Domain, F> Linear<Domain> for Scaled<F> | |
| 943 | where | |
| 944 | F: Float, | |
| 163 | 945 | Domain: Space, |
| 164 | 946 | Domain::Principal: Mul<F>, |
| 947 | <Domain::Principal as Mul<F>>::Output: ClosedSpace, | |
| 104 | 948 | { |
| 949 | } |