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.");
54 template <
typename Other>
68 template <
typename Other>
83 template <
typename Other>
88 template <
typename Other>
92 operator Eigen::Ref<PlainObject>() {
return m_data; }
93 operator Eigen::Ref<const PlainObject>()
const {
return m_data; }
99 "Constructor only supported for vector types.");
145 template <
typename Other>
147 assert(other.rows() ==
m_data.rows());
148 assert(other.cols() ==
m_data.cols());
178 std::vector<long> subRowDims;
179 subRowDims.resize(n);
180 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
181 long ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
186 static_assert(n <=
N,
187 "Cannot take n block rows of matrix with <n block rows.");
188 using RefType = Eigen::Ref<MatrixType>;
190 std::array<long, n> subRowDims;
191 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
192 long ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
197 return oss << self.
m_data;
210 for (
size_t i = 0; i <
m_rowDims.size(); i++) {
214 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)