pub struct SparseIndex {
pub rows: usize,
pub cols: usize,
pub values: Vec<i8>,
pub col_idx: Vec<u32>,
pub row_ptr: Vec<u64>,
pub nnz: usize,
pub sparsity: f64,
}Expand description
Compressed Sparse Row index for one weight matrix.
Fields§
§rows: usize§cols: usize§values: Vec<i8>Non-zero trit values, stored as i8 (+1 or -1).
col_idx: Vec<u32>Column of each non-zero value. Same length as values.
row_ptr: Vec<u64>row_ptr[r] = index into values where row r starts.
Length = rows + 1. row_ptr[rows] = values.len().
nnz: usizeNumber of non-zero elements.
sparsity: f64Sparsity = 1 - nnz / (rows * cols).
Implementations§
Source§impl SparseIndex
impl SparseIndex
Sourcepub fn from_trits(rows: usize, cols: usize, data: &[Trit]) -> Self
pub fn from_trits(rows: usize, cols: usize, data: &[Trit]) -> Self
Build a CSR index from a flat row-major slice of trits.
Sourcepub fn to_dense(&self) -> Vec<Trit>
pub fn to_dense(&self) -> Vec<Trit>
Reconstruct the dense trit slice (for testing / correctness checks).
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Memory footprint in bytes.
Sourcepub fn is_efficient(&self) -> bool
pub fn is_efficient(&self) -> bool
Whether CSR is more memory-efficient than a 2-bit packed dense matrix.
Trait Implementations§
Source§impl Clone for SparseIndex
impl Clone for SparseIndex
Source§fn clone(&self) -> SparseIndex
fn clone(&self) -> SparseIndex
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SparseIndex
impl Debug for SparseIndex
Source§impl<'de> Deserialize<'de> for SparseIndex
impl<'de> Deserialize<'de> for SparseIndex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SparseIndex
impl RefUnwindSafe for SparseIndex
impl Send for SparseIndex
impl Sync for SparseIndex
impl Unpin for SparseIndex
impl UnsafeUnpin for SparseIndex
impl UnwindSafe for SparseIndex
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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