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

时间:2017-01-15 16:53:06

标签: eigen3

我想创建一个全局矩阵

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

是否可以创建对每个块的引用?这样我可以将每个块单独考虑为矩阵吗?

1 个答案:

答案 0 :(得分:1)

是的,有Ref类:

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>(当然,这些是只读的)。

相关问题