Trait Matrix

Source
pub trait Matrix:
    MatrixCommon
    + Mul<Scale<Self::T>, Output = Self>
    + Clone
    + 'static {
    type Sparsity: MatrixSparsity<Self>;
    type SparsityRef<'a>: MatrixSparsityRef<'a, Self>
       where Self: 'a;

Show 18 methods // Required methods fn sparsity(&self) -> Option<Self::SparsityRef<'_>>; fn context(&self) -> &Self::C; fn partition_indices_by_zero_diagonal( &self, ) -> (<Self::V as Vector>::Index, <Self::V as Vector>::Index); fn gemv(&self, alpha: Self::T, x: &Self::V, beta: Self::T, y: &mut Self::V); fn copy_from(&mut self, other: &Self); fn zeros(nrows: IndexType, ncols: IndexType, ctx: Self::C) -> Self; fn new_from_sparsity( nrows: IndexType, ncols: IndexType, sparsity: Option<Self::Sparsity>, ctx: Self::C, ) -> Self; fn from_diagonal(v: &Self::V) -> Self; fn set_column(&mut self, j: IndexType, v: &Self::V); fn add_column_to_vector(&self, j: IndexType, v: &mut Self::V); fn set_data_with_indices( &mut self, dst_indices: &<Self::V as Vector>::Index, src_indices: &<Self::V as Vector>::Index, data: &Self::V, ); fn gather(&mut self, other: &Self, indices: &<Self::V as Vector>::Index); fn scale_add_and_assign(&mut self, x: &Self, beta: Self::T, y: &Self); fn triplet_iter( &self, ) -> impl Iterator<Item = (IndexType, IndexType, Self::T)>; fn try_from_triplets( nrows: IndexType, ncols: IndexType, triplets: Vec<(IndexType, IndexType, Self::T)>, ctx: Self::C, ) -> Result<Self, DiffsolError>; // Provided methods fn is_sparse() -> bool { ... } fn split( &self, algebraic_indices: &<Self::V as Vector>::Index, ) -> [(Self, <Self::V as Vector>::Index); 4] { ... } fn combine( ul: &Self, ur: &Self, ll: &Self, lr: &Self, algebraic_indices: &<Self::V as Vector>::Index, ) -> Self { ... }
}
Expand description

A base matrix trait (including sparse and dense matrices)

Required Associated Types§

Source

type Sparsity: MatrixSparsity<Self>

Source

type SparsityRef<'a>: MatrixSparsityRef<'a, Self> where Self: 'a

Required Methods§

Source

fn sparsity(&self) -> Option<Self::SparsityRef<'_>>

Return sparsity information (None if the matrix is dense)

Source

fn context(&self) -> &Self::C

Source

fn partition_indices_by_zero_diagonal( &self, ) -> (<Self::V as Vector>::Index, <Self::V as Vector>::Index)

Source

fn gemv(&self, alpha: Self::T, x: &Self::V, beta: Self::T, y: &mut Self::V)

Perform a matrix-vector multiplication y = alpha * self * x + beta * y.

Source

fn copy_from(&mut self, other: &Self)

Copy the contents of other into self

Source

fn zeros(nrows: IndexType, ncols: IndexType, ctx: Self::C) -> Self

Create a new matrix of shape nrows x ncols filled with zeros

Source

fn new_from_sparsity( nrows: IndexType, ncols: IndexType, sparsity: Option<Self::Sparsity>, ctx: Self::C, ) -> Self

Create a new matrix from a sparsity pattern, the non-zero elements are not initialized

Source

fn from_diagonal(v: &Self::V) -> Self

Create a new diagonal matrix from a Vector holding the diagonal elements

Source

fn set_column(&mut self, j: IndexType, v: &Self::V)

sets the values of column j to be equal to the values in v For sparse matrices, only the existing non-zero elements are updated

Source

fn add_column_to_vector(&self, j: IndexType, v: &mut Self::V)

Source

fn set_data_with_indices( &mut self, dst_indices: &<Self::V as Vector>::Index, src_indices: &<Self::V as Vector>::Index, data: &Self::V, )

assign the values in the data vector to the matrix at the indices in dst_indices from the indices in src_indices dst_index can be obtained using the get_index method on the Sparsity type - for dense matrices, the dst_index is the data index in column-major order - for sparse matrices, the dst_index is the index into the data array

Source

fn gather(&mut self, other: &Self, indices: &<Self::V as Vector>::Index)

gather the values in the matrix other at the indices in indices to the matrix self for sparse matrices: the index idx_i in indices is an index into the data array for other, and is copied to the index idx_i in the data array for self for dense matrices: the index idx_i in indices is the data index in column-major order for other, and is copied to the index idx_i in the data array for self (again in column-major order)

See also Self::split which can be used to generate these indices

Source

fn scale_add_and_assign(&mut self, x: &Self, beta: Self::T, y: &Self)

Perform the assignment self = x + beta * y where x and y are matrices and beta is a scalar Panics if the sparsity of self, x, and y do not match (i.e. sparsity of self must be the union of the sparsity of x and y)

Source

fn triplet_iter(&self) -> impl Iterator<Item = (IndexType, IndexType, Self::T)>

Source

fn try_from_triplets( nrows: IndexType, ncols: IndexType, triplets: Vec<(IndexType, IndexType, Self::T)>, ctx: Self::C, ) -> Result<Self, DiffsolError>

Create a new matrix from a vector of triplets (i, j, value) where i and j are the row and column indices of the value

Provided Methods§

Source

fn is_sparse() -> bool

Source

fn split( &self, algebraic_indices: &<Self::V as Vector>::Index, ) -> [(Self, <Self::V as Vector>::Index); 4]

Split the matrix into four submatrices, based on the indices in algebraic_indices

M = [UL, UR] [LL, LR]

UL contains the rows and columns not in algebraic_indices UR contains the rows not in algebraic_indices and the columns in algebraic_indices LL contains the rows in algebraic_indices and the columns not in algebraic_indices LR contains the rows and columns in algebraic_indices

The function returns an array of tuples, where each tuple contains a submatrix, and the indices of the original matrix that were used to create the submatrix Self::gather can be used in conjunction with these indices to update the submatrix

The order of the submatrices in the array is as follows: [UL, UR, LL, LR]

Source

fn combine( ul: &Self, ur: &Self, ll: &Self, lr: &Self, algebraic_indices: &<Self::V as Vector>::Index, ) -> Self

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§