pub struct SparseCSC<T: TensorElement> { /* private fields */ }Expand description
Sparse tensor in CSC (Compressed Sparse Column) format
CSC format is optimized for column-wise operations. It stores:
col_ptr: Array of size (num_cols + 1) indicating where each column startsrow_indices: Row indices for each non-zero valuevalues: Non-zero values in column-major order
§Example
use torsh_tensor::sparse::SparseCSC;
// Create a 3x3 sparse matrix in CSC format
// [[1.0, 0.0, 2.0],
// [0.0, 3.0, 0.0],
// [4.0, 0.0, 5.0]]
let col_ptr = vec![0, 2, 3, 5]; // Column pointers
let row_indices = vec![0, 2, 1, 0, 2]; // Row indices
let values = vec![1.0, 4.0, 3.0, 2.0, 5.0]; // Values
let shape = vec![3, 3];
let sparse = SparseCSC::new(col_ptr, row_indices, values, shape).expect("CSC creation should succeed");Implementations§
Source§impl<T: TensorElement> SparseCSC<T>
impl<T: TensorElement> SparseCSC<T>
Sourcepub fn new(
col_ptr: Vec<usize>,
row_indices: Vec<usize>,
values: Vec<T>,
shape: Vec<usize>,
) -> Result<Self>
pub fn new( col_ptr: Vec<usize>, row_indices: Vec<usize>, values: Vec<T>, shape: Vec<usize>, ) -> Result<Self>
Create a new CSC sparse tensor
§Arguments
col_ptr- Column pointers (length: num_cols + 1)row_indices- Row indices for non-zero valuesvalues- Non-zero valuesshape- Shape [num_rows, num_cols]
Sourcepub fn from_coo(coo: &SparseTensor<T>) -> Result<Self>where
T: Copy,
pub fn from_coo(coo: &SparseTensor<T>) -> Result<Self>where
T: Copy,
Convert from COO format to CSC format
Sourcepub fn to_coo(&self) -> Result<SparseTensor<T>>where
T: Copy,
pub fn to_coo(&self) -> Result<SparseTensor<T>>where
T: Copy,
Convert to COO format
Sourcepub fn transpose_matvec(&self, vec: &[T]) -> Result<Vec<T>>
pub fn transpose_matvec(&self, vec: &[T]) -> Result<Vec<T>>
Matrix-vector multiplication with transposed matrix (A^T * v) - optimized for CSC
Sourcepub fn get_col(&self, col: usize) -> Result<(Vec<usize>, Vec<T>)>where
T: Copy,
pub fn get_col(&self, col: usize) -> Result<(Vec<usize>, Vec<T>)>where
T: Copy,
Get a specific column as a sparse vector
pub fn shape(&self) -> &[usize]
pub fn device(&self) -> DeviceType
pub fn col_ptr(&self) -> &[usize]
pub fn row_indices(&self) -> &[usize]
pub fn values(&self) -> &[T]
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for SparseCSC<T>
impl<T> RefUnwindSafe for SparseCSC<T>where
T: RefUnwindSafe,
impl<T> Send for SparseCSC<T>
impl<T> Sync for SparseCSC<T>
impl<T> Unpin for SparseCSC<T>where
T: Unpin,
impl<T> UnsafeUnpin for SparseCSC<T>
impl<T> UnwindSafe for SparseCSC<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
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