Jonathan Leto: November 2008 Archives

Updates and Promises

| | Comments (0) | TrackBacks (0)
Yes, it has been quiet here but development on Math::GSL has steadily continued behind-the-scenes. I just pushed a dev release (0.15_04) to CPAN, it should be hitting a mirror near you soon. If the CPANTesters don't find anything horribly wrong with it, it will probably become 0.16. Some new features of 0.16 will be:

  • New subsytems: VectorComplex and MatrixComplex
  • Operator overloading for addition and subtraction with vectors
  • Added example: examples/matrix/nonsymmetric_eigen
        Shows how to find the eigenvalues of a nonsymmetric matrix
  • Added copy() method to vectors
  •  Improved Vector docs
  • Sped up vector dot products by 15x using BLAS function gsl_blas_ddot
        NOTE: using gsl_blas_ddot($x->raw,$y->raw) directly is still about 10 times faster 
              than $x * $y due to error checking and function call overhead
  • Separated POD and Perl code out of SWIG interface files, yay for proper syntax highlighting
  • Added stub test files for Heapsort, IEEEUtils, Multimin, Siman, Wavelet2D
  • All test files now keep track of how many tests should run and other important infrastructure changes

Only a few of the changes are user-facing but they are important in terms of the long-term development and health of Math::GSL. 

While I have been making these back-end changes I have been prototyping a web-based interface to Math::GSL using jQuery. I have many functional parts but no coherent interface that I am willing to inflict on users. But I promise you that soon you will be able to use Math::GSL via your browser and bypass the whole "what-do-you-mean-i-have-to-compile-it" issue. 

Complex Eigenvalues with Math::GSL

| | Comments (0) | TrackBacks (0)
After a question arose recently about finding complex eigenvalues of non-symmetric matrices, I wrote this example to show how it can be done with Math::GSL. The current example is called examples/matrix/nonsymmetric_eigen in the Math::GSL source, which will be in the 0.16 Math::GSL release. It uses the gsl_eigen_nonsymmv() function to do all the hard work, the rest is twiddling complex numbers. The documentation for this can be found with perldoc Math::GSL::Eigen or here.(The HTML rendering of the POD needs some work...) You can read the original C documentation for this function here.

 It is a well known theorem of linear algebra that symmetric matrices can have only real eigenvalues. Thus it is much easier to find eigenvalues of symmetric matrices because there is no possibility of complex numbers arising. You can do this with Math::MatrixReal, which is written in pure-Perl.

The output of examples/matrix/nonsymmetric_eigen looks like:

Finding eigenvalue/eigenvectors for
[ 0  -1 ]
[ 1   0 ]

Eigenvectors:

u = (0.707106781186547,-0.707106781186547i)
v = (0.707106781186547,0.707106781186547i)

Eigenvalues:

lambda_0 = i
lambda_1 = -i


By the way, sqrt(2)/2 = 0.707106...

I am not quite happy with how long the program is, mainly because I have not written a Perlish interface around Complex Vectors and Matrices yet, so it is all in that script right now. The stringification could be built into the object and therefore reduce the length of that code dramatically.

Inside Look of Math::GSL

| | Comments (0) | TrackBacks (0)
Here is a breakdown of how many lines of code (roughly) are in different languages in the Math::GSL codebase:

  • 280889 lines - XS ( C-like Perl internals autogenerated by SWIG)
  • 60181 lines  - Total Perl (generated by SWIG)
  •  22941  lines- Hand-written Perl 
    •  8617 lines - Tests
    • 13731 lines - POD (this actually includes some Perl implementation, probably <5%). Much of this was autogenerated from the GSL C documentation and reformatted, but it stills needs work, especially in making the POD render to HTML in a more pleasant way.
  • 1112   lines - SWIG
The reason why Math::GSL requires something like SWIG becomes very apparent. The SWIG interface files are roughly 1/280th the length of the raw XS source code. No reasonable  person would be hacking on Perl internals, but not even a reasonable Perl hacker wants to write all that error checking boilerplate cruft. Thanks SWIG!

This was made possible by ripping all Perl code out of the SWIG interface files and putting them in the pod/ directory. It is not strictly POD but a simple naming scheme was key and the majority of the files do happen to be POD, so whatev. And now vim correctly syntax highlights the files! I think there is something to be said for sticking to one language per file. 

Post-Mentor-Summit Wrap Up

| | Comments (0) | TrackBacks (0)
I took a bit of a break after releasing Math::GSL 0.14 and tried not to stare at a screen too much  during the GSOC08 conference, when I could be interacting with open source developers from around the world IRL. I met developers from Git, Xmms2, VLC, PHP, Zikula, OpenAFS, Boost, Jikes RVM, Squeak, MusicBrainz, Worldforge, Minix3, the list goes on. People shared many ideas about making sustainable open source projects, getting and keeping members in your community and dealing with "troublesome" members.  Daniel Svensson from Xmms2 also showed me some git-fu relating to rebasing.

But that doesn't mean that Math::GSL development has come to a halt! Since 0.14 Thierry added operator overloading for addition in Vector. This sparked my interest and I then did subtraction. The current code will vectorize operations that you learn "don't make sense" in grade school, such as: $v - 5 , where v is a vector. Math::GSL will go ahead and subtract 5 from every element in $v. You can also do 2 + $v and you will get a new vector where 2 has been added to each element of $v.


Also, I reorganized the directory structure so that all SWIG interface files are now in the swig/ subdirectory, instead of clogging up the root directory. All SWIG-generated XS code and object files are thrown in there as well. This should make the Math::GSL codebase easier to navigate. 

About this Archive

This page is a archive of recent entries written by Jonathan Leto in November 2008.

Jonathan Leto: October 2008 is the previous archive.

Jonathan Leto: December 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Screw you, spammers! Clicky Web Analytics