If you want something that perhaps is more readable but probably less efficient & certainly less general than Derek's solution this one might work:

  use PDL::NiceSlice;
  sub setme_jb {
     my ($x, $y, $value) = @_;

     # Error checking non-existent.

    # Find those positions that are != 0
   my $ii = which($found->index2d($x, $y) != 0);
   if ($ii->nelem() == 0) {
       return;
   }

   # Set the relevant parts.
   $found->index2d($x($ii), $y($ii)) .= $value;

}

This is really written as a 2D version and doesn't generalise very well, but I thought you might find it useful as an alternative approach (extending this using whichND and indexND is a non-trivial task btw as it seems like whichND is a bit broken...)

                                                Cheers,
                                                        J.

On 3 Jan 2008, at 23:30, [EMAIL PROTECTED] wrote:

Quoting Derek Lamb <[EMAIL PROTECTED]>:

And since indexND is implemented as a call to range, this might work for
you.

It does! Thanks. My real data has sped up from about 500 loops per hour to
8000 in 4 minutes. Obviously a massive improvement.

It may or may not be easier for you to read at the moment!

Right now, it's totally incomprehensible. But I'm no longer kicking a dead Lamborghini down the highway, and learning from code which works is always
easier than trying to code something you don't understand.

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


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

Reply via email to