Thank you very much,
in fact I just do the first steps in PDL.
With $table->sumover it does not need to loop, indeed!
The sever step solves my issue in the original code too.
Thanks again.
 
VE
[email protected]
02.09.2013 


----- Folgende Nachricht wurde empfangen ----- 


Absender: Derek Lamb 
Empfänger: wanderdoc 
Zeit: 2013-09-02, 05:51:53
Betreff: Re: [Perldl] Run out of memory while modifying the piddle
There are probably better ways to do what you're doing, but I'm assuming this 
is a minimum working example from a more complex use case.  If not, you might 
like to just do a $table->sumover and then have a look at ran_shuffle in 
PDL::GSL::RNG.  If would probably accomplish the same thing, but much much 
quicker (4 lines, and no for loops).  e.g.,


$table = random(10,$size)->rint;
$sums = $table->sumover;
$rng = PDL::GSL::RNG->new('default');
$rng->ran_shuffle($sums); #sums is shuffled in place.



For your code, my guess is that the last row "$table = $table(,$rkeep);" is 
causing you trouble.  It is generating a new child piddle for every iteration, 
but keeping the parent piddle in memory (though now inaccessible, since you 
named the new variable the same thing as the parent).  All of those slice 
operations are being stored (all the way back to the original 10 x 900 piddle.  
You may get around this with a call to sever:


$table = $table(,$rkeep)->sever;


Doing that with your code allowed me to push past the segfault limit.


best,
Derek


On Sep 1, 2013, at 10:27 AM, VE wrote:


Dear All,

I played further with this  example 
http://mailman.jach.hawaii.edu/pipermail/perldl/2013-August/008102.html
and run into the following issue now.

The below code should generate a 2D piddle of random 0 and 1, then take a 
random row, calculate a sum of it, then cut this row off the piddle and do so 
again until there are rows.

I run "out of memory" if the initial piddle has more than 900 rows. In fact, I 
wanted to take a lot more :)

Where is my mistake?

Thank you in advance!
VE

The code:
#!/perl
use strict;
use warnings;
use PDL;
use PDL::NiceSlice;
use PDL::Math;
my $size = 900; # the initial number of rows.
my $table = random 10, $size;
$table = rint $table;
my @sums;
for ( 1 .. $size)
{
 my ( $col, $row ) = dims $table;
 my $row_x = $row > 1 ? int(rand($row)) : 0; 
 my $chosen = $table->dice_axis(1, $row_x);
 push @sums, sum $chosen;
 my $rows_to_remove = pdl($row_x); # rows to be removed
 my $rvals = sequence($table->dim(1)); # all rows indexes
 my $rkeep = setops($rows_to_remove, 'XOR', $rvals); # rows to keep
 $table = $table(,$rkeep); 
}
# print scalar @sums, $/; # or whatever...






---
[email protected]
01.09.2013 
_______________________________________________
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