![]() |
Eigen
5.0.1
|
#include <Eigen/src/SparseCore/BlockSparseMatrix.h>
A sparse matrix whose stored nonzeros are fixed-size dense blocks.
Each nonzero entry is a BlockRows x BlockCols dense matrix. The block sparsity pattern is stored in block-level compressed-column (ColMajor) or compressed-row (RowMajor) format.
| Scalar_ | Numeric scalar type. |
| Options_ | ColMajor (0) or RowMajor. Controls both the outer iteration direction over blocks and the storage layout within each block. Note: vector-shaped blocks must use a compatible order — BlockCols_=1 requires ColMajor, BlockRows_=1 requires RowMajor. |
| BlockRows_ | Rows per block; must be a fixed positive integer. |
| BlockCols_ | Columns per block; must be a fixed positive integer. |
| StorageIndex_ | Signed integer type for internal index arrays (default: int). |
Populate the matrix via setFromTriplets(), passing an iterator range of BlockTriplet objects in block coordinates. Triplets with the same (blockRow, blockCol) are summed.
Addition, subtraction, and matrix product are supported between compatible BlockSparseMatrix instances. Scalar multiplication is also available.
The matrix product C = A * B requires A.BlockCols == B.BlockRows (enforced at compile time by the template constraint) and A.blockCols() == B.blockRows() (checked at runtime). The result has block type Matrix<Scalar,A.BlockRows,B.BlockCols>.
toSparse() converts to a standard SparseMatrix with element-level sparsity. fromSparse() reconstructs a BlockSparseMatrix from an element-level SparseMatrix whose dimensions are divisible by BlockRows and BlockCols. An implicit conversion operator to SparseMatrix is also provided.
Inheritance diagram for Eigen::BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, StorageIndex_ >:Classes | |
| class | InnerIterator |
| Iterates over stored blocks in outer vector outer. More... | |
Public Member Functions | |
| BlockSparseMatrix< Scalar_, Options_, BlockCols_, BlockRows_, StorageIndex_ > | adjoint () const |
| Index | allocatedBlocks () const |
| Index | blockCols () const |
| Index | blockInnerSize () const |
| Index | blockOuterSize () const |
| BlockMap | blockRef (Index k) |
| ConstBlockMap | blockRef (Index k) const |
| Index | blockRows () const |
| BlockSparseMatrix ()=default | |
| BlockSparseMatrix (Index blockRows, Index blockCols) | |
| Scalar | coeff (Index row, Index col) const |
| Index | cols () const noexcept |
| template<typename ScalarFunc> | |
| BlockSparseMatrix | conjunctionExpr (const BlockSparseMatrix &other, ScalarFunc func) const |
| BlockSparseMatrix | cwiseProduct (const BlockSparseMatrix &other) const |
| Matrix< Scalar, Dynamic, 1 > | diagonal () const |
| template<typename ScalarFunc> | |
| BlockSparseMatrix | disjunctionExpr (const BlockSparseMatrix &other, ScalarFunc func) const |
| Index | innerSize () const |
| Index | nonZeroBlocks () const |
| Index | nonZeros () const |
| operator SparseMatrix< Scalar_, Options_, StorageIndex_ > () const | |
| template<int RhsBlockCols> | |
| BlockSparseMatrix< Scalar_, Options_, BlockRows_, RhsBlockCols, StorageIndex_ > | operator* (const BlockSparseMatrix< Scalar_, Options_, BlockCols_, RhsBlockCols, StorageIndex_ > &rhs) const |
| template<typename OtherDerived> | |
| Product< BlockSparseMatrix, OtherDerived, AliasFreeProduct > | operator* (const MatrixBase< OtherDerived > &rhs) const |
| BlockSparseMatrix | operator* (const Scalar &s) const |
| BlockSparseMatrix | operator+ (const BlockSparseMatrix &other) const |
| BlockSparseMatrix | operator- () const |
| BlockSparseMatrix | operator- (const BlockSparseMatrix &other) const |
| Index | outerSize () const |
| void | reserve (Index n) |
| void | resize (Index blockRows, Index blockCols) |
| Index | rows () const noexcept |
| template<int UpLo, bool DiagIsSelfAdjoint = false> | |
| BlockSparseSelfAdjointView< BlockSparseMatrix, UpLo, DiagIsSelfAdjoint > | selfadjointView () const |
| void | setFromOuterInner (Index blockRows, Index blockCols, Index nnzBlocks, const StorageIndex_ *outerPtr, const StorageIndex_ *innerPtr) |
| template<typename InputIterator> | |
| void | setFromTriplets (InputIterator begin, InputIterator end) |
| void | setIdentity () |
| void | setZero () |
| void | squeeze () |
| SparseMatrix< Scalar, Options_, StorageIndex_ > | toSparse () const |
| BlockSparseMatrix< Scalar_, Options_, BlockCols_, BlockRows_, StorageIndex_ > | transpose () const |
| template<int Mode, bool DiagIsTriangular = false> | |
| BlockSparseTriangularView< BlockSparseMatrix, Mode, DiagIsTriangular > | triangularView () const |
| template<typename ScalarFunc> | |
| BlockSparseMatrix | unaryExpr (ScalarFunc func) const |
Public Member Functions inherited from Eigen::EigenBase< BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, int > > | |
| constexpr Index | cols () const noexcept |
| constexpr BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, int > & | derived () |
| constexpr const BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, int > & | derived () const |
| constexpr Index | rows () const noexcept |
| constexpr Index | size () const noexcept |
Static Public Member Functions | |
| static BlockSparseMatrix | fromSparse (const SparseMatrix< Scalar_, Options_, StorageIndex_ > &sp) |
Additional Inherited Members | |
Public Types inherited from Eigen::EigenBase< BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, int > > | |
| using | Index |
| The interface type of indices. | |
|
default |
Default constructor; creates a 0×0 matrix.
|
inline |
Construct a zero matrix with the given number of block-rows and block-columns.
| BlockSparseMatrix< Scalar_, Options_, BlockCols_, BlockRows_, StorageIndex_ > Eigen::BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, StorageIndex_ >::adjoint | ( | ) | const |
Returns a new BSM whose block dimensions are swapped and each stored block is conjugate-transposed (adjoint). Identical to transpose() for real scalars.
|
inline |
Number of blocks for which storage is currently allocated (capacity).
|
inline |
Number of block-columns.
|
inline |
Inner block dimension (block-rows for ColMajor, block-cols for RowMajor).
|
inline |
Outer block dimension (block-cols for ColMajor, block-rows for RowMajor).
|
inline |
Mutable Map to the k-th stored block.
|
inline |
Read-only Map to the k-th stored block (block storage follows Options_).
|
inline |
Number of block-rows.
|
inline |
Read element (row, col); returns 0 if no block covers that position.
|
inlinenoexcept |
Total number of element columns.
|
inline |
Applies a scalar binary functor with intersection sparsity: only block positions present in both matrices contribute; func is called as func(Scalar a, Scalar b).
|
inline |
Element-wise product. Only blocks present in both operands contribute to the result.
|
inline |
Extract the main scalar diagonal as a dense vector.
Iterates outer slices once and binary-searches for the diagonal block in each slice, then copies the relevant entries from that block — one search per outer slice (square blocks) or per unique inner-block boundary (non-square blocks), vs. one search per scalar element for the coeff-by-coeff approach.
|
inline |
Applies a scalar binary functor with union sparsity.
func must provide three members:
|
static |
Construct a BlockSparseMatrix from an element-level SparseMatrix.
sp.rows() % BlockRows == 0 and sp.cols() % BlockCols == 0.Each scalar entry sp(i,j) is placed into position (iBlockRows, jBlockCols) of block (i/BlockRows, j/BlockCols). Multiple entries mapping to the same element of the same block are accumulated with +=.
|
inline |
|
inline |
Number of stored (structurally non-zero) blocks.
|
inline |
Total number of stored scalar coefficients (= nonZeroBlocks() * BlockRows * BlockCols).
|
inline |
Implicit conversion to SparseMatrix.
| BlockSparseMatrix< Scalar_, Options_, BlockRows_, RhsBlockCols, StorageIndex_ > Eigen::BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, StorageIndex_ >::operator* | ( | const BlockSparseMatrix< Scalar_, Options_, BlockCols_, RhsBlockCols, StorageIndex_ > & | rhs | ) | const |
Block-sparse matrix product.
| RhsBlockCols | Block-column count of the right-hand side. |
The left-hand side has block type Matrix<Scalar,BlockRows,BlockCols> and the right-hand side must have block type Matrix<Scalar,BlockCols,RhsBlockCols> (enforced by the template parameter). The result has block type Matrix<Scalar,BlockRows,RhsBlockCols>.
this->blockCols() == rhs.blockRows() (checked at runtime).
|
inline |
Block-sparse times dense matrix (or vector) product.
Returns a lazy Product<> expression evaluated via generic_product_impl. This enables fused accumulation:
this->cols() == rhs.rows(). AliasFreeProduct, so assignment goes directly through generic_product_impl::evalTo with no aliasing temporary. x = A * x silently corrupts; use an explicit temporary if needed.
|
inline |
Scalar multiplication (returns a new matrix).
|
inline |
Element-wise addition. Both matrices must have the same block dimensions.
|
inline |
Unary negation.
|
inline |
Element-wise subtraction.
|
inline |
|
inline |
Pre-allocate storage for at least n blocks without changing the logical sparsity pattern. Existing block data is preserved up to min(n, nonZeroBlocks()).
|
inline |
Resize to blockRows × blockCols blocks and set the logical nnz to zero. Allocated block storage is retained; call squeeze() to release it.
|
inlinenoexcept |
Total number of element rows.
|
inline |
Returns a block-level self-adjoint view.
Only the triangle selected by UpLo is read; the opposite triangle is reconstructed on-the-fly as the adjoint of each stored off-diagonal block.
| UpLo | Eigen::Upper or Eigen::Lower. |
| DiagIsSelfAdjoint | Set to true when every diagonal block is itself Hermitian and both triangles are explicitly stored. The dense sub-product then uses a plain product rather than selfadjointView, which is more efficient for the small fixed-size blocks typical here. When false (the default), only the UpLo triangle of each diagonal block is assumed valid; selfadjointView<UpLo>() reconstructs the full block. |
|
inline |
Initialize the block structure directly from compressed outer/inner index arrays, zero-initializing all block values.
outerPtr has size blockCols+1 (ColMajor) or blockRows+1 (RowMajor). innerPtr has size nnzBlocks.
| void Eigen::BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, StorageIndex_ >::setFromTriplets | ( | InputIterator | begin, |
| InputIterator | end ) |
Fill the matrix from an iterator range of BlockTriplet objects.
Triplet coordinates are in block space. Triplets with the same (blockRow, blockCol) pair are summed (their block values are added). The input range may be in any order.
| InputIterator | Must dereference to a type with row(), col(), and value() members, matching BlockTriplet's interface. |
|
inline |
Fill the matrix with the block identity: the min(blockRows,blockCols) diagonal blocks are set to the B×B identity; all other blocks are absent.
|
inline |
Clear all stored blocks (logical nnz → 0) while keeping dimensions and allocated storage.
|
inline |
Release any excess allocated block storage so that allocatedBlocks() == nonZeroBlocks().
| SparseMatrix< Scalar_, Options_, StorageIndex_ > Eigen::BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, StorageIndex_ >::toSparse | ( | ) | const |
Convert to a SparseMatrix with scalar nonzeros.
Each stored block of size BlockRows×BlockCols expands into up to BlockRows*BlockCols scalar nonzeros. The resulting SparseMatrix has the same storage order as *this.
| BlockSparseMatrix< Scalar_, Options_, BlockCols_, BlockRows_, StorageIndex_ > Eigen::BlockSparseMatrix< Scalar_, Options_, BlockRows_, BlockCols_, StorageIndex_ >::transpose | ( | ) | const |
Returns a new BSM whose block dimensions are swapped (BlockRows ↔ BlockCols) and each stored block is transposed. Storage order is preserved.
|
inline |
Returns a block-level triangular view.
| Mode | Eigen::Upper or Eigen::Lower. |
| DiagIsTriangular | When false (default), diagonal blocks are treated as triangular regardless of what is stored in the unused triangle — products use triangularView on the block and eval() explicitly zeros the unused triangle. When true, the caller guarantees that the unused triangle of every diagonal block is already zero; products then use a full vectorised GEMV (faster, no zeroing). |
|
inline |
Applies a scalar unary functor to every stored nonzero, preserving the sparsity pattern.