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
Objmode with-block #3166
Objmode with-block #3166
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3166 +/- ##
==========================================
+ Coverage 81.09% 81.17% +0.07%
==========================================
Files 386 388 +2
Lines 76285 76921 +636
Branches 8575 8631 +56
==========================================
+ Hits 61867 62440 +573
- Misses 13100 13155 +55
- Partials 1318 1326 +8 |
# Conflicts: # numba/tests/test_withlifting.py
Merged #3230 into this patch. |
Feature is completed. Ready for early review. I will just be adding more tests for crazy cases; like looplifting calling into objmode and vice versa. |
@sklam this works great! A couple of minor issues:
|
@sklam with this feature in place, I'm wondering if it is now easier to just declare a python function as object mode inside all njit functions. The user just provides type inference and Numba handles boxing/unboxing automatically. For example: @infer_object_mode(foo)
class FooInfer(AbstractTemplate):
def generic(self, args, kws):
return signature(types.float64, *args) |
Changes: - reject list as inputs to objmode due to difficulty in handling reflection - checks and enforces type annotation on outgoing vars - checks invalid control-flow usage inside with-context
add docstring test example in docstring
Notes on new changes:
|
@ehsantn , regarding #3166 (comment), it's definitely easier now. I think one can also just use @overload(mytoy)
def mytoy_ov(x, y):
def impl():
with objmode(out=...):
out = mytoy(x, y)
return out
return impl |
Interesting solution. Makes sense. |
numba/withcontexts.py
Outdated
- with-block cannot use incoming list object. | ||
- with-block cannot use incoming function object. | ||
- with-block cannot ``yield``, ``break``, ``return`` or ``raise`` such that | ||
the execution will leave the with-block immediately. |
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.
need to indent this line so that sphinx doesn't think the list has ended
numba/withcontexts.py
Outdated
- with-block cannot ``yield``, ``break``, ``return`` or ``raise`` such that | ||
the execution will leave the with-block immediately. | ||
- the ``objmode()`` function must be directly referenced as a global. | ||
i.e. ``with numba.objmode():`` doesn't work. |
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.
same need for indent here
Current failures:
|
Ignore as_dtype(typ) error.
(Based on #3017)
can't assign anything yetfixedcan't return anything yetfixedpass thru objectsdeferred to Pass thru pyobjects #3282