src/linops.rs

branch
dev
changeset 83
9b0a7475a786
parent 82
981069ef919b
child 84
4c2e5e65d510
equal deleted inserted replaced
82:981069ef919b 83:9b0a7475a786
47 fn set_zero(&mut self); 47 fn set_zero(&mut self);
48 } 48 }
49 49
50 /// Efficient in-place application for [`Linear`] operators. 50 /// Efficient in-place application for [`Linear`] operators.
51 #[replace_float_literals(F::cast_from(literal))] 51 #[replace_float_literals(F::cast_from(literal))]
52 pub trait GEMV<F : Num, X : Space, Y = <Self as Mapping<X>>::Codomain> : Linear<X> { 52 pub trait GEMV<F : Num, X : Space, Y : AXPY<F> = <Self as Mapping<X>>::Codomain> : Linear<X> {
53 53
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 {
56 y.add_mul(α, self.apply(x), β)
57 }
58
54 /// Computes `y = αAx + βy`, where `A` is `Self`. 59 /// Computes `y = αAx + βy`, where `A` is `Self`.
55 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);
56 61
57 #[inline] 62 #[inline]
58 /// Computes `y = Ax`, where `A` is `Self` 63 /// Computes `y = Ax`, where `A` is `Self`
151 { } 156 { }
152 157
153 #[replace_float_literals(F::cast_from(literal))] 158 #[replace_float_literals(F::cast_from(literal))]
154 impl<F : Num, X, Y> GEMV<F, X, Y> for IdOp<X> 159 impl<F : Num, X, Y> GEMV<F, X, Y> for IdOp<X>
155 where 160 where
156 Y : AXPY<F, X>, 161 Y : AXPY<F>,
157 X : Clone + Space 162 X : Clone + Space
158 { 163 {
159 // Computes `y = αAx + βy`, where `A` is `Self`. 164 // Computes `y = αAx + βy`, where `A` is `Self`.
160 fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F) { 165 fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F) {
161 y.axpy(α, x, β) 166 y.axpy(α, x, β)
285 { } 290 { }
286 291
287 impl<F, S, T, E, X, Y> GEMV<F, X, Y> for Composition<S, T, E> 292 impl<F, S, T, E, X, Y> GEMV<F, X, Y> for Composition<S, T, E>
288 where 293 where
289 F : Num, 294 F : Num,
295 Y : AXPY<F>,
290 X : Space, 296 X : Space,
291 T : Linear<X>, 297 T : Linear<X>,
292 S : GEMV<F, T::Codomain, Y>, 298 S : GEMV<F, T::Codomain, Y>,
293 { 299 {
294 fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F) { 300 fn gemv<I : Instance<X>>(&self, y : &mut Y, α : F, x : I, β : F) {
359 365
360 impl<'b, F, S, T, Y, U, V> GEMV<F, Pair<U, V>, Y> for RowOp<S, T> 366 impl<'b, F, S, T, Y, U, V> GEMV<F, Pair<U, V>, Y> for RowOp<S, T>
361 where 367 where
362 U : Space, 368 U : Space,
363 V : Space, 369 V : Space,
370 Y : AXPY<F>,
364 S : GEMV<F, U, Y>, 371 S : GEMV<F, U, Y>,
365 T : GEMV<F, V, Y>, 372 T : GEMV<F, V, Y>,
366 F : Num, 373 F : Num,
367 Self : Linear<Pair<U, V>, Codomain=Y> 374 Self : Linear<Pair<U, V>, Codomain=Y>
368 { 375 {
403 } 410 }
404 411
405 impl<A, S, T> Linear<A> for ColOp<S, T> 412 impl<A, S, T> Linear<A> for ColOp<S, T>
406 where 413 where
407 A : Space, 414 A : Space,
408 S : Mapping<A>, 415 S : Linear<A>,
409 T : Mapping<A>, 416 T : Linear<A>,
410 { } 417 { }
411 418
412 impl<F, S, T, A, B, X> GEMV<F, X, Pair<A, B>> for ColOp<S, T> 419 impl<F, S, T, A, B, X> GEMV<F, X, Pair<A, B>> for ColOp<S, T>
413 where 420 where
414 X : Space, 421 X : Space,
422 A : AXPY<F>,
423 B : AXPY<F>,
424 Pair<A, B> : AXPY<F>,
415 S : GEMV<F, X, A>, 425 S : GEMV<F, X, A>,
416 T : GEMV<F, X, B>, 426 T : GEMV<F, X, B>,
417 F : Num, 427 F : Num,
418 Self : Linear<X, Codomain=Pair<A, B>> 428 Self : Linear<X, Codomain=Pair<A, B>>
419 { 429 {
546 T : Linear<B>, 556 T : Linear<B>,
547 { } 557 { }
548 558
549 impl<F, S, T, A, B, U, V> GEMV<F, Pair<U, V>, Pair<A, B>> for DiagOp<S, T> 559 impl<F, S, T, A, B, U, V> GEMV<F, Pair<U, V>, Pair<A, B>> for DiagOp<S, T>
550 where 560 where
551 A : Space, 561 A : AXPY<F>,
552 B : Space, 562 B : AXPY<F>,
563 Pair<A, B> : AXPY<F>,
553 U : Space, 564 U : Space,
554 V : Space, 565 V : Space,
555 S : GEMV<F, U, A>, 566 S : GEMV<F, U, A>,
556 T : GEMV<F, V, B>, 567 T : GEMV<F, V, B>,
557 F : Num, 568 F : Num,

mercurial