Re: [eigen] Lazy evaluation bug, feature, or PEBKAC?

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


Hi,

I can reproduce the crash with Eigen2. It's a plain Eigen2 bug which
I'm surprised we didn't catch before.

This is not affecting Eigen3. You program compiles unmodified against
Eigen3 with -DEIGEN2_SUPPORT and there it works fine.

Benoit

2011/3/1 Dave Steffen <dave.steffen@xxxxxxxxxxx>:
> Hi Folks
>
> We're just getting into Eigen (very impressive library), and I
> encountered the following suprising (to me) behavior:
>
> #include <Eigen/Dense>
>
> using std::cout;
> using std::endl;
>
> // import most common Eigen types
> USING_PART_OF_NAMESPACE_EIGEN
>
> int main()
> {
>  Vector3d a, b;
>
>  a << 1, 2, 3;
>  b << 7, 8, 9;
>
>  auto x = (a+b).col(0);   // line 1
>
>  cout << x[0] << endl;
>  cout << x[1] << endl;
> }
>
> ... produces a core dump, or worse behavior.
>
> Replacing line 1 with:
>
>  auto x = (a+b).eval().col(0);
>
> fixes the problem.
>
> This looks like a lazy-evaluation bug, in that operator[] probably
> ought to evaluate the expression. OTOH I've been wrong before. :-)
>
> This is using Eigen 2.0.15 with GCC 4.5.1.
>
> Any insights appreciated.  Thanks very much!
>
>
> --
> Dave Steffen, Ph.D. - Software Engineer
>
> Numerica Corporation <http://www.numerica.us>
> 4850 Hahns Peak Drive, Suite 200
> Loveland, Colorado 80538
> main (970) 461-2000 x 227   direct (970) 612-2327
> Email: dave.steffen@xxxxxxxxxxx
>
>
>
>



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