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) {
74 matrix_.resize(height, variableColOffsets_.back());
79 template<
typename CONTAINER,
typename DERIVED>
83 rowStart_(0), rowEnd_(
matrix.
rows()), blockStart_(0) {
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);
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());
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_);