pub struct CscMatrix<T> { /* private fields */ }
Expand description
Compressed Sparse Column (CSC) matrix
A sparse matrix format that compresses columns, making it efficient for column operations and matrix operations.
Implementations§
Source§impl<T> CscMatrix<T>
impl<T> CscMatrix<T>
Sourcepub fn new(
data: Vec<T>,
rowindices: Vec<usize>,
colindices: Vec<usize>,
shape: (usize, usize),
) -> SparseResult<Self>
pub fn new( data: Vec<T>, rowindices: Vec<usize>, colindices: Vec<usize>, shape: (usize, usize), ) -> SparseResult<Self>
Create a new CSC matrix from raw data
§Arguments
data
- Vector of non-zero valuesrowindices
- Vector of row indices for each non-zero valuecolindices
- Vector of column indices for each non-zero valueshape
- Tuple containing the matrix dimensions (rows, cols)
§Returns
- A new CSC matrix
§Examples
use scirs2_sparse::csc::CscMatrix;
// Create a 3x3 sparse matrix with 5 non-zero elements
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 2, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let matrix = CscMatrix::new(data.clone(), rows, cols, shape).unwrap();
Sourcepub fn from_raw_csc(
data: Vec<T>,
indptr: Vec<usize>,
indices: Vec<usize>,
shape: (usize, usize),
) -> SparseResult<Self>
pub fn from_raw_csc( data: Vec<T>, indptr: Vec<usize>, indices: Vec<usize>, shape: (usize, usize), ) -> SparseResult<Self>
Sourcepub fn from_csc_data(
values: Vec<T>,
rowindices: Vec<usize>,
col_ptrs: Vec<usize>,
shape: (usize, usize),
) -> SparseResult<Self>
pub fn from_csc_data( values: Vec<T>, rowindices: Vec<usize>, col_ptrs: Vec<usize>, shape: (usize, usize), ) -> SparseResult<Self>
Create a new empty CSC matrix
§Arguments
shape
- Tuple containing the matrix dimensions (rows, cols)
§Returns
- A new empty CSC matrix Create a CSC matrix from CSC data (values, row indices, column pointers)
§Arguments
values
- Valuesrowindices
- Row indicescol_ptrs
- Column pointersshape
- Shape of the matrix (rows, cols)
§Returns
- Result containing the CSC matrix
pub fn empty(shape: (usize, usize)) -> Self
Sourcepub fn rowindices(&self) -> &[usize]
pub fn rowindices(&self) -> &[usize]
Get row indices array
Source§impl CscMatrix<f64>
impl CscMatrix<f64>
Sourcepub fn gpu_dot(&self, vec: &[f64]) -> SparseResult<Vec<f64>>
pub fn gpu_dot(&self, vec: &[f64]) -> SparseResult<Vec<f64>>
GPU-accelerated matrix-vector multiplication
This method converts the CSC matrix to CSR format and uses GPU acceleration. CSR format is generally more GPU-friendly for SpMV operations.
§Arguments
vec
- Vector to multiply with
§Returns
- Result of matrix-vector multiplication
§Examples
use scirs2_sparse::csc::CscMatrix;
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 2, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let matrix = CscMatrix::new(data, rows, cols, shape).unwrap();
let vec = vec![1.0, 2.0, 3.0];
let result = matrix.gpu_dot(&vec).unwrap();
Sourcepub fn gpu_dot_with_backend(
&self,
vec: &[f64],
backend: GpuBackend,
) -> SparseResult<Vec<f64>>
pub fn gpu_dot_with_backend( &self, vec: &[f64], backend: GpuBackend, ) -> SparseResult<Vec<f64>>
Source§impl<T> CscMatrix<T>
impl<T> CscMatrix<T>
Sourcepub fn gpu_dot_generic(&self, vec: &[T]) -> SparseResult<Vec<T>>
pub fn gpu_dot_generic(&self, vec: &[T]) -> SparseResult<Vec<T>>
Sourcepub fn should_use_gpu(&self) -> bool
pub fn should_use_gpu(&self) -> bool
Check if this matrix should benefit from GPU acceleration
§Returns
true
if GPU acceleration is likely to provide benefits
Sourcepub fn gpu_backend_info() -> SparseResult<(GpuBackend, String)>
pub fn gpu_backend_info() -> SparseResult<(GpuBackend, String)>
Auto Trait Implementations§
impl<T> Freeze for CscMatrix<T>
impl<T> RefUnwindSafe for CscMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for CscMatrix<T>where
T: Send,
impl<T> Sync for CscMatrix<T>where
T: Sync,
impl<T> Unpin for CscMatrix<T>where
T: Unpin,
impl<T> UnwindSafe for CscMatrix<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> 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