PyrexGsl provides a Pyrex interface for the GNU Scientific Library (GSL).

Pyrex is a language for writing code that mixes Python and C data types, and compiles it into a C extension module for Python.

Currently there are bindings for the modules described in the following chapters of the GSL manual

for which examples from the GSL manual are provided.


Consider the file mbessel.pyx
include "gsl.pxi"

def main():
  cdef int i
  cdef double s
  s = 0.0
  cdef int N
  N = 1000000
  for i from 1 <= i <= N:
    s = s + gsl_sf_bessel_J0 ((1.0 + i)/i)*gsl_sf_bessel_J0 ((2.0 + i)/i)
  print s
With pyrexc mbessel.pyx the source file mbessel.c is generated.
Compile with
gcc -fPIC -I$(PYINCLPATH) -I$(GSLPATH) mbessel.c
gcc -shared mbessel.o -o -lgsl -lgslcblas -lm
where PYINCLPATH is the directory with the Python headers (e.g. /usr/include/python2.3/ ) and GSLPATH is the directory with the GSL headers (e.g. /usr/include/gsl ).
Now the module can be called from a Python program
import mbessel
On a linux 386 machine it runs within 10% from the speed of the corresponding C program; this is a typical speed difference when the extension function performs a lot of operations.


To run some of the tests Numeric is needed.
The programs have been tested only on Linux.


PyrexGsl 0.0.6


Related projects

If you have comments, please write to the author.