Skip to content

Commit 4535cb6

Browse files
authored
Merge pull request #8554 from stuartarchibald/wip/overload_target_generic_default_v2
Make target for `@overload` have 'generic' as default.
2 parents a550ce3 + 4e77659 commit 4535cb6

2 files changed

Lines changed: 28 additions & 33 deletions

File tree

‎numba/core/extending.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ def generic(self):
5353

5454

5555
# By default, an *overload* does not have a cpython wrapper because it is not
56-
# callable from python.
57-
_overload_default_jit_options = {'no_cpython_wrapper': True}
56+
# callable from python. It also has `nopython=True`, this has been default since
57+
# its inception!
58+
_overload_default_jit_options = {'no_cpython_wrapper': True,
59+
'nopython':True}
5860

5961

6062
def overload(func, jit_options={}, strict=True, inline='never',

‎numba/core/typing/templates.py‎

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -716,37 +716,30 @@ def _get_impl(self, args, kws):
716716
def _get_jit_decorator(self):
717717
"""Gets a jit decorator suitable for the current target"""
718718

719-
jitter_str = self.metadata.get('target', None)
720-
if jitter_str is None:
721-
from numba import jit
722-
# There is no target requested, use default, this preserves
723-
# original behaviour
724-
jitter = lambda *args, **kwargs: jit(*args, nopython=True, **kwargs)
725-
else:
726-
from numba.core.target_extension import (target_registry,
727-
get_local_target,
728-
jit_registry)
729-
730-
# target has been requested, see what it is...
731-
jitter = jit_registry.get(jitter_str, None)
732-
733-
if jitter is None:
734-
# No JIT known for target string, see if something is
735-
# registered for the string and report if not.
736-
target_class = target_registry.get(jitter_str, None)
737-
if target_class is None:
738-
msg = ("Unknown target '{}', has it been ",
739-
"registered?")
740-
raise ValueError(msg.format(jitter_str))
741-
742-
target_hw = get_local_target(self.context)
743-
744-
# check that the requested target is in the hierarchy for the
745-
# current frame's target.
746-
if not issubclass(target_hw, target_class):
747-
msg = "No overloads exist for the requested target: {}."
748-
749-
jitter = jit_registry[target_hw]
719+
from numba.core.target_extension import (target_registry,
720+
get_local_target,
721+
jit_registry)
722+
723+
jitter_str = self.metadata.get('target', 'generic')
724+
jitter = jit_registry.get(jitter_str, None)
725+
726+
if jitter is None:
727+
# No JIT known for target string, see if something is
728+
# registered for the string and report if not.
729+
target_class = target_registry.get(jitter_str, None)
730+
if target_class is None:
731+
msg = ("Unknown target '{}', has it been ",
732+
"registered?")
733+
raise ValueError(msg.format(jitter_str))
734+
735+
target_hw = get_local_target(self.context)
736+
737+
# check that the requested target is in the hierarchy for the
738+
# current frame's target.
739+
if not issubclass(target_hw, target_class):
740+
msg = "No overloads exist for the requested target: {}."
741+
742+
jitter = jit_registry[target_hw]
750743

751744
if jitter is None:
752745
raise ValueError("Cannot find a suitable jit decorator")

0 commit comments

Comments
 (0)