pub struct DiagonalBlockMatrix<T> { /* private fields */ }Expand description
A sparse matrix composed of block diagonal matrices.
This structure efficiently stores matrices that have a block diagonal structure, where non-zero elements are only present in square blocks along the main diagonal. This is commonly found in physical simulations, finite element methods, and systems with localized interactions.
§Format
The matrix stores all block data in three arrays:
values: All block elements stored contiguously in column-major orderblock_row_offsets: Starting row index for each blockblock_element_offsets: Starting index invaluesarray for each block
§Examples
use algebra_sparse::DiagonalBlockMatrix;
// Create a block diagonal matrix with blocks of size 2 and 3
// 2x2 block [1 2; 3 4] stored as [1, 3, 2, 4] in column-major
// 3x3 block [5 6 7; 8 9 10; 11 12 13] stored as [5, 8, 11, 6, 9, 12, 7, 10, 13]
let block_values = vec![1.0, 3.0, 2.0, 4.0, // 2x2 block
5.0, 8.0, 11.0, 6.0, 9.0, 12.0, 7.0, 10.0, 13.0]; // 3x3 block
let block_sizes = [2, 3];
let matrix = DiagonalBlockMatrix::from_block_values(block_values, &block_sizes);
println!("Matrix shape: {}x{}", matrix.nrows(), matrix.ncols());Implementations§
Source§impl<T> DiagonalBlockMatrix<T>
impl<T> DiagonalBlockMatrix<T>
Sourcepub fn from_block_values(values: Vec<T>, block_sizes: &[usize]) -> Self
pub fn from_block_values(values: Vec<T>, block_sizes: &[usize]) -> Self
Creates a block diagonal matrix from block values and sizes.
§Arguments
values- All block elements stored contiguously in column-major orderblock_sizes- Size of each square block along the diagonal
§Examples
use algebra_sparse::DiagonalBlockMatrix;
// Create blocks: [1 2; 3 4] and [5 6 7; 8 9 10; 11 12 13]
// Stored in column-major order: [1, 3, 2, 4] for first block
let values = vec![1.0, 3.0, 2.0, 4.0, 5.0, 8.0, 11.0, 6.0, 9.0, 12.0, 7.0, 10.0, 13.0];
let block_sizes = [2, 3]; // 2x2 block and 3x3 block
let matrix = DiagonalBlockMatrix::from_block_values(values, &block_sizes);pub fn nrows(&self) -> usize
pub fn ncols(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DiagonalBlockMatrix<T>
impl<T> RefUnwindSafe for DiagonalBlockMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for DiagonalBlockMatrix<T>where
T: Send,
impl<T> Sync for DiagonalBlockMatrix<T>where
T: Sync,
impl<T> Unpin for DiagonalBlockMatrix<T>where
T: Unpin,
impl<T> UnwindSafe for DiagonalBlockMatrix<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
Mutably borrows from an owned value. Read more
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.