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