January Weiner <> writes:
> 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.
If I'm reading you correctly, all your calculations involve getting a
value from the matrix, processing it in pure perl and then setting it
back. That is not how you get good speed from PDL. You want to move as
many calculations as you can to the PDL operators, especially those
operators that can act on groups of values.
I only have very limited knowledge of PDL, but it seems to me that you
could probably do your averaging by using the PDL projection
operators. See
<http://www.johnlapeyre.com/pdl/pdldoc/newbook/node4.html#SECTION00440000000000000000>
and the section immediately after that.
--
Joost Diepenmaat | blog:
http://joost.zeekat.nl/ | work:
http://zeekat.nl/