Hello January

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.

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

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


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

Reply via email to