gpt4 book ai didi

python - Numba Prange 示例不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 03:50:52 25 4
gpt4 key购买 nike

我正在从这里测试 prange 示例:

http://numba.pydata.org/numba-doc/0.11/prange.html

我有 numba 版本 0.11.1

不幸的是,它给了我这个错误:

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

这是我正在使用的代码:

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 模块,则该示例有效:

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。我在原始代码中遇到了同样的错误。

关于python - Numba Prange 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21352315/

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