Regarding the text just before where you rewrote, then the compiler adds defaults for you, something like:
-> $x = @foo.shape[0].range, $y = @foo.shape[1].range { @foo[$x;$y] } where each such range is autoiterated for you. That doesn't really work. If you used these defaults instead of autoindex, with a real example like -> $i, $j, $k, $l { @c[$i; $j; $k; $l] = @a[$i; $j] * @b[$k; $l] }(); the same Range object is used in all occurances of the variable. As an aside, the use of a Range value in a subscript that is written as a simple scalar variable will make a mess of the compiler's determining that it was supposed to be a single value not a slice! I think it would not turn into a list but would fail as not being a number. In any case, if * worked between lists as returned by the slices, it would not do anything like the implied iteration would do, and it would not be stuffed back into the @c in any semblance of an answer. So, the example of @foo[$x;$y] is pointless, and saying that it uses a Range as the default does not illustrate what it really means. So, (1) use an example that has the salent features of a dependant and a defining occurance of the index; and (2) show (near) equivilent code that is correct. My stab at it: (please check) " -> $x, $y { @foo[$x;$y] = f($x)[EMAIL PROTECTED] } becomes for @foo.shape[0].range Z @foo.shape[1].range-> $x, $y { @foo[$x;$y] = f($x)[EMAIL PROTECTED] } where the iteration limits on the variables are determined by their use in subscripts. For the exact rules of which subscript usage is deemed to be the defining occurance, see the PDL docs. " I have more thoughts on this feature, but I'll save it for later. I think it will jell more after I digest some of Larry's posts today. --John Audrey Tang audreyt-at-audreyt.org |Perl 6| wrote: > 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. > " > > >