[Pdx-pm] Math::GSL::Core

Jonathan Leto jaleto at gmail.com
Thu Dec 25 10:22:25 PST 2008


Howdy,

I was thinking of making something like

use Math::GSL::Core;

which would include the most commonly used Math::GSL modules,
something like Complex, Matrix, Vector, Eigen, Linalg, Errno, BLAS,
Const, and possibly a few others. This would only give you access to
the OO interface, if you wanted all of the low-level access to the
c-style functions (gsl_*) then you would do:

use Math::GSL::Core qw/:all/;

which would basically pass the :all to the corresponding modules.

My philosophy is thus: Optimize the OO interface for ease of use, but
expose the c-style interface for those wanting nothing but speed. The
trade off is that the OO interface is roughly 10 times slower but it
condenses 10-20 lines of code into one chainable method call. When you
find yourself chaining 3 or 4 methods like this:

# this code only works in the latest git bleed branch
use Math::GSL::Matrix;
printf "%.4f %.4f\n%.4f %.4f\n",
Math::GSL::Matrix->new(2,2)->identity->inverse->as_list;

OUTPUT:

1.0000 0.0000
0.0000 1.0000

the power of chainable method calls shines through.

This shows that the inverse of the identity matrix is
.....(drumroll).... the identity matrix. Good to be sure, don't trust
a numerical algorithm farther than you can throw it! The equivalent
code in low-level routines is probably about 20 lines with proper
error checking.

What do y'all think about this and do you have any other hints for
making Math::GSL more user-friendly?

Cheers and Happy Holidays,

Math::GSL blog: http://leto.net/code/Math-GSL

-- 
[---------------------]
  Jonathan Leto
jaleto at gmail.com


More information about the Pdx-pm-list mailing list