Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Lapack, inline and Perl

by ambrus (Abbot)
on Mar 26, 2005 at 12:37 UTC ( #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__


Comment on Re: Lapack, inline and Perl
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-12-21 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls