Numba编译失败,出现了一条非常奇怪的消息——看起来这应该有效吗



我有一个简单的函数,无法使用Numba的@njit装饰器进行编译:

@njit(fastmath=True, nogil=True)
def insert_into_array(array, pos, array_to_insert):
start = array[0:pos]
end = array[pos:len(array)]
inserted = np.concatenate((start, array_to_insert))
return np.concatenate(inserted, end)

它失败了,消息是:

Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function concatenate at 0x000001E88B04E8B0>) with argument(s) of type(s): (array(uint8, 1d, C), array(uint8, 1d, C))
* parameterized
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function concatenate at 0x000001E88B04E8B0>)

注意,失败的类型是(array(uint8, 1d, C), array(uint8, 1d, C))——基本上是试图连接两个简单的1d数组。

由于NumPy的concatenate函数被Numba列为支持的函数,我很难理解应该怎么做才能解决这个问题。

我在Python 3.7和Numba 0.50 上

你知道我做错了什么吗?

谢谢!

这看起来像是一个一开始就被麻木了的函数。无论如何,np.concatenate的第一个参数应该是元组,不能传递var参数。你的最后一个电话正在尝试。

相关内容

最新更新