[SciPy-dev] gsl and scipy

pearu at scipy.org pearu at scipy.org
Fri May 3 17:51:25 EDT 2002


On Fri, 3 May 2002 arnd.baecker at physik.uni-ulm.de wrote:

> Personally I think that (at least for me) it boils down
> how much time it would cost to write a full wrapper for gsl
> (this seems also relevant for future upgrades of gsl).
> If most of this could be done automatically, this would be optimal.

I think the structure of gsl makes it difficult to automate the wrapping,
at least the parts where functions take struct arguments. See also
previous messages of this thread.

> Are there any example scripts for f2py2e which could be used to wrap some
> bigger library in an automatic way ?
> ((I havn't had a detailed look at f2py2e, but at first sight
> I could not find it ...))

Is lapack library big enough? If yes, then hit [1]:

cd LAPACK-3.0

f2py -c -m lp SRC/*.f -L/path/to/blas/lib -lblas

python
>>> import lp
>>> len(dir(lp))
1306
>>> lp.zlanht('1',4,[1,2,3,2],[4,5,2])
11.0
>>>
;-)

Though I discourage this kind of automatic wrapping (use it for small
libraries or if you want to claim having a complete wrapper to something).

To use the wrappers in an enjoyable way then some effort is needed for
designing the interfaces. For example, one hardly needs all the
functions from a library (usually big libraries contain a number of
auxiliary functions). In addition, C/Fortran functions tend to take many
arguments that are releated to each other -- with some modifications to
signature files one can reduce the number of required arguments
considerably for calling these functions from Python.

For example, scipy/linalg uses f2py2e to wrap LAPACK and BLAS routines
using some helper scripts to reduce the design effort for routines with
the same functionality but with the different types of arguments.

Pearu

[1] I acctually did that. Here follows some useless statistics:
Constructing the wrapper (including reading the source
files and compiling) took approx 30 minutes on an 1GHz Pentium III,
memory consumption was approx. 35MB. The resulting wrapper code
(lapackmodule.c) was 10.5MB in size having 280000 lines of C code, LAPACK 
source itself is only a bit larger.





More information about the SciPy-Dev mailing list