Jeremy Howard wrote:
> @b = (1,2,3);
> @c = (2,4,6);
> @d = (-2,-4,-6);
> $sum = reduce ^_+^_, @b * @c + @d;
>
> should be evaluated as if it read:
>
> $sum = 0;
> $sum += $b[$_] * $c[$_] + $d[_] for (0..$#a-1));
>
> That is, no temporary list is created, and only one loop is required.
> </quote>
>
> This way, we use Perl's internal looping mechanisms, which can be at full C
> speed.
They will only be at full C speed if they are JIT compiled to what is equivalent
C code. i.e.
for(i=0; i<=n; i++)
sum += b[i]*c[i]+d[i];
Since the loop contents can be any expression, JIT compilation is needed to go
beyond what PDL currently provides (i.e. sumover($b*$c+$d) which is fast but
creates tmps)
Karl