23 #include <gtsam/dllexport.h> 24 #include <boost/serialization/nvp.hpp> 30 namespace serialization {
38 class VerticalBlockMatrix;
69 variableColOffsets_.push_back(0);
74 template<
typename CONTAINER>
78 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
79 matrix_.resize(variableColOffsets_.back(), variableColOffsets_.back());
84 template<
typename ITERATOR>
88 fillOffsets(firstBlockDim, lastBlockDim, appendOneDimension);
89 matrix_.resize(variableColOffsets_.back(), variableColOffsets_.back());
94 template<
typename CONTAINER>
98 matrix_.resize(matrix.rows(), matrix.cols());
100 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
101 if(matrix_.rows() != matrix_.cols())
102 throw std::invalid_argument(
"Requested to create a SymmetricBlockMatrix from a non-square matrix.");
103 if(variableColOffsets_.back() != matrix_.cols())
104 throw std::invalid_argument(
"Requested to create a SymmetricBlockMatrix with dimensions that do not sum to the total size of the provided matrix.");
119 DenseIndex rows()
const { assertInvariants();
return variableColOffsets_.back() - variableColOffsets_[blockStart_]; }
129 return calcIndices(block, block, 1, 1)[2];
151 return block_(J, J).diagonal();
164 return block_(I, I, J - I, J - I).selfadjointView<
Eigen::Upper>();
171 return block_(I, I, J - I, J - I).triangularView<
Eigen::Upper>();
179 assert(i_startBlock < j_startBlock);
180 assert(i_endBlock <= j_startBlock);
181 return block_(i_startBlock, j_startBlock, i_endBlock - i_startBlock,
182 j_endBlock - j_startBlock);
188 assert(i_startBlock < j_startBlock);
189 assert(i_endBlock <= j_startBlock);
190 return block_(i_startBlock, j_startBlock, i_endBlock - i_startBlock,
191 j_endBlock - j_startBlock);
199 template <
typename XprType>
201 block_(I, I).triangularView<
Eigen::Upper>() = xpr.template triangularView<Eigen::Upper>();
205 template <
typename XprType>
211 block_(J, I) = xpr.transpose();
216 template <
typename XprType>
220 auto dest = block_(I, I);
221 assert(dest.rows() == xpr.rows());
222 assert(dest.cols() == xpr.cols());
232 template <
typename XprType>
236 block_(I, J).noalias() += xpr;
238 block_(J, I).noalias() += xpr.transpose();
257 template <
typename XprType>
259 full().triangularView<
Eigen::Upper>() = xpr.template triangularView<Eigen::Upper>();
274 const auto identity = Matrix::Identity(
rows(),
rows());
316 return variableColOffsets_.size();
321 return nOffsets() - 1;
327 const DenseIndex actual_index = block + blockStart();
328 assert(actual_index < nOffsets());
329 return variableColOffsets_[actual_index];
335 const std::array<DenseIndex, 4> indices =
336 calcIndices(iBlock, jBlock, blockRows, blockCols);
337 return matrix_.block(indices[0], indices[1], indices[2], indices[3]);
343 const std::array<DenseIndex, 4> indices =
344 calcIndices(iBlock, jBlock, blockRows, blockCols);
345 return matrix_.block(indices[0], indices[1], indices[2], indices[3]);
350 return block_(0, 0, nBlocks(), nBlocks());
355 return block_(0, 0, nBlocks(), nBlocks());
362 assert(blockRows >= 0);
363 assert(blockCols >= 0);
370 return {{denseI, denseJ, denseRows, denseCols}};
375 assert(matrix_.rows() == matrix_.cols());
376 assert(matrix_.cols() == variableColOffsets_.back());
377 assert(blockStart_ < (
DenseIndex)variableColOffsets_.size());
380 template<
typename ITERATOR>
381 void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim,
bool appendOneDimension)
383 variableColOffsets_.resize((lastBlockDim-firstBlockDim) + 1 + (appendOneDimension ? 1 : 0));
384 variableColOffsets_[0] = 0;
386 for(ITERATOR
dim=firstBlockDim;
dim!=lastBlockDim; ++
dim) {
387 variableColOffsets_[j+1] = variableColOffsets_[
j] + *
dim;
390 if(appendOneDimension)
392 variableColOffsets_[j+1] = variableColOffsets_[
j] + 1;
398 template<
typename SymmetricBlockMatrixType>
friend class SymmetricBlockMatrixBlockExpr;
402 friend class boost::serialization::access;
403 template<
class ARCHIVE>
409 ar & BOOST_SERIALIZATION_NVP(matrix_);
410 ar & BOOST_SERIALIZATION_NVP(variableColOffsets_);
411 ar & BOOST_SERIALIZATION_NVP(blockStart_);
Eigen::SelfAdjointView< constBlock, Eigen::Upper > selfadjointView() const
Get self adjoint view.
DenseIndex offset(DenseIndex block) const
Get an offset for a block index (in the active view).
Typedefs for easier changing of types.
m m block(1, 0, 2, 2)<< 4
void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim, bool appendOneDimension)
void setOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
Set an off-diagonal block. Only the upper triangular portion of xpr is evaluated. ...
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
Eigen::Block< Matrix > Block
Block full()
Get the full matrix as a block.
Matrix matrix_
The full matrix.
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
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.
vector< size_t > dimensions(L.begin(), L.end())
DenseIndex blockStart() const
ptrdiff_t DenseIndex
The index type for Eigen objects.
SymmetricBlockMatrix(ITERATOR firstBlockDim, ITERATOR lastBlockDim, bool appendOneDimension=false)
Construct from iterator over the sizes of each vertical block.
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...
void invertInPlace()
Invert the entire active matrix in place.
void split(const G &g, const PredecessorMap< KEY > &tree, G &Ab1, G &Ab2)
void setDiagonalBlock(DenseIndex I, const XprType &xpr)
Set a diagonal block. Only the upper triangular portion of xpr is evaluated.
Eigen::SelfAdjointView< constBlock, Eigen::Upper > diagonalBlock(DenseIndex J) const
Return the J'th diagonal block as a self adjoint 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.
SymmetricBlockMatrix This
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.
void serialize(ARCHIVE &ar, const unsigned int)
Vector diagonal(DenseIndex J) const
Get the diagonal of the J'th diagonal block.
void negate()
Negate the entire active matrix.
void updateDiagonalBlock(DenseIndex I, const XprType &xpr)
Increment the diagonal block by the values in xpr. Only reads the upper triangular part of xpr...
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.
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
constBlock aboveDiagonalBlock(DenseIndex I, DenseIndex J) const
Get block above the diagonal (I, J).
JacobiRotation< float > 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. ...
Eigen::SelfAdjointView< Block, Eigen::Upper > selfadjointView()
Get self adjoint view.
bool choleskyPartial(Matrix &ABC, size_t nFrontal, size_t topleft)
void setFullMatrix(const XprType &xpr)
Set the entire active matrix. Only reads the upper triangular part of xpr.
A thin wrapper around std::vector that uses a custom allocator.
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
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.
Expression of a fixed-size or dynamic-size block.
DenseIndex nActualBlocks() const
Number of actual blocks in the full matrix.
void assertInvariants() const
void setZero()
Set the entire active matrix zero.
Eigen::Block< const Matrix > constBlock
DenseIndex cols() const
Column size.
Expression of a triangular part in a matrix.
Eigen::SelfAdjointView< constBlock, Eigen::Upper > selfadjointView(DenseIndex I, DenseIndex J) const
Return the square sub-matrix that contains blocks(i:j, i:j).
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
SymmetricBlockMatrix()
Construct from an empty matrix (asserts that the matrix is empty)
void updateOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
DenseIndex & blockStart()
Indicate Cholesky factorization failure.
DenseIndex getDim(DenseIndex block) const
Number of dimensions for variable on this diagonal block.
Eigen::SelfAdjointView< Block, Eigen::Upper > diagonalBlock(DenseIndex J)
Return the J'th diagonal block as a self adjoint view.
DenseIndex nOffsets() const
Number of offsets in the full matrix.
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
DenseIndex nBlocks() const
Block count.
SymmetricBlockMatrix(const CONTAINER &dimensions, bool appendOneDimension=false)
Construct from a container of the sizes of each block.
DenseIndex rows() const
Row size.