src/linops.rs

Fri, 20 Dec 2024 16:14:17 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 20 Dec 2024 16:14:17 -0500
branch
dev
changeset 79
d63e40672dd6
parent 78
cebedc4a8331
permissions
-rw-r--r--

AXPY as LinSpace attempts, difficulties with Pairs and nalgebra

nalgebra should allow various storages, so InstanceMut as &self, but that won't work.

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

mercurial