Re: [eigen] Problem with g++-4.4 -O2 and Eigen3

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


the fix is very obvious, change the last line of your CMakeLists.txt to:

ADD_EXECUTABLE(test foo.cpp main.cpp foo.h)

(reverse foo.cpp and main.cpp). The effect is to change the order of
the .o files at linking stage, and here that does the trick.

btw, I was kidding, this makes no sense to me :) But at least we know
that something very strange happens during the linking.

gael


On Thu, Apr 7, 2011 at 5:30 PM, hauke strasdat <strasdat@xxxxxxxxx> wrote:
> Hi all,
>
> I think I found a bug related to g++-4.4 and Eigen3.
>
> If I multiply two matrices A=[1 1;0 0] and B=[1 0; 1 0] to each other,
> the sign of the result is flipped: [-2 0; 0 0] instead of [2 0; 0 0].
> A.row(0).dot(B.col(0)) always provides the correct result 2.
>
> What triggers the bug:
>  - Apply lu().inverse() on a random matrix,
>  - and A*B is calculated in a member function of a separate class.
>  - and the program is complied using g++-4.4 with optimisation O2 or O3.
>
> The bug does not happen if I compile the program with O0/O1 or with
> g++-4.3/g++-4.5.
>
> g++-4.4 is the standard compiler for Ubuntu 10.04 (v 4.4.3) and 10.10
> (v 4.4.5) and I could reproduce the bug on both operating systems
> (both 64 bit).
> I tried the Eigen3 release version as well as a very recent version
> from the hg repository.
>
> This could be a regression in g++-4.4, but I thought it is a good idea
> to contact you guys first.
> It would be awesome, if somebody would know a work-around, since it
> would be very difficult for me
> to switch to g++-4.3 or g++-4.5.
>
> A small test case is attached below.
>
> Cheers,
> Hauke S.
>
>
>
> --- FILE foo.cpp:
>
> #include "foo.h"
> #include <iostream>
>
> using namespace std;
>
> double Foo::method()
> {
>  Matrix<double, 2,2> A;
>  A << 1,1,
>      0,0;
>  MatrixXd B(2,2);
>  B <<1,0,
>      1,0;
>  MatrixXd C = (A*B);
>  cerr << "A*B = " << C << endl;
>  cerr << "a*b =  " << A.row(0).dot(B.col(0)) << endl;
>
>  return 0;
> }
>
> -- FILE foo.h:
>
> #ifndef FOO_H
> #define FOO_H
>
> #include <Eigen/Core>
> #include <Eigen/LU>
> using namespace Eigen;
>
> class Foo
> {
> public:
>  double method();
> };
>
> #endif
>
> -- FILE main.cpp:
>
> #include "foo.h"
>
> int main()
> {
>  MatrixXd X(1,1);
>    X << 2;
>     X.lu().inverse();
>
>  Foo foo;
>  foo.method();
> }
>
> --- FILE CMakeLists.txt:
>
> SET (PROJECT_NAME TEST)
>
> PROJECT(${PROJECT_NAME})
> CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
> SET (CMAKE_VERBOSE_MAKEFILE ON)
>
> SET(CMAKE_CXX_COMPILER /usr/bin/g++-4.4)
>
> SET(CMAKE_CXX_FLAGS_RELEASE  "-O2 -g -Werror -Wall")
> SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g  -Werror -Wall")
>
> # override by appending -DCMAKE_BUILD_TYPE=Debug to cmake argument list
> IF( NOT CMAKE_BUILD_TYPE )
>   SET( CMAKE_BUILD_TYPE Release )
> ENDIF()
>
> SET (INCLUDE_DIRS "eigen3/"  )
> INCLUDE_DIRECTORIES( ${INCLUDE_DIRS})
>
> ADD_EXECUTABLE(test main.cpp foo.cpp foo.h)
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/