Skip to main content

BsrMatrix

Struct BsrMatrix 

Source
pub struct BsrMatrix { /* private fields */ }
Expand description

Block Sparse Row matrix.

A matrix of shape (block_rows * block_size) × (block_cols * block_size), where non-zero blocks are stored in CSR-of-blocks layout.

Implementations§

Source§

impl BsrMatrix

Source

pub fn new( block_rows: usize, block_cols: usize, block_size: usize, offsets: Vec<u32>, col_indices: Vec<u32>, values: Vec<f32>, ) -> Result<Self, SparseError>

Create a new BSR matrix.

§Arguments
  • block_rows, block_cols: number of block rows/columns
  • block_size: dimension of each square block
  • offsets: CSR-style row offsets for blocks
  • col_indices: block column indices
  • values: dense block data (row-major per block)
§Errors

Returns error if structure is invalid.

Source

pub fn from_dense( data: &[f32], rows: usize, cols: usize, block_size: usize, ) -> Self

Create BSR from a dense matrix.

Pads the matrix if dimensions aren’t divisible by block_size. Only stores blocks with at least one non-zero element.

Source

pub fn to_csr(&self) -> Result<CsrMatrix<f32>, SparseError>

Convert to CSR format.

§Errors

Returns error if the internal conversion produces invalid CSR.

Source

pub fn rows(&self) -> usize

Total matrix rows.

Source

pub fn cols(&self) -> usize

Total matrix columns.

Source

pub fn nnz_blocks(&self) -> usize

Number of non-zero blocks.

Source

pub fn block_size(&self) -> usize

Block size.

Trait Implementations§

Source§

impl Clone for BsrMatrix

Source§

fn clone(&self) -> BsrMatrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BsrMatrix

Source§

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

Formats the value using the given formatter. Read more
Source§

impl SparseOps for BsrMatrix

Source§

fn spmv( &self, alpha: f32, x: &[f32], beta: f32, y: &mut [f32], ) -> Result<(), SparseError>

Sparse matrix-vector multiply: y = α * A * x + β * y Read more
Source§

fn spmm( &self, alpha: f32, b: &[f32], b_cols: usize, beta: f32, c: &mut [f32], ) -> Result<(), SparseError>

Sparse matrix-dense matrix multiply: C = α * A * B + β * C Read more

Auto Trait Implementations§

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