Lazy evaluation handles transpose expression wrong
Submitted by Magnus Lindhé
Assigned to Nobody
Link to original bugzilla bug (#536)
Version: 3.1
Operating system: Linux
Description
The lazy evaluation makes an expression of the type A = A.transpose() + A evaluate to the wrong result. Sometimes the built-in checks in Eigen misses this. A simplified code example (compiled with gcc 4.6.1):
Eigen::Matrix<float,2,2> A,B;
A << 1, 2, 3, 4;
B=A;
//A = A.transpose() + A; // Causes a failed assertion in Eigen
A = A.transpose() + A + A; // Runs, but gives wrong result
B = B.transpose().eval() + B + B; // Correct
The result is A=3, 12, 8, 12 (wrong) and B=3, 7, 8, 12 (correct). When I run the commented line, I get a failed assertion, with the help text "aliasing detected during tranposition, use transposeInPlace() " "or evaluate the rhs into a temporary using .eval()", but when I add an extra term, it seems that Eigen doesn't detect the problem.