Created attachment 495 [details] output of my program. "MatrixXi E= expression" and "auto E=expression" give different result!(see E and EAuto below.) and even "expression" and "expression.eval()" give different result! What I expected is that D, E, and EAuto are with the same value! Here is my full program: #include <iostream> #include <Eigen/Core> void main() { #define printlnExpln(exp) std::cout<<#exp<<" is:\n"<<exp<<std::endl; using namespace Eigen; MatrixXi A = MatrixXi::Ones (2, 3); MatrixXi B = MatrixXi::Ones (2, 3); auto ABColSum = (A.array() * B.array() ).colwise().sum().eval(); auto D = A.array().rowwise() - ABColSum; printlnExpln (A); printlnExpln (B); printlnExpln (ABColSum); printlnExpln (D); MatrixXi E = (A.array().rowwise() ) - ( (A.array() * B.array() ).colwise().sum().eval() ); printlnExpln (E); auto EAuto = (A.array().rowwise() ) - ( (A.array() * B.array() ).colwise().sum().eval() ); printlnExpln (typeid (EAuto).name() ); printlnExpln(EAuto); printlnExpln (EAuto.eval() ); }
Basically the same problem as bug 505. *** This bug has been marked as a duplicate of bug 505 ***
In reply to comment http://eigen.tuxfamily.org/bz/show_bug.cgi?id=505#c13, I agree that this bug report is slightly different. I would call it invalid because in the line: auto EAuto = (A.array().rowwise() ) - ( (A.array() * B.array() ).colwise().sum().eval() ); you *explicitly* introduced a temporary by calling eval. Eigen cannot know this temporary is nested inside a bugger expression which is not evaluated within the current statement. What would you expect? Eigen is an expression template library, so auto has to be used with care. If you wanted a MatrixXi why writing 'auto' instead of MatrixXi? If you wanted the result of the expression while letting Eigen picks the "best" type, then you should encapsulate the whole right hand side with (...).eval().
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/883.