[SciPy-user] C/Fortran callbacks [was "integrate.odeint"]

Robert Kern rkern at ucsd.edu
Sun Oct 17 10:26:01 CDT 2004


Travis Oliphant wrote:

> We have been interested in something like this for a while.    I would 
> like to see the user be able to write c and/or fortran code to compute 
> the function to be integrated.

How about this for a sketch:

C or Fortran function bodies can be defined as a Python string a la weave.

   C: We use the weave framework to make an extension module with the 
function body embedded into a properly defined function.

   Fortran: The Fortran code will be put into a separate Fortran file as 
a subroutine. A C extension module is written out which will reference 
the subroutine.

The extension module will create a CObject which contains a direct 
function pointer to the function.

f2py could be modified (I hope) to accept one of these CObjects as an 
valid input for a callback.

An additional nicety would be for f2py to (either optionally or 
additionally) provide these CObjects for any subroutine wrapped by f2py. 
That way, one could write a single Fortran file (with helpful "cf2py" 
comments) with all of one's callbacks instead of semi-inline weave 
code*. In fact, if this modification is made to f2py, then both the C 
and Fortran can use it as the back end for generating the extension 
module which holds the user-defined callback.

Pearu, do you have any feelings about the feasibility of this sketch?

* Not to disparage weave, but I've found that although I'm too young to 
have been "raised" in a Fortran culture, f2py makes writing new FORTRAN 
(77 even!) code my preferred method for making fast, array-oriented 
computational routines.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the SciPy-user mailing list