Re: [eigen] Lazy evaluation bug, feature, or PEBKAC? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
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.
Ouch.
>
> 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.
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.
> 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
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.