[SciPy-dev] Cython, f2py and GSoC

Dag Sverre Seljebotn dagss@student.matnat.uio...
Thu Mar 26 14:43:20 CDT 2009


Sturla Molden wrote:
> On 3/26/2009 3:45 PM, Dag Sverre Seljebotn wrote:
> 
>> Though we could always skip wrapping of functions which already are 
>> declared BIND(C), that's actually a nice idea. This would make it 
>> possible to write a wrapper manually and skip this overhead in extreme 
>> situations (where the Fortran compiler also cannot inline the call), 
>> while still having Python bindings generated.
> 
> 
> If the idea is to take a Fortran module and autogenerate an .f03 file 
> with C bindings and a corresponding C/C++ header, I don't really see 
> where Cython comes in. Such a tool would be useful beyond the Python 
> community.

Indeed. Thanks for bringing that up. If somebody had already done the 
"f2c" (f2py with C backend) part I'm sure both me and Kurt would like to 
focus on Cython; but as it is, necessity is the mother of invention.

The "f2c" will be kept seperate from Cython; we hope that it can go into 
f2py (as that's who has the parser) but that is not up to us.

Some further thoughts:
a) As Kurt touched upon, there's some Cython-specific features needed as 
well to make this happen. I hope that about 50% of the project can be on 
the Cython part and 50% on "f2c".

b) While there's a clear technical seperation between Fortran <-> C and 
C <-> Cython, the main challenge is the same both places (dealing with 
strided arrays on a C level) and so it's benefitial to have them within 
the same project.

c) Going via C one will have "information loss" in the function 
signature as there's no canonical strided array type for C. Therefore a 
pxd for Cython must be generated directly as well.


BTW, part of that Cython work would involve getting 90% of the way towards

cdef utility_function_of_buffer(ndarray[int] foo):
    ...

without reacquisition of the buffer :-) (i.e. caller-acquired buffer)

(The only similar thing I found to "f2c" to this was some Babel-specific 
XSLT transforms in Chasm... if you know of anything else please tell us!)

-- 
Dag Sverre


More information about the Scipy-dev mailing list