13template <
typename _MatrixType,
int _N,
int _M = _N>
class BlkMatrix {
17 using Scalar =
typename MatrixType::Scalar;
18 enum {
N = _N,
M = _M,
Options = PlainObject::Options };
20 using row_dim_t = std::conditional_t<
N != -1, std::array<long, size_t(
N)>,
22 using col_dim_t = std::conditional_t<
M != -1, std::array<long, size_t(
M)>,
25 static_assert(
N != 0 &&
M != 0,
26 "The BlkMatrix template class only supports nonzero numbers of "
27 "blocks in either direction.");
29 static_assert(!MatrixType::IsVectorAtCompileTime || (
M == 1),
30 "Compile-time vector cannot have more than one column block.");
43 template <
typename Other>
52 template <
typename Other>
62 template <
typename Other>
67 template <
typename Other>
117 template <
typename Other>
119 assert(other.rows() ==
m_data.rows());
120 assert(other.cols() ==
m_data.cols());
127 template <
typename Other>
inline void swap(BlkMatrix<Other, N, M> &other) {
128 m_data.swap(other.matrix());
143 using OutType = BlkMatrix<Eigen::Ref<MatrixType>, -1,
M>;
144 std::vector<long> subRowDims;
145 subRowDims.resize(n);
146 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
147 long ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
152 static_assert(n <=
N,
153 "Cannot take n block rows of matrix with <n block rows.");
154 using RefType = Eigen::Ref<MatrixType>;
155 using OutType = BlkMatrix<RefType, n, M>;
156 std::array<long, n> subRowDims;
157 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
158 long ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
163 return oss << self.m_data;
181 for (
size_t i = 0; i <
m_rowDims.size(); i++) {
185 for (
size_t i = 0; i <
m_colDims.size(); i++) {
Block matrix class, with a fixed-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
auto topBlkRows(size_t n)
typename MatrixType::PlainObject PlainObject
const row_dim_t & rowDims() const
BlkMatrix(const row_dim_t &dims, std::true_type)
BlkMatrix(const Eigen::MatrixBase< Other > &data, const row_dim_t &dims)
Only-rows constructor (only for vectors)
BlkMatrix(const row_dim_t &dims)
Only-rows constructor (only for vectors)
auto operator()(size_t i, size_t j)
Get the block in position ( i, j )
BlkMatrix(const row_dim_t &dims, std::false_type)
BlkMatrix(const Eigen::MatrixBase< Other > &data, const row_dim_t &rowDims, const col_dim_t &colDims)
auto operator[](size_t i) const
auto blockCol(size_t j) const
auto operator()(size_t i, size_t j) const
const row_dim_t & rowIndices() const
BlkMatrix(Eigen::MatrixBase< Other > &data, const row_dim_t &dims)
Only-rows constructor (only for vectors)
typename MatrixType::Scalar Scalar
const MatrixType & matrix() const
auto blockRow(size_t i) const
const col_dim_t & colDims() const
std::conditional_t< M !=-1, std::array< long, size_t(M)>, std::vector< long > > col_dim_t
const col_dim_t & colIndices() const
BlkMatrix & operator=(const Eigen::MatrixBase< Other > &other)
Set the data to be equal to some other Eigen object.
BlkMatrix(const row_dim_t &rowDims, const col_dim_t &colDims)
std::conditional_t< N !=-1, std::array< long, size_t(N)>, std::vector< long > > row_dim_t
BlkMatrix(Eigen::MatrixBase< Other > &data, const row_dim_t &rowDims, const col_dim_t &colDims)
auto operator[](size_t i)