OGS
EigenBlockMatrixView.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <Eigen/Core>
13
14namespace MathLib
15{
16template <int D, typename M>
18{
19public:
20 static constexpr int rows = M::RowsAtCompileTime == Eigen::Dynamic
21 ? Eigen::Dynamic
22 : D * M::RowsAtCompileTime;
23 static constexpr int cols = M::ColsAtCompileTime == Eigen::Dynamic
24 ? Eigen::Dynamic
25 : D * M::ColsAtCompileTime;
26 using Scalar = typename M::Scalar;
27 using Matrix = Eigen::Matrix<Scalar, rows, cols, Eigen::ColMajor>;
28
29 constexpr explicit EigenBlockMatrixViewFunctor(const M& matrix)
30 : matrix_(matrix){};
31
32 constexpr const Scalar operator()(Eigen::Index row, Eigen::Index col) const
33 {
34 if (row / matrix_.rows() != col / matrix_.cols())
35 {
36 return 0;
37 }
38 return matrix_(row % matrix_.rows(), col % matrix_.cols());
39 }
40
41private:
42 const typename M::Nested& matrix_;
43};
44
45template <int D, typename M>
46constexpr Eigen::CwiseNullaryOp<
49eigenBlockMatrixView(const Eigen::MatrixBase<M>& matrix)
50{
51 using Matrix = typename EigenBlockMatrixViewFunctor<D, M>::Matrix;
52 return Matrix::NullaryExpr(
53 D * matrix.rows(), D * matrix.cols(),
54 EigenBlockMatrixViewFunctor<D, M>(matrix.derived()));
55}
56} // namespace MathLib
constexpr const Scalar operator()(Eigen::Index row, Eigen::Index col) const
constexpr EigenBlockMatrixViewFunctor(const M &matrix)
Eigen::Matrix< Scalar, rows, cols, Eigen::ColMajor > Matrix
constexpr Eigen::CwiseNullaryOp< EigenBlockMatrixViewFunctor< D, M >, typename EigenBlockMatrixViewFunctor< D, M >::Matrix > eigenBlockMatrixView(const Eigen::MatrixBase< M > &matrix)