pub struct SparseMatrix { /* private fields */ }Expand description
A sparse matrix stored in Compressed Sparse Row (CSR) format. Only non-zero elements are stored, making it efficient for sparse matrices.
Implementations§
Source§impl SparseMatrix
impl SparseMatrix
Sourcepub fn new(rows: usize, cols: usize) -> Self
pub fn new(rows: usize, cols: usize) -> Self
Creates a new sparse matrix with the given dimensions.
Sourcepub fn from_dense(dense: &Matrix) -> Self
pub fn from_dense(dense: &Matrix) -> Self
Creates a sparse matrix from a dense matrix.
Sourcepub fn get(&self, row: usize, col: usize) -> Rational64
pub fn get(&self, row: usize, col: usize) -> Rational64
Gets the element at position (row, col).
Sourcepub fn set(&mut self, row: usize, col: usize, value: Rational64)
pub fn set(&mut self, row: usize, col: usize, value: Rational64)
Sets the element at position (row, col). Note: This is inefficient for CSR format. Consider building the matrix incrementally using a builder pattern or from a dense matrix.
Sourcepub fn mul_vec(&self, v: &[Rational64]) -> Vec<Rational64> ⓘ
pub fn mul_vec(&self, v: &[Rational64]) -> Vec<Rational64> ⓘ
Sparse matrix-vector multiplication: returns A * v
Sourcepub fn mul(&self, other: &SparseMatrix) -> SparseMatrix
pub fn mul(&self, other: &SparseMatrix) -> SparseMatrix
Sparse matrix-matrix multiplication: returns A * B
Sourcepub fn transpose(&self) -> SparseMatrix
pub fn transpose(&self) -> SparseMatrix
Transposes the sparse matrix.
Trait Implementations§
Source§impl Clone for SparseMatrix
impl Clone for SparseMatrix
Source§fn clone(&self) -> SparseMatrix
fn clone(&self) -> SparseMatrix
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SparseMatrix
impl Debug for SparseMatrix
Source§impl Display for SparseMatrix
impl Display for SparseMatrix
Source§impl PartialEq for SparseMatrix
impl PartialEq for SparseMatrix
impl StructuralPartialEq for SparseMatrix
Auto Trait Implementations§
impl Freeze for SparseMatrix
impl RefUnwindSafe for SparseMatrix
impl Send for SparseMatrix
impl Sync for SparseMatrix
impl Unpin for SparseMatrix
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more