gpt4 book ai didi

python - 使用 nopython 模式在 numba 装饰器@njit 中为字符串的 ndarray 签名

转载 作者:行者123 更新时间:2023-12-05 07:07:15 32 4
gpt4 key购买 nike

我正在尝试在 numba decorator @ 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.7 NumPy 的:1.18.3编号:0.48.0

最佳答案

关于python - 使用 nopython 模式在 numba 装饰器@njit 中为字符串的 ndarray 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62231195/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com