Numba Prange 示例不起作用 [英] Numba Prange Example does not work
本文介绍了Numba Prange 示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在测试这里的 prange 示例:
I am testing the prange example from here:
http://numba.pydata.org/numba-doc/0.11/prange.html
我有 numba 版本 0.11.1
I have numba version 0.11.1
不幸的是,它给了我这个错误:
Unfortunately, it gives me this error:
Traceback (most recent call last):
File "C:\Anaconda\envs\p33\lib\site-packages\IPython\core\interactiveshell.py", line 2732, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-d9c777b2b461>", line 1, in <module>
execfile('C:\\Users\\Jon\\workspace\\Examples\\numba\\parallel_numba.py')
File "C:\eclipse_kepler\plugins\org.python.pydev_2.7.5.2013052819\pysrc\_pydev_execfile.py", line 38, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script
File "C:\Users\Jon\workspace\Examples\numba\parallel_numba.py", line 19, in <module>
s0 = parallel_sum(B)
File "numbawrapper.pyx", line 192, in numba.numbawrapper._NumbaSpecializingWrapper.__call__ (numba\numbawrapper.c:3768)
SystemError: NULL result without error in PyObject_Call
这是我正在使用的代码:
This is the code that I am using:
from numba import autojit, prange
import numpy as np
@autojit
def parallel_sum(A):
sum = 0.0
for i in prange(A.shape[0]):
sum += A[i]
return sum
B = np.array( [1,2,3] )
s0 = parallel_sum(B)
推荐答案
出于某种原因,如果您明确命名 numba 模块,则示例有效:
For some reason, if you name the numba modules, explicitly, the example works:
import numba
@numba.autojit
def parallel_sum(A):
sum = 0.0
for i in numba.prange(A.shape[0]):
sum += A[i]
return sum
另外,我通过 conda 使用 python 2.7 和 numba 0.11.1.我在原始代码中遇到了同样的错误.
Also, I'm using python 2.7 and numba 0.11.1 via conda. I got the same error with the original code.
这篇关于Numba Prange 示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文