pub struct CsrMatrix<T> {
pub indptr: Vec<usize>,
pub indices: Vec<usize>,
pub data: Vec<T>,
/* private fields */
}
Expand description
Compressed Sparse Row (CSR) matrix
A sparse matrix format that compresses rows, making it efficient for row operations and matrix-vector multiplication.
Fields§
§indptr: Vec<usize>
Row pointers (size rows+1)
indices: Vec<usize>
Column indices
data: Vec<T>
Data values
Implementations§
Source§impl<T> CsrMatrix<T>
impl<T> CsrMatrix<T>
Sourcepub fn get_triplets(&self) -> (Vec<usize>, Vec<usize>, Vec<T>)
pub fn get_triplets(&self) -> (Vec<usize>, Vec<usize>, Vec<T>)
Get the triplets (row indices, column indices, data)
Sourcepub fn new(
data: Vec<T>,
row_indices: Vec<usize>,
col_indices: Vec<usize>,
shape: (usize, usize),
) -> SparseResult<Self>
pub fn new( data: Vec<T>, row_indices: Vec<usize>, col_indices: Vec<usize>, shape: (usize, usize), ) -> SparseResult<Self>
Create a new CSR matrix from raw data
§Arguments
data
- Vector of non-zero valuesrow_indices
- Vector of row indices for each non-zero valuecol_indices
- Vector of column indices for each non-zero valueshape
- Tuple containing the matrix dimensions (rows, cols)
§Returns
- A new CSR matrix
§Examples
use scirs2_sparse::csr::CsrMatrix;
// 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 = CsrMatrix::new(data.clone(), rows, cols, shape).unwrap();
Sourcepub fn from_raw_csr(
data: Vec<T>,
indptr: Vec<usize>,
indices: Vec<usize>,
shape: (usize, usize),
) -> SparseResult<Self>
pub fn from_raw_csr( data: Vec<T>, indptr: Vec<usize>, indices: Vec<usize>, shape: (usize, usize), ) -> SparseResult<Self>
Source§impl<T: Clone + Copy + AddAssign + MulAssign + PartialEq + Debug + Zero + Add<Output = T> + Mul<Output = T>> CsrMatrix<T>
impl<T: Clone + Copy + AddAssign + MulAssign + PartialEq + Debug + Zero + Add<Output = T> + Mul<Output = T>> CsrMatrix<T>
Trait Implementations§
Source§impl<F: Float + NumAssign + Sum + 'static + Debug> AsLinearOperator<F> for CsrMatrix<F>
impl<F: Float + NumAssign + Sum + 'static + Debug> AsLinearOperator<F> for CsrMatrix<F>
Source§fn as_linear_operator(&self) -> Box<dyn LinearOperator<F>>
fn as_linear_operator(&self) -> Box<dyn LinearOperator<F>>
Convert to a linear operator
Auto Trait Implementations§
impl<T> Freeze for CsrMatrix<T>
impl<T> RefUnwindSafe for CsrMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for CsrMatrix<T>where
T: Send,
impl<T> Sync for CsrMatrix<T>where
T: Sync,
impl<T> Unpin for CsrMatrix<T>where
T: Unpin,
impl<T> UnwindSafe for CsrMatrix<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