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 static constexpr int N = _N;
26 static constexpr int M = _M;
27 static constexpr int Options = PlainObject::Options;
29 MatrixType::IsVectorAtCompileTime;
36 static_assert(
N != 0 &&
M != 0,
37 "The BlkMatrix template class only supports nonzero numbers of "
38 "blocks in either direction.");
41 "Compile-time vector cannot have more than one column block.");
63 template <
typename Other>
76 template <
typename Other>
90 template <
typename Other>
95 template <
typename Other>
99 operator Eigen::Ref<PlainObject>() {
return m_data; }
100 operator Eigen::Ref<const PlainObject>()
const {
return m_data; }
106 "Constructor only supported for vector types.");
152 template <
typename Other>
154 assert(other.rows() ==
m_data.rows());
155 assert(other.cols() ==
m_data.cols());
176 template <
typename D>
178 const Eigen::EigenBase<D> &other,
179 const Scalar prec = Eigen::NumTraits<Scalar>::dummy_precision())
const {
180 return matrix().isApprox(other, prec);
183 template <
typename D,
int N2,
int M2>
186 const Scalar prec = Eigen::NumTraits<Scalar>::dummy_precision())
const {
201 std::vector<Index> subRowDims;
202 subRowDims.resize(n);
203 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
204 Index ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
211 static_assert(n <=
N,
212 "Cannot take n block rows of matrix with <n block rows.");
213 using RefType = Eigen::Ref<MatrixType>;
215 std::array<Index, n> subRowDims;
216 std::copy_n(
m_rowDims.cbegin(), n, subRowDims.begin());
217 Index ntr = std::accumulate(subRowDims.begin(), subRowDims.end(), 0);
222 return oss << self.
m_data;
237 for (
size_t i = 0; i <
m_rowDims.size(); i++) {
241 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
auto topBlkRows(size_t n)
Take the top n block rows of the block matrix.
const ColDimsType & colDims() const
bool isApprox(const BlkMatrix< D, N2, M2 > &other, const Scalar prec=Eigen::NumTraits< Scalar >::dummy_precision()) 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
bool isApprox(const Eigen::EigenBase< D > &other, const Scalar prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
auto topBlkRows()
This version returns a fixed-size block. This version returns a fixed-size block.
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
static constexpr int Options
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)