我正在尝试对numba装饰器@ njit中的文本数组使用签名。例如,这个无意义的功能:
import numpy as np
import numba as nb
@nb.njit(nb.int64
(nb.types.unicode_type, nb.int8[:], nb.types.unicode_type[:]),
error_model='numpy')
def foo(paramText, paramArrayOfInts, paramArrayOfTexts):
print(paramText)
return 1
a = 'Hello'
b = np.array([1, 2], dtype=np.int8)
c = np.array(['dog', 'cat', 'me'], dtype=np.dtype('U3'))
aNumber = foo(a, b, c)
print(aNumber)
显示此错误:
File "C:\OSGeo4W64\apps\Python37\Lib\site-packages\numba\dispatcher.py", line 574, in _explain_matching_error
raise TypeError(msg) TypeError: No matching definition for argument type(s) unicode_type, array(int8, 1d, C), array([unichr x 3], 1d, C)
如果我坚持使用装饰器,则有解决方案:
nb.typeof(np.array(['1', '2'], dtype='U3'))
而不是:
nb.types.unicode_type[:]
它有效,但不是我想要的。
版本:python 3.7numpy的:1.18.3numba:0.48.0