问题
I am using numba (0.10.2-5-gda3e2bb-dirty) to speed up my code. Now I am trying the following:
from numba import void, int_, double, jit
import numpy as np
@jit
class bla(object)
@void
def my_fun
k = np.int_(1)
f = np.int_(np.array([1, 2 , 3, 4, 5]))
if k in f:
do something
However numba appears to choke on the in command. If I type something like
if k == 1:
everything is fine. However with the in command numba won't compile. Any thoughts?
Btw: I am running python 2.7 and
numpy.version
returns
numpy-1.7.1-py2.7-linux-i686.egg
Thanks in advance!
Nick
回答1:
There are a number of basic issues with your code syntax (indentation, missing parentheses, etc.), but if I re-write it as follows, I an error message that in
type comparisons are not implemented yet:
NumbaError: (see below)
--------------------- Numba Encountered Errors or Warnings ---------------------
Error <class '_ast.In'> comparisons not yet implemented
--------------------------------------------------------------------------------
import numpy as np
from numba import void, int_, double, jit
@jit
class bla(object):
@void()
def __init__(self):
self.x = 1
@void()
def my_fun(self):
self.x = 1
k = np.int_(1)
f = np.int_(np.array([1, 2 , 3, 4, 5]))
if k in f:
print 'aaa'
I had to throw in the self.x
lines because numba seems to fail on compile with unused variables, including self
.
来源:https://stackoverflow.com/questions/19526791/find-numpy-int-in-array-of-int-s-using-numba