MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::mat::block_diagonal2D< Value > Class Template Reference

Block diagonal matrix – stores vector of dense2D blocks. More...

#include <block_diagonal2D.hpp>

Public Types

using value_type = Value
using size_type = std::size_t
using const_reference = Value
using reference = Value

Public Member Functions

 block_diagonal2D ()=default
 block_diagonal2D (std::vector< dense2D< Value > > blocks)
 Construct from a vector of dense blocks.
 block_diagonal2D (std::initializer_list< dense2D< Value > > blocks)
 Construct from initializer list of dense blocks.
void add_block (dense2D< Value > block)
 Add a block to the diagonal.
value_type operator() (size_type r, size_type c) const
 Element (r, c).
size_type num_rows () const
size_type num_cols () const
size_type size () const
size_type num_blocks () const
 Number of diagonal blocks.
const dense2D< Value > & block (size_type k) const
 Access the k-th block.
dense2D< Value > block (size_type k)
 Write access to the k-th block's elements: a dense2D over the block's storage, in the block's shape.
void set_block (size_type k, dense2D< Value > block)
 Replace the k-th block, of any shape, and update the offsets.

Detailed Description

template<typename Value = double>
class mtl::mat::block_diagonal2D< Value >

Block diagonal matrix – stores vector of dense2D blocks.

Total dimension is sum of block dimensions.

Member Typedef Documentation

◆ const_reference

template<typename Value = double>
using mtl::mat::block_diagonal2D< Value >::const_reference = Value

◆ reference

template<typename Value = double>
using mtl::mat::block_diagonal2D< Value >::reference = Value

◆ size_type

template<typename Value = double>
using mtl::mat::block_diagonal2D< Value >::size_type = std::size_t

◆ value_type

template<typename Value = double>
using mtl::mat::block_diagonal2D< Value >::value_type = Value

Constructor & Destructor Documentation

◆ block_diagonal2D() [1/3]

template<typename Value = double>
mtl::mat::block_diagonal2D< Value >::block_diagonal2D ( )
default

◆ block_diagonal2D() [2/3]

template<typename Value = double>
mtl::mat::block_diagonal2D< Value >::block_diagonal2D ( std::vector< dense2D< Value > > blocks)
inlineexplicit

Construct from a vector of dense blocks.

◆ block_diagonal2D() [3/3]

template<typename Value = double>
mtl::mat::block_diagonal2D< Value >::block_diagonal2D ( std::initializer_list< dense2D< Value > > blocks)
inline

Construct from initializer list of dense blocks.

Member Function Documentation

◆ add_block()

template<typename Value = double>
void mtl::mat::block_diagonal2D< Value >::add_block ( dense2D< Value > block)
inline

Add a block to the diagonal.

O(1): it appends the new block's offsets, where it recomputed all of them, O(n) per call (#826).

◆ block() [1/2]

template<typename Value = double>
dense2D< Value > mtl::mat::block_diagonal2D< Value >::block ( size_type k)
inline

Write access to the k-th block's elements: a dense2D over the block's storage, in the block's shape.

Writing its elements writes the block, and so does assigning to it: bd.block(k) = X copies X into the block (#829). It used to return the block itself, and change_dim on that left the offsets and the total shape stale (#826). The block keeps its shape whatever is done to the returned matrix:

  • copy- or expression-assigning a matrix with another element count throws std::domain_error; move-assigning one (a temporary, as in bd.block(k) = dense2D<Value>(3, 3)) is noexcept, so it aborts, in every build (#856);
  • change_dim to a different element count, an explicit resize, gives it storage of its own, detached from the block;
  • assigning, or change_dim, with the same count in another shape (2x2 to 1x4) keeps the block's storage under the new shape, so its writes still land in the block, in that layout. Don't reshape it; use set_block.

◆ block() [2/2]

template<typename Value = double>
const dense2D< Value > & mtl::mat::block_diagonal2D< Value >::block ( size_type k) const
inline

Access the k-th block.

◆ num_blocks()

template<typename Value = double>
size_type mtl::mat::block_diagonal2D< Value >::num_blocks ( ) const
inline

Number of diagonal blocks.

◆ num_cols()

template<typename Value = double>
size_type mtl::mat::block_diagonal2D< Value >::num_cols ( ) const
inline

◆ num_rows()

template<typename Value = double>
size_type mtl::mat::block_diagonal2D< Value >::num_rows ( ) const
inline

◆ operator()()

template<typename Value = double>
value_type mtl::mat::block_diagonal2D< Value >::operator() ( size_type r,
size_type c ) const
inline

Element (r, c).

The block holding row r is found by binary search over the row offsets: O(log blocks), where it scanned every block (#826). A block with no rows holds no element, so the last block starting at or before r is the only candidate.

◆ set_block()

template<typename Value = double>
void mtl::mat::block_diagonal2D< Value >::set_block ( size_type k,
dense2D< Value > block )
inline

Replace the k-th block, of any shape, and update the offsets.

◆ size()

template<typename Value = double>
size_type mtl::mat::block_diagonal2D< Value >::size ( ) const
inline

The documentation for this class was generated from the following file: