pub struct CscMatrix<T> { /* private fields */ }Expand description
Compressed Sparse Column (CSC) sparse matrix.
Stores non-zero entries in column-major order using three arrays: indptr
(column pointer array of length n_cols + 1), indices (row indices of
each non-zero), and data (values of each non-zero).
§Type Parameter
T — the scalar element type.
Implementations§
Source§impl<T> CscMatrix<T>where
T: Clone,
impl<T> CscMatrix<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 CSC matrix from raw components.
§Arguments
n_rows— number of rows.n_cols— number of columns.indptr— column pointer array of lengthn_cols + 1.indices— row 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_csr(csr: &CsrMatrix<T>) -> Result<Self, FerroError>
pub fn from_csr(csr: &CsrMatrix<T>) -> Result<Self, FerroError>
Sourcepub fn from_dense(dense: &ArrayView2<'_, T>, epsilon: T) -> Self
pub fn from_dense(dense: &ArrayView2<'_, T>, epsilon: T) -> Self
Sourcepub fn col_slice(
&self,
start: usize,
end: usize,
) -> Result<CscMatrix<T>, FerroError>
pub fn col_slice( &self, start: usize, end: usize, ) -> Result<CscMatrix<T>, FerroError>
Return a new CSC matrix containing only the columns in start..end.
§Errors
Returns FerroError::InvalidParameter if start > end or
end > n_cols().
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) -> CscMatrix<T>
pub fn mul_scalar(&self, scalar: T) -> CscMatrix<T>
Scalar multiplication returning a new matrix.
Sourcepub fn add(&self, rhs: &CscMatrix<T>) -> Result<CscMatrix<T>, FerroError>
pub fn add(&self, rhs: &CscMatrix<T>) -> Result<CscMatrix<T>, FerroError>
Element-wise addition of two CSC matrices with the same shape.
§Errors
Returns FerroError::ShapeMismatch if the matrices have different shapes.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CscMatrix<T>
impl<T> RefUnwindSafe for CscMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for CscMatrix<T>where
T: Send,
impl<T> Sync for CscMatrix<T>where
T: Sync,
impl<T> Unpin for CscMatrix<T>where
T: Unpin,
impl<T> UnsafeUnpin for CscMatrix<T>
impl<T> UnwindSafe for CscMatrix<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.