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
Float Literal Support #7124
Comments
Interesting. Can you tell me how it will be advantageous for the compiler to know that literal value of the |
Yes I mean for This is just one example where I believe it could be useful, but in general I think Literal Floats could be used to push simple runtime checks into compile time, which when used with caching may prove to be beneficial for overall performance. |
To clarify, I'm not proposing a PR to provide this change in |
Summarizing important notes from today's Numba meeting: Overspecialization concern Concerns that Numba will overspecialize and significantly increase compile time for a lot of the code given that float literals are common. Let LLVM do the work Runtime benefits can be achieved without float literal in Numba. Consider @jit
def foo(val):
if val == 1.0: # specialize on float value being 1
return loopy_code_optimize_for_one(val) # code containing loops
else:
return loopy_code_generic(val) # code containing loops
@jit
def user():
foo(1.0) # uses with float literal Even without recognizing the float literal in Numba, LLVM (Numba's backend) will still see the literal value and elide the comparison in In other places, literal values are needed only because the typing, particularly the return type, is dependent on the argument values; e.g. Our current recommendation is to reserve the use of literals to cases where compilation cannot succeed unless a literal value is provided. Runtime performance benefit is likely achievable via LLVM optimization without any literal specialization within Numba. |
Hi @sklam. I think the overspecialization concern is a solid reason for not proceeding with this feature. Thank you for considering it. |
Maybe |
Feature request Float Literal Type
I'd like to see support for a Float Literal type, similar to the Integer Literal and Boolean Literal types that currently exist.
The main motivations for this use case would be to situations where users provide floats to APIs that require constants for typings (and in practice accept integers or floats) or to support the option to avoid runtime checks for common cases with users tend to provide literals (i.e. numpy.quantile https://numpy.org/doc/stable/reference/generated/numpy.quantile.html).
I'm happy to provide this feature in a PR myself.
The text was updated successfully, but these errors were encountered: