简体   繁体   English

为什么numba在numpy方法时抛出错误(nopython = True)?

[英]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.

相关问题 Numba @jit(nopython = True)函数无法在较重的Numpy函数上提高速度 - Numba @jit(nopython=True) function offers no speed improvement on heavy Numpy function 在用`numba`的`@jit(nopython = True)`装饰的函数内创建`NumPy`数组? - Creating `NumPy` arrays inside a function decorated with `numba`'s `@jit(nopython=True)`? 如何使 numba(nopython=true) 与元素数量未知的 1D numpy.ndarray 输入一起使用 - How to make numba(nopython=true) work with 1D numpy.ndarray input with unknown number of elements 在 Numba 'nopython' 模式下使用 numpy.fill - Using numpy.fill with Numba 'nopython' mode 为什么在此函数上不能将`nopython = True`与`numba.guvectorize`一起使用? - Why can't I use `nopython=True` with `numba.guvectorize` on this function? 推动Numba @jit遇到警告消息,并且@jit(nopython = True)将显示错误 - improt Numba @jit meet warning message and @jit(nopython=True) will show error Nopython模式下Numba的递归函数错误 - Error in recursive function with Numba in nopython mode Np.sum的Numba nopython错误 - Numba nopython error with np.sum numba @jit(nopython=True):使用字典作为值的重构函数 - numba @jit(nopython=True): Refactor function that uses dictionary with lists as values 为什么numba在numpy linspace中引发类型错误 - Why numba raise a type error in numpy linspace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM