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

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

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>, adal.dev@xxxxxxxxxxxxxx*Subject*: [eigen] "plain": a new keyword for auto with implicit evaluation*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Sat, 16 Feb 2019 14:16:01 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=GrIRXT15DdeRp1jO33y4Q2dEN5xDqMadOM7OMXCBrbE=; b=jpOIwn02ACEKR2C133f5G0H1+AJZY329XR5z4+mqV+sorKjnjYcZNYL9oH5CVJnvXf /6IQFRGbBpcbXaKGJjv2rFehaeV9A1cRkEZvCai3pPE1zqLDSJu6p0c/IOicN0ie1+Dn joUe0n5VI0PEC1byigaE8zpNMC3625aDT/bJEksH294GiahKSbHu4I8Na0fGFi1SNbZm Ay+AxZKvdE4nKUMizeulv9rhXoFmu9PYAMC3PbZuhqDhAwlHdjbYze+p5M1eVGJQqBvF FD+kksrDZVo6bkL2F2emZLesq8pnfB2WQlTuZUM10jWbm6qol0lOLb9AFlYkRlmULFyu rjyg==

Hi,

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();

??

Actually, I just realized this is already possible in C++17 thanks to template deduction guides. The proof-of-concept implementation of such a "plain" is embarrassingly simple:

namespace Eigen {

template<typename T>

struct plain : T::PlainObject {

using Base = typename T::PlainObject;

using Base::operator=;

plain(const T& x) : Base(x) {}

};

}

Thats's all!

Ok, to be fair this is not strictly equivalent to auto+eval() because here decltype(C) != decltype(A*B)::PlainObject, but at a first glance this should not make much difference. This look to simple though. Am I overseeing some severe limitations?

Of course, you cannot write plain& or plain&& as you would do with auto but I cannot find an example where this would make a practical limitation compared to auto+eval().

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

Cheers,

Gaël

**Follow-Ups**:**Re: [eigen] "plain": a new keyword for auto with implicit evaluation***From:*David Tellenbach

**Messages sorted by:**[ date | thread ]- Prev by Date:
**The "star" problem, was Re: [eigen] ISO C++ working groups on Linear Algebra / Machine Learning** - Next by Date:
**Re: [eigen] ISO C++ working groups on Linear Algebra / Machine Learning** - Previous by thread:
**Re: The "star" problem, was Re: [eigen] ISO C++ working groups on Linear Algebra / Machine Learning** - Next by thread:
**Re: [eigen] "plain": a new keyword for auto with implicit evaluation**

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