问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/10766969/f2py-wrapping-fortran-module-which-makes-use-of-subrouines-distributed-in-diffe