Array operations -- not actually so difficult

Bill Baxter wbaxter at gmail.com
Fri Dec 15 08:50:53 PST 2006


Don Clugston wrote:
> Array operations are one of the very few 2.0 features that haven't made 
> it into 1.0. My experiments into expression templates suggest that it 
> might not be very complicated after all.
> 
> Consider something like a dot product,
> 
> real a[], b[], c[];
> real d = dot(a+b, c);
> 
> For performance, it would be better if the compiler actually *didn't* 
> evaluate a+b. Instead, that should compile to:
> 
> real sum = 0;
> for (int i=0; i<c.length; ++i) {
>      sum+=(a[i]+b[i])*c[i];
> }
> d=sum;
> 
> In fact, we could create a fantastic library implementation of array 
> operations with a tiny bit of syntactic sugar:
> instead of generating an error message for array operations, look for an 
> opXXX function, and treat it the same way the implicit array properties 
> work.

How does that result in the above code for dot product?
Looks to me like if all you have is calling opXXX functions the above 
dot would still become two loops with a tmp for the a+b.

--bb



More information about the Digitalmars-d mailing list