27 class SymmetricBlockMatrix;
61 rowStart_(0), rowEnd_(0), blockStart_(0)
63 variableColOffsets_.push_back(0);
68 template<
typename CONTAINER>
70 bool appendOneDimension =
false) :
71 variableColOffsets_(dimensions.
size() + (appendOneDimension ? 2 : 1)),
72 rowStart_(0), rowEnd_(height), blockStart_(0) {
73 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
74 matrix_.resize(height, variableColOffsets_.back());
79 template<
typename CONTAINER,
typename DERIVED>
82 matrix_(matrix), variableColOffsets_(dimensions.
size() + (appendOneDimension ? 2 : 1)),
83 rowStart_(0), rowEnd_(matrix.
rows()), blockStart_(0) {
84 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
85 if (variableColOffsets_.back() != matrix_.cols())
86 throw std::invalid_argument(
87 "Requested to create a VerticalBlockMatrix with dimensions that do not sum to the total columns of the provided matrix.");
92 template<
typename ITERATOR>
94 DenseIndex height,
bool appendOneDimension =
false) :
95 variableColOffsets_((lastBlockDim-firstBlockDim) + (appendOneDimension ? 2 : 1)),
96 rowStart_(0), rowEnd_(height), blockStart_(0) {
97 fillOffsets(firstBlockDim, lastBlockDim, appendOneDimension);
98 matrix_.resize(height, variableColOffsets_.back());
118 DenseIndex cols()
const { assertInvariants();
return variableColOffsets_.back() - variableColOffsets_[blockStart_]; }
121 DenseIndex nBlocks()
const { assertInvariants();
return variableColOffsets_.size() - 1 - blockStart_; }
132 DenseIndex actualStartBlock = startBlock + blockStart_;
133 DenseIndex actualEndBlock = endBlock + blockStart_;
134 if(startBlock != 0 || endBlock != 0) {
135 checkBlock(actualStartBlock);
136 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
138 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
139 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
140 return matrix_.block(rowStart_, startCol, this->
rows(), rangeCols);
145 DenseIndex actualStartBlock = startBlock + blockStart_;
146 DenseIndex actualEndBlock = endBlock + blockStart_;
147 if(startBlock != 0 || endBlock != 0) {
148 checkBlock(actualStartBlock);
149 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
151 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
152 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
153 return ((
const Matrix&)matrix_).
block(rowStart_, startCol, this->
rows(), rangeCols);
160 const constBlock
full()
const {
return range(0, nBlocks()); }
165 checkBlock(actualBlock);
166 return variableColOffsets_[actualBlock];
195 assert(matrix_.cols() == variableColOffsets_.back());
196 assert(blockStart_ < (
DenseIndex)variableColOffsets_.size());
197 assert(rowStart_ <= matrix_.rows());
198 assert(rowEnd_ <= matrix_.rows());
199 assert(rowStart_ <= rowEnd_);
203 static_cast<void>(
block);
204 assert(matrix_.cols() == variableColOffsets_.back());
205 assert(block < (
DenseIndex)variableColOffsets_.size() - 1);
206 assert(variableColOffsets_[block] < matrix_.cols() && variableColOffsets_[block+1] <= matrix_.cols());
209 template<
typename ITERATOR>
210 void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim,
bool appendOneDimension) {
211 variableColOffsets_[0] = 0;
213 for(ITERATOR dim=firstBlockDim; dim!=lastBlockDim; ++dim, ++
j)
214 variableColOffsets_[j+1] = variableColOffsets_[j] + *dim;
215 if(appendOneDimension)
216 variableColOffsets_[j+1] = variableColOffsets_[
j] + 1;
222 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 224 friend class boost::serialization::access;
225 template<
class ARCHIVE>
226 void serialize(ARCHIVE & ar,
const unsigned int ) {
227 ar & BOOST_SERIALIZATION_NVP(matrix_);
228 ar & BOOST_SERIALIZATION_NVP(variableColOffsets_);
229 ar & BOOST_SERIALIZATION_NVP(rowStart_);
230 ar & BOOST_SERIALIZATION_NVP(rowEnd_);
231 ar & BOOST_SERIALIZATION_NVP(blockStart_);
const constBlock range(DenseIndex startBlock, DenseIndex endBlock) const
DenseIndex cols() const
Column size.
VerticalBlockMatrix(const CONTAINER &dimensions, const Eigen::MatrixBase< DERIVED > &matrix, bool appendOneDimension=false)
m m block(1, 0, 2, 2)<< 4
std::string serialize(const T &input)
serializes to a string
DenseIndex nBlocks() const
Block count.
const constBlock full() const
DenseIndex rows() const
Row size.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
const Matrix & matrix() const
Block operator()(DenseIndex block)
DenseIndex offset(DenseIndex block) const
void assertInvariants() const
Eigen::Block< const Matrix > constBlock
ptrdiff_t DenseIndex
The index type for Eigen objects.
void checkBlock(DenseIndex block) const
Matrix matrix_
The full matrix.
VerticalBlockMatrix(ITERATOR firstBlockDim, ITERATOR lastBlockDim, DenseIndex height, bool appendOneDimension=false)
void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim, bool appendOneDimension)
const DenseIndex & rowEnd() const
DenseIndex rowStart_
Changes apparent matrix view, see main class comment.
Serialization for matrices.
DenseIndex & firstBlock()
Block range(DenseIndex startBlock, DenseIndex endBlock)
A thin wrapper around std::vector that uses a custom allocator.
Expression of a fixed-size or dynamic-size block.
const constBlock operator()(DenseIndex block) const
Double_ range(const Point2_ &p, const Point2_ &q)
Eigen::Block< Matrix > Block
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
VerticalBlockMatrix(const CONTAINER &dimensions, DenseIndex height, bool appendOneDimension=false)
const DenseIndex & firstBlock() const
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
DenseIndex rowEnd_
Changes apparent matrix view, see main class comment.
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
const std::vector< size_t > dimensions
Base class for all dense matrices, vectors, and expressions.
const DenseIndex & rowStart() const