Well, I had to use a few Math::GSL::Linalg functions, so I wrote
a few simplistic Math::GSL::{Vector,Matrix} to PDL “and back
again” conversion functions (MIME'd.)
BTW, are there any plans to provide an interface to Math::GSL
from within the PDL framework?
--
FSF associate member #7257
### e0b620da-4c12-11e0-8626-00195b7187be.pm -*- Perl -*-
### Ivan Shmakov, 2011
## This code is in the public domain.
### Code:
# use Data::Dump qw (pp);
require Math::GSL::Matrix;
require Math::GSL::Vector;
require PDL::Lite;
sub as_list_ref {
my ($m) = @_;
return undef
unless defined ($m);
my @a
= $m->as_list ();
## .
\@a;
}
sub as_pdl {
my ($m) = @_;
my $ref
= as_list_ref ($m);
return undef
unless (defined ($ref));
## .
PDL->pdl ($ref);
}
sub matrix_as_pdl {
my ($m) = @_;
## .
as_pdl ($m)->reshape ($m->cols (), $m->rows ());
}
sub pdl_as_matrix {
my ($pdl) = @_;
my @dims
= reverse ($pdl->dims ());
my $m
= Math::GSL::Matrix->new (@dims);
for (my $i = 0; $i < $dims[0]; $i++) {
my @l
= $pdl->mslice ([], [$i])->list ();
$m->set_row ($i, \@l);
}
## .
$m;
}
sub pdl_as_vector {
## NB: untested
my ($pdl) = @_;
my @values
= $pdl->list ();
## .
Math::GSL::Vector->new (\@values);
}
### Emacs trailer
## Local variables:
## indent-tabs-mode: nil
## fill-column: 72
## End:
### e0b620da-4c12-11e0-8626-00195b7187be.pm ends here
pgpQIfByIiJNQ.pgp
Description: PGP signature
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
