pub struct CompressedSparse<T> {
pub data: Vec<T>,
pub indices: Vec<u32>,
pub indptr: Vec<u32>,
pub format: SparseFormat,
pub shape: (usize, usize),
}Expand description
A sparse matrix in compressed row or column form.
Fields are public so buffers can go straight to a kernel, but only
CompressedSparse::validate guarantees consistency. Prefer the
constructors.
Fields§
§data: Vec<T>Non-zero values, ordered by the compressed axis then by indices.
indices: Vec<u32>Index along the non-compressed axis for each value in data.
indptr: Vec<u32>Offsets into data/indices, one per compressed slice plus a trailing total.
format: SparseFormatWhether indptr walks rows or columns.
shape: (usize, usize)Logical shape as (n_rows, n_cols), independent of format.
Implementations§
Source§impl<T: Copy> CompressedSparse<T>
impl<T: Copy> CompressedSparse<T>
Sourcepub fn from_parts(
data: Vec<T>,
indices: Vec<u32>,
indptr: Vec<u32>,
format: SparseFormat,
shape: (usize, usize),
) -> Result<Self, EdgeErrors>
pub fn from_parts( data: Vec<T>, indices: Vec<u32>, indptr: Vec<u32>, format: SparseFormat, shape: (usize, usize), ) -> Result<Self, EdgeErrors>
Assembles a matrix from its parts without copying.
§Params
data- Non-zero valuesindices- Index along the non-compressed axis per valueindptr- Offsets per compressed slice, lengthouter_len + 1format- Which axisindptrwalksshape- Logical(n_rows, n_cols)
§Returns
The matrix, or EdgeErrors::MalformedSparse if the parts disagree.
Sourcepub fn validate(&self) -> Result<(), EdgeErrors>
pub fn validate(&self) -> Result<(), EdgeErrors>
Checks the structural invariants.
data and indices must match in length, indptr must have the right
length, be non-decreasing and end at the non-zero count, and every index
must be inside the non-compressed axis.
§Returns
Ok(()) when consistent, otherwise EdgeErrors::MalformedSparse.
Sourcepub fn outer_len(&self) -> usize
pub fn outer_len(&self) -> usize
Length of the compressed axis, that is, how many slices indptr walks.
§Returns
Row count for CSR, column count for CSC.
Sourcepub fn inner_len(&self) -> usize
pub fn inner_len(&self) -> usize
Length of the non-compressed axis, that is, the range indices spans.
§Returns
Column count for CSR, row count for CSC.
Sourcepub fn transpose(self) -> Self
pub fn transpose(self) -> Self
The transposed matrix, for free.
A CSR over (m, n) describes the same bytes as a CSC over (n, m).
§Returns
A matrix representing the transpose, sharing this one’s layout.
Sourcepub fn convert(&self) -> Selfwhere
T: Default,
pub fn convert(&self) -> Selfwhere
T: Default,
The same matrix stored in the other format.
A pass over the non-zeros plus a counting sort. Sequential; meant to be called once at ingest.
§Returns
An equivalent matrix with the opposite format.
Sourcepub fn from_dense<F>(
dense: &[T],
n_rows: usize,
n_cols: usize,
format: SparseFormat,
is_zero: F,
) -> Result<Self, EdgeErrors>
pub fn from_dense<F>( dense: &[T], n_rows: usize, n_cols: usize, format: SparseFormat, is_zero: F, ) -> Result<Self, EdgeErrors>
Builds a compressed matrix from a dense row-major buffer.
For tests and small inputs.
§Params
dense-n_rows * n_colsvalues, row-majorn_rows- Number of rowsn_cols- Number of columnsformat- Storage format to buildis_zero- Predicate deciding which values to drop
§Returns
The compressed matrix, or EdgeErrors::LengthMismatch if dense does
not match the stated shape.
Trait Implementations§
Source§impl<T: Clone> Clone for CompressedSparse<T>
impl<T: Clone> Clone for CompressedSparse<T>
Auto Trait Implementations§
impl<T> Freeze for CompressedSparse<T>
impl<T> RefUnwindSafe for CompressedSparse<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for CompressedSparse<T>
impl<T> Sync for CompressedSparse<T>
impl<T> Unpin for CompressedSparse<T>
impl<T> UnsafeUnpin for CompressedSparse<T>where
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for CompressedSparse<T>where
Vec<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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,
impl<T, U> Imply<T> for U
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
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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§fn to_subset_unchecked(&self) -> SS
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.