pub struct SparseMatrix { /* private fields */ }Expand description
Main sparse matrix implementation supporting multiple storage formats.
Implementations§
Source§impl SparseMatrix
impl SparseMatrix
Sourcepub fn from_triplets(
triplets: Vec<(usize, usize, Precision)>,
rows: DimensionType,
cols: DimensionType,
) -> Result<Self>
pub fn from_triplets( triplets: Vec<(usize, usize, Precision)>, rows: DimensionType, cols: DimensionType, ) -> Result<Self>
Create a new sparse matrix from coordinate (triplet) format.
§Arguments
triplets- Vector of (row, col, value) tripletsrows- Number of rowscols- Number of columns
§Example
use sublinear_solver::SparseMatrix;
let matrix = SparseMatrix::from_triplets(
vec![(0, 0, 4.0), (0, 1, 1.0), (1, 0, 2.0), (1, 1, 5.0)],
2, 2
).unwrap();Sourcepub fn from_dense(
data: &[Precision],
rows: DimensionType,
cols: DimensionType,
) -> Result<Self>
pub fn from_dense( data: &[Precision], rows: DimensionType, cols: DimensionType, ) -> Result<Self>
Create a sparse matrix from dense row-major data.
Zero elements are automatically filtered out.
Sourcepub fn identity(size: DimensionType) -> Result<Self>
pub fn identity(size: DimensionType) -> Result<Self>
Create an identity matrix of the given size.
Sourcepub fn diagonal(diag: &[Precision]) -> Result<Self>
pub fn diagonal(diag: &[Precision]) -> Result<Self>
Create a diagonal matrix from the given diagonal values.
Sourcepub fn convert_to_format(&mut self, new_format: SparseFormat) -> Result<()>
pub fn convert_to_format(&mut self, new_format: SparseFormat) -> Result<()>
Convert the matrix to a different storage format.
This operation may be expensive for large matrices.
Sourcepub fn to_triplets(&self) -> Result<Vec<(usize, usize, Precision)>>
pub fn to_triplets(&self) -> Result<Vec<(usize, usize, Precision)>>
Extract the matrix as coordinate triplets.
Sourcepub fn format(&self) -> SparseFormat
pub fn format(&self) -> SparseFormat
Get the current storage format.
Sourcepub fn as_csr(&mut self) -> Result<&CSRStorage>
pub fn as_csr(&mut self) -> Result<&CSRStorage>
Get a reference to the underlying CSR storage.
Converts to CSR format if necessary.
Sourcepub fn as_csc(&mut self) -> Result<&CSCStorage>
pub fn as_csc(&mut self) -> Result<&CSCStorage>
Get a reference to the underlying CSC storage.
Converts to CSC format if necessary.
Sourcepub fn as_graph(&mut self) -> Result<&GraphStorage>
pub fn as_graph(&mut self) -> Result<&GraphStorage>
Get a reference to the underlying graph storage.
Converts to graph format if necessary.
Sourcepub fn add_diagonal(&mut self, alpha: Precision) -> Result<()>
pub fn add_diagonal(&mut self, alpha: Precision) -> Result<()>
Add a scalar multiple of the identity matrix: A = A + alpha * I
Trait Implementations§
Source§impl Clone for SparseMatrix
impl Clone for SparseMatrix
Source§fn clone(&self) -> SparseMatrix
fn clone(&self) -> SparseMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SparseMatrix
impl Debug for SparseMatrix
Source§impl<'de> Deserialize<'de> for SparseMatrix
impl<'de> Deserialize<'de> for SparseMatrix
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for SparseMatrix
impl Display for SparseMatrix
Source§impl Matrix for SparseMatrix
impl Matrix for SparseMatrix
Source§fn rows(&self) -> DimensionType
fn rows(&self) -> DimensionType
Source§fn cols(&self) -> DimensionType
fn cols(&self) -> DimensionType
Source§fn get(&self, row: usize, col: usize) -> Option<Precision>
fn get(&self, row: usize, col: usize) -> Option<Precision>
Source§fn row_iter(
&self,
row: usize,
) -> Box<dyn Iterator<Item = (IndexType, Precision)> + '_>
fn row_iter( &self, row: usize, ) -> Box<dyn Iterator<Item = (IndexType, Precision)> + '_>
Source§fn col_iter(
&self,
col: usize,
) -> Box<dyn Iterator<Item = (IndexType, Precision)> + '_>
fn col_iter( &self, col: usize, ) -> Box<dyn Iterator<Item = (IndexType, Precision)> + '_>
Source§fn multiply_vector(
&self,
x: &[Precision],
result: &mut [Precision],
) -> Result<()>
fn multiply_vector( &self, x: &[Precision], result: &mut [Precision], ) -> Result<()>
Source§fn multiply_vector_add(
&self,
x: &[Precision],
result: &mut [Precision],
) -> Result<()>
fn multiply_vector_add( &self, x: &[Precision], result: &mut [Precision], ) -> Result<()>
Source§fn is_diagonally_dominant(&self) -> bool
fn is_diagonally_dominant(&self) -> bool
Source§fn diagonal_dominance_factor(&self) -> Option<Precision>
fn diagonal_dominance_factor(&self) -> Option<Precision>
Source§fn sparsity_info(&self) -> SparsityInfo
fn sparsity_info(&self) -> SparsityInfo
Source§fn conditioning_info(&self) -> ConditioningInfo
fn conditioning_info(&self) -> ConditioningInfo
Source§fn format_name(&self) -> &'static str
fn format_name(&self) -> &'static str
Source§fn frobenius_norm(&self) -> Precision
fn frobenius_norm(&self) -> Precision
Source§fn spectral_radius_estimate(&self) -> Precision
fn spectral_radius_estimate(&self) -> Precision
Auto Trait Implementations§
impl Freeze for SparseMatrix
impl RefUnwindSafe for SparseMatrix
impl Send for SparseMatrix
impl Sync for SparseMatrix
impl Unpin for SparseMatrix
impl UnwindSafe for SparseMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.