#[non_exhaustive]pub struct CsrMatrix { /* private fields */ }Expand description
Compressed Sparse Row matrix.
Efficient for row iteration (KNN predict, tree predict).
Standard CSR layout: indptr[i]..indptr[i+1] gives the range
into indices and data for row i.
Implementations§
Source§impl CsrMatrix
impl CsrMatrix
Sourcepub fn from_triplets(
rows: &[usize],
cols: &[usize],
vals: &[f64],
n_rows: usize,
n_cols: usize,
) -> Result<Self>
pub fn from_triplets( rows: &[usize], cols: &[usize], vals: &[f64], n_rows: usize, n_cols: usize, ) -> Result<Self>
Build a CSR matrix from COO (triplet) format.
Duplicate entries at the same (row, col) are summed.
Sourcepub fn from_dense(rows: &[Vec<f64>]) -> Self
pub fn from_dense(rows: &[Vec<f64>]) -> Self
Convert a dense row-major matrix to CSR (zeros are skipped).
Sourcepub fn density(&self) -> f64
pub fn density(&self) -> f64
Fraction of non-zero entries: nnz / (n_rows * n_cols).
Returns 0.0 for an empty (0×0) matrix.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CsrMatrix
impl RefUnwindSafe for CsrMatrix
impl Send for CsrMatrix
impl Sync for CsrMatrix
impl Unpin for CsrMatrix
impl UnsafeUnpin for CsrMatrix
impl UnwindSafe for CsrMatrix
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more