pub struct SparseMatrix { /* private fields */ }Expand description
Compressed Sparse Row (CSR) matrix for memory-efficient storage of
mostly-zero 2-D data, mirroring scipy.sparse csr_matrix.
Three arrays define the non-zero entries:
indptr(lengthnrows + 1): rowioccupiesindptr[i]..indptr[i+1]inindices/data.indices: column index of each non-zero.data: value of each non-zero.
Implementations§
Source§impl SparseMatrix
impl SparseMatrix
Sourcepub fn new(
nrows: usize,
ncols: usize,
indptr: Vec<usize>,
indices: Vec<usize>,
data: Vec<f64>,
) -> Result<Self>
pub fn new( nrows: usize, ncols: usize, indptr: Vec<usize>, indices: Vec<usize>, data: Vec<f64>, ) -> Result<Self>
Build a CSR matrix from raw CSR arrays.
indptr must be non-decreasing and stay within the stored-entry count.
Column indices must be strictly increasing within every row.
Sourcepub fn from_triplets(
nrows: usize,
ncols: usize,
triplets: &[(usize, usize, f64)],
) -> Result<Self>
pub fn from_triplets( nrows: usize, ncols: usize, triplets: &[(usize, usize, f64)], ) -> Result<Self>
Build from (row, col, value) triplets. Zero-valued triplets are
dropped automatically. Within a row, entries are sorted by column and
duplicate coordinates are summed.
Sourcepub fn zeros(nrows: usize, ncols: usize) -> Result<Self>
pub fn zeros(nrows: usize, ncols: usize) -> Result<Self>
Create an all-zeros sparse matrix with the given shape.
Sourcepub fn get(&self, i: usize, j: usize) -> f64
pub fn get(&self, i: usize, j: usize) -> f64
Get element at (i, j). Returns 0.0 if not stored.
§Panics
Panics if i >= nrows() or j >= ncols(). Use
checked_get for bounds-checked access.
Sourcepub fn checked_get(&self, i: usize, j: usize) -> Option<f64>
pub fn checked_get(&self, i: usize, j: usize) -> Option<f64>
Returns Some(element) at row i, column j, including Some(0.0)
when the value is not stored, or None if either index is out of bounds.
Trait Implementations§
Source§impl Clone for SparseMatrix
impl Clone for SparseMatrix
Source§fn clone(&self) -> SparseMatrix
fn clone(&self) -> SparseMatrix
1.0.0 (const: unstable) · 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
Available on crate feature serde only.
impl<'de> Deserialize<'de> for SparseMatrix
serde only.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 PartialEq for SparseMatrix
impl PartialEq for SparseMatrix
Source§impl Serialize for SparseMatrix
impl Serialize 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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