John M. Dlugosz 提到:

> = on Parallelized parameters and autothreading
>     use autoindex;
>     do { @c[$^i, $^j, $^k, $^l] = @a[$^i, $^j] * @b[$^k, $^l] };
> Shouldn't those be semicolons?  Ditto for subsequent examples.
> Also, what does the "do" do?  I think it is only meaningful if there was 
> something using this block's return value.  I suspect it is a relic of p5 
> notation.

No, something more subtle is going on -- the "do STATEMENT" notation
sees a stand-alone block in statement position, so it's automatically
called with no arguments.

Here is a rewrite of that section starting from line 1044 onward.
Sanity-check before I check it in?

In the abstract (and often in the concrete), this puts an implicit
loop around the block of the closure that visits all the possible
subscript values for that dimension (unless the parameter is actually
supplied to the closure, in which case the supplied value is used as
the slice subscript instead).

This implicit loop is assumed to be parallelizable.
So to write a typical tensor multiplication:

    Cijkl = Aij * Bkl

you can simply call a closure with no arguments, allowing the C<autoindex>
pragma to fill in the defaults:

    use autoindex;
    -> $i, $j, $k, $l { @c[$i; $j; $k; $l] = @a[$i; $j] * @b[$k; $l] }();

or you can use the C<do STATEMENT> syntax to execute a stand-alone closure,
which also implicit loops:

    use autoindex;
    do -> $i, $j, $k, $l {
        @c[$i; $j; $k; $l] = @a[$i; $j] * @b[$k; $l]

or even use placeholder variables instead of a parameter list:

    use autoindex;
    do { @c[$^i; $^j; $^k; $^l] = @a[$^i; $^j] * @b[$^k; $^l] };

That's almost pretty.

Reply via email to