pub struct BSCMatrix<T> {
pub nrows: usize,
pub ncols: usize,
pub block_size: (usize, usize),
pub block_rows: usize,
pub block_cols: usize,
pub data: Vec<T>,
pub indices: Vec<usize>,
pub indptr: Vec<usize>,
}Expand description
Block Sparse Column matrix with flat block storage.
Each non-zero block is stored contiguously in data (row-major within the
block). block_size = (r, c) means each block has r rows and c
columns.
Fields§
§nrows: usizeTotal number of matrix rows.
ncols: usizeTotal number of matrix columns.
block_size: (usize, usize)Block dimensions (rows per block, cols per block).
block_rows: usizeNumber of block-rows.
block_cols: usizeNumber of block-columns.
data: Vec<T>Flat block storage: length = nnz_blocks * r * c.
indices: Vec<usize>Block-row indices: length = nnz_blocks.
indptr: Vec<usize>Column pointer array: length = block_cols + 1.
Implementations§
Source§impl<T> BSCMatrix<T>
impl<T> BSCMatrix<T>
Sourcepub fn new(
data: Vec<T>,
indices: Vec<usize>,
indptr: Vec<usize>,
shape: (usize, usize),
block_size: (usize, usize),
) -> SparseResult<Self>
pub fn new( data: Vec<T>, indices: Vec<usize>, indptr: Vec<usize>, shape: (usize, usize), block_size: (usize, usize), ) -> SparseResult<Self>
Create a BSCMatrix from pre-built flat data.
§Arguments
data: flat block data, length must equalindices.len() * r * c.indices: block-row indices.indptr: column pointer, lengthblock_cols + 1.shape:(nrows, ncols)of the full matrix.block_size:(r, c)block dimensions.
Sourcepub fn zeros(
shape: (usize, usize),
block_size: (usize, usize),
) -> SparseResult<Self>
pub fn zeros( shape: (usize, usize), block_size: (usize, usize), ) -> SparseResult<Self>
Create an empty BSCMatrix (all-zero) of the given shape and block size.
Sourcepub fn from_bsr(bsr: &BSRMatrix<T>) -> SparseResult<Self>
pub fn from_bsr(bsr: &BSRMatrix<T>) -> SparseResult<Self>
Convert a BSRMatrix to BSCMatrix (essentially a block-level transpose and re-index).
The resulting BSCMatrix represents the same matrix but stored column-major.
Sourcepub fn from_dense(
dense: &[T],
nrows: usize,
ncols: usize,
block_size: (usize, usize),
) -> SparseResult<Self>
pub fn from_dense( dense: &[T], nrows: usize, ncols: usize, block_size: (usize, usize), ) -> SparseResult<Self>
Build a BSCMatrix from a row-major dense slice.
Sourcepub fn to_dense(&self) -> Vec<T>
pub fn to_dense(&self) -> Vec<T>
Convert the BSCMatrix to a row-major dense vector (nrows × ncols).
Sourcepub fn to_bsr(&self) -> SparseResult<BSRMatrix<T>>
pub fn to_bsr(&self) -> SparseResult<BSRMatrix<T>>
Convert to a BSRMatrix (re-index as row-based).
Sourcepub fn spmv(&self, x: &[T]) -> SparseResult<Vec<T>>
pub fn spmv(&self, x: &[T]) -> SparseResult<Vec<T>>
Sparse matrix-vector product: y = A * x.
Iterates over block-columns and scatters partial sums back to y.
Sourcepub fn transpose_to_bsr(&self) -> SparseResult<BSRMatrix<T>>
pub fn transpose_to_bsr(&self) -> SparseResult<BSRMatrix<T>>
Compute the transpose as a BSRMatrix with swapped block_size.
Sourcepub fn nnz_blocks(&self) -> usize
pub fn nnz_blocks(&self) -> usize
Return the number of non-zero blocks.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for BSCMatrix<T>
impl<T> RefUnwindSafe for BSCMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for BSCMatrix<T>where
T: Send,
impl<T> Sync for BSCMatrix<T>where
T: Sync,
impl<T> Unpin for BSCMatrix<T>where
T: Unpin,
impl<T> UnsafeUnpin for BSCMatrix<T>
impl<T> UnwindSafe for BSCMatrix<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