-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
First-class function type #5287
Conversation
eadca0b
to
4990ca7
Compare
@stuartarchibald to reproduce the issue of constant functions:
|
It needs to handle njit functions that are generators, or reject gracefully: from numba import njit
@njit(firstclass=True)
def gen(xs):
for x in xs:
x += 1
yield x
@njit
def con(gen_fn, xs):
return [it for it in gen_fn(xs)]
con(gen, (1, 2, 3)) currently, it fails with: numba/core/pythonapi.py in serialize_object(self, obj)
1327 try:
-> 1328 gv = self.module.__serialized[obj]
1329 except KeyError:
KeyError: (UniTuple(int64 x 3),) -> int64 generator(func=<function gen at 0x116defb90>, args=(UniTuple(int64 x 3),), has_finalizer=True) |
In nopython mode, generators cannot be used as first-class function types because of the corresponding cfunc wrapper functions cannot hold the state of generators. So, raising In python mode, however, generators can be used as first-class functions. |
To eliminate the need for Also, the implementation of |
…s in nopython mode
…ing first-class functions in object-mode.
… WIP: needs a clean up.
…AddressProtocol instances.
…ion support is enabled.
…t first-class function objects)
…unction_pointer in lowering.py
@sklam I have addressed all your comments and feedback. Please review. |
@sklam some notes from our discussion.
Merge conditions:
|
@stuartarchibald @sklam , yes, I would be happy to continue improving the feature and fix any related bugs. |
Thanks @pearu, that's great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed the user docs.
#5441 should be merged immediately after merging this |
Closes #3405
This PR (as a continuation of PR #4967) implements:
firstclass=True
option. For instance: