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 bool appendOneDimension =
false) :
70 variableColOffsets_(dimensions.size() + (appendOneDimension ? 2 : 1)),
71 rowStart_(0), rowEnd_(height), blockStart_(0) {
72 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
73 matrix_.resize(height, variableColOffsets_.back());
78 template<
typename CONTAINER,
typename DERIVED>
80 const Eigen::MatrixBase<DERIVED>& matrix,
bool appendOneDimension =
false) :
81 matrix_(matrix), variableColOffsets_(dimensions.size() + (appendOneDimension ? 2 : 1)),
82 rowStart_(0), rowEnd_(matrix.rows()), blockStart_(0) {
83 fillOffsets(dimensions.begin(), dimensions.end(), appendOneDimension);
84 if (variableColOffsets_.back() != matrix_.cols())
85 throw std::invalid_argument(
86 "Requested to create a VerticalBlockMatrix with dimensions that do not sum to the total columns of the provided matrix.");
91 template<
typename ITERATOR>
93 DenseIndex height,
bool appendOneDimension =
false) :
94 variableColOffsets_((lastBlockDim-firstBlockDim) + (appendOneDimension ? 2 : 1)),
95 rowStart_(0), rowEnd_(height), blockStart_(0) {
96 fillOffsets(firstBlockDim, lastBlockDim, appendOneDimension);
97 matrix_.resize(height, variableColOffsets_.back());
117 DenseIndex cols()
const { assertInvariants();
return variableColOffsets_.back() - variableColOffsets_[blockStart_]; }
120 DenseIndex nBlocks()
const { assertInvariants();
return variableColOffsets_.size() - 1 - blockStart_; }
131 DenseIndex actualStartBlock = startBlock + blockStart_;
132 DenseIndex actualEndBlock = endBlock + blockStart_;
133 if(startBlock != 0 || endBlock != 0) {
134 checkBlock(actualStartBlock);
135 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
137 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
138 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
139 return matrix_.block(rowStart_, startCol, this->rows(), rangeCols);
144 DenseIndex actualStartBlock = startBlock + blockStart_;
145 DenseIndex actualEndBlock = endBlock + blockStart_;
146 if(startBlock != 0 || endBlock != 0) {
147 checkBlock(actualStartBlock);
148 assert(actualEndBlock < (
DenseIndex)variableColOffsets_.size());
150 const DenseIndex startCol = variableColOffsets_[actualStartBlock];
151 const DenseIndex rangeCols = variableColOffsets_[actualEndBlock] - startCol;
152 return ((
const Matrix&)matrix_).block(rowStart_, startCol, this->rows(), rangeCols);
156 Block
full() {
return range(0, nBlocks()); }
159 const constBlock
full()
const {
return range(0, nBlocks()); }
164 checkBlock(actualBlock);
165 return variableColOffsets_[actualBlock];
187 const Matrix&
matrix()
const {
return matrix_; }
193 void assertInvariants()
const {
194 assert(matrix_.cols() == variableColOffsets_.back());
195 assert(blockStart_ < (
DenseIndex)variableColOffsets_.size());
196 assert(rowStart_ <= matrix_.rows());
197 assert(rowEnd_ <= matrix_.rows());
198 assert(rowStart_ <= rowEnd_);
202 static_cast<void>(block);
203 assert(matrix_.cols() == variableColOffsets_.back());
204 assert(block < (
DenseIndex)variableColOffsets_.size() - 1);
205 assert(variableColOffsets_[block] < matrix_.cols() && variableColOffsets_[block+1] <= matrix_.cols());
208 template<
typename ITERATOR>
209 void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim,
bool appendOneDimension) {
210 variableColOffsets_[0] = 0;
212 for(ITERATOR dim=firstBlockDim; dim!=lastBlockDim; ++dim, ++j)
213 variableColOffsets_[j+1] = variableColOffsets_[j] + *dim;
214 if(appendOneDimension)
215 variableColOffsets_[j+1] = variableColOffsets_[j] + 1;
218 friend class SymmetricBlockMatrix;
222 friend class boost::serialization::access;
223 template<
class ARCHIVE>
224 void serialize(ARCHIVE & ar,
const unsigned int ) {
225 ar & BOOST_SERIALIZATION_NVP(matrix_);
226 ar & BOOST_SERIALIZATION_NVP(variableColOffsets_);
227 ar & BOOST_SERIALIZATION_NVP(rowStart_);
228 ar & BOOST_SERIALIZATION_NVP(rowEnd_);
229 ar & BOOST_SERIALIZATION_NVP(blockStart_);
VerticalBlockMatrix()
Construct an empty VerticalBlockMatrix.
Definition: VerticalBlockMatrix.h:59
DenseIndex cols() const
Column size.
Definition: VerticalBlockMatrix.h:117
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:63
A thin wrapper around std::vector that uses a custom allocator.
Block range(DenseIndex startBlock, DenseIndex endBlock)
access ranges of blocks at a time
Definition: VerticalBlockMatrix.h:129
const constBlock operator()(DenseIndex block) const
Access a const block view.
Definition: VerticalBlockMatrix.h:126
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:79
const DenseIndex & rowStart() const
Get the apparent first row of the underlying matrix for all operations.
Definition: VerticalBlockMatrix.h:169
Block operator()(DenseIndex block)
Access a single block in the underlying matrix with read/write access.
Definition: VerticalBlockMatrix.h:123
Definition: VerticalBlockMatrix.h:41
DenseIndex rowStart_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:52
DenseIndex & rowStart()
Get or set the apparent first row of the underlying matrix for all operations.
Definition: VerticalBlockMatrix.h:172
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
Definition: VerticalBlockMatrix.h:50
const DenseIndex & firstBlock() const
Get the apparent first block for all operations.
Definition: VerticalBlockMatrix.h:181
DenseIndex nBlocks() const
Block count.
Definition: VerticalBlockMatrix.h:120
const DenseIndex & rowEnd() const
Get the apparent last row (exclusive, i.e.
Definition: VerticalBlockMatrix.h:175
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:54
Block full()
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(),...
Definition: VerticalBlockMatrix.h:156
const constBlock full() const
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(),...
Definition: VerticalBlockMatrix.h:159
Matrix & matrix()
Non-const access to full matrix (including any portions excluded by rowStart(), rowEnd(),...
Definition: VerticalBlockMatrix.h:190
VerticalBlockMatrix(const CONTAINER &dimensions, DenseIndex height, bool appendOneDimension=false)
Construct from a container of the sizes of each vertical block.
Definition: VerticalBlockMatrix.h:68
VerticalBlockMatrix(ITERATOR firstBlockDim, ITERATOR lastBlockDim, DenseIndex height, bool appendOneDimension=false)
Construct from iterator over the sizes of each vertical block.
Definition: VerticalBlockMatrix.h:92
DenseIndex & rowEnd()
Get or set the apparent last row (exclusive, i.e.
Definition: VerticalBlockMatrix.h:178
Definition: SymmetricBlockMatrix.h:51
const Matrix & matrix() const
Access to full matrix (including any portions excluded by rowStart(), rowEnd(), and firstBlock())
Definition: VerticalBlockMatrix.h:187
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
DenseIndex rows() const
Row size.
Definition: VerticalBlockMatrix.h:114
DenseIndex rowEnd_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:53
typedef and functions to augment Eigen's MatrixXd
Matrix matrix_
The full matrix.
Definition: VerticalBlockMatrix.h:49
DenseIndex & firstBlock()
Get or set the apparent first block for all operations.
Definition: VerticalBlockMatrix.h:184