pub struct CooMatrix<T> { /* private fields */ }Expand description
Coordinate-format (COO / triplet) sparse matrix.
Stores non-zero entries as (row, col, value) triplets. Duplicate entries
at the same position are summed during conversion to CSR/CSC. This
format is most convenient for construction; prefer CsrMatrix
or CscMatrix for arithmetic.
§Type Parameter
T — the scalar type stored in the matrix. No additional bounds are
required for construction; conversion methods impose their own bounds.
Implementations§
Source§impl<T> CooMatrix<T>
impl<T> CooMatrix<T>
Sourcepub fn new(n_rows: usize, n_cols: usize) -> Self
pub fn new(n_rows: usize, n_cols: usize) -> Self
Create an empty COO matrix with the given shape.
§Arguments
n_rows— number of rows.n_cols— number of columns.
Sourcepub fn with_capacity(n_rows: usize, n_cols: usize, capacity: usize) -> Self
pub fn with_capacity(n_rows: usize, n_cols: usize, capacity: usize) -> Self
Create a COO matrix with the given shape and pre-allocated capacity.
§Arguments
n_rows— number of rows.n_cols— number of columns.capacity— expected number of non-zero entries.
Sourcepub fn from_triplets(
n_rows: usize,
n_cols: usize,
row_inds: Vec<usize>,
col_inds: Vec<usize>,
data: Vec<T>,
) -> Result<Self, FerroError>
pub fn from_triplets( n_rows: usize, n_cols: usize, row_inds: Vec<usize>, col_inds: Vec<usize>, data: Vec<T>, ) -> Result<Self, FerroError>
Build a CooMatrix from raw triplet components.
All three slices must have the same length. Row indices must be less
than n_rows; column indices must be less than n_cols.
§Errors
Returns FerroError::InvalidParameter if the slice lengths differ or
if any index is out of bounds.
Sourcepub fn push(
&mut self,
row: usize,
col: usize,
value: T,
) -> Result<(), FerroError>
pub fn push( &mut self, row: usize, col: usize, value: T, ) -> Result<(), FerroError>
Append a single non-zero entry (row, col, value).
§Errors
Returns FerroError::InvalidParameter if row >= n_rows() or
col >= n_cols().
Sourcepub fn nnz(&self) -> usize
pub fn nnz(&self) -> usize
Returns the number of stored non-zero entries (counting duplicates).
Sourcepub fn inner(&self) -> &TriMat<T>
pub fn inner(&self) -> &TriMat<T>
Returns a reference to the underlying sprs::TriMat<T>.
Sourcepub fn into_inner(self) -> TriMat<T>
pub fn into_inner(self) -> TriMat<T>
Consume this matrix and return the underlying sprs::TriMat<T>.
Trait Implementations§
Source§impl<T: Clone> Clone for CooMatrix<T>
impl<T: Clone> Clone for CooMatrix<T>
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clone by rebuilding the inner sprs::TriMat from raw components.
sprs::TriMat does not implement Clone generically, so we
reconstruct it from the stored row indices, column indices, and data.
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T> Freeze for CooMatrix<T>
impl<T> RefUnwindSafe for CooMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for CooMatrix<T>where
T: Send,
impl<T> Sync for CooMatrix<T>where
T: Sync,
impl<T> Unpin for CooMatrix<T>where
T: Unpin,
impl<T> UnsafeUnpin for CooMatrix<T>
impl<T> UnwindSafe for CooMatrix<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.