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.
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.
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 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, or None if i is
out of bounds or the value is not stored (equivalent to 0.0).
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<'de> Deserialize<'de> for SparseMatrix
impl<'de> Deserialize<'de> for SparseMatrix
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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more
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>
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