Re: [eigen] Lazy evaluation bug, feature, or PEBKAC? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Lazy evaluation bug, feature, or PEBKAC?
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Wed, 2 Mar 2011 10:31:40 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=7FUzu1jM8LyNFfZXWiYHOBWgn7N3mu6SiTH9gNLB/AE=; b=g9QtHlYDREGlGYRdZeqP6RH0RUAAvuHwYMkI9iOINxqj3zgvUMc/ADl9WhUk9W8QKv 3FzaRIi2DpGMyKWnQ+sSFjA3XSeyc5wHYJKwHZPEnY1Tre1YINBS++orDTPPAFykPrgu jPn1gFGS/QzNwf+ceMKaO+WNyDjuy3gp2mtw8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=h/55K6LjaocbNaROLhwtrDKco9VzS5TQNBPUcsAyUwcQRJQFY1NdCzcXZ4g2Hb8136 Cy1KTg4HPluVg1WCgca0hKojMg+yZUzs4hpRuIN1YxmPvxxPyVFYP/ZOCFCt2US+TGzH GiOl/Tm6CQrT9OCUc+VgZqyrSDvPU3F7QoaNA=
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
>>
>>
>>
>>
>
>
>