26 class SymmetricBlockMatrix;
45 typedef Eigen::Block<Matrix> Block;
46 typedef Eigen::Block<const Matrix> constBlock;
60 rowStart_(0), rowEnd_(0), blockStart_(0)
62 variableColOffsets_.push_back(0);
67 template<
typename CONTAINER>
69 rowStart_(0), rowEnd_(height), blockStart_(0)
71 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
72 matrix_.resize(height, variableColOffsets_.back());
77 template<
typename CONTAINER>
78 VerticalBlockMatrix(
const CONTAINER& dimensions,
const Matrix& matrix,
bool appendOneDimension =
false) :
79 matrix_(matrix), rowStart_(0), rowEnd_(matrix.rows()), blockStart_(0)
81 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
82 if(variableColOffsets_.back() != matrix_.cols())
83 throw std::invalid_argument(
"Requested to create a VerticalBlockMatrix with dimensions that do not sum to the total columns of the provided matrix.");
89 template<
typename ITERATOR>
91 rowStart_(0), rowEnd_(height), blockStart_(0)
93 fillOffsets(firstBlockDim, lastBlockDim, appendOneDimension);
94 matrix_.resize(height, variableColOffsets_.back());
114 DenseIndex cols()
const { assertInvariants();
return variableColOffsets_.back() - variableColOffsets_[blockStart_]; }
117 DenseIndex nBlocks()
const { assertInvariants();
return variableColOffsets_.size() - 1 - blockStart_; }
128 DenseIndex actualStartBlock = startBlock + blockStart_;
129 DenseIndex actualEndBlock = endBlock + blockStart_;
130 if(startBlock != 0 || endBlock != 0) {
131 checkBlock(actualStartBlock);
132 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
134 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
135 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
136 return matrix_.block(rowStart_, startCol, this->rows(), rangeCols);
141 DenseIndex actualStartBlock = startBlock + blockStart_;
142 DenseIndex actualEndBlock = endBlock + blockStart_;
143 if(startBlock != 0 || endBlock != 0) {
144 checkBlock(actualStartBlock);
145 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
147 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
148 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
149 return ((
const Matrix&)matrix_).block(rowStart_, startCol, this->rows(), rangeCols);
153 Block
full() {
return range(0, nBlocks()); }
156 const constBlock
full()
const {
return range(0, nBlocks()); }
161 checkBlock(actualBlock);
162 return variableColOffsets_[actualBlock];
184 const Matrix&
matrix()
const {
return matrix_; }
190 void assertInvariants()
const {
191 assert(matrix_.cols() == variableColOffsets_.back());
192 assert(blockStart_ < (
DenseIndex)variableColOffsets_.size());
193 assert(rowStart_ <= matrix_.rows());
194 assert(rowEnd_ <= matrix_.rows());
195 assert(rowStart_ <= rowEnd_);
199 assert(matrix_.cols() == variableColOffsets_.back());
200 assert(block < (
DenseIndex)variableColOffsets_.size() - 1);
201 assert(variableColOffsets_[block] < matrix_.cols() && variableColOffsets_[block+1] <= matrix_.cols());
204 template<
typename ITERATOR>
205 void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim,
bool appendOneDimension) {
206 variableColOffsets_.resize((lastBlockDim-firstBlockDim) + 1 + (appendOneDimension ? 1 : 0));
207 variableColOffsets_[0] = 0;
209 for(ITERATOR
dim=firstBlockDim;
dim!=lastBlockDim; ++
dim) {
210 variableColOffsets_[j+1] = variableColOffsets_[j] + *
dim;
213 if(appendOneDimension)
215 variableColOffsets_[j+1] = variableColOffsets_[j] + 1;
220 friend class SymmetricBlockMatrix;
224 friend class boost::serialization::access;
225 template<
class ARCHIVE>
226 void serialize(ARCHIVE & ar,
const unsigned int version) {
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_);
Block full()
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(), and firstBlock()
Definition: VerticalBlockMatrix.h:153
DenseIndex rows() const
Row size.
Definition: VerticalBlockMatrix.h:111
DenseIndex & firstBlock()
Get or set the apparent first block for all operations.
Definition: VerticalBlockMatrix.h:172
Matrix & matrix()
Non-const access to full matrix (including any portions excluded by rowStart(), rowEnd(), and firstBlock())
Definition: VerticalBlockMatrix.h:187
Block operator()(DenseIndex block)
Access a single block in the underlying matrix with read/write access.
Definition: VerticalBlockMatrix.h:120
DenseIndex rowEnd_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:53
DenseIndex cols() const
Column size.
Definition: VerticalBlockMatrix.h:114
Definition: VerticalBlockMatrix.h:41
DenseIndex nBlocks() const
Block count.
Definition: VerticalBlockMatrix.h:117
DenseIndex & rowStart()
Get or set the apparent first row of the underlying matrix for all operations.
Definition: VerticalBlockMatrix.h:166
size_t dim(const Vector &v)
dimensionality == size
Definition: Vector.h:90
VerticalBlockMatrix(ITERATOR firstBlockDim, ITERATOR lastBlockDim, DenseIndex height, bool appendOneDimension=false)
Construct from iterator over the sizes of each vertical block.
Definition: VerticalBlockMatrix.h:90
DenseIndex rowStart_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:52
const constBlock full() const
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(), and firstBlock()
Definition: VerticalBlockMatrix.h:156
VerticalBlockMatrix()
Construct an empty VerticalBlockMatrix.
Definition: VerticalBlockMatrix.h:59
DenseIndex rowStart() const
Get the apparent first row of the underlying matrix for all operations.
Definition: VerticalBlockMatrix.h:175
Matrix matrix_
The full matrix.
Definition: VerticalBlockMatrix.h:49
VerticalBlockMatrix(const CONTAINER &dimensions, DenseIndex height, bool appendOneDimension=false)
Construct from a container of the sizes of each vertical block.
Definition: VerticalBlockMatrix.h:68
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
Definition: VerticalBlockMatrix.h:50
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:74
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:54
const constBlock operator()(DenseIndex block) const
Access a const block view.
Definition: VerticalBlockMatrix.h:123
typedef and functions to augment Eigen's MatrixXd
Definition: SymmetricBlockMatrix.h:40
DenseIndex firstBlock() const
Get the apparent first block for all operations.
Definition: VerticalBlockMatrix.h:181
const Matrix & matrix() const
Access to full matrix (including any portions excluded by rowStart(), rowEnd(), and firstBlock()) ...
Definition: VerticalBlockMatrix.h:184
VerticalBlockMatrix(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...
Definition: VerticalBlockMatrix.h:78
DenseIndex & rowEnd()
Get or set the apparent last row (exclusive, i.e.
Definition: VerticalBlockMatrix.h:169
DenseIndex rowEnd() const
Get the apparent last row (exclusive, i.e.
Definition: VerticalBlockMatrix.h:178
A thin wrapper around std::vector that uses boost's pool_allocator.
Block range(DenseIndex startBlock, DenseIndex endBlock)
access ranges of blocks at a time
Definition: VerticalBlockMatrix.h:126