pub struct CSRTensor {
pub values: Vec<f32>,
pub col_indices: Vec<usize>,
pub row_ptrs: Vec<usize>,
pub nrows: usize,
pub ncols: usize,
}Expand description
Compressed Sparse Row (CSR) representation.
§Memory Layout
For a matrix with nnz non-zeros and nrows rows:
values: [nnz] - Non-zero values in row-major ordercol_indices: [nnz] - Column index for each valuerow_ptrs: [nrows + 1] - Start index invalues/col_indicesfor each row
§Example
Dense: [[1, 0, 2], CSR:
[0, 0, 3], values: [1, 2, 3, 4]
[4, 0, 0]] col_indices: [0, 2, 2, 0]
row_ptrs: [0, 2, 3, 4]Fields§
§values: Vec<f32>Non-zero values.
col_indices: Vec<usize>Column indices for each value.
row_ptrs: Vec<usize>Row pointers (start index for each row).
nrows: usizeNumber of rows.
ncols: usizeNumber of columns.
Implementations§
Source§impl CSRTensor
impl CSRTensor
Sourcepub fn new(
values: Vec<f32>,
col_indices: Vec<usize>,
row_ptrs: Vec<usize>,
nrows: usize,
ncols: usize,
) -> Result<Self, PruningError>
pub fn new( values: Vec<f32>, col_indices: Vec<usize>, row_ptrs: Vec<usize>, nrows: usize, ncols: usize, ) -> Result<Self, PruningError>
Create a new CSR tensor from components.
§Arguments
values- Non-zero valuescol_indices- Column index for each valuerow_ptrs- Row pointer arraynrows- Number of rowsncols- Number of columns
Sourcepub fn from_dense(tensor: &Tensor) -> Result<Self, PruningError>
pub fn from_dense(tensor: &Tensor) -> Result<Self, PruningError>
Create CSR tensor from dense tensor.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Memory usage in bytes (approximate).
Sourcepub fn dense_memory_bytes(&self) -> usize
pub fn dense_memory_bytes(&self) -> usize
Dense memory usage for comparison.
Sourcepub fn memory_savings_ratio(&self) -> f32
pub fn memory_savings_ratio(&self) -> f32
Memory savings ratio (dense / sparse).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CSRTensor
impl RefUnwindSafe for CSRTensor
impl Send for CSRTensor
impl Sync for CSRTensor
impl Unpin for CSRTensor
impl UnwindSafe for CSRTensor
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> 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