Struct scirust::matrix::matrix::Matrix [] [src]

pub struct Matrix<T: MagmaBase> {
    // some fields omitted
}

Represents a matrix of numbers.

The numbers are stored in column-major order. This is the standard in Fortran and MATLAB.

Methods

impl<T: MagmaBase> Matrix<T>

Static functions for creating a matrix

fn new(rows: usize, cols: usize) -> Matrix<T>

Constructs a new matrix of given size (uninitialized).

Remarks

The contents of the matrix are not initialized. Hence, it doesn't make sense to use this function liberally. Still the function is internally useful since different constructor functions need to initialize the matrix differently.

impl<T: CommutativeMonoidAddPartial> Matrix<T>

Static functions for creating a matrix of numbers

fn from_scalar(scalar: T) -> Matrix<T>

Constructs a scalar matrix

fn zeros(rows: usize, cols: usize) -> Matrix<T>

Constructs a matrix of all zeros

fn from_slice_cw(rows: usize, cols: usize, values: &[T]) -> Matrix<T>

Constructs a matrix from a slice of data reading data in column wise order.

fn from_slice_rw(rows: usize, cols: usize, values: &[T]) -> Matrix<T>

Constructs a matrix from a slice of data reading data in row wise order.

Remarks

In source code, when we are constructing matrices from slices, a slice looks easier to read in row wise order. Thus, this function should be more useful in constructing matrices by hand.

fn from_iter_cw<A: Iterator<Item=T>>(rows: usize, cols: usize, iter: A) -> Matrix<T>

fn from_iter_rw<A: Iterator<Item=T>>(rows: usize, cols: usize, iter: A) -> Matrix<T>

Builds a matrix from an iterator reading numbers in a row-wise order

fn diag_from_vec(v: &Matrix<T>) -> Matrix<T>

Construct a diagonal matrix from a vector

impl<T: CommutativeMonoidAddPartial + One> Matrix<T>

Static functions for creating a matrix of numbers

fn ones(rows: usize, cols: usize) -> Matrix<T>

Constructs a matrix of all ones.

fn identity(rows: usize, cols: usize) -> Matrix<T>

Constructs an identity matrix

fn unit_vector(length: usize, dim: usize) -> Matrix<T>

Constructs a unit vector (1, 0, 0), (0, 1, 0), (0, 0, 1), etc.

impl<T: MagmaBase> Matrix<T>

Main methods of a matrix

fn capacity(&self) -> usize

Returns the capacity of the matrix i.e. the number of elements it can hold

fn reshape(&mut self, rows: usize, cols: usize) -> bool

Reshapes the matrix

impl<T: Debug + Clone + Copy + PartialEq> Matrix<T>

Functions to access matrix elements safely and without bounds checking.

fn row_iter(&self, r: isize) -> RowIterator<T>

Returns an iterator over a specific row of matrix

fn col_iter(&self, c: isize) -> ColIterator<T>

Returns an iterator over a specific column of the matrix

fn cell_iter(&self) -> CellIterator<T>

Returns an iterator over all cells of the matrix

fn diagonal_iter(&self) -> DiagIterator<T>

Provide the main diagonal elements

impl<T: CommutativeMonoidAddPartial + One> Matrix<T>

Functions to construct new matrices out of a matrix and other conversions

fn repeat_matrix(&self, num_rows: usize, num_cols: usize) -> Matrix<T>

fn diagonal_vector(&self) -> Matrix<T>

Extracts the primary diagonal from the matrix as a vector

fn diagonal_matrix(&self) -> Matrix<T>

Extracts the primary diagonal from the matrix as a matrix of same size

fn ut(&self) -> Matrix<T>

Returns the upper triangular part of the matrix as a new matrix

fn lt(&self) -> Matrix<T>

Returns the lower triangular part of the matrix as a new matrix

fn permuted_rows(&self, permutation: &MatrixU16) -> Matrix<T>

Returns the matrix with permuted rows

fn permuted_cols(&self, permutation: &MatrixU16) -> Matrix<T>

Returns the matrix with permuted columns

impl<T: CommutativeMonoidAddPartial + CommutativeMonoidMulPartial> Matrix<T>

fn pow(&self, exp: usize) -> Matrix<T>

Computes power of a matrix Returns a new matrix

fn inner_prod(&self, other: &Matrix<T>) -> T

Inner product or dot product of two vectors Both must be column vectors Both must have same length result = a' * b.

fn outer_prod(&self, other: &Matrix<T>) -> Matrix<T>

Outer product of two vectors Both must be column vectors Both must have same length result = a * b'.

impl<T: CommutativeGroupAddPartial> Matrix<T>

fn unary_minus(&self) -> Matrix<T>

Computes the unary minus of a matrix

impl<T: MagmaBase> Matrix<T>

These methods modify the matrix itself

fn append_columns(&mut self, other: &Matrix<T>) -> &mut Matrix<T>

Appends one or more columns at the end of matrix

fn prepend_columns(&mut self, other: &Matrix<T>) -> &mut Matrix<T>

Prepends one or more columns at the beginning of matrix

fn insert_columns(&mut self, index: usize, other: &Matrix<T>) -> &mut Matrix<T>

Inserts columns at the specified location

fn append_rows(&mut self, other: &Matrix<T>) -> &mut Matrix<T>

Appends one or more rows at the bottom of matrix

fn prepend_rows(&mut self, other: &Matrix<T>) -> &mut Matrix<T>

Prepends one or more rows at the top of matrix

fn insert_rows(&mut self, index: usize, other: &Matrix<T>) -> &mut Matrix<T>

Inserts rows at the specified location

impl<T: MagmaBase> Matrix<T>

Views of a matrix

fn view(&self, start_row: usize, start_col: usize, num_rows: usize, num_cols: usize) -> MatrixView<T>

Creates a view on the matrix

impl<T: CommutativeMonoidAddPartial + PartialOrd> Matrix<T>

These functions are available only for types which support ordering [at least partial ordering for floating point numbers].

fn min_scalar(&self) -> (T, usize, usize)

fn max_scalar(&self) -> (T, usize, usize)

fn min_scalar_value(&self) -> T

Returns the minimum scalar value

fn max_scalar_value(&self) -> T

Returns the maximum scalar value

impl<T: MagmaBase + Signed + PartialOrd> Matrix<T>

fn min_abs_scalar(&self) -> (T, usize, usize)

fn max_abs_scalar(&self) -> (T, usize, usize)

fn min_abs_scalar_value(&self) -> T

Returns the absolute minimum scalar value

fn max_abs_scalar_value(&self) -> T

Returns the absolute maximum scalar value

impl<T: MagmaBase + Signed> Matrix<T>

These functions are available only for integer matrices

fn is_logical(&self) -> bool

Returns if an integer matrix is a logical matrix

impl<T: FieldPartial + Float> Matrix<T>

These functions are available only for floating point matrices

fn is_finite(&self) -> Matrix<u8>

Returns a matrix showing all the cells which are finite

fn is_infinite(&self) -> Matrix<u8>

Returns a matrix showing all the cells which are infinite

impl<T: CommutativeMonoidAddPartial> Matrix<T>

fn add_elt(&self, rhs: &Matrix<T>) -> Matrix<T>

Adds matrices element by element

impl<T: CommutativeMonoidAddPartial + Sub<Output=T>> Matrix<T>

fn sub_elt(&self, rhs: &Matrix<T>) -> Matrix<T>

Subtracts matrices element by element

impl<T: CommutativeMonoidMulPartial> Matrix<T>

fn mul_elt(&self, rhs: &Matrix<T>) -> Matrix<T>

Multiplies matrices element by element

fn pow_elt(&self, n: usize) -> Matrix<T>

Computs power of matrix elements

impl<T: CommutativeMonoidMulPartial + Div<Output=T>> Matrix<T>

fn div_elt(&self, rhs: &Matrix<T>) -> Matrix<T>

Divides matrices element by element

impl<T: MagmaBase> Matrix<T>

fn print_state(&self)

impl<T: MagmaBase> Matrix<T>

fn as_slice_<'a>(&'a self) -> &'a [T]

Returns a slice into self`self`.

Trait Implementations

impl<T: MagmaBase> Shape<T> for Matrix<T>

Core methods for all matrix types

fn num_rows(&self) -> usize

fn num_cols(&self) -> usize

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

fn num_cells(&self) -> usize

unsafe fn get_unchecked(&self, r: usize, c: usize) -> T

fn set(&mut self, r: usize, c: usize, value: T)

fn is_row(&self) -> bool

fn is_col(&self) -> bool

fn is_scalar(&self) -> bool

fn is_vector(&self) -> bool

fn is_empty(&self) -> bool

fn is_square(&self) -> bool

fn get(&self, r: usize, c: usize) -> Option<T>

fn index_to_cell(&self, index: usize) -> (usize, usize)

fn cell_to_index(&self, r: usize, c: usize) -> usize

fn smaller_dim(&self) -> usize

fn larger_dim(&self) -> usize

impl<T: CommutativeMonoidAddPartial + CommutativeMonoidMulPartial> NumberMatrix<T> for Matrix<T>

Methods available to number matrices

fn is_identity(&self) -> bool

fn is_diagonal(&self) -> bool

fn is_lt(&self) -> bool

fn is_ut(&self) -> bool

fn is_symmetric(&self) -> bool

fn trace(&self) -> T

fn is_triangular(&self) -> bool

impl<T> Introspection for Matrix<T>

Introspection support

fn is_standard_matrix_type(&self) -> bool

fn is_matrix_view_type(&self) -> bool

fn is_triangular_matrix_type(&self) -> bool

impl<T: MagmaBase> Strided for Matrix<T>

Strided buffer

fn stride(&self) -> usize

impl<T: FieldPartial> StridedNumberMatrix<T> for Matrix<T>

impl<T: FieldPartial + Float> StridedFloatMatrix<T> for Matrix<T>

impl<T: MagmaBase> MatrixBuffer<T> for Matrix<T>

Buffer access

fn as_ptr(&self) -> *const T

fn as_mut_ptr(&mut self) -> *mut T

fn cell_to_offset(&self, r: usize, c: usize) -> isize

fn start_offset(&self) -> isize

impl<T: MagmaBase + Signed + PartialOrd> Search<T> for Matrix<T>

Implementation of Matrix search operations.

fn max_abs_scalar_in_row(&self, row: usize, start_col: usize, end_col: usize) -> (T, usize)

fn max_abs_scalar_in_col(&self, col: usize, start_row: usize, end_row: usize) -> (T, usize)

impl<T: MagmaBase> Index<usize> for Matrix<T>

type Output = T

fn index<'a>(&'a self, index: usize) -> &'a T

impl<T: MagmaBase> Clone for Matrix<T>

Implementation of Clone interface

fn clone(&self) -> Matrix<T>

fn clone_from(&mut self, source: &Self)

impl<T: MagmaBase> Debug for Matrix<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: MagmaBase> Display for Matrix<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<'a, 'b, T: CommutativeMonoidAddPartial> Add<&'b Matrix<T>> for &'a Matrix<T>

Matrix addition support

type Output = Matrix<T>

fn add(self, rhs: &'b Matrix<T>) -> Matrix<T>

impl<'a, 'b, T: QuasiGroupAddPartial> Sub<&'b Matrix<T>> for &'a Matrix<T>

Matrix subtraction support

type Output = Matrix<T>

fn sub(self, rhs: &'b Matrix<T>) -> Matrix<T>

impl<T: MagmaBase> PartialEq for Matrix<T>

Matrix equality check support

fn eq(&self, other: &Matrix<T>) -> bool

fn ne(&self, other: &Rhs) -> bool

impl<T: MagmaBase> Drop for Matrix<T>

fn drop(&mut self)

impl<T: MagmaBase + Num> ERO<T> for Matrix<T>

Implementation of Elementary row operations.

fn ero_switch(&mut self, i: usize, j: usize) -> &mut Self

fn ero_scale(&mut self, r: usize, scale: T) -> &mut Self

fn ero_scale_slice(&mut self, r: usize, scale: T, start: usize, end: usize) -> &mut Self

fn ero_scale_add(&mut self, i: usize, j: isize, scale: T) -> &mut Self

impl<T: MagmaBase + Num> ECO<T> for Matrix<T>

Implementation of Elementary column operations.

fn eco_switch(&mut self, i: usize, j: usize) -> &mut Self

fn eco_scale(&mut self, c: usize, scale: T) -> &mut Self

fn eco_scale_slice(&mut self, c: usize, scale: T, start: usize, end: usize) -> &mut Self

fn eco_scale_add(&mut self, i: usize, j: isize, scale: T) -> &mut Self

impl<T: MagmaBase + Num> InPlaceUpdates<T> for Matrix<T>

Implementation of Matrix general update operations.

fn add_scalar(&mut self, rhs: T) -> &mut Matrix<T>

fn mul_scalar(&mut self, rhs: T) -> &mut Matrix<T>

fn div_scalar(&mut self, rhs: T) -> SRResult<&mut Matrix<T>>

fn scale_row_lt(&mut self, r: usize, scale_factor: T) -> &mut Matrix<T>

fn scale_col_lt(&mut self, c: usize, scale_factor: T) -> &mut Matrix<T>

fn scale_row_ut(&mut self, r: usize, scale_factor: T) -> &mut Matrix<T>

fn scale_col_ut(&mut self, c: usize, scale_factor: T) -> &mut Matrix<T>

fn scale_rows(&mut self, scale_factors: &Matrix<T>) -> &mut Matrix<T>

fn scale_cols(&mut self, scale_factors: &Matrix<T>) -> &mut Matrix<T>

fn sub_vec_from_cols(&mut self, vec: &Matrix<T>) -> SRResult<()>

fn sub_vec_from_rows(&mut self, vec: &Matrix<T>) -> SRResult<()>

fn add_vec_to_cols(&mut self, vec: &Matrix<T>) -> SRResult<()>

fn add_vec_to_rows(&mut self, vec: &Matrix<T>) -> SRResult<()>

fn mul_vec_to_cols(&mut self, vec: &Matrix<T>) -> SRResult<()>

fn mul_vec_to_rows(&mut self, vec: &Matrix<T>) -> SRResult<()>

fn ut_to_lt(&mut self) -> &mut Matrix<T>

fn set_diagonal(&mut self, value: T) -> &mut Self

fn set_row(&mut self, r: usize, value: T) -> &mut Self

fn set_col(&mut self, c: usize, value: T) -> &mut Self

fn set_block(&mut self, start_row: isize, start_col: isize, num_rows: usize, num_cols: usize, value: T) -> &mut Self

impl<T: MagmaBase + Num> CopyUpdates<T> for Matrix<T>

Implementation of Matrix general copy and update operations. TODO Optimize implementations.

fn copy_add_scalar(&self, rhs: T) -> Matrix<T>

fn copy_mul_scalar(&self, rhs: T) -> Matrix<T>

fn copy_div_scalar(&self, rhs: T) -> Matrix<T>

fn copy_sub_vec_from_cols(&self, vec: &Matrix<T>) -> SRResult<Matrix<T>>

fn copy_sub_vec_from_rows(&self, vec: &Matrix<T>) -> SRResult<Matrix<T>>

fn copy_add_vec_to_cols(&self, vec: &Matrix<T>) -> SRResult<Matrix<T>>

fn copy_add_vec_to_rows(&self, vec: &Matrix<T>) -> SRResult<Matrix<T>>

fn copy_mul_vec_to_cols(&self, vec: &Matrix<T>) -> SRResult<Matrix<T>>

fn copy_mul_vec_to_rows(&self, vec: &Matrix<T>) -> SRResult<Matrix<T>>

impl<T: MagmaBase> Transpose<T> for Matrix<T>

fn transpose(&self) -> Matrix<T>

impl<T: CommutativeMonoidAddPartial + CommutativeMonoidMulPartial> Frame<T> for Matrix<T>

fn gram(&self) -> Matrix<T>

impl<'a, 'b, T: CommutativeMonoidAddPartial + CommutativeMonoidMulPartial> Mul<&'b Matrix<T>> for &'a Matrix<T>

Matrix multiplication support

type Output = Matrix<T>

fn mul(self, rhs: &Matrix<T>) -> Matrix<T>

impl<T: CommutativeMonoidAddPartial> Extraction<T> for Matrix<T>

Implements matrix extraction API

fn row(&self, r: isize) -> Matrix<T>

fn col(&self, c: isize) -> Matrix<T>

fn sub_matrix(&self, start_row: isize, start_col: isize, num_rows: usize, num_cols: usize) -> Matrix<T>

fn lt_matrix(&self) -> Matrix<T>

fn ut_matrix(&self) -> Matrix<T>

impl<T: MagmaBase> Conversion<T> for Matrix<T>

Implements matrix conversion API

fn to_std_vec(&self) -> Vec<T>

fn to_scalar(&self) -> T

impl<T: CommutativeMonoidAddPartial + PartialOrd> MinMax<T> for Matrix<T>

Implements matrix extraction API

fn max_row_wise(&self) -> Matrix<T>

fn min_row_wise(&self) -> Matrix<T>

fn max_col_wise(&self) -> Matrix<T>

fn min_col_wise(&self) -> Matrix<T>

impl<T: CommutativeRingPartial + Signed> LANumberMatrix<T> for Matrix<T>

fn det(&self) -> Result<T, SRError>

impl<T: CommutativeMonoidAddPartial + CommutativeMonoidMulPartial> Sums<T> for Matrix<T>

fn sum_cw(&self) -> Matrix<T>

fn sum_rw(&self) -> Matrix<T>

fn sum_sqr_cw(&self) -> Matrix<T>

fn sum_sqr_rw(&self) -> Matrix<T>

impl<T: FieldPartial + Float + FromPrimitive> Moments<T> for Matrix<T>

fn mean_cw(&self) -> Matrix<T>

fn mean_rw(&self) -> Matrix<T>

fn mean_sqr_cw(&self) -> Matrix<T>

fn mean_sqr_rw(&self) -> Matrix<T>

fn var_cw(&self) -> Matrix<T>

fn var_rw(&self) -> Matrix<T>

fn cov(&self) -> Matrix<T>