17template <
typename _MatrixType,
int N,
int M = N>
class BlkMatrix;
19template <
typename _MatrixType,
int _N,
int _M>
class BlkMatrix {
23 using Scalar =
typename MatrixType::Scalar;
25 enum {
N = _N,
M = _M,
Options = PlainObject::Options };
27 MatrixType::IsVectorAtCompileTime;
34 static_assert(
N != 0 &&
M != 0,
35 "The BlkMatrix template class only supports nonzero numbers of "
36 "blocks in either direction.");
39 "Compile-time vector cannot have more than one column block.");
61 template <
typename Other>
74 template <
typename Other>
88 template <
typename Other>
93 template <
typename Other>
97 operator Eigen::Ref<PlainObject>() {
return m_data; }
98 operator Eigen::Ref<const PlainObject>()
const {
return m_data; }
104 "Constructor only supported for vector types.");
150 template <
typename Other>
152 assert(other.rows() ==
m_data.rows());
153 assert(other.cols() ==
m_data.cols());
184 std::vector<Index> subRowDims;
185 subRowDims.resize(n);
186 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
187 Index ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
192 static_assert(n <=
N,
193 "Cannot take n block rows of matrix with <n block rows.");
194 using RefType = Eigen::Ref<MatrixType>;
196 std::array<Index, n> subRowDims;
197 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
198 Index ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
203 return oss << self.
m_data;
218 for (
size_t i = 0; i <
m_rowDims.size(); i++) {
222 for (
size_t i = 0; i <
m_colDims.size(); i++) {
Block matrix class, with a fixed or dynamic-size number of row and column blocks.
auto blockSegment(size_t i)
void swap(BlkMatrix< Other, N, M > &other)
friend std::ostream & operator<<(std::ostream &oss, const BlkMatrix &self)
auto blockSegment(size_t i) const
ConstVectorRef MatrixType
auto topBlkRows(size_t n)
const ColDimsType & colDims() const
static constexpr bool IsVectorAtCompileTime
typename MatrixType::PlainObject PlainObject
std::conditional_t< N !=-1, std::array< Index, size_t(N)>, std::vector< Index > > RowDimsType
std::conditional_t< M !=-1, std::array< Index, size_t(M)>, std::vector< Index > > ColDimsType
const ColDimsType & colIndices() const
BlkMatrix(const Eigen::MatrixBase< Other > &data, const RowDimsType &dims)
Only-rows constructor (only for vectors)
static BlkMatrix Zero(const RowDimsType &rowDims, const ColDimsType &colDims)
auto operator()(size_t i, size_t j)
Get the block in position ( i, j )
const RowDimsType & rowDims() const
auto operator[](size_t i) const
auto blockCol(size_t j) const
auto operator()(size_t i, size_t j) const
typename MatrixType::Scalar Scalar
const RowDimsType & rowIndices() const
const MatrixType & matrix() const
auto blockRow(size_t i) const
BlkMatrix(Eigen::MatrixBase< Other > &data, const RowDimsType &rowDims, const ColDimsType &colDims)
BlkMatrix(const RowDimsType &rowDims, const ColDimsType &colDims)
BlkMatrix(Eigen::MatrixBase< Other > &data, const RowDimsType &dims)
Only-rows constructor (only for vectors)
BlkMatrix & operator=(const Eigen::MatrixBase< Other > &other)
Set the data to be equal to some other Eigen object.
BlkMatrix(const Eigen::MatrixBase< Other > &data, const RowDimsType &rowDims, const ColDimsType &colDims)
BlkMatrix(const RowDimsType &dims)
Only-rows constructor (only for vectors)
auto operator[](size_t i)