2

我试过这段代码

from numba import jit
from numpy import arange
@jit
def sum2d(arr):
    M, N = arr.shape
    result = 0.0
    for i in range(M):
        for j in range(N):
            result += arr[i,j]
    return result

a = arange(9).reshape(3,3)
print(sum2d(a))

并得到一个运行时异常:AttributeError: 'numpy.ndarray' object has no attribute '__code__'

我在 numba 的文档中找不到任何关于 numpy 的版本要求。目前我已经安装了 numpy 1.7.1。我的 python 版本 2.6.6

AttributeError的原因是什么?

编辑

一些堆栈跟踪信息;

 File "c:\pylib\numba\decorators.py", line 228, in _jit_decorator
    if func.__code__.co_argcount == 0 and argtys is None:
AttributeError: 'numpy.ndarray' object has no attribute '__code__'
Locals:
argtypes: 'None'
  argtys: 'None'
     env: 'NumbaEnvironment(numba)'
env_name: 'None'
    func: '[[0 1 2]\n [3 4 5]\n [6 7 8]]'
  kwargs: '{backend:ast}'
 restype: '<function sum2d at 0x1C89F5F0>'
4

0 回答 0