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 MatrixType::IsVectorAtCompileTime;
22 using row_dim_t = std::conditional_t<
N != -1, std::array<long, size_t(
N)>,
24 using col_dim_t = std::conditional_t<
M != -1, std::array<long, size_t(
M)>,
27 static_assert(
N != 0 &&
M != 0,
28 "The BlkMatrix template class only supports nonzero numbers of "
29 "blocks in either direction.");
32 "Compile-time vector cannot have more than one column block.");
44 template <
typename Other>
53 template <
typename Other>
63 template <
typename Other>
68 template <
typename Other>
72 operator Eigen::Ref<PlainObject>() {
return m_data; }
73 operator Eigen::Ref<const PlainObject>()
const {
return m_data; }
78 "Constructor only supported for vector types.");
124 template <
typename Other>
126 assert(other.rows() ==
m_data.rows());
127 assert(other.cols() ==
m_data.cols());
157 std::vector<long> subRowDims;
158 subRowDims.resize(n);
159 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
160 long ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
165 static_assert(n <=
N,
166 "Cannot take n block rows of matrix with <n block rows.");
167 using RefType = Eigen::Ref<MatrixType>;
169 std::array<long, n> subRowDims;
170 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
171 long ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
176 return oss << self.
m_data;
189 for (
size_t i = 0; i <
m_rowDims.size(); i++) {
193 for (
size_t i = 0; i <
m_colDims.size(); i++) {
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)
static constexpr bool IsVectorAtCompileTime
typename MatrixType::PlainObject PlainObject
const row_dim_t & rowDims() const
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 Eigen::MatrixBase< Other > &data, const row_dim_t &rowDims, const col_dim_t &colDims)
static BlkMatrix Zero(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)