pub struct CsrMatrix<T> { /* private fields */ }Expand description
Compressed Sparse Row (CSR) sparse matrix.
Stores non-zero entries in row-major order using three arrays: indptr
(row pointer array of length n_rows + 1), indices (column indices of
each non-zero), and data (values of each non-zero).
§Type Parameter
T — the scalar element type. No bounds are required for basic structural
methods; arithmetic methods impose their own bounds.
§Dataset Trait
Implements ferrolearn_core::Dataset when T: Float + Send + Sync + 'static,
reporting n_samples() == n_rows(), n_features() == n_cols(), and
is_sparse() == true.
Implementations§
Source§impl<T> CsrMatrix<T>where
T: Clone,
impl<T> CsrMatrix<T>where
T: Clone,
Sourcepub fn new(
n_rows: usize,
n_cols: usize,
indptr: Vec<usize>,
indices: Vec<usize>,
data: Vec<T>,
) -> Result<Self, FerroError>
pub fn new( n_rows: usize, n_cols: usize, indptr: Vec<usize>, indices: Vec<usize>, data: Vec<T>, ) -> Result<Self, FerroError>
Construct a CSR matrix from raw components.
§Arguments
n_rows— number of rows.n_cols— number of columns.indptr— row pointer array of lengthn_rows + 1.indices— column index of each non-zero entry.data— value of each non-zero entry.
§Errors
Returns FerroError::InvalidParameter if the data is structurally
invalid (wrong lengths, out-of-bound indices, unsorted inner indices).
Sourcepub fn inner(&self) -> &CsMat<T>
pub fn inner(&self) -> &CsMat<T>
Returns a reference to the underlying sprs::CsMat<T>.
Sourcepub fn into_inner(self) -> CsMat<T>
pub fn into_inner(self) -> CsMat<T>
Consume this matrix and return the underlying sprs::CsMat<T>.
Sourcepub fn from_coo(coo: &CooMatrix<T>) -> Result<Self, FerroError>
pub fn from_coo(coo: &CooMatrix<T>) -> Result<Self, FerroError>
Sourcepub fn from_csc(csc: &CscMatrix<T>) -> Result<Self, FerroError>
pub fn from_csc(csc: &CscMatrix<T>) -> Result<Self, FerroError>
Sourcepub fn to_coo(&self) -> CooMatrix<T>
pub fn to_coo(&self) -> CooMatrix<T>
Convert to CooMatrix.
Each non-zero becomes one triplet entry.
Sourcepub fn from_dense(dense: &ArrayView2<'_, T>, epsilon: T) -> Self
pub fn from_dense(dense: &ArrayView2<'_, T>, epsilon: T) -> Self
Sourcepub fn row_slice(
&self,
start: usize,
end: usize,
) -> Result<CsrMatrix<T>, FerroError>
pub fn row_slice( &self, start: usize, end: usize, ) -> Result<CsrMatrix<T>, FerroError>
Return a new CSR matrix containing only the rows in start..end.
§Errors
Returns FerroError::InvalidParameter if start > end or
end > n_rows().
Sourcepub fn scale(&mut self, scalar: T)
pub fn scale(&mut self, scalar: T)
Scalar multiplication in-place: multiplies every non-zero by scalar.
Requires T: for<'r> MulAssign<&'r T>, which is satisfied by all
primitive numeric types.
Sourcepub fn mul_scalar(&self, scalar: T) -> CsrMatrix<T>
pub fn mul_scalar(&self, scalar: T) -> CsrMatrix<T>
Scalar multiplication returning a new matrix.
Sourcepub fn add(&self, rhs: &CsrMatrix<T>) -> Result<CsrMatrix<T>, FerroError>
pub fn add(&self, rhs: &CsrMatrix<T>) -> Result<CsrMatrix<T>, FerroError>
Element-wise addition of two CSR matrices with the same shape.
§Errors
Returns FerroError::ShapeMismatch if the matrices have different shapes.
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
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.