DiagonalBlockMatrix

Struct DiagonalBlockMatrix 

Source
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 order
  • block_row_offsets: Starting row index for each block
  • block_element_offsets: Starting index in values array 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>

Source

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 order
  • block_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);
Source

pub fn nrows(&self) -> usize

Source

pub fn ncols(&self) -> usize

Trait Implementations§

Source§

impl<'a, T> IntoView for &'a DiagonalBlockMatrix<T>

Source§

type View = DiagonalBlockMatrixView<'a, T>

The view type produced by this trait.
Source§

fn into_view(self) -> Self::View

Converts the type into an immutable view. Read more

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.