You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FWIW: here is an example that attempts to execute the resulting ufunc:
import numpy as np
from numba import vectorize
# this works
@vectorize(nopython=True)
def foo(x):
return x + 1
# this doesn't
def bar(x):
return x + 1
bar = vectorize(bar, nopython=True)
a = np.ones(42)
print(foo(a))
print(bar(a))
Using the following patch:
diff --git i/numba/np/ufunc/decorators.py w/numba/np/ufunc/decorators.py
index 57776a466d..9fffd9f9d2 100644
--- i/numba/np/ufunc/decorators.py
+++ w/numba/np/ufunc/decorators.py
@@ -115,7 +115,8 @@ def vectorize(ftylist_or_function=(), **kws):
# Common user mistake
ftylist = [ftylist_or_function]
elif inspect.isfunction(ftylist_or_function):
- return dufunc.DUFunc(ftylist_or_function, **kws)
+ vec = Vectorize(ftylist_or_function, **kws)
+ return vec.build_ufunc()
elif ftylist_or_function is not None:
ftylist = ftylist_or_function
I can get the code to run and both print statements yield the same output, which is a good indication.
@stuartarchibald@sklam does this look like an appropriate fix? If yes, I can stage a PR with an accompanying test.
@timothymillar we discussed this in our weekly meeting today and it seems like the semantics of the vectorize decorator are different from the @njit decorator.
Doing the following instead will yield the result you are expecting:
importnumpyasnpfromnumbaimportvectorize# this works@vectorize(nopython=True)deffoo(x):
returnx+1# this doesn'tdefbar(x):
returnx+1bar=vectorize(nopython=True)(bar)
a=np.ones(42)
print(foo(a))
print(bar(a))
Reporting a bug
When calling
vectorize
without decorator syntax any use of thenopython
argument results in a type error due tounexpected keyword argument 'nopython'
.visible in the change log (https://github.com/numba/numba/blob/main/CHANGE_LOG).
i.e. it's possible to run as 'python bug.py'.
Minimal example:
Traceback:
This doesn't seem to be an issue with the
jit
orguvectorize
decorators and it's not an issue when using thecache
argument forvectorize
The text was updated successfully, but these errors were encountered: