简体   繁体   中英

f2py: Wrapping fortran module which makes use of subrouines distributed in different files?

For reasons I described earlier , I need to use LAPACKs dgesvd and zgesvd methods in Python instead of the ones wrapped in numpy.

Someone pointed out, that I could use f2py, to create my own python package. The trouble is, that, dgesdd in lapack calls a bunch of other methods like dbdsqr, dgelqf and also some BLAS routines, and I don't know, how I should proceed about that.

Can anyone point out, what would be the propper way of creating a dgesvd python module without having to recompile the whole lapack library ?

Thanks a lot Mischa

You don't need to wrap the whole LAPACK library, just the LAPACK routines you want. The routines are connected with Fortran calls underneath. I have successfully done this with Intel's MKL, for one of the solvers similar to dgesvd (and obviously I can't recompile that since it's closed source!).

The only requirement is that you provide the path to link to the LAPACK library (which you would have needed for the top level routine anyway):

f2py -L/path/to/lapack -llapack -m module -c module.f

(of course, replace the library path and the library name with what is applicable on your machine)

Only a wrapper is needed around the code in module.f because all calls inside module.f are done as if they are pure Fortran.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM