Re: [eigen] "plain": a new keyword for auto with implicit evaluation

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


Hi Gaël,

as you all know here 'auto' does not always play well with Eigen, especially
for users who are not well aware of _expression_ templates [1]. So what about
an "auto" like keyword but with implicit evaluation:

    plain C = A * b;

which would have the same behavior as:

   auto C = (A*B).eval();

??

In principle I like the idea of having such a "keyword" but here are some
critical thoughts about this:

1. If a user is not familiar with the library to such an extend that he doesn't
know that auto should be avoided, how can we expect him to be aware of plain?
Therefore the advantage I see is to provide a way to avoid verbose syntax for
users that are aware of the auto problem.

2. Using plain (using the implementation you provided) can have performance
penalties in the case of object slicing:

MatriXi foo() {
  MatriXi a, b;
  plain c = a * b;
  return c;
}

Object slicing prevents copy elision! That said, you would somehow need to
communicate that you can use plain but shouldn't in that or that use case. Don't
know if it isn't easier to just remeber that auto should be avoided.

As a side note, yes we should add deduction guides for Array,Matrix,SparseMatrix
from expressions, but that's another topic.

There are a lot of awesome things possible if we enable C++17 (or even C++14)
functionality and I'm sure we should allow some of them some day. However, using
a deduction guide for this case could be problematic since there could be existing code
around that uses auto knowing that the result will be an _expression_.

Cheers,
DT


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