Eigen中的混叠(aliasing)问题
Eigen中aliasing指的是在赋值表达式的左右两边存在矩阵的重叠区域,这种情况下,有可能得到非预期的结果。如mat = 2*mat
或者mat = mat.transpose()
,第一个例子中的alias是没有问题的,而第二的例子则会导致非预期的计算结果。
下面例子:
MatrixXi mat(3,3);
mat << 1, 2, 3, 4, 5, 6, 7, 8, 9;
cout << "Here is the matrix mat:\n" << mat << endl;
// This assignment shows the aliasing problem
mat.bottomRightCorner(2,2) = mat.topLeftCorner(2,2);
cout << "After the assignment, mat = \n"<