New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid calling typers/overloads without literal types #5411
Comments
A numba/numba/tests/test_literal_dispatch.py Lines 249 to 252 in 0a8b811
|
Thanks @sklam . But my point is about avoiding rerun of overload function with import numba
from numba.extending import overload, SentryLiteralArgs
def do_this(x, y):
return x + y
@overload(do_this)
def ov_do_this(x, y):
SentryLiteralArgs(['x']).for_function(ov_do_this).bind(x, y)
return lambda x, y: x + y + UNKNOWN_GLOBAL # invalid impl
@numba.njit
def foo(a, b):
return do_this(a, b)
foo(1, 3)
|
I also have an issue that related to this that really confused me in the beginning. Say I have code like this: @overload(do_this)
def ov_do_this(x, y):
if not isinstance(x, types.Integer):
raise TypeError('do_this: parameter x may only be an integer')
if not isinstance(y, types.Literal):
raise RequireLiteralValue('do_this: parameter y must be literal')
pass Let's say this is called with When I first encountered this, I was searching high and low in my code why numba did not recognize Not sure if and how the user experience could be improved though. Once one know one has to scroll up to identify the real issue it is not a big problem but it is far from obvious to somebody new to numba. |
Feature request
Type inference currently calls every typing template twice: once using literal types if available, and again without literal types. I believe the original purpose was backwards compatibility when literal types were introduced.
However, this can be confusing for developers. For example, if an overload expects a literal type but fails due to another reason, Numba tries again without literal types. The developer doesn't see the original error, and may be confused why the overload is called without literal types (our engineers have experienced these issues many times).
Ideally, all templates should handle literal types so Numba wouldn't need to have this behavior. In the short term, there could be an option for overloads (e.g. "literal_only=True").
The text was updated successfully, but these errors were encountered: