1

我正在尝试在内部使用 Numba cfunc,但是我面临签名匹配问题。如果我将返回类型设置为它识别为好像我设置为或它说。两个签名不能匹配。匹配问题在返回类型中 scipy.LowLevelCallablendi.generic_filterint16shortint32intclong

import numpy as np
import scipy
from numba import cfunc, carray, types
import scipy.ndimage as ndi

@cfunc("intc (CPointer(float64),intp, CPointer(float64), voidptr)") #problematic
def myfunc(values_ptr, len_values, result, data):
    #some work here
    return 1

footprint = np.array([[0, 1, 0],[1, 1, 1],[0, 1, 0]], dtype=bool)
from scipy import ndimage as ndi

a=np.random.random((100,100))
ndi.generic_filter(a, scipy.LowLevelCallable(myfunc.ctypes), footprint=footprint)

这是错误:

ValueError: Invalid scipy.LowLevelCallable signature "long (double *, long, double *, void *)". Expected one of: ['int (double *, intptr_t, double *, void *)', 'int (double *, npy_intp, double *, void *)', 'int (double *, int, double *, void *)', 'int (double *, long, double *, void *)']

系统规格(如果相关):Python 2.7.10(32 位)、Numba 0.39.0

4

1 回答 1

2

您似乎遇到了这个已知问题。具体来说,似乎无法在大小相同的平台上使用 Numba 生成预期的签名(LowLevelCallable例如64 位版本的 Windows)。intlong

我建议你支持 GitHub 上的修复。同时,最好的办法是将 Numba 函数直接传递到generic_filter并接受一些函数调用开销,或者以支持的方式包装函数,例如通过 Cython。

于 2018-08-06T05:40:46.380 回答