Dear Karl, > If you write things in the same element by element way as regular Perl > then PDL will be even slower. set() and at() are functions of last > resort.
Thanks for the explanation. > The idea of PDL is to use fast internal functions for vector ops. > What you want can be accomplished in one line with PDL's > Image2D::conv2d(...) and will be a bazillion times faster than regular > perl I imagined so much (although I just considered adding up slices of the matrix which would have the same effect). But this is not even the step that takes the most time. The initial filling up of the matrix with scores is what really takes a lot time. I have one scoring matrix, 20x20 (call it $scoring), containing a score for each pair of the amino acids. I have two sequences, which constitute the matrix that I am calculating. For each two amino acids from the two sequences, I look up the scoring matrix and enter the respective value into my main matrix ($matrix). I can't imagine of a way of doing it fast if set() and at() is slow. Is an assignement between elements of two piddles faster? Like that: set($matrix, $i, $j, at( $scoring, $p, $q) ) maybe a better way of doing that? Cheers j. > > Karl > > > On 10/02/2008, at 8:26 PM, January Weiner wrote: > > > Hello, > > > > in my program, I am using a matrix which has usually a size of > > 2000x2000 or > > similar. It contains short integers. The matrix is filled in one by > > one in > > a loop over rows and columns. > > > > The only calculation that I am doing with this matrix is averaging > > over a window sliding along the diagonals. Finally, I need to access > > each > > matrix element one after another in a loop to calculate something. > > > > At first, I used a regular Perl matrix, constructed as [ [ .... ], > > [ ... ], > > .... ]. This was quite slow and took a lot of memory (the memory > > footprint > > of my program grews up by roughly 50MB), so I googled and found PDL > > -- Perl > > Data Language. > > > > PDL is supposed to be much faster and to have a smaller memory > > footprint. > > > > While I can see the latter (the footprint is now negligible compared > > to the > > whole program), it is roughly three to four times slower than the > > regular > > perlish way. I am creating the matrix as follows [please bear with > > me -- I > > am not posting actual code, because it is rather complex, and you > > will see > > that answering my question doesn't require finding out whether my > > code is > > correct]: > > > > $matrix = short(zeroes($l1, $l2)) ; > > > > (where $l1 and $l2 are dimensions of the matrix), and accessing / > > setting > > the elements using at() and set(): > > > > set( $matrix, $i, $j, $value ) ; > > $value = at( $matrix, $i, $j ) ; > > > > There is another way of doing it using PDL::NiceSlice, which uses > > constructs like $matrix->($i, $j), but I found it to be even slower. > > > > QUESTION: Is this a normal behaviour? Is it normal that a standard > > perlish > > matrix is few times faster than the PDL implementation? Or should I > > start > > finding out where I messed things up? > > > > Thank you in advance, > > > > January > > > > > > > > -- > > ------------ January Weiner 3 ---------------------+--------------- > > Division of Bioinformatics, University of Muenster | Schloßplatz 4 > > (+49)(251)8321634 | D48149 Münster > > http://www.uni-muenster.de/Evolution/ebb/ | Germany > > > > _______________________________________________ > > Perldl mailing list > > [email protected] > > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > > -- ------------ January Weiner 3 ---------------------+--------------- Division of Bioinformatics, University of Muenster | Schloßplatz 4 (+49)(251)8321634 | D48149 Münster http://www.uni-muenster.de/Evolution/ebb/ | Germany _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
