Thread overview
Easy vectorization
Jun 07, 2005
Lionello Lunesu
Jun 07, 2005
zwang
Jun 07, 2005
James Dunne
Jun 08, 2005
Lionello Lunesu
Jun 08, 2005
Lionello Lunesu
Jun 07, 2005
Knud Sørensen
Jun 08, 2005
Lionello Lunesu
June 07, 2005
Hey, just an idea for 1.0:

What if the compiler would generate multiple calls to a function if you pass an array of values (instead of a single value)?

Examples:

float[] a;
sin(a) // would generate a "foreach"
float[] b;
atan2(a,b) // would generate a single "foreach" (will throw/assert if sizes
differ)
atan2(4,a) // same as before, but now with a constant for the first
parameter.

Seems easy enough to do, just an extended type-check. The type of the array should still match, of course.

L.


June 07, 2005
Lionello Lunesu wrote:
> Hey, just an idea for 1.0:
> 
> What if the compiler would generate multiple calls to a function if you pass an array of values (instead of a single value)?
> 
> Examples:
> 
> float[] a;
> sin(a) // would generate a "foreach"
> float[] b;
> atan2(a,b) // would generate a single "foreach" (will throw/assert if sizes differ)
> atan2(4,a) // same as before, but now with a constant for the first parameter.
> 
> Seems easy enough to do, just an extended type-check. The type of the array should still match, of course.
> 
> L. 
> 
> 

Looks ambiguous.  What if there exists an overloaded function that takes an array of values?
June 07, 2005
In article <d83vof$27cc$1@digitaldaemon.com>, zwang says...
>
>Lionello Lunesu wrote:
>> Hey, just an idea for 1.0:
>> 
>> What if the compiler would generate multiple calls to a function if you pass an array of values (instead of a single value)?
>> 
>> Examples:
>> 
>> float[] a;
>> sin(a) // would generate a "foreach"
>> float[] b;
>> atan2(a,b) // would generate a single "foreach" (will throw/assert if sizes
>> differ)
>> atan2(4,a) // same as before, but now with a constant for the first
>> parameter.
>> 
>> Seems easy enough to do, just an extended type-check. The type of the array should still match, of course.
>> 
>> L.
>> 
>> 
>
>Looks ambiguous.  What if there exists an overloaded function that takes an array of values?

Now we're just getting lazy =P.  Yes, it is ambiguous for the exact reason specified.

Just for argument's sake, where do you store your return values from sin(a)
where (float[] a) if it's implicitly converted into a foreach loop?

Regards,
James Dunne
June 07, 2005
How is that better than the old suggestions for vectorization ?

http://all-technology.com/eigenpolls/dwishlist/index.php?it=10 http://www.google.com/custom?domains=www.digitalmars.com&q=vectorization&sa=Search&sitesearch=www.digitalmars.com&client=pub-5628673096434613&forid=1&ie=ISO-8859-1&oe=ISO-8859-1&safe=active&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3AFFFFFF%3BALC%3A000000%3BLC%3A000000%3BT%3A0000FF%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BLH%3A50%3BLW%3A270%3BL%3Ahttp%3A%2F%2Fwww.digitalmars.com%2Fdmlogo.gif%3BS%3Ahttp%3A%2F%2F%3BFORID%3A1%3B&hl=en

On Tue, 07 Jun 2005 13:43:20 +0300, Lionello Lunesu wrote:

> Hey, just an idea for 1.0:
> 
> What if the compiler would generate multiple calls to a function if you pass an array of values (instead of a single value)?
> 
> Examples:
> 
> float[] a;
> sin(a) // would generate a "foreach"
> float[] b;
> atan2(a,b) // would generate a single "foreach" (will throw/assert if sizes
> differ)
> atan2(4,a) // same as before, but now with a constant for the first
> parameter.
> 
> Seems easy enough to do, just an extended type-check. The type of the array should still match, of course.
> 
> L.

June 08, 2005
| How is that better than the old suggestions for vectorization ?


Uh... Syntax?

L.


June 08, 2005
| Looks ambiguous.  What if there exists an overloaded function that takes | an array of values?

You solve that the same way similar problems are already solved:

If you have a func(int) and call it with a short, it'll convert the short to an int, but if you also have func(short) then that's the one being called.

L.


June 08, 2005
| Now we're just getting lazy =P.  Yes, it is ambiguous for the exact reason | specified.

If we weren't we wouldn't have invented in the PCs and programming languages in the first place :-)

| Just for argument's sake, where do you store your return values from
sin(a)
| where (float[] a) if it's implicitly converted into a foreach loop?

Well, sin is maybe a strange example, but I guess the call to sin with an array results in an array with the return values. Seems easy enough to implement.

Maybe it's tricky though, a "sin(a)" can be very slow and might get easily overlooked for a bottleneck.

L.