Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I tried this code

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))

and got a runtime exception: AttributeError: 'numpy.ndarray' object has no attribute '__code__'

I cannot find any version requirement on numpy in numba's documentation. Currently I have numpy 1.7.1 installed. My python version 2.6.6

What is the cause of the AttributeError?

EDIT

Some stacktrace info;

 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>'
share|improve this question
    
This works for me with numpy 1.8.0 and numba 0.12.1. As a side note, although I get the correct answer, if I try accessing np.ndarray.__code__, I get the same error message. What version of numba are you using? –  JoshAdel Mar 3 at 3:14
    
Can you show the full traceback? –  user2357112 Mar 3 at 3:18
    
@JoshAdel numba.__version__ gives me 0.8.1 –  Anthony Kong Mar 3 at 3:40
    
@user2357112 For various non-technical reasons, I can't show you the full stacktrace, but I will attach as much info as I can –  Anthony Kong Mar 3 at 3:41
1  
@AnthonyKong That version is in the stone ages given Numba's rapid development and beta-esque status. I would upgrade at least to 0.11. The latest version (0.12) is a major refactoring and there are a bunch of regressions so you might not want to get the latest, although Continuum is rapidly fixing it and in the long run, it will be better. –  JoshAdel Mar 3 at 12:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.