26 class SymmetricBlockMatrix;
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>
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];
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;
222 friend class boost::serialization::access;
223 template<
class ARCHIVE>
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_);
const DenseIndex & firstBlock() const
VerticalBlockMatrix(const CONTAINER &dimensions, const Eigen::MatrixBase< DERIVED > &matrix, bool appendOneDimension=false)
m m block(1, 0, 2, 2)<< 4
const Matrix & matrix() const
Block operator()(DenseIndex block)
vector< size_t > dimensions(L.begin(), L.end())
Eigen::Block< const Matrix > constBlock
ptrdiff_t DenseIndex
The index type for Eigen objects.
void checkBlock(DenseIndex block) const
Matrix matrix_
The full matrix.
const DenseIndex & rowStart() const
DenseIndex nBlocks() const
Block count.
const constBlock range(DenseIndex startBlock, DenseIndex endBlock) const
DenseIndex offset(DenseIndex block) const
VerticalBlockMatrix(ITERATOR firstBlockDim, ITERATOR lastBlockDim, DenseIndex height, bool appendOneDimension=false)
void fillOffsets(ITERATOR firstBlockDim, ITERATOR lastBlockDim, bool appendOneDimension)
DenseIndex rowStart_
Changes apparent matrix view, see main class comment.
const DenseIndex & rowEnd() const
const constBlock operator()(DenseIndex block) const
DenseIndex & firstBlock()
const constBlock full() const
Block range(DenseIndex startBlock, DenseIndex endBlock)
A thin wrapper around std::vector that uses a custom allocator.
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
void assertInvariants() const
Expression of a fixed-size or dynamic-size block.
void serialize(ARCHIVE &ar, const unsigned int)
Eigen::Block< Matrix > Block
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
VerticalBlockMatrix(const CONTAINER &dimensions, DenseIndex height, bool appendOneDimension=false)
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
DenseIndex rowEnd_
Changes apparent matrix view, see main class comment.
DenseIndex cols() const
Column size.
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Base class for all dense matrices, vectors, and expressions.
DenseIndex rows() const
Row size.