Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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__

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://442474]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-03-18 10:16 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (229 votes). Check out past polls.