50 typedef Eigen::Block<Matrix> Block;
51 typedef Eigen::Block<const Matrix> constBlock;
82 : matrix_(std::move(other.matrix_)),
83 variableColOffsets_(std::move(other.variableColOffsets_)),
84 rowStart_(other.rowStart_),
85 rowEnd_(other.rowEnd_),
86 blockStart_(other.blockStart_) {
89 other.blockStart_ = 0;
93 VerticalBlockMatrix& operator=(VerticalBlockMatrix&& other)
noexcept {
95 matrix_ = std::move(other.matrix_);
96 variableColOffsets_ = std::move(other.variableColOffsets_);
97 rowStart_ = other.rowStart_;
98 rowEnd_ = other.rowEnd_;
99 blockStart_ = other.blockStart_;
103 other.blockStart_ = 0;
109 template <
typename CONTAINER>
111 bool appendOneDimension =
false)
116 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
123 template <
typename CONTAINER,
typename DERIVED>
125 const Eigen::MatrixBase<DERIVED>&
matrix,
126 bool appendOneDimension =
false)
132 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
134 throw std::invalid_argument(
135 "Requested to create a VerticalBlockMatrix with dimensions that do "
136 "not sum to the total columns of the provided matrix.");
141 template <
typename ITERATOR>
143 DenseIndex height,
bool appendOneDimension =
false)
145 (appendOneDimension ? 2 : 1)),
149 fillOffsets(firstBlockDim, lastBlockDim, appendOneDimension);
191 return range(block, block + 1);
199 if (startBlock != 0 || endBlock != 0) {
200 checkBlock(actualStartBlock);
210 DenseIndex actualStartBlock = startBlock + blockStart_;
211 DenseIndex actualEndBlock = endBlock + blockStart_;
212 if (startBlock != 0 || endBlock != 0) {
213 checkBlock(actualStartBlock);
214 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
216 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
217 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
218 return ((
const Matrix&)matrix_)
219 .block(rowStart_, startCol, this->rows(), rangeCols);
231 assert(beginRow >= 0 && beginRow <= endRow && endRow <=
matrix_.rows());
233 checkBlock(actualBlock);
237 return matrix_.block(beginRow, startCol, endRow - beginRow, blockCols);
251 checkBlock(actualBlock);
252 return variableColOffsets_[actualBlock];
285 void assertInvariants()
const {
286 assert(matrix_.cols() == variableColOffsets_.back());
287 assert(blockStart_ < (
DenseIndex)variableColOffsets_.size());
288 assert(rowStart_ <= matrix_.rows());
289 assert(rowEnd_ <= matrix_.rows());
290 assert(rowStart_ <= rowEnd_);
293 void checkBlock(DenseIndex block)
const {
294 static_cast<void>(block);
295 assert(matrix_.cols() == variableColOffsets_.back());
296 assert(block < (DenseIndex)variableColOffsets_.size() - 1);
297 assert(variableColOffsets_[block] < matrix_.cols() &&
298 variableColOffsets_[block + 1] <= matrix_.cols());
301 template <
typename ITERATOR>
302 void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim,
303 bool appendOneDimension) {
304 variableColOffsets_[0] = 0;
306 for (ITERATOR dim = firstBlockDim; dim != lastBlockDim; ++dim, ++j)
307 variableColOffsets_[j + 1] = variableColOffsets_[j] + *dim;
308 if (appendOneDimension)
309 variableColOffsets_[j + 1] = variableColOffsets_[j] + 1;
312 friend class SymmetricBlockMatrix;
315#if GTSAM_ENABLE_BOOST_SERIALIZATION
317 friend class boost::serialization::access;
318 template <
class ARCHIVE>
319 void serialize(ARCHIVE& ar,
const unsigned int ) {
320 ar& BOOST_SERIALIZATION_NVP(matrix_);
321 ar& BOOST_SERIALIZATION_NVP(variableColOffsets_);
322 ar& BOOST_SERIALIZATION_NVP(rowStart_);
323 ar& BOOST_SERIALIZATION_NVP(rowEnd_);
324 ar& BOOST_SERIALIZATION_NVP(blockStart_);
A thin wrapper around std::vector that uses a custom allocator.
typedef and functions to augment Eigen's MatrixXd
Serialization for matrices.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
Global functions in a separate testing namespace.
Definition chartTesting.h:28
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition types.h:49
This class stores a dense matrix and allows it to be accessed as a collection of blocks.
Definition SymmetricBlockMatrix.h:80
This class stores a dense matrix and allows it to be accessed as a collection of vertical blocks.
Definition VerticalBlockMatrix.h:47
VerticalBlockMatrix()
Construct an empty VerticalBlockMatrix.
Definition VerticalBlockMatrix.h:67
Block full()
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(),...
Definition VerticalBlockMatrix.h:242
Block range(DenseIndex startBlock, DenseIndex endBlock)
access ranges of blocks at a time
Definition VerticalBlockMatrix.h:195
constBlock blockRows(DenseIndex block, DenseIndex beginRow, DenseIndex endRow) const
Access one logical block over an explicit underlying row range.
Definition VerticalBlockMatrix.h:228
const DenseIndex & firstBlock() const
Get the apparent first block for all operations.
Definition VerticalBlockMatrix.h:271
const Matrix & matrix() const
Access to full matrix (including any portions excluded by rowStart(), rowEnd(), and firstBlock()).
Definition VerticalBlockMatrix.h:278
VerticalBlockMatrix(const CONTAINER &dimensions, DenseIndex height, bool appendOneDimension=false)
Construct from a container of the sizes of each vertical block.
Definition VerticalBlockMatrix.h:110
DenseIndex rowEnd_
Changes apparent matrix view, see main class comment.
Definition VerticalBlockMatrix.h:61
const DenseIndex & rowEnd() const
Get the apparent last row (exclusive, i.e.
Definition VerticalBlockMatrix.h:264
DenseIndex rows() const
Row size.
Definition VerticalBlockMatrix.h:169
Block operator()(DenseIndex block)
Access a single block in the underlying matrix with read/write access.
Definition VerticalBlockMatrix.h:187
DenseIndex & firstBlock()
Get or set the apparent first block for all operations.
Definition VerticalBlockMatrix.h:274
DenseIndex cols() const
Column size.
Definition VerticalBlockMatrix.h:175
VerticalBlockMatrix(ITERATOR firstBlockDim, ITERATOR lastBlockDim, DenseIndex height, bool appendOneDimension=false)
Construct from iterator over the sizes of each vertical block.
Definition VerticalBlockMatrix.h:142
const constBlock operator()(DenseIndex block) const
Access a const block view.
Definition VerticalBlockMatrix.h:190
const DenseIndex & rowStart() const
Get the apparent first row of the underlying matrix for all operations.
Definition VerticalBlockMatrix.h:256
Matrix matrix_
The full matrix.
Definition VerticalBlockMatrix.h:54
DenseIndex nBlocks() const
Block count.
Definition VerticalBlockMatrix.h:181
const constBlock full() const
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(),...
Definition VerticalBlockMatrix.h:246
DenseIndex & rowStart()
Get or set the apparent first row of the underlying matrix for all operations.
Definition VerticalBlockMatrix.h:260
Matrix & matrix()
Non-const access to full matrix (including any portions excluded by rowStart(), rowEnd(),...
Definition VerticalBlockMatrix.h:282
DenseIndex & rowEnd()
Get or set the apparent last row (exclusive, i.e.
Definition VerticalBlockMatrix.h:268
DenseIndex rowStart_
Changes apparent matrix view, see main class comment.
Definition VerticalBlockMatrix.h:59
VerticalBlockMatrix(const CONTAINER &dimensions, const Eigen::MatrixBase< DERIVED > &matrix, bool appendOneDimension=false)
Construct from a container of the sizes of each vertical block and a pre-prepared matrix.
Definition VerticalBlockMatrix.h:124
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
Definition VerticalBlockMatrix.h:63
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
Definition VerticalBlockMatrix.h:56