cdherold has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I am about to start trying to use perl to do some matrix manipulation. I have been looking around the web and found that there is a module called Perl:Matrix as well as something called Perl Data Language (PDL).

Does anyone have experience with maxtrix manipulation in PERL and whether there is anything special I should focus on? Right now I'm thinking of just loading up Perl:Matrix and getting to it.

Chris Herold

Replies are listed 'Best First'.
Re: Matrix Manipulation with Perl
by halley (Prior) on Jun 28, 2005 at 00:11 UTC
    There are several modules for Matrix math, but most are only useful for lightweight occasional use. Any serious number crunching (where millions of iterations is just getting started) should be done in a native implementation.

    The PDL is native code, but I've found it to be a bit immature: a good implementation for some problems, but not as general-purpose as it may first appear.

    The good thing about Perl is that you can usually refactor quickly if you have to use some other module instead of the first one you try.

    --
    [ e d @ h a l l e y . c c ]

      Could you elaborate on precisely what you found immature about PDL?

      So I went and installed Math::Matrix, which does matrices ok, except I could not find a way to do an inverse (which I really really need) even though it said as the header for the documentation it could do inversion, but there was no routine for it.

      So then I decided to try the PDL because it said that it could do inversion and actually had a command called "inv" listed. I got PDL::Matrix and PDL::MatrixOps modules loaded up,

      root@admin PDL-2.4.2# perl -MPDL::Matrix -e shell
      root@admin PDL-2.4.2# perl -MPDL::MatrixOps -e shell
      root@admin PDL-2.4.2#

      but when I tried to run a simple program to confirm it was working I got this error:

      Can't locate object method "xchg" via package "PDL::Matrix" at /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi/PDL/Matrix.pm line 137.

      I am now lost. I do not know what this means except that there might be some module that I need loaded that I forgot to load. Any ideas?

      Chris Herold
        The above does not "get modules loaded up". It runs two Perl processes each of which load a given module, try to execute the string "shell" (which will evaluate to a string, doing nothing), then exit.

        Instead, the way forward is to run either perldl or pdl2 on the command line, which will load the PDL REPL. It has builtin help, and there is also the MetaCPAN page: https://metacpan.org/pod/perldl.

        Not that I know anything about PDL at all, but seeing as no one else has responded: can you pare down the simple program to show the error with as few lines as is reasonably possible? That way I could go and install this stuff here and try it out, for example. Or someone else might beat me to it <crossing fingers> ;-)