pub struct Csr<T> {
pub indptr: Vec<usize>,
pub indices: Vec<usize>,
pub data: Vec<T>,
pub nrows: usize,
pub ncols: usize,
}Expand description
Lightweight CSR for label propagation sparse algebra.
Fields§
§indptr: Vec<usize>Row index pointers
indices: Vec<usize>Column indices
data: Vec<T>Data for the sparse matrix
nrows: usizeNumber of rows
ncols: usizeNumber of columns
Implementations§
Source§impl<T: EvocFloat> Csr<T>
impl<T: EvocFloat> Csr<T>
Sourcepub fn new(
indptr: Vec<usize>,
indices: Vec<usize>,
data: Vec<T>,
nrows: usize,
ncols: usize,
) -> Self
pub fn new( indptr: Vec<usize>, indices: Vec<usize>, data: Vec<T>, nrows: usize, ncols: usize, ) -> Self
Construct a CSR matrix from its raw components.
No reordering or deduplication is performed; the caller is responsible for providing a valid CSR representation.
§Params
indptr- Row pointer array of lengthnrows + 1indices- Column indices of each stored entrydata- Values corresponding to each entry inindicesnrows- Number of rowsncols- Number of columns
Sourcepub fn from_coo(coo: &CoordinateList<T>) -> Self
pub fn from_coo(coo: &CoordinateList<T>) -> Self
Build a square CSR matrix from a COO coordinate list, summing duplicate entries.
Triplets are sorted by (row, column) in parallel before assembly. Consecutive entries sharing the same (row, column) pair are folded into a single stored value.
§Params
coo- Coordinate list withn_samples x n_sampleslogical shape
§Returns
A square n_samples x n_samples CSR matrix
Sourcepub fn from_partition(partition: &[usize], n_parts: usize) -> Self
pub fn from_partition(partition: &[usize], n_parts: usize) -> Self
Build a partition indicator matrix of shape n_points x n_parts.
Row i contains a single 1.0 at column partition[i], encoding a
hard cluster assignment as a sparse one-hot matrix.
§Params
partition- Slice of lengthn_pointswherepartition[i]is the part index assigned to pointin_parts- Total number of parts (column count)
Sourcepub fn transpose(&self) -> Self
pub fn transpose(&self) -> Self
Transpose into a new CSR matrix.
Constructs the transpose via a two-pass counting sort: the first pass
builds column counts to allocate indptr; the second scatters each
entry to its transposed position using per-column cursors.
§Returns
A new ncols x nrows CSR matrix equal to self^T
Sourcepub fn elementwise_mul(&self, other: &Csr<T>) -> Self
pub fn elementwise_mul(&self, other: &Csr<T>) -> Self
Sourcepub fn normalise_cols_l2(&self) -> Self
pub fn normalise_cols_l2(&self) -> Self
Column-wise L2 normalisation.
Each column is scaled by the reciprocal of its L2 norm. Columns with zero norm are left unchanged (scale factor of 1).
§Returns
A new CSR matrix with the same sparsity pattern and unit-norm columns
Sourcepub fn normalise_rows_l1(&self) -> Self
pub fn normalise_rows_l1(&self) -> Self
Row-wise L1 normalisation.
Each row is scaled by the reciprocal of the sum of absolute values of its entries. Rows with zero norm are left unchanged.
§Returns
A new CSR matrix with the same sparsity pattern and unit-L1-norm rows
Sourcepub fn clip_values(&mut self, lo: T, hi: T)
pub fn clip_values(&mut self, lo: T, hi: T)
Sourcepub fn to_adjacency_list(&self) -> Vec<Vec<(usize, T)>>
pub fn to_adjacency_list(&self) -> Vec<Vec<(usize, T)>>
Convert to an adjacency list representation.
Each entry graph[i] is a Vec of (column, value) pairs for row
i, suitable for consumption by evoc_embedding.
§Returns
A Vec of length nrows, where graph[i] contains the neighbours and
edge weights of node i
Sourcepub fn matmul_dense(&self, rhs: &MatRef<'_, T>) -> Mat<T>
pub fn matmul_dense(&self, rhs: &MatRef<'_, T>) -> Mat<T>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Csr<T>
impl<T> RefUnwindSafe for Csr<T>where
T: RefUnwindSafe,
impl<T> Send for Csr<T>where
T: Send,
impl<T> Sync for Csr<T>where
T: Sync,
impl<T> Unpin for Csr<T>where
T: Unpin,
impl<T> UnsafeUnpin for Csr<T>
impl<T> UnwindSafe for Csr<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 more