src/linops.rs

branch
dev
changeset 85
f2fc6115b897
parent 84
4c2e5e65d510
equal deleted inserted replaced
84:4c2e5e65d510 85:f2fc6115b897
20 pub trait AXPY<F, X = Self> : Space + std::ops::MulAssign<F> 20 pub trait AXPY<F, X = Self> : Space + std::ops::MulAssign<F>
21 where 21 where
22 F : Num, 22 F : Num,
23 X : Space, 23 X : Space,
24 { 24 {
25 type Owned : AXPY<F, X>;
26
27 /// Computes `βy + αx`, where `y` is `Self`. 25 /// Computes `βy + αx`, where `y` is `Self`.
28 fn add_mul<I : Instance<X>>(self, α : F, x : I, β : F) -> Self::Owned ; 26 fn add_mul<I : Instance<X>>(self, α : F, x : I, β : F) -> X;
29 27
30 /// Computes `y = βy + αx`, where `y` is `Self`. 28 /// Computes `y = βy + αx`, where `y` is `Self`.
31 fn axpy<I : Instance<X>>(&mut self, α : F, x : I, β : F); 29 fn axpy<I : Instance<X>>(&mut self, α : F, x : I, β : F);
32 30
33 /// Copies `x` to `self`. 31 /// Copies `x` to `self`.
39 fn scale_from<I : Instance<X>>(&mut self, α : F, x : I) { 37 fn scale_from<I : Instance<X>>(&mut self, α : F, x : I) {
40 self.axpy(α, x, 0.0) 38 self.axpy(α, x, 0.0)
41 } 39 }
42 40
43 /// Return a similar zero as `self`. 41 /// Return a similar zero as `self`.
44 fn similar_origin(&self) -> Self::Owned; 42 fn similar_origin(&self) -> X;
45 43
46 /// Set self to zero. 44 /// Set self to zero.
47 fn set_zero(&mut self); 45 fn set_zero(&mut self);
48 } 46 }
49 47
50 /// Efficient in-place application for [`Linear`] operators. 48 /// Efficient in-place application for [`Linear`] operators.
51 #[replace_float_literals(F::cast_from(literal))] 49 #[replace_float_literals(F::cast_from(literal))]
52 pub trait GEMV<F : Num, X : Space, Y : AXPY<F> = <Self as Mapping<X>>::Codomain> : Linear<X> { 50 pub trait GEMV<F : Num, X : Space, Y : AXPY<F> = <Self as Mapping<X>>::Codomain>
51 : Linear<X, Codomain=Y>
52 {
53 53
54 /// Computes `αAx + βy`, where `A` is `Self`. 54 /// Computes `αAx + βy`, where `A` is `Self`.
55 fn apply_add_mul<I : Instance<X>>(&self, y : Y, α : F, x : I, β : F) -> Y::Owned { 55 fn apply_add_mul<I : Instance<X>>(&self, y : Y, α : F, x : I, β : F) -> Y {
56 y.add_mul(α, self.apply(x), β) 56 y.add_mul(α, self.apply(x), β)
57 } 57 }
58 58
59 /// Computes `y = αAx + βy`, where `A` is `Self`. 59 /// Computes `y = αAx + βy`, where `A` is `Self`.
60 fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F); 60 fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F);

mercurial