Wed, 07 May 2025 11:35:17 -0500
Add .hgignore
| 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; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
8 | pub use crate::mapping::{Composition, DifferentiableImpl, Mapping, Space}; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
9 | use crate::norms::{Linfinity, Norm, NormExponent, PairNorm, L1, L2}; |
|
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; |
| 104 | 14 | use std::ops::Mul; |
| 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 | |
| 28 | /// Efficient in-place summation. | |
| 29 | #[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
|
30 | pub trait AXPY<F, X = Self>: Space + std::ops::MulAssign<F> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
31 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
32 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
33 | X: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
34 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
35 | type Owned: AXPY<F, X>; |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
36 | |
| 0 | 37 | /// Computes `y = βy + αx`, where `y` is `Self`. |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
38 | fn axpy<I: Instance<X>>(&mut self, α: F, x: I, β: F); |
| 0 | 39 | |
| 40 | /// Copies `x` to `self`. | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
41 | fn copy_from<I: Instance<X>>(&mut self, x: I) { |
| 0 | 42 | self.axpy(1.0, x, 0.0) |
| 43 | } | |
| 44 | ||
| 5 | 45 | /// Computes `y = αx`, where `y` is `Self`. |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
46 | fn scale_from<I: Instance<X>>(&mut self, α: F, x: I) { |
| 0 | 47 | self.axpy(α, x, 0.0) |
| 48 | } | |
|
62
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
49 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
50 | /// Return a similar zero as `self`. |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
51 | fn similar_origin(&self) -> Self::Owned; |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
52 | |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
53 | /// Set self to zero. |
|
d8305c9b6fdf
Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
54 | fn set_zero(&mut self); |
| 0 | 55 | } |
| 56 | ||
| 57 | /// Efficient in-place application for [`Linear`] operators. | |
| 58 | #[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
|
59 | pub trait GEMV<F: Num, X: Space, Y = <Self as Mapping<X>>::Codomain>: Linear<X> { |
| 5 | 60 | /// 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
|
61 | fn gemv<I: Instance<X>>(&self, y: &mut Y, α: F, x: I, β: F); |
| 0 | 62 | |
| 67 | 63 | #[inline] |
| 5 | 64 | /// 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
|
65 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 0 | 66 | self.gemv(y, 1.0, x, 0.0) |
| 67 | } | |
| 68 | ||
| 67 | 69 | #[inline] |
| 5 | 70 | /// 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
|
71 | fn apply_add<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 0 | 72 | self.gemv(y, 1.0, x, 1.0) |
| 73 | } | |
| 74 | } | |
| 75 | ||
| 76 | /// Bounded linear operators | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
77 | 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
|
78 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
79 | F: Num, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
80 | X: Space + Norm<XExp, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
81 | XExp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
82 | CodExp: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
83 | { |
| 0 | 84 | /// A bound on the operator norm $\|A\|$ for the linear operator $A$=`self`. |
| 85 | /// 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
|
86 | /// reasonably implemented. The [`NormExponent`] `xexp` indicates the norm |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
87 | /// 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
|
88 | /// |
|
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
89 | /// 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
|
90 | fn opnorm_bound(&self, xexp: XExp, codexp: CodExp) -> DynResult<F>; |
| 0 | 91 | } |
| 92 | ||
| 5 | 93 | // Linear operator application into mutable target. The [`AsRef`] bound |
| 94 | // is used to guarantee compatibility with `Yʹ` and `Self::Codomain`; | |
| 95 | // the former is assumed to be e.g. a view into the latter. | |
| 0 | 96 | |
| 97 | /*impl<X,Y,T> Fn(&X) -> Y for T where T : Linear<X,Codomain=Y> { | |
| 98 | fn call(&self, x : &X) -> Y { | |
| 99 | self.apply(x) | |
| 100 | } | |
| 101 | }*/ | |
| 102 | ||
| 5 | 103 | /// 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
|
104 | pub trait Adjointable<X, Yʹ>: Linear<X> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
105 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
106 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
107 | Yʹ: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
108 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
109 | type AdjointCodomain: Space; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
110 | 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
|
111 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
112 | Self: 'a; |
| 0 | 113 | |
| 114 | /// Form the adjoint operator of `self`. | |
| 115 | fn adjoint(&self) -> Self::Adjoint<'_>; | |
| 116 | } | |
| 117 | ||
| 5 | 118 | /// Trait for forming a preadjoint of an operator. |
| 119 | /// | |
|
8
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
120 | /// For an operator $A$ this is an operator $A\_\*$ |
|
4e09b7829b51
Multithreaded bisection tree operations
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
121 | /// such that its adjoint $(A\_\*)^\*=A$. The space `X` is the domain of the `Self` |
| 0 | 122 | /// operator. The space `Ypre` is the predual of its codomain, and should be the |
| 123 | /// domain of the adjointed operator. `Self::Preadjoint` should be | |
| 124 | /// [`Adjointable`]`<'a,Ypre,X>`. | |
|
65
9327d544ca0b
Reduce preadjointing constraints
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
125 | /// 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
|
126 | /// 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
|
127 | /// 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
|
128 | 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
|
129 | Linear<X> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
130 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
131 | type PreadjointCodomain: Space; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
132 | 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
|
133 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
134 | Self: 'a; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
135 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
136 | /// Form the adjoint operator of `self`. |
| 0 | 137 | fn preadjoint(&self) -> Self::Preadjoint<'_>; |
| 138 | } | |
| 139 | ||
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
140 | /// 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
|
141 | 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
|
142 | 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
|
143 | 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
|
144 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
145 | } |
| 0 | 146 | |
| 147 | /// The identity operator | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
148 | #[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
|
149 | 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
|
150 | |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
151 | impl<X> IdOp<X> { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
152 | pub fn new() -> IdOp<X> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
153 | IdOp(PhantomData) |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
154 | } |
|
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
155 | } |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
156 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
157 | impl<X: Clone + Space> Mapping<X> for IdOp<X> { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
158 | type Codomain = X; |
| 0 | 159 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
160 | fn apply<I: Instance<X>>(&self, x: I) -> X { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
161 | x.own() |
|
13
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
162 | } |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
163 | } |
|
465fa2121ccb
Better Linear and Mapping structure that can provide consuming and reference `apply`.
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
164 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
165 | impl<X: Clone + 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
|
166 | |
| 0 | 167 | #[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
|
168 | 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
|
169 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
170 | Y: AXPY<F, X>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
171 | X: Clone + Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
172 | { |
| 0 | 173 | // 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
|
174 | fn gemv<I: Instance<X>>(&self, y: &mut Y, α: F, x: I, β: F) { |
| 0 | 175 | y.axpy(α, x, β) |
| 176 | } | |
| 177 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
178 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 0 | 179 | y.copy_from(x); |
| 180 | } | |
| 181 | } | |
| 182 | ||
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
183 | 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
|
184 | where |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
185 | 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
|
186 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
187 | E: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
188 | { |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
189 | 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
|
190 | Ok(F::ONE) |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
191 | } |
| 0 | 192 | } |
| 193 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
194 | impl<X: Clone + Space> Adjointable<X, X> for IdOp<X> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
195 | type AdjointCodomain = X; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
196 | type Adjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
197 | = IdOp<X> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
198 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
199 | X: 'a; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
200 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
201 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
202 | IdOp::new() |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
203 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
204 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
205 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
206 | impl<X: Clone + Space> Preadjointable<X, X> for IdOp<X> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
207 | type PreadjointCodomain = X; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
208 | type Preadjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
209 | = IdOp<X> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
210 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
211 | X: 'a; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
212 | |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
213 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
214 | IdOp::new() |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
215 | } |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
216 | } |
| 61 | 217 | |
| 66 | 218 | /// The zero operator |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
219 | #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)] |
| 66 | 220 | pub struct ZeroOp<'a, X, XD, Y, F> { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
221 | zero: &'a Y, // TODO: don't pass this in `new`; maybe not even store. |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
222 | dual_or_predual_zero: XD, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
223 | _phantoms: PhantomData<(X, Y, F)>, |
| 66 | 224 | } |
| 225 | ||
| 226 | // TODO: Need to make Zero in Instance. | |
| 227 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
228 | impl<'a, F: Num, X: Space, XD, Y: Space + Clone> ZeroOp<'a, X, XD, Y, F> { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
229 | pub fn new(zero: &'a Y, dual_or_predual_zero: XD) -> Self { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
230 | ZeroOp { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
231 | zero, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
232 | dual_or_predual_zero, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
233 | _phantoms: PhantomData, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
234 | } |
| 66 | 235 | } |
| 236 | } | |
| 237 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
238 | impl<'a, F: Num, X: Space, XD, Y: AXPY<F> + Clone> Mapping<X> for ZeroOp<'a, X, XD, Y, F> { |
| 66 | 239 | type Codomain = Y; |
| 240 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
241 | fn apply<I: Instance<X>>(&self, _x: I) -> Y { |
| 66 | 242 | self.zero.clone() |
| 243 | } | |
| 244 | } | |
| 245 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
246 | impl<'a, F: Num, X: Space, XD, Y: AXPY<F> + Clone> Linear<X> for ZeroOp<'a, X, XD, Y, F> {} |
| 66 | 247 | |
| 248 | #[replace_float_literals(F::cast_from(literal))] | |
| 249 | impl<'a, F, X, XD, Y> GEMV<F, X, Y> for ZeroOp<'a, X, XD, Y, F> | |
| 250 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
251 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
252 | Y: AXPY<F, Y> + Clone, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
253 | X: Space, |
| 66 | 254 | { |
| 255 | // 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
|
256 | fn gemv<I: Instance<X>>(&self, y: &mut Y, _α: F, _x: I, β: F) { |
| 66 | 257 | *y *= β; |
| 258 | } | |
| 259 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
260 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, _x: I) { |
| 66 | 261 | y.set_zero(); |
| 262 | } | |
| 263 | } | |
| 264 | ||
| 265 | impl<'a, F, X, XD, Y, E1, E2> BoundedLinear<X, E1, E2, F> for ZeroOp<'a, X, XD, Y, F> | |
| 266 | where | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
267 | X: Space + Norm<E1, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
268 | Y: AXPY<F> + Clone + Norm<E2, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
269 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
270 | E1: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
271 | E2: NormExponent, |
| 66 | 272 | { |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
273 | 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
|
274 | Ok(F::ZERO) |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
275 | } |
| 66 | 276 | } |
| 277 | ||
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
278 | impl<'a, F: Num, X, XD, Y, Yprime: Space> Adjointable<X, Yprime> for ZeroOp<'a, X, XD, Y, F> |
| 66 | 279 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
280 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
281 | Y: AXPY<F> + Clone + 'static, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
282 | XD: AXPY<F> + Clone + 'static, |
| 66 | 283 | { |
| 284 | type AdjointCodomain = XD; | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
285 | type Adjoint<'b> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
286 | = ZeroOp<'b, Yprime, (), XD, F> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
287 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
288 | Self: 'b; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
289 | // () means not (pre)adjointable. |
| 66 | 290 | |
| 291 | fn adjoint(&self) -> Self::Adjoint<'_> { | |
| 292 | ZeroOp::new(&self.dual_or_predual_zero, ()) | |
| 293 | } | |
| 294 | } | |
| 295 | ||
| 296 | impl<'a, F, X, XD, Y, Ypre> Preadjointable<X, Ypre> for ZeroOp<'a, X, XD, Y, F> | |
| 297 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
298 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
299 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
300 | Y: AXPY<F> + Clone, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
301 | Ypre: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
302 | XD: AXPY<F> + Clone + 'static, |
| 66 | 303 | { |
| 304 | type PreadjointCodomain = XD; | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
305 | type Preadjoint<'b> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
306 | = ZeroOp<'b, Ypre, (), XD, F> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
307 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
308 | Self: 'b; |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
309 | // () means not (pre)adjointable. |
| 66 | 310 | |
| 311 | fn preadjoint(&self) -> Self::Preadjoint<'_> { | |
| 312 | ZeroOp::new(&self.dual_or_predual_zero, ()) | |
| 313 | } | |
| 314 | } | |
| 315 | ||
| 61 | 316 | impl<S, T, E, X> Linear<X> for Composition<S, T, E> |
| 317 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
318 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
319 | T: Linear<X>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
320 | S: Linear<T::Codomain>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
321 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
322 | } |
| 61 | 323 | |
| 324 | impl<F, S, T, E, X, Y> GEMV<F, X, Y> for Composition<S, T, E> | |
| 325 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
326 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
327 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
328 | T: Linear<X>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
329 | S: GEMV<F, T::Codomain, Y>, |
| 61 | 330 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
331 | fn gemv<I: Instance<X>>(&self, y: &mut Y, α: F, x: I, β: F) { |
| 61 | 332 | self.outer.gemv(y, α, self.inner.apply(x), β) |
| 333 | } | |
| 334 | ||
| 335 | /// 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
|
336 | fn apply_mut<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 61 | 337 | self.outer.apply_mut(y, self.inner.apply(x)) |
| 338 | } | |
| 339 | ||
| 340 | /// 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
|
341 | fn apply_add<I: Instance<X>>(&self, y: &mut Y, x: I) { |
| 61 | 342 | self.outer.apply_add(y, self.inner.apply(x)) |
| 343 | } | |
| 344 | } | |
| 345 | ||
| 346 | impl<F, S, T, X, Z, Xexp, Yexp, Zexp> BoundedLinear<X, Xexp, Yexp, F> for Composition<S, T, Zexp> | |
| 347 | where | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
348 | F: Num, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
349 | X: Space + Norm<Xexp, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
350 | Z: Space + Norm<Zexp, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
351 | Xexp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
352 | Yexp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
353 | Zexp: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
354 | 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
|
355 | S: BoundedLinear<Z, Zexp, Yexp, F>, |
| 61 | 356 | { |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
357 | fn opnorm_bound(&self, xexp: Xexp, yexp: Yexp) -> DynResult<F> { |
| 61 | 358 | 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
|
359 | Ok(self.outer.opnorm_bound(zexp, yexp)? * self.inner.opnorm_bound(xexp, zexp)?) |
| 61 | 360 | } |
| 361 | } | |
| 362 | ||
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
363 | /// “Row operator” $(S, T)$; $(S, T)(x, y)=Sx + Ty$. |
| 101 | 364 | #[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
|
365 | 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
|
366 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
367 | use std::ops::Add; |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
368 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
369 | 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
|
370 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
371 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
372 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
373 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
374 | T: Mapping<B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
375 | S::Codomain: Add<T::Codomain>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
376 | <S::Codomain as Add<T::Codomain>>::Output: Space, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
377 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
378 | 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
|
379 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
380 | fn apply<I: Instance<Pair<A, B>>>(&self, x: I) -> Self::Codomain { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
381 | let Pair(a, b) = x.decompose(); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
382 | self.0.apply(a) + self.1.apply(b) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
383 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
384 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
385 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
386 | 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
|
387 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
388 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
389 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
390 | S: Linear<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
391 | T: Linear<B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
392 | S::Codomain: Add<T::Codomain>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
393 | <S::Codomain as Add<T::Codomain>>::Output: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
394 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
395 | } |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
396 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
397 | 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
|
398 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
399 | U: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
400 | V: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
401 | S: GEMV<F, U, Y>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
402 | T: GEMV<F, V, Y>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
403 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
404 | 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
|
405 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
406 | fn gemv<I: Instance<Pair<U, V>>>(&self, y: &mut Y, α: F, x: I, β: F) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
407 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
408 | self.0.gemv(y, α, u, β); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
409 | self.1.gemv(y, α, v, F::ONE); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
410 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
411 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
412 | fn apply_mut<I: Instance<Pair<U, V>>>(&self, y: &mut Y, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
413 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
414 | self.0.apply_mut(y, u); |
| 74 | 415 | self.1.apply_add(y, v); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
416 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
417 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
418 | /// 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
|
419 | fn apply_add<I: Instance<Pair<U, V>>>(&self, y: &mut Y, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
420 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
421 | self.0.apply_add(y, u); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
422 | self.1.apply_add(y, v); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
423 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
424 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
425 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
426 | /// “Column operator” $(S; T)$; $(S; T)x=(Sx, Tx)$. |
| 101 | 427 | #[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
|
428 | 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
|
429 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
430 | 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
|
431 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
432 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
433 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
434 | T: Mapping<A>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
435 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
436 | 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
|
437 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
438 | fn apply<I: Instance<A>>(&self, a: I) -> Self::Codomain { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
439 | Pair(self.0.apply(a.ref_instance()), self.1.apply(a)) |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
440 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
441 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
442 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
443 | 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
|
444 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
445 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
446 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
447 | T: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
448 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
449 | } |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
450 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
451 | 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
|
452 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
453 | X: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
454 | S: GEMV<F, X, A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
455 | T: GEMV<F, X, B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
456 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
457 | 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
|
458 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
459 | fn gemv<I: Instance<X>>(&self, y: &mut Pair<A, B>, α: F, x: I, β: F) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
460 | self.0.gemv(&mut y.0, α, x.ref_instance(), β); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
461 | self.1.gemv(&mut y.1, α, x, β); |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
462 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
463 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
464 | fn apply_mut<I: Instance<X>>(&self, y: &mut Pair<A, B>, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
465 | self.0.apply_mut(&mut y.0, x.ref_instance()); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
466 | 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
|
467 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
468 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
469 | /// 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
|
470 | fn apply_add<I: Instance<X>>(&self, y: &mut Pair<A, B>, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
471 | self.0.apply_add(&mut y.0, x.ref_instance()); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
472 | 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
|
473 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
474 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
475 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
476 | 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
|
477 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
478 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
479 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
480 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
481 | S: Adjointable<A, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
482 | T: Adjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
483 | Self: Linear<Pair<A, B>>, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
484 | // 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
|
485 | // Yʹ, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
486 | // Codomain=Pair<S::AdjointCodomain, T::AdjointCodomain> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
487 | // >, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
488 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
489 | 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
|
490 | type Adjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
491 | = 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
|
492 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
493 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
494 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
495 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
496 | ColOp(self.0.adjoint(), self.1.adjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
497 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
498 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
499 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
500 | 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
|
501 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
502 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
503 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
504 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
505 | S: Preadjointable<A, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
506 | T: Preadjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
507 | Self: Linear<Pair<A, B>>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
508 | 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
|
509 | 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
|
510 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
511 | 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
|
512 | type Preadjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
513 | = 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
|
514 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
515 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
516 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
517 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
518 | ColOp(self.0.preadjoint(), self.1.preadjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
519 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
520 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
521 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
522 | 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
|
523 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
524 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
525 | Xʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
526 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
527 | R: Space + ClosedAdd, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
528 | S: Adjointable<A, Xʹ, AdjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
529 | T: Adjointable<A, Yʹ, AdjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
530 | Self: Linear<A>, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
531 | // 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
|
532 | // Pair<Xʹ,Yʹ>, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
533 | // Codomain=R, |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
534 | // >, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
535 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
536 | type AdjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
537 | type Adjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
538 | = 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
|
539 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
540 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
541 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
542 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
543 | RowOp(self.0.adjoint(), self.1.adjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
544 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
545 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
546 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
547 | 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
|
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 | Xʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
551 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
552 | R: Space + ClosedAdd, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
553 | S: Preadjointable<A, Xʹ, PreadjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
554 | T: Preadjointable<A, Yʹ, PreadjointCodomain = R>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
555 | Self: Linear<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
556 | 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
|
557 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
558 | type PreadjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
559 | type Preadjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
560 | = 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
|
561 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
562 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
563 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
564 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
565 | RowOp(self.0.preadjoint(), self.1.preadjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
566 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
567 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
568 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
569 | /// Diagonal operator |
| 101 | 570 | #[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
|
571 | 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
|
572 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
573 | 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
|
574 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
575 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
576 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
577 | S: Mapping<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
578 | T: Mapping<B>, |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
579 | { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
580 | 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
|
581 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
582 | fn apply<I: Instance<Pair<A, B>>>(&self, x: I) -> Self::Codomain { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
583 | let Pair(a, b) = x.decompose(); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
584 | Pair(self.0.apply(a), self.1.apply(b)) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
585 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
586 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
587 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
588 | 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
|
589 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
590 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
591 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
592 | S: Linear<A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
593 | T: Linear<B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
594 | { |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
595 | } |
|
57
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 | 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
|
598 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
599 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
600 | B: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
601 | U: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
602 | V: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
603 | S: GEMV<F, U, A>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
604 | T: GEMV<F, V, B>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
605 | F: Num, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
606 | 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
|
607 | { |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
608 | fn gemv<I: Instance<Pair<U, V>>>(&self, y: &mut Pair<A, B>, α: F, x: I, β: F) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
609 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
610 | self.0.gemv(&mut y.0, α, u, β); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
611 | self.1.gemv(&mut y.1, α, v, β); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
612 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
613 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
614 | fn apply_mut<I: Instance<Pair<U, V>>>(&self, y: &mut Pair<A, B>, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
615 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
616 | self.0.apply_mut(&mut y.0, u); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
617 | self.1.apply_mut(&mut y.1, v); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
618 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
619 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
620 | /// 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
|
621 | fn apply_add<I: Instance<Pair<U, V>>>(&self, y: &mut Pair<A, B>, x: I) { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
622 | let Pair(u, v) = x.decompose(); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
623 | self.0.apply_add(&mut y.0, u); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
624 | self.1.apply_add(&mut y.1, v); |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
625 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
626 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
627 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
628 | 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
|
629 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
630 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
631 | B: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
632 | Xʹ: Space, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
633 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
634 | R: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
635 | S: Adjointable<A, Xʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
636 | T: Adjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
637 | Self: Linear<Pair<A, B>>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
638 | 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
|
639 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
640 | type AdjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
641 | type Adjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
642 | = 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
|
643 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
644 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
645 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
646 | fn adjoint(&self) -> Self::Adjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
647 | DiagOp(self.0.adjoint(), self.1.adjoint()) |
|
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 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
650 | |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
651 | 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
|
652 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
653 | A: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
654 | B: Space, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
655 | Xʹ: Space, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
656 | Yʹ: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
657 | R: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
658 | S: Preadjointable<A, Xʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
659 | T: Preadjointable<B, Yʹ>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
660 | Self: Linear<Pair<A, B>>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
661 | 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
|
662 | { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
663 | type PreadjointCodomain = R; |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
664 | type Preadjoint<'a> |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
665 | = 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
|
666 | where |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
667 | Self: 'a; |
|
57
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
668 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
669 | fn preadjoint(&self) -> Self::Preadjoint<'_> { |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
670 | DiagOp(self.0.preadjoint(), self.1.preadjoint()) |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
671 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
672 | } |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
673 | |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
674 | /// Block operator |
|
1b3b1687b9ed
Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
675 | 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
|
676 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
677 | macro_rules! pairnorm { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
678 | ($expj:ty) => { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
679 | 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
|
680 | 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
|
681 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
682 | F: Float, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
683 | A: Space + Norm<ExpA, F>, |
|
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
684 | B: Space + Norm<ExpB, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
685 | S: BoundedLinear<A, ExpA, ExpR, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
686 | T: BoundedLinear<B, ExpB, ExpR, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
687 | S::Codomain: Add<T::Codomain>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
688 | <S::Codomain as Add<T::Codomain>>::Output: Space, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
689 | ExpA: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
690 | ExpB: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
691 | ExpR: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
692 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
693 | fn opnorm_bound( |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
694 | &self, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
695 | 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
|
696 | expr: ExpR, |
|
110
a1278320be26
Use DynResult for Lipschitz factors and operator norm bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
104
diff
changeset
|
697 | ) -> DynResult<F> { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
698 | // 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
|
699 | // 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
|
700 | 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
|
701 | 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
|
702 | Ok(na.max(nb)) |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
703 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
704 | } |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
705 | |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
706 | 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
|
707 | for ColOp<S, T> |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
708 | where |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
709 | F: Float, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
710 | A: Space + Norm<ExpA, F>, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
711 | S: BoundedLinear<A, ExpA, ExpS, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
712 | T: BoundedLinear<A, ExpA, ExpT, F>, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
713 | ExpA: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
714 | ExpS: NormExponent, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
715 | ExpT: NormExponent, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
716 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
717 | fn opnorm_bound( |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
718 | &self, |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
719 | expa: ExpA, |
|
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
720 | 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
|
721 | ) -> DynResult<F> { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
722 | // 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
|
723 | // 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
|
724 | 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
|
725 | 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
|
726 | Ok(ns.max(nt)) |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
727 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
728 | } |
|
99
9e5b9fc81c52
Quadratic Mappings; Lipschitz trait (moved from pointsource_algs).
Tuomo Valkonen <tuomov@iki.fi>
parents:
74
diff
changeset
|
729 | }; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
730 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
731 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
732 | pairnorm!(L1); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
733 | pairnorm!(L2); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
57
diff
changeset
|
734 | pairnorm!(Linfinity); |
| 104 | 735 | |
| 736 | /// The simplest linear mapping, scaling by a scalar. | |
| 737 | /// | |
| 738 | /// TODO: redefined/replace [`Weighted`] by composition with [`Scaled`]. | |
| 739 | pub struct Scaled<F: Float>(pub F); | |
| 740 | ||
| 741 | impl<Domain, F> Mapping<Domain> for Scaled<F> | |
| 742 | where | |
| 743 | F: Float, | |
| 744 | Domain: Space + ClosedMul<F>, | |
| 745 | { | |
| 746 | type Codomain = <Domain as Mul<F>>::Output; | |
| 747 | ||
| 748 | /// Compute the value of `self` at `x`. | |
| 749 | fn apply<I: Instance<Domain>>(&self, x: I) -> Self::Codomain { | |
| 750 | x.own() * self.0 | |
| 751 | } | |
| 752 | } | |
| 753 | ||
| 754 | impl<Domain, F> Linear<Domain> for Scaled<F> | |
| 755 | where | |
| 756 | F: Float, | |
| 757 | Domain: Space + ClosedMul<F>, | |
| 758 | { | |
| 759 | } |