def test_exercise_code_path_with_lifted_loop(self): """ Ensures that lifted loops are handled correctly in obj mode """ # the functions to jit def bar(x): return x def foo(x): h = 0. for i in range(x): # py 38 needs two loops for one to lift?! h = h + i for k in range(x): h = h + k if x: h = h - bar(x) return h # compile into an isolated context flags = Flags() flags.enable_pyobject = True flags.enable_looplift = True cres = compile_isolated(foo, [types.intp], flags=flags) ta = cres.type_annotation buf = StringIO() ta.html_annotate(buf) output = buf.getvalue() buf.close() self.assertIn("bar", output) self.assertIn("foo", output) self.assertIn("LiftedLoop", output)
DEFAULT_FLAGS, CompilerBase, DefaultPassBuilder) from numba.core.typed_passes import IRLegalization from numba.core.untyped_passes import PreserveIR import unittest from numba.core.runtime import rtsys from numba.np import numpy_support from numba.pycc.platform import _external_compiler_ok try: import scipy except ImportError: scipy = None enable_pyobj_flags = Flags() enable_pyobj_flags.enable_pyobject = True force_pyobj_flags = Flags() force_pyobj_flags.force_pyobject = True no_pyobj_flags = Flags() nrt_flags = Flags() nrt_flags.nrt = True tag = testing.make_tag_decorator(['important', 'long_running']) _32bit = sys.maxsize <= 2**32 is_parfors_unsupported = _32bit skip_parfors_unsupported = unittest.skipIf( is_parfors_unsupported,
from io import StringIO import numpy as np from numba.core import types from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, MemoryLeakMixin import unittest looplift_flags = Flags() looplift_flags.enable_pyobject = True looplift_flags.enable_looplift = True pyobject_looplift_flags = looplift_flags.copy() pyobject_looplift_flags.enable_pyobject_looplift = True def lift1(x): # Outer needs object mode because of np.empty() a = np.empty(3) for i in range(a.size): # Inner is nopython-compliant a[i] = x return a def lift2(x): # Outer needs object mode because of np.empty() a = np.empty((3, 4)) for i in range(a.shape[0]): for j in range(a.shape[1]): # Inner is nopython-compliant