Numpy f2py tool

Hi all
Does anybody here familiar with numpy f2py tool?
I have some questions about wrapping lapack subroutines in python.

I’ve used it once, a while ago. A basic use case was pretty simple.

f2py -c -m modulename modulename.pyf modulename.f90

That produces the .pyf file and a .so file. Then just put import modulename in your Python script and you have access to whatever was public in your Fortran module.

1 Like

Hi ELNS, I might be able to help (or get answers from someone who will :))


Thank you, but when we deal with lapack , it will be a little complicated.

Thanks @melissawm
For example in scipy/linalg/flapack_gen.pyf.src we have a subroutine signature as below:

I built a signature file for sgetc2 and also wiki page, but i did not get why did we use int i; and for(i=0;i<n;–ipiv[i],–jpiv[i++]); in callstatement?

Is there some specific reason you would like to perform the wrapping yourself?

Scipy already includes a low-level interface to LAPACK:

1 Like

As a member of scipy development team, we need to wrap more lapack functions in linalg module,

@melissawm Can you please help me about this?

Hi ELNS, this is an autogenerated signature file that gets written by building scipy. All that is inside the curly brackets after callstatement replaces the f2py generated call statement, and (*f2py_func) is the actual call statement after this substitution. So what I can see is that, in SciPy, after generating the C extension, *getc2 is called inside the loop defined by that block. However, I don’t know why - this is something from SciPy and not from f2py. I don’t have a lot of experience in that part of SciPy though, so it would be better to ask someone from the project. Sorry I couldn’t help more!


Thank you very mush :pray: :pray: :pray: