29 class SymmetricBlockMatrix;
63 rowStart_(0), rowEnd_(0), blockStart_(0)
65 variableColOffsets_.push_back(0);
70 template<
typename CONTAINER>
72 bool appendOneDimension =
false) :
73 variableColOffsets_(
dimensions.
size() + (appendOneDimension ? 2 : 1)),
74 rowStart_(0), rowEnd_(height), blockStart_(0) {
76 matrix_.resize(height, variableColOffsets_.back());
81 template<
typename CONTAINER,
typename DERIVED>
85 rowStart_(0), rowEnd_(
matrix.
rows()), blockStart_(0) {
87 if (variableColOffsets_.back() != matrix_.cols())
88 throw std::invalid_argument(
89 "Requested to create a VerticalBlockMatrix with dimensions that do not sum to the total columns of the provided matrix.");
94 template<
typename ITERATOR>
96 DenseIndex height,
bool appendOneDimension =
false) :
97 variableColOffsets_((lastBlockDim-firstBlockDim) + (appendOneDimension ? 2 : 1)),
98 rowStart_(0), rowEnd_(height), blockStart_(0) {
99 fillOffsets(firstBlockDim, lastBlockDim, appendOneDimension);
100 matrix_.resize(height, variableColOffsets_.back());
120 DenseIndex cols()
const { assertInvariants();
return variableColOffsets_.back() - variableColOffsets_[blockStart_]; }
123 DenseIndex nBlocks()
const { assertInvariants();
return variableColOffsets_.size() - 1 - blockStart_; }
134 DenseIndex actualStartBlock = startBlock + blockStart_;
135 DenseIndex actualEndBlock = endBlock + blockStart_;
136 if(startBlock != 0 || endBlock != 0) {
137 checkBlock(actualStartBlock);
138 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
140 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
141 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
142 return matrix_.block(rowStart_, startCol, this->
rows(), rangeCols);
147 DenseIndex actualStartBlock = startBlock + blockStart_;
148 DenseIndex actualEndBlock = endBlock + blockStart_;
149 if(startBlock != 0 || endBlock != 0) {
150 checkBlock(actualStartBlock);
151 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
153 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
154 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
155 return ((
const Matrix&)matrix_).block(rowStart_, startCol, this->
rows(), rangeCols);
167 checkBlock(actualBlock);
168 return variableColOffsets_[actualBlock];
197 assert(matrix_.cols() == variableColOffsets_.back());
198 assert(blockStart_ < (
DenseIndex)variableColOffsets_.size());
199 assert(rowStart_ <= matrix_.rows());
200 assert(rowEnd_ <= matrix_.rows());
201 assert(rowStart_ <= rowEnd_);
205 static_cast<void>(
block);
206 assert(matrix_.cols() == variableColOffsets_.back());
208 assert(variableColOffsets_[
block] < matrix_.cols() && variableColOffsets_[
block+1] <= matrix_.cols());
211 template<
typename ITERATOR>
212 void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim,
bool appendOneDimension) {
213 variableColOffsets_[0] = 0;
215 for(ITERATOR dim=firstBlockDim; dim!=lastBlockDim; ++dim, ++
j)
216 variableColOffsets_[
j+1] = variableColOffsets_[
j] + *dim;
217 if(appendOneDimension)
218 variableColOffsets_[
j+1] = variableColOffsets_[
j] + 1;
224 #if GTSAM_ENABLE_BOOST_SERIALIZATION
226 friend class boost::serialization::access;
227 template<
class ARCHIVE>
228 void serialize(ARCHIVE & ar,
const unsigned int ) {
229 ar & BOOST_SERIALIZATION_NVP(matrix_);
230 ar & BOOST_SERIALIZATION_NVP(variableColOffsets_);
231 ar & BOOST_SERIALIZATION_NVP(rowStart_);
232 ar & BOOST_SERIALIZATION_NVP(rowEnd_);
233 ar & BOOST_SERIALIZATION_NVP(blockStart_);