Re: [eigen] is returning Eigen::Ref objects legit?

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


On 20.05.2013 19:06, Sébastien Barthélémy wrote:
ok, got it, I should have returned the Ref object by value. It seems I

Yes, that works as intended, but it has a small drawback that Ref<const FixedSizeMatrix> objects optionally contain a copy of the passed matrix (which is only used if the passed matrix does not have direct access). However, even if it's not used, passing that object by value might cause some significant copy-overhead (very compiler-dependent, look for Return Value Optimization and Copy Elision if you are interested in details).

I do see the usability advantage of that trick, but maybe we should allow this only when explicitly requested so that no silent overhead is introduced. Another situation where silent overhead is introduced is passing objects with non-trivial inner stride, e.g. passing a row of a (column major) matrix. This causes copying all elements, although it could be accessed element-wise. I know there is the possibility to have Ref objects have dynamic stride, but I think it might be not obvious to the user (i.e. the lazy one, who stopped reading the docu after the first paragraph) when that does make a difference.


expect Eigen to be a bit too magical.

Returning references to temporaries is more a C++ issue. As this issue is well known, most compilers are able to warn about that (as you said in your original mail).

Christoph


--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252
----------------------------------------------



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/