Skip to main content

Csr

Struct Csr 

Source
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: usize

Number of rows

§ncols: usize

Number of columns

Implementations§

Source§

impl<T: EvocFloat> Csr<T>

Source

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 length nrows + 1
  • indices - Column indices of each stored entry
  • data - Values corresponding to each entry in indices
  • nrows - Number of rows
  • ncols - Number of columns
Source

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 with n_samples x n_samples logical shape
§Returns

A square n_samples x n_samples CSR matrix

Source

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 length n_points where partition[i] is the part index assigned to point i
  • n_parts - Total number of parts (column count)
Source

pub fn nnz(&self) -> usize

Number of stored non-zero entries.

Source

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

Source

pub fn matmul(&self, other: &Csr<T>) -> Self

Sparse-sparse matrix multiplication: self (m x k) * other (k x n) -> (m x n).

§Params
  • other - Right-hand operand; its row count must equal self.ncols
§Returns

A new m x n CSR matrix

Source

pub fn elementwise_mul(&self, other: &Csr<T>) -> Self

Element-wise (Hadamard) product of two matrices with identical shape.

§Params
  • other - Right-hand operand; must have the same shape as self and sorted column indices per row
§Returns

A new CSR matrix containing only the entries where both operands are non-zero

Source

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

Source

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

Source

pub fn clip_values(&mut self, lo: T, hi: T)

Clamp all stored values to the closed interval [lo, hi].

§Params
  • lo - Lower bound
  • hi - Upper bound
Source

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

Source

pub fn matmul_dense(&self, rhs: &MatRef<'_, T>) -> Mat<T>

Sparse-dense matrix multiplication: self (m x k) * rhs (k x d) -> (m x d).

§Params
  • rhs - Dense right-hand operand; its row count must equal self.ncols
§Returns

A dense m x d matrix

Source

pub fn to_dense(&self) -> Mat<T>

Convert to a dense faer::Mat, filling structural zeros explicitly.

§Returns

A dense nrows x ncols matrix

Trait Implementations§

Source§

impl<T: Clone> Clone for Csr<T>

Source§

fn clone(&self) -> Csr<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Csr<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V