Skip to content

Commit

Permalink
Merge pull request #3577 from stuartarchibald/fix/3575
Browse files Browse the repository at this point in the history
Fix example and docs typos for `objmode` context manager.
  • Loading branch information
stuartarchibald committed Dec 12, 2018
2 parents d6a11c7 + eacd307 commit ff74d7f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions numba/withcontexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ def mutate_with_body(self, func_ir, blocks, blk_start, blk_end,
class _ObjModeContextType(WithContext):
"""Creates a contextmanager to be used inside jitted functions to enter
*object-mode* for using interpreter features. The body of the with-context
is lifted into a function that is compiled into *object-mode*. This
transformation process is limitated and cannot process all possible
is lifted into a function that is compiled in *object-mode*. This
transformation process is limited and cannot process all possible
Python code. However, users can wrap complicated logic in another
Python function, which will then be executed by the interpreter.
Use this as a function that takes keyword arguments only.
The argument names must correspond to the output variables from the
with-block. Their respective values are strings representing the expected
types. When exiting the with-context, the output variables are casted
types. When exiting the with-context, the output variables are cast
to the expected nopython types according to the annotation. This process
is the same as passing Python objects into arguments of a nopython
function.
Expand All @@ -140,20 +140,21 @@ class _ObjModeContextType(WithContext):
def bar(x):
# This code is executed by the interpreter.
return np.asarray(list(reversed(x.tolist()))
return np.asarray(list(reversed(x.tolist())))
@njit
def foo():
x = np.arange(5)
y = np.zeros_like(x)
with objmode(y='intp[:]'): # annotate return type
# this region is executed by object-mode.
y += bar(x)
return y
.. note:: Known limitation:
.. note:: Known limitations:
- with-block cannot use incoming list object.
- with-block cannot use incoming function object.
- with-block cannot use incoming list objects.
- with-block cannot use incoming function objects.
- with-block cannot ``yield``, ``break``, ``return`` or ``raise`` \
such that the execution will leave the with-block immediately.
- with-block cannot contain `with` statements.
Expand Down

0 comments on commit ff74d7f

Please sign in to comment.