pub trait MathMatrix<'a, T>where
    Self: BasicMatrix<'a, T> + BasicMatrixOpt<'a, T>,
    T: Copy + Clone,{
    // Provided methods
    fn add<Q>(&'a self, other: &'a Q) -> Option<MatrixFull<T>>
       where T: Add<Output = T> + AddAssign,
             Q: BasicMatrix<'a, T>,
             Self: Sized { ... }
    fn scaled_add<Q>(
        &'a self,
        other: &'a Q,
        scale_factor: T
    ) -> Option<MatrixFull<T>>
       where T: Add + AddAssign + Mul<Output = T>,
             Q: BasicMatrix<'a, T>,
             Self: Sized { ... }
    fn self_add<Q>(&'a mut self, bm: &'a Q)
       where T: Add + AddAssign,
             Q: BasicMatrix<'a, T>,
             Self: Sized { ... }
    fn self_scaled_add<Q>(&'a mut self, bm: &'a Q, b: T)
       where T: Add + AddAssign + Mul<Output = T>,
             Q: BasicMatrix<'a, T>,
             Self: Sized { ... }
    fn self_general_add<Q>(&'a mut self, bm: &'a Q, a: T, b: T)
       where T: Add<Output = T> + AddAssign + Mul<Output = T>,
             Q: BasicMatrix<'a, T>,
             Self: Sized { ... }
    fn sub<Q>(&'a self, other: &'a Q) -> Option<MatrixFull<T>>
       where T: Sub + SubAssign,
             Q: BasicMatrix<'a, T>,
             Self: Sized { ... }
    fn self_sub<Q>(&'a mut self, bm: &'a Q)
       where T: Sub + SubAssign,
             Q: BasicMatrix<'a, T>,
             Self: Sized { ... }
    fn self_multiple(&mut self, a: T)
       where T: Mul<Output = T> + MulAssign { ... }
}

Provided Methods§

source

fn add<Q>(&'a self, other: &'a Q) -> Option<MatrixFull<T>>where T: Add<Output = T> + AddAssign, Q: BasicMatrix<'a, T>, Self: Sized,

source

fn scaled_add<Q>( &'a self, other: &'a Q, scale_factor: T ) -> Option<MatrixFull<T>>where T: Add + AddAssign + Mul<Output = T>, Q: BasicMatrix<'a, T>, Self: Sized,

source

fn self_add<Q>(&'a mut self, bm: &'a Q)where T: Add + AddAssign, Q: BasicMatrix<'a, T>, Self: Sized,

For A += B

source

fn self_scaled_add<Q>(&'a mut self, bm: &'a Q, b: T)where T: Add + AddAssign + Mul<Output = T>, Q: BasicMatrix<'a, T>, Self: Sized,

For A += c*B where c is a scale factor

source

fn self_general_add<Q>(&'a mut self, bm: &'a Q, a: T, b: T)where T: Add<Output = T> + AddAssign + Mul<Output = T>, Q: BasicMatrix<'a, T>, Self: Sized,

For aA + bB -> A

source

fn sub<Q>(&'a self, other: &'a Q) -> Option<MatrixFull<T>>where T: Sub + SubAssign, Q: BasicMatrix<'a, T>, Self: Sized,

For A - B -> C

source

fn self_sub<Q>(&'a mut self, bm: &'a Q)where T: Sub + SubAssign, Q: BasicMatrix<'a, T>, Self: Sized,

For A - B -> A

source

fn self_multiple(&mut self, a: T)where T: Mul<Output = T> + MulAssign,

For a*A -> A

Implementors§

source§

impl<'a, T> MathMatrix<'a, T> for SubMatrixFull<'a, T>where T: Copy + Clone,

source§

impl<'a, T> MathMatrix<'a, T> for SubMatrixFullMut<'a, T>where T: Copy + Clone,

source§

impl<'a, T> MathMatrix<'a, T> for MatrixFullSlice<'a, T>where T: Copy + Clone,

source§

impl<'a, T> MathMatrix<'a, T> for MatrixFullSliceMut<'a, T>where T: Copy + Clone,

source§

impl<'a, T> MathMatrix<'a, T> for MatrixFull<T>where T: Copy + Clone,

more math operations for the rest package

These operators are provided by the trait of MathMatrix.
Here, we illustrate the usage mainly using the MatrixFull struct. You can perform these operations for MatrixFullSlice, MatrixFullSliceMut, SubMatrixFull, and SubMatrixFullMut.

We also provide the rayon parallel version of these operators by the trait of ParMathMatrix.

Several examples are given as follow:

    1. add and self_sub
  use rest_tensors::{MatrixFull, MathMatrix};
  let vec_a = vec![
         1.0,  2.0,  3.0, 
         4.0,  5.0,  6.0, 
         7.0,  8.0,  9.0, 
        10.0, 11.0, 12.0];
  let matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
  //          |  1.0 |  4.0 |  7.0 | 10.0 |
  //matr_a =  |  2.0 |  5.0 |  8.0 | 11.0 |
  //          |  3.0 |  6.0 |  9.0 | 12.0 |
 
  let vec_b = (13..25).map(|x| x as f64).collect::<Vec<f64>>();
  let matr_b = MatrixFull::from_vec([3,4],vec_b).unwrap();
  //          | 13.0 | 16.0 | 19.0 | 22.0 |
  //matr_b =  | 14.0 | 17.0 | 20.0 | 23.0 |
  //          | 15.0 | 18.0 | 21.0 | 24.0 |
 
  // matr_c = matr_a + matr_b;   
  let mut matr_c = MatrixFull::add(&matr_a, &matr_b).unwrap();
  //          | 14.0 | 20.0 | 26.0 | 32.0 |
  //matr_c =  | 16.0 | 22.0 | 28.0 | 34.0 |
  //          | 18.0 | 24.0 | 30.0 | 36.0 |
  assert_eq!(matr_c[(..,3)], [32.0,34.0,36.0]);
 
  // matr_c_ref: MatrixFullSliceMut<f64>
  let mut matr_c_ref = matr_c.to_matrixfullslicemut();
  // matr_c -= matr_b = matr_a
  matr_c_ref.self_sub(&matr_b);
  assert_eq!(matr_c, matr_a);
 
    1. scaled add and self_sub
  use rest_tensors::{MatrixFull, MathMatrix, ParMathMatrix};
  let vec_a = vec![
         1.0,  2.0,  3.0, 
         4.0,  5.0,  6.0, 
         7.0,  8.0,  9.0, 
        10.0, 11.0, 12.0];
  let matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
  //          |  1.0 |  4.0 |  7.0 | 10.0 |
  //matr_a =  |  2.0 |  5.0 |  8.0 | 11.0 |
  //          |  3.0 |  6.0 |  9.0 | 12.0 |
 
  let vec_b = (13..25).map(|x| x as f64).collect::<Vec<f64>>();
  let mut matr_b = MatrixFull::from_vec([3,4],vec_b).unwrap();
  //          | 13.0 | 16.0 | 19.0 | 22.0 |
  //matr_b =  | 14.0 | 17.0 | 20.0 | 23.0 |
  //          | 15.0 | 18.0 | 21.0 | 24.0 |
 
  // matr_c = 1.0*matr_a + matr_b
  let mut matr_c = matr_b.scaled_add(&matr_a, 1.0).unwrap();
  //          | 14.0 | 20.0 | 26.0 | 32.0 |
  //matr_c =  | 16.0 | 22.0 | 28.0 | 34.0 |
  //          | 18.0 | 24.0 | 30.0 | 36.0 |
  assert_eq!(matr_c[(..,3)], [32.0,34.0,36.0]);
 
  // matr_c_ref: MatrixFullSliceMut<f64>
  let mut matr_c_ref = matr_c.to_matrixfullslicemut();
  // matr_c -= matr_b = matr_a, using the rayon parallel version
  matr_c_ref.par_self_sub(&matr_b);
  assert_eq!(matr_c, matr_a);