|
gtsam
|
This class stores a dense matrix and allows it to be accessed as a collection of blocks.
When constructed, the caller must provide the dimensions of the blocks.
The block structure is symmetric, but the underlying matrix does not necessarily need to be.
This class also has a parameter that can be changed after construction to change the apparent matrix view. firstBlock() determines the block that appears to have index 0 for all operations (except re-setting firstBlock()).
Public Member Functions | |
| SymmetricBlockMatrix () | |
| Construct from an empty matrix (asserts that the matrix is empty). | |
| template<typename CONTAINER> | |
| SymmetricBlockMatrix (const CONTAINER &dimensions, bool appendOneDimension=false) | |
| Construct from a container of the sizes of each block. | |
| template<typename ITERATOR> | |
| SymmetricBlockMatrix (ITERATOR firstBlockDim, ITERATOR lastBlockDim, bool appendOneDimension=false) | |
| Construct from iterator over the sizes of each vertical block. | |
| template<typename CONTAINER> | |
| SymmetricBlockMatrix (const CONTAINER &dimensions, const Matrix &matrix, bool appendOneDimension=false) | |
| Construct from a container of the sizes of each vertical block and a pre-prepared matrix. | |
| DenseIndex | rows () const |
| Row size. | |
| DenseIndex | cols () const |
| Column size. | |
| DenseIndex | nBlocks () const |
| Block count. | |
| DenseIndex | getDim (DenseIndex block) const |
| Number of dimensions for variable on this diagonal block. | |
| DenseIndex | blockScalarOffset (DenseIndex block) const |
| Return the scalar offset of a block in the underlying matrix. | |
| DenseIndex & | blockStart () |
| Retrieve or modify the first logical block, i.e. | |
| DenseIndex | blockStart () const |
| Retrieve the first logical block, i.e. | |
| void | choleskyPartial (DenseIndex nFrontals) |
| Given the augmented Hessian [A1'A1 A1'A2 A1'b A2'A1 A2'A2 A2'b b'A1 b'A2 b'b] on x1 and x2, does partial Cholesky in-place to obtain [R Sd;0 L] such that R'R = A1'A1 R'Sd = [A1'A2 A1'b] L'L is the augmented Hessian on the the separator x2 R and Sd can be interpreted as a GaussianConditional |R*x1. | |
| VerticalBlockMatrix | split (DenseIndex nFrontals) |
| After partial Cholesky, we can optionally split off R and Sd, to be interpreted as a GaussianConditional |R*x1 + S*x2 - d]^2. | |
| void | split (DenseIndex nFrontals, VerticalBlockMatrix *RSd) |
| I n-place version of split. | |
Block getter methods. | |
| Matrix | block (DenseIndex I, DenseIndex J) const |
| Get a copy of a block (anywhere in the matrix). | |
| constBlock | blockView (DenseIndex I, DenseIndex J) const |
| Get a block view (anywhere in the matrix) without allocating a copy. | |
| Eigen::SelfAdjointView< Block, Eigen::Upper > | diagonalBlock (DenseIndex J) |
| Return the J'th diagonal block as a self adjoint view. | |
| Eigen::SelfAdjointView< constBlock, Eigen::Upper > | diagonalBlock (DenseIndex J) const |
| Return the J'th diagonal block as a self adjoint view. | |
| Vector | diagonal (DenseIndex J) const |
| Get the diagonal of the J'th diagonal block. | |
| constBlock | aboveDiagonalBlock (DenseIndex I, DenseIndex J) const |
| Get block above the diagonal (I, J). | |
| Eigen::SelfAdjointView< constBlock, Eigen::Upper > | selfadjointView (DenseIndex I, DenseIndex J) const |
| Return the square sub-matrix that contains blocks(i:j, i:j). | |
| Eigen::TriangularView< constBlock, Eigen::Upper > | triangularView (DenseIndex I, DenseIndex J) const |
| Return the square sub-matrix that contains blocks(i:j, i:j) as a triangular view. | |
| constBlock | aboveDiagonalRange (DenseIndex i_startBlock, DenseIndex i_endBlock, DenseIndex j_startBlock, DenseIndex j_endBlock) const |
| Get a range [i,j) from the matrix. Indices are in block units. | |
| Block | aboveDiagonalRange (DenseIndex i_startBlock, DenseIndex i_endBlock, DenseIndex j_startBlock, DenseIndex j_endBlock) |
| Get a range [i,j) from the matrix. Indices are in block units. | |
Block setter methods. | |
| template<typename XprType> | |
| void | setDiagonalBlock (DenseIndex I, const XprType &xpr) |
| Set a diagonal block. | |
| template<typename XprType> | |
| void | setOffDiagonalBlock (DenseIndex I, DenseIndex J, const XprType &xpr) |
| Set an off-diagonal block. | |
| template<typename XprType> | |
| void | updateDiagonalBlock (DenseIndex I, const XprType &xpr) |
| Increment the diagonal block by the values in xpr. | |
| template<typename XprType> | |
| void | updateDiagonalBlockAt (DenseIndex scalarOffset, const XprType &xpr) |
| Increment a diagonal block using its cached scalar offset. | |
| template<int Dimension, typename XprType> | |
| void | updateFixedDiagonalBlockAt (DenseIndex scalarOffset, const XprType &xpr) |
| Increment a fixed-size diagonal block using its cached scalar offset. | |
| void | addToDiagonalBlock (DenseIndex I, const Vector &deltaDiag) |
| Add a vector to the diagonal entries of block I. | |
| void | addScaledIdentity (DenseIndex I, double lambda) |
| Add lambda * I to the diagonal block I. | |
| template<typename XprType> | |
| void | updateOffDiagonalBlock (DenseIndex I, DenseIndex J, const XprType &xpr) |
| Update an off diagonal block. | |
| template<typename XprType> | |
| void | updateOffDiagonalBlockAt (DenseIndex rowOffset, DenseIndex colOffset, const XprType &xpr) |
| Increment an upper off-diagonal block using cached scalar offsets. | |
| template<int Rows, int Cols, typename XprType> | |
| void | updateFixedOffDiagonalBlockAt (DenseIndex rowOffset, DenseIndex colOffset, const XprType &xpr) |
| Increment a fixed-size upper block using cached scalar offsets. | |
| void | updateFromMappedBlocks (const SymmetricBlockMatrix &other, const std::vector< DenseIndex > &blockIndices) |
| Update this matrix with blocks from another block matrix using a mapping. | |
| void | updateFromMappedBlocks (const SymmetricBlockMatrix &other, const std::vector< DenseIndex > &blockIndices, const std::vector< DenseIndex > &scalarOffsets) |
| Update mapped blocks using cached scalar offsets in this matrix. | |
| void | updateFromMappedBlocks (const SymmetricBlockMatrix &other, DenseIndex sourceBlockStart, const std::vector< DenseIndex > &blockIndices, const std::vector< DenseIndex > &scalarOffsets) |
| Update mapped blocks from an explicit source-block range. | |
| void | updateFromMappedBlockColumn (const SymmetricBlockMatrix &other, DenseIndex sourceBlockStart, DenseIndex ownedSourceBlock, const std::vector< DenseIndex > &blockIndices, const std::vector< DenseIndex > &scalarOffsets, bool ownLastCrossBlock=false) |
| Update one mapped destination column from an explicit source range. | |
| void | updateFromOuterProductBlocks (const VerticalBlockMatrix &other, const std::vector< DenseIndex > &blockIndices, double alpha=1.0) |
| Update this matrix with scaled blockwise outer products from a vertical block matrix. | |
| void | updateFromOuterProductBlocks (const VerticalBlockMatrix &other, DenseIndex sourceRowBegin, DenseIndex sourceRowEnd, DenseIndex sourceBlockStart, const std::vector< DenseIndex > &blockIndices, const std::vector< DenseIndex > &scalarOffsets, double alpha=1.0) |
| Update with mapped blockwise outer products from explicit source rows and blocks, without changing other's active view. | |
| void | addUpperTriangular (const SymmetricBlockMatrix &other) |
| Add the upper-triangular part of another symmetric block matrix. | |
Accessing the full matrix. | |
| Eigen::SelfAdjointView< Block, Eigen::Upper > | selfadjointView () |
| Get self adjoint view. | |
| Eigen::SelfAdjointView< constBlock, Eigen::Upper > | selfadjointView () const |
| Get self adjoint view. | |
| template<typename XprType> | |
| void | setFullMatrix (const XprType &xpr) |
| Set the entire active matrix. | |
| void | setZero () |
| Set the entire active matrix zero. | |
| void | setAllZero () |
| Set entire matrix zero. | |
| void | setZeroColumns (DenseIndex beginCol, DenseIndex endCol) |
| Set the block columns between beginCol (inclusive) and endCol (exclusive) to zero. | |
| void | negate () |
| Negate the entire active matrix. | |
| void | invertInPlace () |
| Invert the entire active matrix in place. | |
Static Public Member Functions | |
| static SymmetricBlockMatrix | LikeActiveViewOf (const SymmetricBlockMatrix &other) |
| Copy the block structure, but do not copy the matrix data. | |
| static SymmetricBlockMatrix | LikeActiveViewOf (const VerticalBlockMatrix &other) |
| Copy the block structure, but do not copy the matrix data. | |
Public Types | |
| typedef SymmetricBlockMatrix | This |
| typedef Eigen::Block< Matrix > | Block |
| typedef Eigen::Block< const Matrix > | constBlock |
Protected Member Functions | |
| DenseIndex | nOffsets () const |
| Number of offsets in the full matrix. | |
| DenseIndex | nActualBlocks () const |
| Number of actual blocks in the full matrix. | |
| DenseIndex | offset (DenseIndex block) const |
| Get an offset for a block index (in the active view). | |
| constBlock | block_ (DenseIndex iBlock, DenseIndex jBlock, DenseIndex blockRows=1, DenseIndex blockCols=1) const |
| Get an arbitrary block from the matrix. Indices are in block units. | |
| Block | block_ (DenseIndex iBlock, DenseIndex jBlock, DenseIndex blockRows=1, DenseIndex blockCols=1) |
| Get an arbitrary block from the matrix. Indices are in block units. | |
| constBlock | full () const |
| Get the full matrix as a block. | |
| Block | full () |
| Get the full matrix as a block. | |
| std::array< DenseIndex, 4 > | calcIndices (DenseIndex iBlock, DenseIndex jBlock, DenseIndex blockRows, DenseIndex blockCols) const |
| Compute the indices into the underlying matrix for a given block. | |
| void | assertInvariants () const |
| template<typename ITERATOR> | |
| void | fillOffsets (ITERATOR firstBlockDim, ITERATOR lastBlockDim, bool appendOneDimension) |
Protected Attributes | |
| Matrix | matrix_ |
| The full matrix. | |
| FastVector< DenseIndex > | variableColOffsets_ |
| the starting columns of each block (0-based) | |
| DenseIndex | blockStart_ |
| Changes apparent matrix view, see main class comment. | |
Friends | |
| class | VerticalBlockMatrix |
| class | internal::CompactLeafSchurKernel |
| template<typename SymmetricBlockMatrixType> | |
| class | SymmetricBlockMatrixBlockExpr |
| Matrix gtsam::SymmetricBlockMatrix::block | ( | DenseIndex | I, |
| DenseIndex | J ) const |
Get a copy of a block (anywhere in the matrix).
This method makes a copy - use the methods below if performance is critical.
|
inline |
Retrieve or modify the first logical block, i.e.
the block referenced by block index 0. Blocks before it will be inaccessible, except by accessing the underlying matrix using matrix().
|
inline |
Retrieve the first logical block, i.e.
the block referenced by block index
|
inline |
Get a block view (anywhere in the matrix) without allocating a copy.
This method returns a const reference to the block for efficient read access.
| I | The row block index. |
| J | The column block index. |
| void gtsam::SymmetricBlockMatrix::choleskyPartial | ( | DenseIndex | nFrontals | ) |
Given the augmented Hessian [A1'A1 A1'A2 A1'b A2'A1 A2'A2 A2'b b'A1 b'A2 b'b] on x1 and x2, does partial Cholesky in-place to obtain [R Sd;0 L] such that R'R = A1'A1 R'Sd = [A1'A2 A1'b] L'L is the augmented Hessian on the the separator x2 R and Sd can be interpreted as a GaussianConditional |R*x1.
|
static |
Copy the block structure, but do not copy the matrix data.
If blockStart() has been modified, this copies the structure of the corresponding matrix view. In the destination SymmetricBlockMatrix, blockStart() will be 0.
|
static |
Copy the block structure, but do not copy the matrix data.
If blockStart() has been modified, this copies the structure of the corresponding matrix view. In the destination SymmetricBlockMatrix, blockStart() will be 0.
|
inline |
Set a diagonal block.
Only the upper triangular portion of xpr is evaluated.
|
inline |
Set the entire active matrix.
Only reads the upper triangular part of xpr.
|
inline |
Set an off-diagonal block.
Only the upper triangular portion of xpr is evaluated.
| VerticalBlockMatrix gtsam::SymmetricBlockMatrix::split | ( | DenseIndex | nFrontals | ) |
After partial Cholesky, we can optionally split off R and Sd, to be interpreted as a GaussianConditional |R*x1 + S*x2 - d]^2.
We leave the symmetric lower block L in place, and adjust block_start so now *this refers to it.
|
inline |
Increment the diagonal block by the values in xpr.
Only reads the upper triangular part of xpr.
| void gtsam::SymmetricBlockMatrix::updateFromMappedBlockColumn | ( | const SymmetricBlockMatrix & | other, |
| DenseIndex | sourceBlockStart, | ||
| DenseIndex | ownedSourceBlock, | ||
| const std::vector< DenseIndex > & | blockIndices, | ||
| const std::vector< DenseIndex > & | scalarOffsets, | ||
| bool | ownLastCrossBlock = false ) |
Update one mapped destination column from an explicit source range.
The source block selected by ownedSourceBlock owns all stored blocks in its mapped physical column. When ownLastCrossBlock is true, it also owns its cross block with the last mapped block; the last diagonal is omitted so callers can reduce it separately.
| void gtsam::SymmetricBlockMatrix::updateFromMappedBlocks | ( | const SymmetricBlockMatrix & | other, |
| const std::vector< DenseIndex > & | blockIndices ) |
Update this matrix with blocks from another block matrix using a mapping.
Entries with index -1 are skipped.
| void gtsam::SymmetricBlockMatrix::updateFromMappedBlocks | ( | const SymmetricBlockMatrix & | other, |
| DenseIndex | sourceBlockStart, | ||
| const std::vector< DenseIndex > & | blockIndices, | ||
| const std::vector< DenseIndex > & | scalarOffsets ) |
Update mapped blocks from an explicit source-block range.
This overload does not modify either matrix's active view. blockIndices maps source blocks beginning at sourceBlockStart; entries with index -1 are skipped. scalarOffsets caches their scalar destinations.
| void gtsam::SymmetricBlockMatrix::updateFromOuterProductBlocks | ( | const VerticalBlockMatrix & | other, |
| const std::vector< DenseIndex > & | blockIndices, | ||
| double | alpha = 1.0 ) |
Update this matrix with scaled blockwise outer products from a vertical block matrix.
Adds alpha * S_i^T S_j into block (I,J), using a block mapping; entries with index -1 are skipped. The range to use is controlled by other.firstBlock().
|
inline |
Update an off diagonal block.
NOTE(emmett): This assumes noalias().