I've been really struggling with numba lately. Copied this code snippet directly from numba docs and it works fine:
@guvectorize([(int64[:], int64, int64[:])], '(n),()->(n)')
def g(x, y, res):
for i in range(x.shape[0]):
res[i] = x[i] + y
a = np.arange(5)
g(a,2)
Giving y an array results in a grid. Summing 2 arrays is something I do a lot though, so here's the code I came up with by modifying the snippet.
@guvectorize([(int64[:], int64[:], int64[:])], '(n),(n)->(n)')
def add_arr(x, y, res):
for i in range(x.shape[0]):
res[i] = x[i] + y[i]
p = np.ones(1000000)
q = np.ones(1000000)
r = np.zeros(1000000)
add_arr(p,q)
This gives me the error:
TypeError Traceback (most recent call last)
<ipython-input-75-074c0fd345aa> in <module>()
----> 1 add_arr(p,q)
TypeError: ufunc 'add_arr' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I have encountered this error a few times before but I've no idea what it means or how to fix it. How do I get the desired result? Thanks in advance.
----> 1 add_arr(p,q,r)
. You did make sure to reset your environment so you're not running stale bytecode?