Why not extend array operations to full Fortran90 power ?
Timon Gehr
timon.gehr at gmx.ch
Wed Nov 16 14:50:12 PST 2011
On 11/16/2011 10:48 PM, Simen Kjærås wrote:
> On Wed, 16 Nov 2011 22:31:31 +0100, Xinok <xinok at live.com> wrote:
>
>> On 11/16/2011 2:08 PM, Joachim Wuttke <j.wuttke at fz-juelich.de> wrote:
>>> Compare
>>>
>>> (1) Y[] = X[]*X[];
>>> (2) Y[] = sin( X[] );
>>>
>>> With gdc 4.4.6,
>>> (1) compiles and executes as I expected, whereas
>>> (2) is not allowed (fails at compile time).
>>> Why?
>>>
>>> The semantics of (2) is unambiguous,
>>> and it works perfectly well in Fortran90.
>>> Allowing (2) would make D really attractive
>>> for formula-heavy mathematical work.
>>>
>>> - Joachim
>>>
>> I think vector operations are designed to avoid turning them into
>> loops. In (2), this would require several calls to sin().
>
> Really? How would you do Y[] = X[] * X[] without a loop?
In the special case that the type of X and Y is eg. float[4], use SIMD :o).
Joachim's example points out an performance limitation of the current
array vector operations:
if we have
Y[] = sin( X[] );
Then there is currently no way to implement an overload for sin such
that it can benefit from RVO. It should be able to write the sinuses
directly to Y, but it cannot.
That is merely syntax though.
copy(map!sin(X), Y); // good enough for me.
More information about the Digitalmars-d
mailing list