|Re: [eigen] Lazy evaluation bug, feature, or PEBKAC?|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Lazy evaluation bug, feature, or PEBKAC?
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Wed, 2 Mar 2011 13:04:06 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=dLLmN2b5xGPFS3EXfCuUZLRc+y5Wiv9YFYqBztsnJKo=; b=rozwJlkgNsKg0AmHiPmdmnn+AOKYYpRsZSlA/aiuvVxqF79nwTQrIZkovbQAMqI8t6 dTyB/lYIACXzSgisGlSR/s/hyRDRdXSrOgCD6RwVJ/oUkgNEk+8asqezXlvIGuerlUQd J2VSHXpDbmoQckeG49MUCXJpuC6Sr9NHNnCTM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=P8eQmYcp3/+i7cXnmFIMpgFO62arpqgzO/mDnGsEl4YHOOvT1AWzomOX4N0zw1YHCX UJ7xBW+yNv1pMRDSlA/IvcvKACXEzQz3FiHPB0+aiCY6rxi8VNhqoM/vz/vjoHLAsguj ODS+nAcNjTOnpW9uq9GCCvbe+s+tmHuOQkYu8=
2011/3/2 Dave Steffen <dave.steffen@xxxxxxxxxxx>:
> On Wednesday, March 02, 2011 02:31:40 am Gael Guennebaud wrote:
>> 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.
> Ouch. It looks to me like I just need to make that 'const auto&',
> to keep the temporaries bound; alternately, maybe I just need to
> evaluate the expression into a vector, E.G.
> Vector3d x = (a+b).col(0)
>> 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.
> What's the right way to do it in Eigen 3? I'm going to port our
> little test project over to that this morning.
>> 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.
> Well, right, I'd do that if I had the option.
> In my application, I really *do* need to add two matrices, which
> might or might not happen to have 1 column, and then operate
> (read-only) on individual columns. That doesn't strike me as a
> terribly unusual thing to do.
The unusual thing here is to want to construct the expression object
once and then reuse it.
Constructing these expression objects has zero runtime cost in
optimized builds, because we make it very easy for the compiler to
optimize away the expression objects completely.
Therefore, there is no overhead in doing "a+b" everytime you need this
sum expression: zero overhead.
That's why practically nobody is trying to do what you're doing here :)
> It sounds like I just need to actually evaluate the thing, that is
> make a Matrix containing the results, instead of having this
> expression hanging around.
>> On Tue, Mar 1, 2011 at 10:07 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
>> > 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
> Again, thanks to both of you for your help.
> 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
> fax (970) 461-2004
> This message and any attachments are intended only for the individual
> or entity to which the message is addressed. This is a private
> message and may contain privileged information. If you are neither
> the intended recipient nor the agent responsible for delivering the
> message to the intended recipient, you are hereby notified that any
> review, retransmission, dissemination, or taking of any action in
> reliance upon, the information in this communication is strictly
> prohibited, and may be unlawful. If you feel you have received this
> communication in error, please notify me immediately by returning this
> email to me and deleting it from your computer.