PyrexGsl
Introduction
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
- Mathematical Functions
- Complex Numbers
- Polynomials
- Special Functions
- Vectors and Matrices
- Permutations
- Combinations
- Sorting
- BLAS Support
- Linear Algebra
- Eigensystems
- Fast Fourier Transforms
- Numerical Integration
- Random Number Generation
- Quasi-Random Sequences
- Random Number Distributions
- Statistics
- Histograms
- N-tuples
- Monte Carlo Integration
- Ordinary Differential Equations
- Interpolation
- Numerical Differentiation
- Chebyshev Approximations
- Series Acceleration
- One dimensional Root-Finding
- One dimensional Minimization
- Least-Squares Fitting
for which examples from the GSL manual are provided.
Example
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 mbessel.so -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
mbessel.main()
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.
Dependencies
- GSL 1.4
- Pyrex 0.9
- Python >= 2.2
To run some of the tests Numeric is needed.
The programs have been tested only on Linux.
Download
PyrexGsl 0.0.6
History
Related projects
If you have comments, please write to the
author.