src/linops.rs

branch
dev
changeset 130
0a689881b0f1
parent 129
d2994e34a5f5
child 131
8264d72aa347
child 133
2b13f8a0c8ba
equal deleted inserted replaced
129:d2994e34a5f5 130:0a689881b0f1
9 use crate::norms::{HasDual, Linfinity, Norm, NormExponent, PairNorm, L1, L2}; 9 use crate::norms::{HasDual, Linfinity, Norm, NormExponent, PairNorm, L1, L2};
10 use crate::types::*; 10 use crate::types::*;
11 use numeric_literals::replace_float_literals; 11 use numeric_literals::replace_float_literals;
12 use serde::Serialize; 12 use serde::Serialize;
13 use std::marker::PhantomData; 13 use std::marker::PhantomData;
14 use std::ops::Mul; 14 use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
15 15
16 /// Trait for linear operators on `X`. 16 /// Trait for linear operators on `X`.
17 pub trait Linear<X: Space>: Mapping<X> {} 17 pub trait Linear<X: Space>: Mapping<X> {}
18 18
19 // impl<X: Space, A: Linear<X>> DifferentiableImpl<X> for A { 19 // impl<X: Space, A: Linear<X>> DifferentiableImpl<X> for A {
25 // } 25 // }
26 // } 26 // }
27 27
28 /// Efficient in-place summation. 28 /// Efficient in-place summation.
29 #[replace_float_literals(Self::Field::cast_from(literal))] 29 #[replace_float_literals(Self::Field::cast_from(literal))]
30 pub trait AXPY<X = Self>: Space + std::ops::MulAssign<Self::Field> 30 pub trait AXPY<X = Self>:
31 Space
32 + MulAssign<Self::Field>
33 + DivAssign<Self::Field>
34 + AddAssign<Self>
35 + AddAssign<Self::Owned>
36 + SubAssign<Self>
37 + SubAssign<Self::Owned>
38 + Mul<Self::Field, Output = Self::Owned>
39 + Div<Self::Field, Output = Self::Owned>
40 + Add<Self, Output = Self::Owned>
41 + Add<Self::Owned, Output = Self::Owned>
42 + Sub<Self, Output = Self::Owned>
43 + Sub<Self::Owned, Output = Self::Owned>
44 + Neg
31 where 45 where
32 X: Space, 46 X: Space,
33 { 47 {
34 type Field: Num; 48 type Field: Num;
35 type Owned: AXPY<X, Field = Self::Field>; 49 type Owned: AXPY<X, Field = Self::Field>;
501 } 515 }
502 516
503 /// “Row operator” $(S, T)$; $(S, T)(x, y)=Sx + Ty$. 517 /// “Row operator” $(S, T)$; $(S, T)(x, y)=Sx + Ty$.
504 #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)] 518 #[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq)]
505 pub struct RowOp<S, T>(pub S, pub T); 519 pub struct RowOp<S, T>(pub S, pub T);
506
507 use std::ops::Add;
508 520
509 impl<A, B, S, T> Mapping<Pair<A, B>> for RowOp<S, T> 521 impl<A, B, S, T> Mapping<Pair<A, B>> for RowOp<S, T>
510 where 522 where
511 A: Space, 523 A: Space,
512 B: Space, 524 B: Space,

mercurial