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

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


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/