pub struct BlockCSR<T> {
pub nrows: usize,
pub ncols: usize,
pub block_rows: usize,
pub block_cols: usize,
pub num_block_rows: usize,
pub num_block_cols: usize,
pub indptr: Vec<usize>,
pub block_col_indices: Vec<usize>,
pub data: Vec<T>,
}Expand description
Block Compressed Sparse Row (BCSR / BSR) format.
The matrix is divided into (r × c) blocks. Only blocks containing at least
one non-zero are stored. Internally each stored block is a dense r * c array.
§When to use
Use BlockCSR when the sparse pattern has a natural block structure (e.g.,
FEM stiffness matrices, graph problems with vector unknowns per node). Dense
block kernels (GEMV) run much faster than scalar scatter operations.
Fields§
§nrows: usizeMatrix rows.
ncols: usizeMatrix cols.
block_rows: usizeBlock row size.
block_cols: usizeBlock col size.
num_block_rows: usizeNumber of block rows = ceil(nrows / block_rows).
num_block_cols: usizeNumber of block cols = ceil(ncols / block_cols).
indptr: Vec<usize>CSR-like indptr over block rows; length = num_block_rows + 1.
block_col_indices: Vec<usize>Block column indices; length = number of stored blocks.
data: Vec<T>Dense block data; length = #blocks * block_rows * block_cols.
Block k occupies data[k * block_rows * block_cols .. (k+1) * block_rows * block_cols]
in row-major order.
Implementations§
Source§impl<T> BlockCSR<T>
impl<T> BlockCSR<T>
Sourcepub fn from_csr(
csr: &CsrMatrix<T>,
block_rows: usize,
block_cols: usize,
) -> SparseResult<Self>
pub fn from_csr( csr: &CsrMatrix<T>, block_rows: usize, block_cols: usize, ) -> SparseResult<Self>
Build a BlockCSR from a CSR matrix with given block dimensions.
§Arguments
csr- Source CSR matrix.block_rows- Block row size (must be ≥ 1).block_cols- Block col size (must be ≥ 1).
Sourcepub fn spmv(&self, x: &[T]) -> SparseResult<Vec<T>>
pub fn spmv(&self, x: &[T]) -> SparseResult<Vec<T>>
SpMV: y = self * x.
Sourcepub fn to_csr(&self) -> SparseResult<CsrMatrix<T>>
pub fn to_csr(&self) -> SparseResult<CsrMatrix<T>>
Convert back to CSR.
Sourcepub fn num_blocks(&self) -> usize
pub fn num_blocks(&self) -> usize
Number of stored blocks.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for BlockCSR<T>
impl<T> RefUnwindSafe for BlockCSR<T>where
T: RefUnwindSafe,
impl<T> Send for BlockCSR<T>where
T: Send,
impl<T> Sync for BlockCSR<T>where
T: Sync,
impl<T> Unpin for BlockCSR<T>where
T: Unpin,
impl<T> UnsafeUnpin for BlockCSR<T>
impl<T> UnwindSafe for BlockCSR<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
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