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§
type Sparsity: MatrixSparsity<Self>
type SparsityRef<'a>: MatrixSparsityRef<'a, Self> where Self: 'a
Required Methods§
Sourcefn sparsity(&self) -> Option<Self::SparsityRef<'_>>
fn sparsity(&self) -> Option<Self::SparsityRef<'_>>
Return sparsity information (None if the matrix is dense)
fn context(&self) -> &Self::C
fn partition_indices_by_zero_diagonal( &self, ) -> (<Self::V as Vector>::Index, <Self::V as Vector>::Index)
Sourcefn gemv(&self, alpha: Self::T, x: &Self::V, beta: Self::T, y: &mut Self::V)
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
.
Sourcefn zeros(nrows: IndexType, ncols: IndexType, ctx: Self::C) -> Self
fn zeros(nrows: IndexType, ncols: IndexType, ctx: Self::C) -> Self
Create a new matrix of shape nrows
x ncols
filled with zeros
Sourcefn new_from_sparsity(
nrows: IndexType,
ncols: IndexType,
sparsity: Option<Self::Sparsity>,
ctx: Self::C,
) -> Self
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
Sourcefn from_diagonal(v: &Self::V) -> Self
fn from_diagonal(v: &Self::V) -> Self
Create a new diagonal matrix from a Vector holding the diagonal elements
Sourcefn set_column(&mut self, j: IndexType, v: &Self::V)
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
fn add_column_to_vector(&self, j: IndexType, v: &mut Self::V)
Sourcefn set_data_with_indices(
&mut self,
dst_indices: &<Self::V as Vector>::Index,
src_indices: &<Self::V as Vector>::Index,
data: &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, )
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
Sourcefn gather(&mut self, other: &Self, indices: &<Self::V as Vector>::Index)
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
Sourcefn scale_add_and_assign(&mut self, x: &Self, beta: Self::T, y: &Self)
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)
fn triplet_iter(&self) -> impl Iterator<Item = (IndexType, IndexType, Self::T)>
Provided Methods§
fn is_sparse() -> bool
Sourcefn split(
&self,
algebraic_indices: &<Self::V as Vector>::Index,
) -> [(Self, <Self::V as Vector>::Index); 4]
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]
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.