Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Lapack, inline and Perl

by ambrus (Abbot)
on Mar 26, 2005 at 12:37 UTC ( [id://442474]=note: print w/replies, xml ) Need Help??


in reply to Lapack, inline and Perl

If you can install octave, then you could try using Inline::Octave (which I've never tried), or just call octave directly. Octave is a free matrix manipulation program similar to matlab, and it has some lapack functions.

Here's a quick example script that calculates the determinant of a 2x2 matrix with octave.

#!perl use warnings; use strict; my $OCTAVE = "octave"; use File::Temp "tempfile"; my($datafile, $dataname) = tempfile; my($cmdfile, $cmdname) = tempfile; my @matrix = ( [3.5, 1.2], [-0.9, 4.5], ); my $mrows = @matrix; my $mcols = @{$matrix[0]}; print $datafile pack("d*", map { @$_ } @matrix) or die "error writing data: $!"; close $datafile or die "error closing data: $!"; print $cmdfile qq{ dataname = "$dataname"; % we trust tempfile not to return wier +d characters in filename mcols = $mcols; mrows = $mrows; } . q{ page_screen_output = 0; [datafile, msg] = fopen(dataname, "r"); if (datafile < 0) error ("error opening datafile: %s", msg); e +ndif; d = fread(datafile, mrows * mcols, "double"); % you should che +ck for errors here fclose(datafile); matrix = reshape(d, mcols, mrows).'; result = det(matrix); fwrite(stdout, result, "double"); % check for errors here too }; close $cmdfile or die "error closing data: $!"; open my $octave, "-|", $OCTAVE, "-q", $cmdname or die "cannot launch octave: $!"; my $result = unpack("d*", do { local undef $/; <$octave>; }); close $octave or die "could not close octave: $!"; $? and die "octave died"; print $result, "\n"; __END__

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://442474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found