pub struct CsrMatrix<T> { /* private fields */ }Expand description
Compressed Sparse Row matrix.
Three-array representation: offsets (len = rows+1), col_indices (len = nnz),
values (len = nnz). Row i has nonzeros at positions offsets[i]..offsets[i+1].
All invariants are validated at construction time (provable contract).
Implementations§
Source§impl<T: Clone + Default> CsrMatrix<T>
impl<T: Clone + Default> CsrMatrix<T>
Sourcepub fn new(
rows: usize,
cols: usize,
offsets: Vec<u32>,
col_indices: Vec<u32>,
values: Vec<T>,
) -> Result<Self, SparseError>
pub fn new( rows: usize, cols: usize, offsets: Vec<u32>, col_indices: Vec<u32>, values: Vec<T>, ) -> Result<Self, SparseError>
Sourcepub fn from_coo(coo: &CooMatrix<T>) -> Self
pub fn from_coo(coo: &CooMatrix<T>) -> Self
Convert from COO format to CSR.
Sorts triplets by row, then by column within each row. Duplicate entries are summed (standard convention).
Sourcepub fn col_indices(&self) -> &[u32]
pub fn col_indices(&self) -> &[u32]
Column indices array (len = nnz).
Sourcepub fn avg_nnz_per_row(&self) -> f64
pub fn avg_nnz_per_row(&self) -> f64
Average number of nonzeros per row.
Sourcepub fn row_length_variance(&self) -> f64
pub fn row_length_variance(&self) -> f64
Variance of row lengths (key metric for algorithm selection).
High variance → merge-based SpMV; low variance → row-split SpMV.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CsrMatrix<T>
impl<T> RefUnwindSafe for CsrMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for CsrMatrix<T>where
T: Send,
impl<T> Sync for CsrMatrix<T>where
T: Sync,
impl<T> Unpin for CsrMatrix<T>where
T: Unpin,
impl<T> UnsafeUnpin for CsrMatrix<T>
impl<T> UnwindSafe for CsrMatrix<T>where
T: UnwindSafe,
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