www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - expression templates vs D arrays

reply Jay Norwood <jayn prismnet.com> writes:
I've been reading about the use of expression templates in this blitz page,
which provides arrays implemented by c++ templates.  They have some convenient
features, such as array initialization with auto-incrementing array index
values in the expressions and applying a cast operator to an entire array
within an expression.   Do  D built-in array operations and initialization
include these type of features, or would you need to create some similar D
template implementation to guarantee the efficient expression evaluation and
similar initialization features?   

http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80
Dec 07 2011
parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Wed, 07 Dec 2011 23:27:41 -0500, Jay Norwood <jayn prismnet.com> wrote:

 I've been reading about the use of expression templates in this blitz page,
which provides arrays implemented by c++ templates.  They have some convenient
features, such as array initialization with auto-incrementing array index
values in the expressions and applying a cast operator to an entire array
within an expression.   Do  D built-in array operations and initialization
include these type of features, or would you need to create some similar D
template implementation to guarantee the efficient expression evaluation and
similar initialization features?

 http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80
Built-in? No, not everything. But std.range, std.array and std.algorithm have a lot of the convenience features you're looking for. Actual D array operations, i.e. x[] = y[] + z[] * b;, are more efficient than expression templates. Currently, what you can do in an array op is somewhat limited, but generalization, i.e. x[] = sin(iota(0,x.length)[]) + y[] is on Don's todo list.
Dec 07 2011
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/7/2011 11:11 PM, Robert Jacques wrote:
 On Wed, 07 Dec 2011 23:27:41 -0500, Jay Norwood <jayn prismnet.com> wrote:

 I've been reading about the use of expression templates in this blitz page,
 which provides arrays implemented by c++ templates. They have some convenient
 features, such as array initialization with auto-incrementing array index
 values in the expressions and applying a cast operator to an entire array
 within an expression. Do D built-in array operations and initialization
 include these type of features, or would you need to create some similar D
 template implementation to guarantee the efficient expression evaluation and
 similar initialization features?

 http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80
Built-in? No, not everything. But std.range, std.array and std.algorithm have a lot of the convenience features you're looking for. Actual D array operations, i.e. x[] = y[] + z[] * b;, are more efficient than expression templates. Currently, what you can do in an array op is somewhat limited, but generalization, i.e. x[] = sin(iota(0,x.length)[]) + y[] is on Don's todo list.
I'll add that you can do expression templates in D, but there's no point to them.
Dec 07 2011
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 12/08/2011 08:55 AM, Walter Bright wrote:
 On 12/7/2011 11:11 PM, Robert Jacques wrote:
 On Wed, 07 Dec 2011 23:27:41 -0500, Jay Norwood <jayn prismnet.com>
 wrote:

 I've been reading about the use of expression templates in this blitz
 page,
 which provides arrays implemented by c++ templates. They have some
 convenient
 features, such as array initialization with auto-incrementing array
 index
 values in the expressions and applying a cast operator to an entire
 array
 within an expression. Do D built-in array operations and initialization
 include these type of features, or would you need to create some
 similar D
 template implementation to guarantee the efficient expression
 evaluation and
 similar initialization features?

 http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80
Built-in? No, not everything. But std.range, std.array and std.algorithm have a lot of the convenience features you're looking for. Actual D array operations, i.e. x[] = y[] + z[] * b;, are more efficient than expression templates. Currently, what you can do in an array op is somewhat limited, but generalization, i.e. x[] = sin(iota(0,x.length)[]) + y[] is on Don's todo list.
I'll add that you can do expression templates in D, but there's no point to them.
Expression templates in D are syntactically more limited because it is impossible to overload the 'not' and comparison operators. Why is there no point to them?
Dec 08 2011
next sibling parent so <so so.so> writes:
On Thu, 08 Dec 2011 14:16:46 +0200, Timon Gehr <timon.gehr gmx.ch> wrote:

 Expression templates in D are syntactically more limited because it is  
 impossible to overload the 'not' and comparison operators. Why is there  
 no point to them?
I also want to know why. Another thing is that ET problem has no solution in C++. Aliasing, which i think with in D it might be possible.
Dec 08 2011
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/8/11 6:16 AM, Timon Gehr wrote:
 Expression templates in D are syntactically more limited because it is
 impossible to overload the 'not' and comparison operators.
I think all operators must be overloadable. The key is to overload them _properly_. C++ botched a few (&&, ||, comma, ++, --) and that gave a bad reputation to the whole notion. We've shown in D that e.g. ++ and -- are great to overload because it's done right. We can and we should do the same with all operators. Andrei
Dec 08 2011
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/8/11 1:55 AM, Walter Bright wrote:
 I'll add that you can do expression templates in D, but there's no point
 to them.
There is, just for other things such as dimensional analysis. Andrei
Dec 08 2011