Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用f2py编译函数到带有';诺皮顿';模式_Python_Fortran_Numba_F2py - Fatal编程技术网

Python 使用f2py编译函数到带有';诺皮顿';模式

Python 使用f2py编译函数到带有';诺皮顿';模式,python,fortran,numba,f2py,Python,Fortran,Numba,F2py,我试图将一个f2py编译函数用于一个python函数,该函数由来自numba的@njit decorator修饰。由f2py包装的函数的签名为: stp,f,g,task = xxx(stp,f,g,ftol,gtol,xtol,task,stpmin,stpmax,isave,dsave) Wrapper for ``xxx``. Parameters ---------- stp : input float f : input float g : input float ftol : i

我试图将一个f2py编译函数用于一个python函数,该函数由来自numba的@njit decorator修饰。由f2py包装的函数的签名为:

stp,f,g,task = xxx(stp,f,g,ftol,gtol,xtol,task,stpmin,stpmax,isave,dsave)

Wrapper for ``xxx``.

Parameters
----------
stp : input float
f : input float
g : input float
ftol : input float
gtol : input float
xtol : input float
task : input string(len=60)
stpmin : input float
stpmax : input float
isave : in/output rank-1 array('i') with bounds (2)
dsave : in/output rank-1 array('d') with bounds (13)

Returns
-------
stp : float
f : float
g : float
task : string(len=60)
签名文件包括:

        subroutine xxx(stp,f,g,ftol,gtol,xtol,task,stpmin,stpmax,isave,dsave)
            double precision, intent(in,out) :: stp
            double precision, intent(in,out) :: f
            double precision, intent(in,out) :: g
            double precision, intent(in) :: ftol
            double precision, intent(in) :: gtol
            double precision, intent(in) :: xtol
            character*60, intent(in, out) :: task
            double precision, intent(in) :: stpmin
            double precision, intent(in) :: stpmax
            integer dimension(2), intent(inout) :: isave
            double precision dimension(13), intent(inout) :: dsave
        end subroutine xxx
因为在“nopython”模式下,numba必须知道外部函数的签名,所以我当前的方法是直接用ctypes加载f2py生成的xxx.so文件,而不是标准的“导入”方法。然后,我按照以下方式将函数的输入和输出参数注册为ctypes:

lib = ctypes.cdll.LoadLibrary('xxx.so')
lib.dcsrch_.argtypes = [ctypes.c_double, ctypes.c_double, ctypes.c_double,
                        ctypes.c_double, ctypes.c_double, ctypes.c_double,
                        ctypes.c_char_p(???), ctypes.c_double, ctypes.c_double,
                        np.ctypeslib.ndpointer(dtype=np.intc, ndim=1, shape=2), 
                        np.ctypeslib.ndpointer(dtype=np.double, ndim=1, shape=13)]
lib.dcsrch_.restype = ctypes.py_object(???).
这里,(??)表示我对签名特别不确定。当我尝试使用该函数时,我总是得到seg。错误。同时,当以标准方式导入功能时,即从xxx导入xxx,一切都会顺利运行


我真的很想在这里得到一些帮助。谢谢

我认为您可以通过执行以下操作在
\uuuu doc\uuuu
的参数规范中找到答案

from xxx import xxx
print(xxx.__doc__)
# or
print(xxx.function_name.__doc__)