[英]Why is numba throwing an error regarding numpy methods when (nopython=True)?
I am trying to use numba to improve the speed of some code that I've written that is rather slow. 我正在尝试使用numba来提高我编写的一些代码的速度,这些代码相当慢。 The majority of the time spent is in a single function. 花费的大部分时间都在一个功能中。 First I tried using just 首先我尝试使用
@jit
before my function definition, which improved timing a bit. 在我的函数定义之前,它改进了时序。 Then, I tried using 然后,我尝试使用
@jit(nopython=True)
instead. 代替。 From what I've read in the documentation, the numpy methods that I am using within the function should be supported (eg transpose). 从我在文档中看到的内容,我应该支持我在函数中使用的numpy方法(例如转置)。 However, I am getting an error 但是,我收到了一个错误
Failed at nopython (nopython frontend)
Untyped global name 'transpose'
In order to use transpose
, you need to call it (as the docs describe ) in the form of a method of a numpy array. 为了使用transpose
,您需要以numpy数组的方法的形式调用它(如文档描述的那样 )。 So the following works: 以下是有效的:
import numpy as np
import numba as nb
@nb.jit(nopython=True)
def func(x):
y = x.transpose() # or x.T
return y
x = np.random.normal(size=(4,4))
x_t = func(x)
But calling y = np.transpose(x)
in the function does not. 但是在函数中调用y = np.transpose(x)
则不行。 I assume you're doing the latter. 我假设你正在做后者。 Note, I'm using Numba 0.25.0 for reference. 注意,我使用Numba 0.25.0作为参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.