Jellomima
Jellomima

Reputation: 223

numba type error when using both python3 and python 2.7

I have two python environments (python3 and python2.7) and I used both of them to test on a program which involved numba. Despite the version of Python, I got the same TypeError message, while my friend told me that the program only throws an error if he used Python 2.7, but works in his Python3 setup.

The error is as follows:

TypeError: No matching definition for argument type(s) int64, int64, int64, array(float64, 3d, C), array(int64, 2d, C)

I've tried to update package in the virtual Python3 environment, but it still doesn't work. The code is a bit too long, but my question is only on why my setup can't have the numba functions worked. Any suggestion would be appreciated.

Upvotes: 2

Views: 325

Answers (1)

JoshAdel
JoshAdel

Reputation: 68732

If you look at the error message, what it is telling you is the inputs into nbody don't match the signature you assigned (I ran it outside of the timeit call to make that more explicit). It appears as if you're working on a machine that defaults to 64-bit, but you say that body_pairs should be int32[:,:].

The solution is to explicitly specify the type in the creation of this variable:

BODY_PAIRS = np.array(list(itertools.combinations(np.arange(BODIES.shape[0]), 2)), dtype=np.int32)

Note the specification of dtype.

Upvotes: 3

Related Questions