|
| 1 | +//! Linear operator algebra |
| 2 | +
|
| 3 | +use ndarray::*; |
| 4 | + |
| 5 | +pub trait LinearOperator { |
| 6 | + /// Apply operator out-place |
| 7 | + fn apply<S: Data>(&self, a: &ArrayBase<S, Ix1>) -> Array1<S::Elem> { |
| 8 | + self.apply_tensor(a, 0) |
| 9 | + } |
| 10 | + /// Apply operator in-place |
| 11 | + fn apply_mut<S: DataMut>(&self, a: &mut ArrayBase<S, Ix1>) { |
| 12 | + self.apply_tensor_mut(a, 0) |
| 13 | + } |
| 14 | + /// Apply operator with move |
| 15 | + fn apply_into<S: DataOwned + DataMut>(&self, a: ArrayBase<S, Ix1>) -> ArrayBase<S, Ix1> { |
| 16 | + self.apply_tensor_into(a, 0) |
| 17 | + } |
| 18 | + |
| 19 | + /// Apply operator to matrix out-place |
| 20 | + fn apply2<S: Data>(&self, a: &ArrayBase<S, Ix2>) -> Array2<S::Elem> { |
| 21 | + self.apply_tensor(a, 0) |
| 22 | + } |
| 23 | + /// Apply operator to matrix in-place |
| 24 | + fn apply2_mut<S: DataMut>(&self, a: &mut ArrayBase<S, Ix2>) { |
| 25 | + self.apply_tensor_mut(a, 0) |
| 26 | + } |
| 27 | + /// Apply operator to matrix with move |
| 28 | + fn apply2_into<S: DataOwned + DataMut>(&self, a: ArrayBase<S, Ix2>) -> ArrayBase<S, Ix2> { |
| 29 | + self.apply_tensor_into(a, 0) |
| 30 | + } |
| 31 | + |
| 32 | + /// Apply operator to the n-th index of the tensor (out-place) |
| 33 | + fn apply_tensor<S, D>(&self, a: &ArrayBase<S, D>, n: usize) -> Array<S::Elem, D> |
| 34 | + where |
| 35 | + S: Data, |
| 36 | + D: Dimension; |
| 37 | + /// Apply operator to the n-th index of the tensor (in-place) |
| 38 | + fn apply_tensor_mut<S, D>(&self, a: &mut ArrayBase<S, D>, n: usize) |
| 39 | + where |
| 40 | + S: DataMut, |
| 41 | + D: Dimension; |
| 42 | + /// Apply operator to the n-th index of the tensor (with move) |
| 43 | + fn apply_tensor_into<S, D>(&self, a: ArrayBase<S, D>, n: usize) -> ArrayBase<S, D> |
| 44 | + where |
| 45 | + S: DataOwned + DataMut, |
| 46 | + D: Dimension; |
| 47 | +} |
0 commit comments