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