pub struct SparseMatrix {
pub n: usize,
/* private fields */
}Expand description
Sparse matrix in CSR (compressed sparse row) format.
Triplets added via add() are stored uncompressed. Call compress()
once to convert to canonical CSR (summing duplicates, sorting by row/col).
After compression, matvec/matvec_into use the CSR structure.
Fields§
§n: usizeImplementations§
Source§impl SparseMatrix
impl SparseMatrix
pub fn new(n: usize) -> Self
Sourcepub fn add(&mut self, row: usize, col: usize, val: f64)
pub fn add(&mut self, row: usize, col: usize, val: f64)
Add a triplet (duplicates allowed, summed on compress).
Sourcepub fn compress(&mut self)
pub fn compress(&mut self)
Convert COO triplets to canonical CSR (sum duplicates, sort). Idempotent: safe to call multiple times.
Sourcepub fn matvec(&self, x: &[f64]) -> Vec<f64>
pub fn matvec(&self, x: &[f64]) -> Vec<f64>
Matrix-vector product y = A*x (requires compress() first).
Sourcepub fn matvec_into(&self, x: &[f64], y: &mut [f64])
pub fn matvec_into(&self, x: &[f64], y: &mut [f64])
Matrix-vector product into a caller-provided buffer (requires compress() first).
Sourcepub fn matvec_diag(&self, i: usize) -> f64
pub fn matvec_diag(&self, i: usize) -> f64
Diagonal entry of row i (requires compress() first).
Sourcepub fn frobenius_norm(&self) -> f64
pub fn frobenius_norm(&self) -> f64
Frobenius norm of the matrix.
Sourcepub fn symmetry_max_error(&self) -> f64
pub fn symmetry_max_error(&self) -> f64
Maximum symmetry error max_{i<j} |A_ij - A_ji|.
Sourcepub fn is_symmetric(&self, tol: f64) -> bool
pub fn is_symmetric(&self, tol: f64) -> bool
Check if matrix is symmetric within tolerance.
Trait Implementations§
Source§impl Clone for SparseMatrix
impl Clone for SparseMatrix
Auto Trait Implementations§
impl Forget for SparseMatrix
impl Freeze for SparseMatrix
impl Move 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