I'm struggling with a numba error
Untyped global name 'is_a_subset': Cannot determine Numba type of <class 'numba.np.ufunc.gufunc.GUFunc'>
This usually means I have fumbled and used a method that isn't supported by numba. The following code fails.
@guvectorize("(n),(n)->(n)",nopython=True)
def is_a_subset(x,y,out):
out[:]=np.array([item in x for item in y])
@njit()
def test(x,y,z):
is_a_subset(x,y,z)
return z.mean()
x=np.array([[1,2,3],[3,2,1]])
y=np.array([[3,6,1],[1,2,3]])
z = np.empty_like(x)
test(x,y,z)
However removing njit on the test function makes everything work.
def test(x,y,z):
is_a_subset(x,y,z)
return z.mean()
Why is numba struggling to resolve types when in no-python mode?
I had also tried without different results
@guvectorize(["f8[:],f8[:],f8[:]"],"(n),(n)->(n)",nopython=True)
def is_a_subset(x,y,out):
out[:]=np.array([item in x for item in y])
I am using Numba 0.53.1 and can replicate this error. This blog on the dynamic dispatch update to guvectorize
in Numba 0.53 mentions this at the end (emphasis added):
In the future we would like to bring the
@guvectorize
capabilities closer to the@vectorize
ones. For instance, currently it is not possible to call a guvectorize function from a jitted (@jit
) function.
There is a similar open issue with vectorize
, but it demonstrates that @vectorize
functions can be called in @jit
functions, just that it's restricted to the default target = "cpu"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With