是否可以在 Eigen3 中创建对块的引用

Is it possible to create a reference to block in Eigen3

我想创建一个全局矩阵

G=+---+---+
  | A | B |
  +---+---+
  | C | D |
  +---+---+

是否可以为每个块创建一个引用?这样我就可以将每个块单独视为一个矩阵?

是的,有 Ref class:

MatrixXd G(100,100); // global matrix

// reference to sub-blocks:
Ref<MatrixXd> A = G.topLeftCorner(50,50);
Ref<MatrixXd> B = G.topRightCorner(50,50);
Ref<MatrixXd> C = G.bottomLeftCorner(50,50);
Ref<MatrixXd> D = G.bottomRightCorner(50,50);

// Accessing/modifiying the submatrices:
A.setOnes(); 
B.setRandom(); 
C.setIdentity(); 
D = A+B+C;

如果Gconst,你可以Ref<const MatrixXd>到sub-matrices(当然是read-only)