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

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


This has to be expected. In Eigen2 expressions are nested by
reference, therefore after the line

auto x = (a+b).col(0);

the expression of (a+b) has been deleted and x refers to a dead object.

Same with:

auto x = (a+b).eval().col(0);

In this later case even Eigen3 fails. This can be observed using
VectorXd (instead of Vector3d) and using valgrind.

In Eigen2, the correct way to do this should be:

auto x = (a+b).nestByValue().col(0);

however this does not work either. This is a real bug.

Nevertheless, I'd not encourage you to store Eigen's expression this
way, and I would rather advise to evaluate your sub expression to not
lost the benefit of unrolling and vectorization.

Gael

On Tue, Mar 1, 2011 at 10:07 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> 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/