pub struct CsrMatrix {
pub num_rows: usize,
pub num_cols: usize,
pub values: Vec<Complex64>,
pub col_indices: Vec<usize>,
pub row_ptrs: Vec<usize>,
}Expand description
Compressed Sparse Row (CSR) matrix format
Memory-efficient storage for sparse matrices with O(nnz) space complexity. Matrix-vector products are O(nnz) instead of O(n²) for dense matrices.
Fields§
§num_rows: usizeNumber of rows
num_cols: usizeNumber of columns
values: Vec<Complex64>Non-zero values in row-major order
col_indices: Vec<usize>Column indices for each value
row_ptrs: Vec<usize>Row pointers: row_ptrs[i] is the start index in values/col_indices for row i
row_ptrs[num_rows] = nnz (total number of non-zeros)
Implementations§
Source§impl CsrMatrix
impl CsrMatrix
Sourcepub fn with_capacity(
num_rows: usize,
num_cols: usize,
nnz_estimate: usize,
) -> Self
pub fn with_capacity( num_rows: usize, num_cols: usize, nnz_estimate: usize, ) -> Self
Create a CSR matrix with pre-allocated capacity
Sourcepub fn from_dense(dense: &Array2<Complex64>, threshold: f64) -> Self
pub fn from_dense(dense: &Array2<Complex64>, threshold: f64) -> Self
Create a CSR matrix from a dense matrix
Only stores entries with magnitude > threshold
Sourcepub fn from_triplets(
num_rows: usize,
num_cols: usize,
triplets: Vec<(usize, usize, Complex64)>,
) -> Self
pub fn from_triplets( num_rows: usize, num_cols: usize, triplets: Vec<(usize, usize, Complex64)>, ) -> Self
Create a CSR matrix from COO (Coordinate) format triplets
Triplets are (row, col, value). Duplicate entries are summed.
Sourcepub fn row_range(&self, row: usize) -> Range<usize>
pub fn row_range(&self, row: usize) -> Range<usize>
Get the range of indices in values/col_indices for a given row
Sourcepub fn row_entries(
&self,
row: usize,
) -> impl Iterator<Item = (usize, Complex64)> + '_
pub fn row_entries( &self, row: usize, ) -> impl Iterator<Item = (usize, Complex64)> + '_
Get the (col, value) pairs for a row
Sourcepub fn matvec(&self, x: &Array1<Complex64>) -> Array1<Complex64>
pub fn matvec(&self, x: &Array1<Complex64>) -> Array1<Complex64>
Matrix-vector product: y = A * x
Sourcepub fn matvec_add(&self, x: &Array1<Complex64>, y: &mut Array1<Complex64>)
pub fn matvec_add(&self, x: &Array1<Complex64>, y: &mut Array1<Complex64>)
Matrix-vector product with accumulation: y += A * x
Sourcepub fn matvec_transpose(&self, x: &Array1<Complex64>) -> Array1<Complex64>
pub fn matvec_transpose(&self, x: &Array1<Complex64>) -> Array1<Complex64>
Transpose matrix-vector product: y = A^T * x
Sourcepub fn matvec_hermitian(&self, x: &Array1<Complex64>) -> Array1<Complex64>
pub fn matvec_hermitian(&self, x: &Array1<Complex64>) -> Array1<Complex64>
Hermitian (conjugate transpose) matrix-vector product: y = A^H * x
Sourcepub fn get(&self, i: usize, j: usize) -> Complex64
pub fn get(&self, i: usize, j: usize) -> Complex64
Get element at (i, j), returns 0 if not stored
Sourcepub fn add_diagonal(&mut self, scalar: Complex64)
pub fn add_diagonal(&mut self, scalar: Complex64)
Add a scalar to the diagonal
Sourcepub fn from_diagonal(diag: &Array1<Complex64>) -> Self
pub fn from_diagonal(diag: &Array1<Complex64>) -> Self
Create diagonal matrix from vector
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CsrMatrix
impl RefUnwindSafe for CsrMatrix
impl Send for CsrMatrix
impl Sync for CsrMatrix
impl Unpin for CsrMatrix
impl UnsafeUnpin for CsrMatrix
impl UnwindSafe for CsrMatrix
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
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>
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>
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