Skip to main content

BSCMatrix

Struct BSCMatrix 

Source
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: usize

Total number of matrix rows.

§ncols: usize

Total number of matrix columns.

§block_size: (usize, usize)

Block dimensions (rows per block, cols per block).

§block_rows: usize

Number of block-rows.

§block_cols: usize

Number 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>

Source

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 equal indices.len() * r * c.
  • indices: block-row indices.
  • indptr: column pointer, length block_cols + 1.
  • shape: (nrows, ncols) of the full matrix.
  • block_size: (r, c) block dimensions.
Source

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.

Source

pub fn from_bsr(bsr: &BSRMatrix<T>) -> SparseResult<Self>
where T: Add<Output = T> + Mul<Output = T>,

Convert a BSRMatrix to BSCMatrix (essentially a block-level transpose and re-index).

The resulting BSCMatrix represents the same matrix but stored column-major.

Source

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.

Source

pub fn to_dense(&self) -> Vec<T>

Convert the BSCMatrix to a row-major dense vector (nrows × ncols).

Source

pub fn to_bsr(&self) -> SparseResult<BSRMatrix<T>>
where T: Add<Output = T> + Mul<Output = T>,

Convert to a BSRMatrix (re-index as row-based).

Source

pub fn spmv(&self, x: &[T]) -> SparseResult<Vec<T>>
where T: Add<Output = T> + Mul<Output = T>,

Sparse matrix-vector product: y = A * x.

Iterates over block-columns and scatters partial sums back to y.

Source

pub fn transpose_to_bsr(&self) -> SparseResult<BSRMatrix<T>>
where T: Add<Output = T> + Mul<Output = T>,

Compute the transpose as a BSRMatrix with swapped block_size.

Source

pub fn nnz_blocks(&self) -> usize

Return the number of non-zero blocks.

Source

pub fn nnz(&self) -> usize

Return the total number of stored scalar values.

Source

pub fn shape(&self) -> (usize, usize)

Return (nrows, ncols).

Source

pub fn get(&self, row: usize, col: usize) -> T

Get the scalar value at position (row, col).

Trait Implementations§

Source§

impl<T: Clone> Clone for BSCMatrix<T>

Source§

fn clone(&self) -> BSCMatrix<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for BSCMatrix<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V