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_);
A thin wrapper around std::vector that uses a custom allocator.
typedef and functions to augment Eigen's MatrixXd
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:75
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:112
Definition: SymmetricBlockMatrix.h:52
Definition: VerticalBlockMatrix.h:42
VerticalBlockMatrix()
Construct an empty VerticalBlockMatrix.
Definition: VerticalBlockMatrix.h:59
Block full()
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(),...
Definition: VerticalBlockMatrix.h:156
Block range(DenseIndex startBlock, DenseIndex endBlock)
access ranges of blocks at a time
Definition: VerticalBlockMatrix.h:129
const 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:187
VerticalBlockMatrix(const CONTAINER &dimensions, DenseIndex height, bool appendOneDimension=false)
Construct from a container of the sizes of each vertical block.
Definition: VerticalBlockMatrix.h:68
DenseIndex rowEnd_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:53
const DenseIndex & rowEnd() const
Get the apparent last row (exclusive, i.e.
Definition: VerticalBlockMatrix.h:175
DenseIndex rows() const
Row size.
Definition: VerticalBlockMatrix.h:114
Block operator()(DenseIndex block)
Access a single block in the underlying matrix with read/write access.
Definition: VerticalBlockMatrix.h:123
DenseIndex & firstBlock()
Get or set the apparent first block for all operations.
Definition: VerticalBlockMatrix.h:184
DenseIndex cols() const
Column size.
Definition: VerticalBlockMatrix.h:117
VerticalBlockMatrix(ITERATOR firstBlockDim, ITERATOR lastBlockDim, DenseIndex height, bool appendOneDimension=false)
Construct from iterator over the sizes of each vertical block.
Definition: VerticalBlockMatrix.h:92
const constBlock operator()(DenseIndex block) const
Access a const block view.
Definition: VerticalBlockMatrix.h:126
const DenseIndex & rowStart() const
Get the apparent first row of the underlying matrix for all operations.
Definition: VerticalBlockMatrix.h:169
Matrix matrix_
The full matrix.
Definition: VerticalBlockMatrix.h:49
DenseIndex nBlocks() const
Block count.
Definition: VerticalBlockMatrix.h:120
const constBlock full() const
Return the full matrix, not including any portions excluded by rowStart(), rowEnd(),...
Definition: VerticalBlockMatrix.h:159
DenseIndex & rowStart()
Get or set the apparent first row of the underlying matrix for all operations.
Definition: VerticalBlockMatrix.h:172
Matrix & matrix()
Non-const access to full matrix (including any portions excluded by rowStart(), rowEnd(),...
Definition: VerticalBlockMatrix.h:190
DenseIndex & rowEnd()
Get or set the apparent last row (exclusive, i.e.
Definition: VerticalBlockMatrix.h:178
DenseIndex rowStart_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:52
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
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
Definition: VerticalBlockMatrix.h:54
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
Definition: VerticalBlockMatrix.h:50