> I probably should (have?) put something in range's documentation about this
> -- but your life example will both run faster and be shorter if you range()
> the other way:  instead of getting your neighbor counts with
>
>     $n =
> ($a->range(ndcoords($a)-1,3,3)->reorder(2,3,0,1)->sumover->sumover)-$a;
>
> you could instead use:
>
>     $n = ( $a->range(ndcoords(3,3)->clump(1,2)-1, [$a->dims], p)->sumover )
> - $a;

*scratches head* wow, that's very neat! I see what you're doing, but
I'm still trying to grok how it works...

More importantly, p silently fails without single quotes around it -
that's why I stuck with using '3' instead:

perldl> $a = sequence(9,11)

perldl> p $a->range(ndcoords(3,3)-1,pdl([1,1]),'p')

[
 [
  [
   [98 90 91]
   [ 8  0  1]
   [17  9 10]
  ]
 ]
]

perldl> p $a->range(ndcoords(3,3)-1,pdl([1,1]),p)

[
 [
  [
   [ 0  0  0]
   [ 0  0  1]
   [ 0  9 10]
  ]
 ]
]


> Here, range() is faster because large range sizes run faster than large
> index variables (range() doesn't have to store as many index coordinates
> when building the transformed PDL).  You'll get a much smaller memory
> footprint and probably 30% faster runs.
>
> I post this here because I think this is a big oversight in the range()
> documentation...

Yes, please add it to the official PDL documentation. Tricks like this
are useful to know if someone is trying to squeeze some more
efficiency out. And maybe a note in the wiki in the PDL Tips and
Tricks section would be good too.

Matt

-- 
Matthew Kenworthy / Assistant Astronomer / Steward Observatory
933 N. Cherry Ave. / Tucson AZ 85721 / vox 520 626 6720

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to