GeneralMatrix

Trait GeneralMatrix 

Source
pub trait GeneralMatrix:
    Add<Self, Output = Self>
    + AddAssign<Self>
    + Index<(usize, usize), Output = f64>
    + Mul<f64, Output = Self>
    + MulAssign<f64>
    + Neg<Output = Self>
    + Sized
    + Sub<Self, Output = Self>
    + SubAssign<Self> {
    // Required methods
    fn zeros() -> Self;
    fn shape(&self) -> (usize, usize);
}
Expand description

Common operations for all matrices.

Matrices can be added:

use hoomd_linear_algebra::{Full, GeneralMatrix, matrix::Matrix};
let a = Matrix {
    rows: [[1.0, -3.0], [-2.0, 4.0]],
};
let b = Matrix {
    rows: [[4.0, -8.0], [6.0, 7.0]],
};

let mut c = a + b;
c += a;

subtracted:

use hoomd_linear_algebra::{Full, GeneralMatrix, matrix::Matrix};
let a = Matrix {
    rows: [[1.0, -3.0], [-2.0, 4.0]],
};
let b = Matrix {
    rows: [[4.0, -8.0], [6.0, 7.0]],
};

let mut c = a - b;
c += a;

multiplied by a scalar:

use hoomd_linear_algebra::{Full, GeneralMatrix, matrix::Matrix};
let a = Matrix {
    rows: [[4.0, -8.0], [6.0, 7.0]],
};
let b = -2.0;

let mut c = a * b;
c *= b;

negated:

use hoomd_linear_algebra::{Full, GeneralMatrix, matrix::Matrix};
let a = Matrix {
    rows: [[1.0, -3.0], [-2.0, 4.0]],
};

let b = -a;

and indexed (in row,column ordering):

use hoomd_linear_algebra::{Full, GeneralMatrix, matrix::Matrix};
let a = Matrix {
    rows: [[1.0, -3.0], [-2.0, 4.0]],
};

let element = a[(1, 0)];

Required Methods§

Source

fn zeros() -> Self

Fill a matrix with zeros.

§Example
use hoomd_linear_algebra::{GeneralMatrix, matrix::Matrix};

let a = Matrix::zeros();

assert_eq!(a.rows, [[0.0, 0.0], [0.0, 0.0]]);
Source

fn shape(&self) -> (usize, usize)

Get the shape of a matrix (n_rows,n_columns).

§Example
use hoomd_linear_algebra::{GeneralMatrix, matrix::Matrix};

let a = Matrix::<5, 7>::zeros();
assert_eq!(a.shape(), (5, 7));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<const N: usize> GeneralMatrix for DiagonalMatrix<N>

Source§

impl<const N: usize, const M: usize> GeneralMatrix for Matrix<N, M>