From b528205463b6c532c361980f5cb3cd4a5d402a4d Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 25 Sep 2019 17:04:43 -0600 Subject: [PATCH 001/595] Add get_num_threads and set_num_threads functions to tbbpool.cpp These will be used to allow masking threads. --- numba/npyufunc/tbbpool.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index d976c8f8974..b763e228a8f 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -37,6 +37,7 @@ Implement parallel vectorize workqueue on top of Intel TBB. static tbb::task_group *tg = NULL; static tbb::task_scheduler_init *tsi = NULL; static int tsi_count = 0; +int num_threads = 0; static void add_task(void *fn, void *args, void *dims, void *steps, void *data) @@ -206,6 +207,15 @@ static void ready(void) { } +static void set_num_threads(int count) +{ + num_threads = count; +} + +static int get_num_threads(void) +{ + return num_threads; +} MOD_INIT(tbbpool) { @@ -235,7 +245,10 @@ MOD_INIT(tbbpool) PyLong_FromVoidPtr((void*)&do_scheduling_signed)); PyObject_SetAttrString(m, "do_scheduling_unsigned", PyLong_FromVoidPtr((void*)&do_scheduling_unsigned)); - + PyObject_SetAttrString(m, "set_num_threads", + PyLong_FromVoidPtr((void*)&set_num_threads)); + PyObject_SetAttrString(m, "get_num_threads", + PyLong_FromVoidPtr((void*)&get_num_threads)); return MOD_SUCCESS_VAL(m); } From 066c61b97f137ff374ee7170e034d356b264442f Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 25 Sep 2019 17:29:41 -0600 Subject: [PATCH 002/595] Add get_num_threads and set_num_threads to omppool.cpp and workqueue.c --- numba/npyufunc/omppool.cpp | 17 +++++++++++++++++ numba/npyufunc/workqueue.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index 32293fd94df..c8dd0d8d31c 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -40,6 +40,8 @@ Threading layer on top of OpenMP. static pid_t parent_pid = 0; // 0 is not set, users can't own this anyway #endif +int num_threads = 0; + static void add_task(void *fn, void *args, void *dims, void *steps, void *data) { @@ -182,6 +184,16 @@ static void ready(void) { } +static void set_num_threads(int count) +{ + num_threads = count; +} + +static int get_num_threads(void) +{ + return num_threads; +} + MOD_INIT(omppool) { PyObject *m; @@ -205,5 +217,10 @@ MOD_INIT(omppool) PyLong_FromVoidPtr((void*)&do_scheduling_unsigned)); PyObject_SetAttrString(m, "openmp_vendor", PyString_FromString(_OMP_VENDOR)); + PyObject_SetAttrString(m, "set_num_threads", + PyLong_FromVoidPtr((void*)&set_num_threads)); + PyObject_SetAttrString(m, "get_num_threads", + PyLong_FromVoidPtr((void*)&get_num_threads)); + return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 17c29d22f87..f1366bbe48a 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -51,6 +51,8 @@ typedef struct pthread_mutex_t mutex; } queue_condition_t; +int num_threads = 0; + static int queue_condition_init(queue_condition_t *qc) { @@ -450,6 +452,16 @@ static void reset_after_fork(void) NUM_THREADS = -1; } +static void set_num_threads(int count) +{ + num_threads = count; +} + +static int get_num_threads(void) +{ + return num_threads; +} + MOD_INIT(workqueue) { PyObject *m; @@ -471,6 +483,10 @@ MOD_INIT(workqueue) PyLong_FromVoidPtr(&do_scheduling_signed)); PyObject_SetAttrString(m, "do_scheduling_unsigned", PyLong_FromVoidPtr(&do_scheduling_unsigned)); + PyObject_SetAttrString(m, "set_num_threads", + PyLong_FromVoidPtr((void*)&set_num_threads)); + PyObject_SetAttrString(m, "get_num_threads", + PyLong_FromVoidPtr((void*)&get_num_threads)); return MOD_SUCCESS_VAL(m); } From 33c4c8b72adcb5f5fea1d4152997713ea63c1593 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 25 Sep 2019 17:30:32 -0600 Subject: [PATCH 003/595] Add a basic API to mask the number of threads used by parfor This is still a work in progress. Still todo are: - Fix it for workqueue. For some reason if you set the number of threads to a lower number than the max, it only uses 1 thread. - Do the masking in the reduction phase as well. - Clean up the API (better function names?). - Tests. --- numba/npyufunc/parallel.py | 10 ++++++++++ numba/npyufunc/parfor.py | 12 +++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index d2e52e81088..67324d7f45f 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -442,9 +442,14 @@ def raise_with_hint(required): ll.add_symbol('numba_parallel_for', lib.parallel_for) ll.add_symbol('do_scheduling_signed', lib.do_scheduling_signed) ll.add_symbol('do_scheduling_unsigned', lib.do_scheduling_unsigned) + ll.add_symbol('get_num_threads', lib.get_num_threads) + ll.add_symbol('set_num_threads', lib.set_num_threads) launch_threads = CFUNCTYPE(None, c_int)(lib.launch_threads) launch_threads(NUM_THREADS) + global _set_num_threads + _set_num_threads = CFUNCTYPE(None, c_int)(lib.set_num_threads) + _set_num_threads(NUM_THREADS) # set library name so it can be queried global _threading_layer @@ -452,6 +457,11 @@ def raise_with_hint(required): _is_initialized = True +def set_num_threads(n): + if n > NUM_THREADS or n < 0: + raise ValueError("The number of threads must be between 0 and %s" % NUM_THREADS) + _set_num_threads(n) + _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 1096f32873d..9386794a9dc 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1291,11 +1291,17 @@ def load_range(v): do_scheduling = builder.module.get_or_insert_function(scheduling_fnty, name="do_scheduling_unsigned") + get_num_threads = builder.module.get_or_insert_function( + lc.Type.function(lc.Type.int(types.intp.bitwidth), []), + name="get_num_threads") + + num_threads = builder.call(get_num_threads, []) + builder.call( do_scheduling, [ context.get_constant( - types.uintp, num_dim), dim_starts, dim_stops, context.get_constant( - types.uintp, get_thread_count()), sched, context.get_constant( + types.uintp, num_dim), dim_starts, dim_stops, num_threads, + sched, context.get_constant( types.intp, debug_flag)]) # Get the LLVM vars for the Numba IR reduction array vars. @@ -1422,7 +1428,7 @@ def load_range(v): nshapes = len(sig_dim_dict) + 1 shapes = cgutils.alloca_once(builder, intp_t, size=nshapes, name="pshape") # For now, outer loop size is the same as number of threads - builder.store(context.get_constant(types.intp, get_thread_count()), shapes) + builder.store(num_threads, shapes) # Individual shape variables go next i = 1 for dim_sym in occurances: From c404b2eb3dbcbed508a12efda4fab18c768dcf97 Mon Sep 17 00:00:00 2001 From: Ethan Pronovost Date: Wed, 25 Sep 2019 21:24:06 -0700 Subject: [PATCH 004/595] Add implementation for `np.argwhere` Will likely fail tests for array-like input on numpy < 1.15, but I wanted to test --- docs/source/reference/numpysupported.rst | 1 + numba/targets/arraymath.py | 9 ++++++ numba/tests/test_array_manipulation.py | 36 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index fab892deaa4..0d737bfa4f7 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -303,6 +303,7 @@ The following top-level functions are supported: * :func:`numpy.arange` * :func:`numpy.argsort` (``kind`` key word argument supported for values ``'quicksort'`` and ``'mergesort'``) +* :func:`numpy.argwhere` * :func:`numpy.array` (only the 2 first arguments) * :func:`numpy.asarray` (only the 2 first arguments) * :func:`numpy.asfortranarray` (only the first argument) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 9a25cec4183..2e4298aa294 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -2520,6 +2520,15 @@ def np_corrcoef_impl_single_variable(x, y=None, rowvar=True): #---------------------------------------------------------------------------- # Element-wise computations +@overload(np.argwhere) +def np_argwhere(a): + + def impl(a): + return np.transpose(np.nonzero(a)) + + return impl + + @overload(np.flatnonzero) def np_flatnonzero(a): diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index d8a9b09f1da..23b9916c058 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -142,6 +142,10 @@ def numpy_flatnonzero(a): return np.flatnonzero(a) +def numpy_argwhere(a): + return np.argwhere(a) + + class TestArrayManipulation(MemoryLeakMixin, TestCase): """ Check shape-changing operations on arrays. @@ -768,6 +772,29 @@ def a_variations(): got = cfunc(a) self.assertPreciseEqual(expected, got) + def test_argwhere_basic(self): + pyfunc = numpy_argwhere + cfunc = jit(nopython=True)(pyfunc) + + def a_variations(): + yield np.arange(-5, 5) > 2 + yield np.full(5, fill_value=0) + yield np.full(5, fill_value=1) + yield np.array([]) + yield np.array([-1.0, 0.0, 1.0]) + a = self.random.randn(100) + yield a > 0.2 + yield a.reshape(5, 5, 4) > 0.5 + yield a.reshape(50, 2, order='F') > 0.5 + yield a.reshape(25, 4)[1::2] > 0.5 + yield a == a - 1 + yield a > -a + + for a in a_variations(): + expected = pyfunc(a) + got = cfunc(a) + self.assertPreciseEqual(expected, got) + @staticmethod def array_like_variations(): yield ((1.1, 2.2), (3.3, 4.4), (5.5, 6.6)) @@ -817,6 +844,15 @@ def test_flatnonzero_array_like_pre_115(self): self.assertIn("object has no attribute 'ravel'", str(e.exception)) + # This will probably fail pre 1.15 + def test_argwhere_array_like(self): + pyfunc = numpy_argwhere + cfunc = jit(nopython=True)(pyfunc) + + for a in self.array_like_variations(): + expected = pyfunc(a) + got = cfunc(a) + self.assertPreciseEqual(expected, got) if __name__ == '__main__': unittest.main() From 96cc3d354f73be3e2f7452aa2c5792ab2fe01726 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 27 Sep 2019 16:24:11 -0600 Subject: [PATCH 005/595] Some work in progress on masking threads in the reduction phase --- numba/npyufunc/parfor.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 9386794a9dc..3a864a62597 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -6,6 +6,8 @@ import linecache import os import sys +import operator + import numpy as np import llvmlite.llvmpy.core as lc @@ -19,7 +21,7 @@ get_definition, guard, find_callname, get_call_table, is_pure, get_np_ufunc_typ, get_unused_var_name, find_potential_aliases, - is_const_call) + is_const_call, next_label) from numba.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) from ..typing import signature @@ -58,6 +60,7 @@ def _lower_parfor_parallel(lowerer, parfor): lowerer.fndesc.typemap = copy.copy(orig_typemap) typemap = lowerer.fndesc.typemap varmap = lowerer.varmap + builder = lowerer.builder if config.DEBUG_ARRAY_OPT: print("_lower_parfor_parallel") @@ -97,6 +100,23 @@ def _lower_parfor_parallel(lowerer, parfor): parfor_redvars, parfor_reddict = numba.parfor.get_parfor_reductions( parfor, parfor.params, lowerer.fndesc.calltypes) + + + builder.module.get_or_insert_function( + lc.Type.function(lc.Type.int(types.intp.bitwidth), []), + name="get_num_threads") + + get_num_threads_sig = signature(types.intp) + get_num_threads_intrinsic = ir.Intrinsic('get_num_threads', get_num_threads_sig, []) + + num_threads = ir.Expr.call(get_num_threads_intrinsic, (), (), loc) + lowerer.fndesc.calltypes[num_threads] = get_num_threads_sig + + get_num_threads_var = ir.Var(scope, mk_unique_var('get_num_threads'), loc) + get_num_threads_assign = ir.Assign(num_threads, get_num_threads_var, loc) + typemap[get_num_threads_var.name] = types.intp + lowerer.lower_inst(get_num_threads_assign) + # init reduction array allocation here. nredvars = len(parfor_redvars) redarrs = {} @@ -221,6 +241,17 @@ def _lower_parfor_parallel(lowerer, parfor): typemap[index_var.name] = types.uintp lowerer.lower_inst(index_var_assign) + cond = ir.Expr.binop(operator.gt, index_var, get_num_threads_var, loc) + cond_var = ir.Var(scope, mk_unique_var('cond'), loc) + cond_assign = ir.Assign(cond, cond_var, loc) + typemap[cond_var.name] = types.intp + ir.lower_inst(cond_assign) + + truebr = next_label() + falsebr = next_label() + branch = ir.Branch(cond, truebr, falsebr, loc) + lowerer.lower_inst(branch) + redsetitem = ir.SetItem(redarr_var, index_var, redtoset, loc) lowerer.fndesc.calltypes[redsetitem] = signature(types.none, typemap[redarr_var.name], typemap[index_var.name], redvar_typ) From 6438b94037e26f0429d84d4971e85f1348d5c625 Mon Sep 17 00:00:00 2001 From: Ethan Pronovost Date: Sun, 29 Sep 2019 14:14:16 -0700 Subject: [PATCH 006/595] Simplify to only support array arguments --- numba/targets/arraymath.py | 2 +- numba/tests/test_array_manipulation.py | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 2e4298aa294..bb97694c135 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -2524,7 +2524,7 @@ def np_corrcoef_impl_single_variable(x, y=None, rowvar=True): def np_argwhere(a): def impl(a): - return np.transpose(np.nonzero(a)) + return np.transpose(np.stack(np.nonzero(a), axis=0)) return impl diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 23b9916c058..ecaa5e9ecbd 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -844,15 +844,5 @@ def test_flatnonzero_array_like_pre_115(self): self.assertIn("object has no attribute 'ravel'", str(e.exception)) - # This will probably fail pre 1.15 - def test_argwhere_array_like(self): - pyfunc = numpy_argwhere - cfunc = jit(nopython=True)(pyfunc) - - for a in self.array_like_variations(): - expected = pyfunc(a) - got = cfunc(a) - self.assertPreciseEqual(expected, got) - if __name__ == '__main__': unittest.main() From 163fe597a1c54ae8e86a0ce5039f8725d37c79dd Mon Sep 17 00:00:00 2001 From: Ethan Pronovost Date: Sun, 29 Sep 2019 19:37:25 -0700 Subject: [PATCH 007/595] Switch `np.stack` to `np.vstack` The former did not exist in numpy 1.9 --- numba/targets/arraymath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index bb97694c135..f9468c7dc12 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -2524,7 +2524,7 @@ def np_corrcoef_impl_single_variable(x, y=None, rowvar=True): def np_argwhere(a): def impl(a): - return np.transpose(np.stack(np.nonzero(a), axis=0)) + return np.transpose(np.vstack(np.nonzero(a))) return impl From 2ea2cbb1cd323f15445eb6802316b6acd983246e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 14 Oct 2019 16:25:20 -0600 Subject: [PATCH 008/595] Correct the code for calling get_num_threads in the parfor reduction phase --- numba/npyufunc/parfor.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 3a864a62597..1285fb05ff0 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -100,20 +100,20 @@ def _lower_parfor_parallel(lowerer, parfor): parfor_redvars, parfor_reddict = numba.parfor.get_parfor_reductions( parfor, parfor.params, lowerer.fndesc.calltypes) - - - builder.module.get_or_insert_function( + get_num_threads = builder.module.get_or_insert_function( lc.Type.function(lc.Type.int(types.intp.bitwidth), []), name="get_num_threads") - get_num_threads_sig = signature(types.intp) - get_num_threads_intrinsic = ir.Intrinsic('get_num_threads', get_num_threads_sig, []) + num_threads = builder.call(get_num_threads, []) - num_threads = ir.Expr.call(get_num_threads_intrinsic, (), (), loc) - lowerer.fndesc.calltypes[num_threads] = get_num_threads_sig + # get_num_threads_sig = signature(types.intp) + # get_num_threads_intrinsic = ir.Intrinsic('get_num_threads', get_num_threads_sig, []) + # + # num_threads = ir.Expr.call(get_num_threads_intrinsic, (), (), loc) + # lowerer.fndesc.calltypes[num_threads] = get_num_threads_sig get_num_threads_var = ir.Var(scope, mk_unique_var('get_num_threads'), loc) - get_num_threads_assign = ir.Assign(num_threads, get_num_threads_var, loc) + get_num_threads_assign = ir.Assign(ir.Const(num_threads, loc), get_num_threads_var, loc) typemap[get_num_threads_var.name] = types.intp lowerer.lower_inst(get_num_threads_assign) From 305c97b76aeb386d9bee3d8a579dfe7f632ffd5c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 14 Oct 2019 18:45:54 -0600 Subject: [PATCH 009/595] Some more work on using get_num_threads in the reduction phase It still doesn't work. I'm not sure exactly how to generate this logic with the numba IR. --- numba/npyufunc/parfor.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 1285fb05ff0..baf96c914fc 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -235,27 +235,41 @@ def _lower_parfor_parallel(lowerer, parfor): redtoset = redvar # For each thread, initialize the per-worker reduction array to the current reduction array value. + redblocks = [] for j in range(get_thread_count()): + block = ir.Block(scope, loc) + redblocks.append(block) index_var = ir.Var(scope, mk_unique_var("index_var"), loc) index_var_assign = ir.Assign(ir.Const(j, loc), index_var, loc) typemap[index_var.name] = types.uintp + block.body.append(index_var_assign) lowerer.lower_inst(index_var_assign) cond = ir.Expr.binop(operator.gt, index_var, get_num_threads_var, loc) cond_var = ir.Var(scope, mk_unique_var('cond'), loc) cond_assign = ir.Assign(cond, cond_var, loc) typemap[cond_var.name] = types.intp - ir.lower_inst(cond_assign) + lowerer.fndesc.calltypes[cond] = signature(types.i1, types.intp, types.intp) + lowerer.lower_inst(cond_assign) truebr = next_label() + true_block = ir.Block(scope, loc) + lowerer.blkmap[truebr] = true_block + # lowerer.blocks[truebr] = true_block falsebr = next_label() - branch = ir.Branch(cond, truebr, falsebr, loc) - lowerer.lower_inst(branch) + false_block = ir.Block(scope, loc) + lowerer.blkmap[falsebr] = false_block + # lowerer.blocks[falsebr] = false_block redsetitem = ir.SetItem(redarr_var, index_var, redtoset, loc) lowerer.fndesc.calltypes[redsetitem] = signature(types.none, typemap[redarr_var.name], typemap[index_var.name], redvar_typ) - lowerer.lower_inst(redsetitem) + false_block.body.append(redsetitem) + + branch = ir.Branch(cond_var, truebr, falsebr, loc) + block.body.append(branch) + # lowerer.lower_inst(branch) + parfor.init_block.body.append(ir.Jump(redblocks[0], loc)) # compile parfor body as a separate function to be used with GUFuncWrapper flags = copy.copy(parfor.flags) From 92bf4867f34aee6336fad9865d2651cfb5d3a398 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Tue, 15 Oct 2019 16:28:14 -0700 Subject: [PATCH 010/595] Only pass lives to parfor dead code removal instead of lives + aliases. --- numba/ir_utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 95601bf7a65..7366c909db7 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -504,6 +504,9 @@ def remove_dead(blocks, args, func_ir, typemap=None, alias_map=None, arg_aliases func_ir) if config.DEBUG_ARRAY_OPT >= 1: print("alias map:", alias_map) + print("live_map:", live_map) + print("usemap:", usedefs.usemap) + print("defmap:", usedefs.defmap) # keep set for easier search alias_set = set(alias_map.keys()) @@ -511,8 +514,12 @@ def remove_dead(blocks, args, func_ir, typemap=None, alias_map=None, arg_aliases for label, block in blocks.items(): # find live variables at each statement to delete dead assignment lives = {v.name for v in block.terminator.list_vars()} + if config.DEBUG_ARRAY_OPT >= 2: + print("remove_dead processing block", label, lives) # find live variables at the end of block for out_blk, _data in cfg.successors(label): + if config.DEBUG_ARRAY_OPT >= 2: + print("succ live_map", out_blk, live_map[out_blk]) lives |= live_map[out_blk] removed |= remove_dead_block(block, lives, call_table, arg_aliases, alias_map, alias_set, func_ir, typemap) @@ -539,6 +546,8 @@ def remove_dead_block(block, lives, call_table, arg_aliases, alias_map, new_body = [block.terminator] # for each statement in reverse order, excluding terminator for stmt in reversed(block.body[:-1]): + if config.DEBUG_ARRAY_OPT >= 2: + print("remove_dead_block", stmt) # aliases of lives are also live alias_lives = set() init_alias_lives = lives & alias_set @@ -549,7 +558,8 @@ def remove_dead_block(block, lives, call_table, arg_aliases, alias_map, # let external calls handle stmt if type matches if type(stmt) in remove_dead_extensions: f = remove_dead_extensions[type(stmt)] - stmt = f(stmt, lives_n_aliases, arg_aliases, alias_map, func_ir, + #stmt = f(stmt, lives_n_aliases, arg_aliases, alias_map, func_ir, + stmt = f(stmt, lives, arg_aliases, alias_map, func_ir, typemap) if stmt is None: removed = True @@ -1356,6 +1366,8 @@ def simplify(func_ir, typemap, calltypes): calltypes) restore_copy_var_names(func_ir.blocks, save_copies, typemap) # remove dead code to enable fusion + if config.DEBUG_ARRAY_OPT >= 1: + dprint_func_ir(func_ir, "after copy prop") remove_dead(func_ir.blocks, func_ir.arg_names, func_ir, typemap) func_ir.blocks = simplify_CFG(func_ir.blocks) if config.DEBUG_ARRAY_OPT >= 1: From 5ef56b3a842ab0cfec715553bcb12d636222071c Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Thu, 17 Oct 2019 09:41:09 -0700 Subject: [PATCH 011/595] Pass lives and lives_n_aliases to remove_dead_extensions. Use lives in parfor_remove_dead to create lives after parfor. --- numba/ir_utils.py | 3 +-- numba/parfor.py | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 7366c909db7..e69884d1a5d 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -558,8 +558,7 @@ def remove_dead_block(block, lives, call_table, arg_aliases, alias_map, # let external calls handle stmt if type matches if type(stmt) in remove_dead_extensions: f = remove_dead_extensions[type(stmt)] - #stmt = f(stmt, lives_n_aliases, arg_aliases, alias_map, func_ir, - stmt = f(stmt, lives, arg_aliases, alias_map, func_ir, + stmt = f(stmt, lives, lives_n_aliases, arg_aliases, alias_map, func_ir, typemap) if stmt is None: removed = True diff --git a/numba/parfor.py b/numba/parfor.py index c5723b21a59..2325225f1ce 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -3439,7 +3439,7 @@ def get_parfor_pattern_vars(parfor): out.add(v.name) return out -def remove_dead_parfor(parfor, lives, arg_aliases, alias_map, func_ir, typemap): +def remove_dead_parfor(parfor, lives, lives_n_aliases, arg_aliases, alias_map, func_ir, typemap): """ remove dead code inside parfor including get/sets """ @@ -3456,7 +3456,7 @@ def remove_dead_parfor(parfor, lives, arg_aliases, alias_map, func_ir, typemap): parfor.loop_body[first_label].body, parfor.index_var, alias_map, first_block_saved_values, - lives + lives_n_aliases ) # remove saved first block setitems if array potentially changed later @@ -3483,13 +3483,13 @@ def remove_dead_parfor(parfor, lives, arg_aliases, alias_map, func_ir, typemap): block = parfor.loop_body[l] saved_values = first_block_saved_values.copy() _update_parfor_get_setitems(block.body, parfor.index_var, alias_map, - saved_values, lives) + saved_values, lives_n_aliases) # after getitem replacement, remove extra setitems blocks = parfor.loop_body.copy() # shallow copy is enough last_label = max(blocks.keys()) - return_label, tuple_var = _add_liveness_return_block(blocks, lives, typemap) + return_label, tuple_var = _add_liveness_return_block(blocks, lives_n_aliases, typemap) # jump to return label jump = ir.Jump(return_label, ir.Loc("parfors_dummy", -1)) blocks[last_label].body.append(jump) From e1346e07307c3a69e779999aa1e7037a7428ea26 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Thu, 17 Oct 2019 10:22:09 -0700 Subject: [PATCH 012/595] Add test for issue4690 and some code to check the number of statements in the init_block. --- numba/tests/test_parfors.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 89e37e84264..0c280640848 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -366,6 +366,19 @@ def countArrays(test_func, args, **kws): test_ir, tp = get_optimized_numba_ir(test_func, args, **kws) return _count_arrays_inner(test_ir.blocks, tp.state.typemap) +def get_init_block_size(test_func, args, **kws): + test_ir, tp = get_optimized_numba_ir(test_func, args, **kws) + blocks = test_ir.blocks + + ret_count = 0 + + for label, block in blocks.items(): + for i, inst in enumerate(block.body): + if isinstance(inst, numba.parfor.Parfor): + ret_count += len(inst.init_block.body) + + return ret_count + def _count_arrays_inner(blocks, typemap): ret_count = 0 arr_set = set() @@ -2853,6 +2866,19 @@ def test_impl(A): # recover global state numba.parfor.sequential_parfor_lowering = old_seq_flag + @skip_unsupported + def test_init_block_dce(self): + # issue4690 + def test_impl(): + res = 0 + arr = [1,2,3,4,5] + numba.parfor.init_prange() + dummy = arr + for i in numba.prange(5): + res += arr[i] + return res + dummy[2] + + self.assertTrue(get_init_block_size(test_impl, ()) == 0) @skip_unsupported class TestParforsDiagnostics(TestParforsBase): From b0a87049e6fbc00ff3c7f8a6fd17b1247fd94f60 Mon Sep 17 00:00:00 2001 From: Ethan Pronovost Date: Thu, 17 Oct 2019 20:29:56 -0700 Subject: [PATCH 013/595] Add support for array_like arguments in `argwhere` Also correct the implementation of `flatnonzero` when taking a "False-y" object that does not pass `type_can_asarray` (e.g. an empty set or string). The test is now failing because `bool` is not defined; see my other PR for that. The array_like tests will likely fail for older versions of numpy. I'll make another commit to fix this (similar to `flatnonzero`) once the full CI suite runs. --- numba/targets/arraymath.py | 18 +++++++++++++----- numba/tests/test_array_manipulation.py | 11 +++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index f9468c7dc12..58ffce187d5 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -2523,8 +2523,16 @@ def np_corrcoef_impl_single_variable(x, y=None, rowvar=True): @overload(np.argwhere) def np_argwhere(a): - def impl(a): - return np.transpose(np.vstack(np.nonzero(a))) + if type_can_asarray(a): + def impl(a): + arr = np.asarray(a) + return np.transpose(np.vstack(np.nonzero(arr))) + else: + def impl(a): + if a is not None and bool(a): + return np.zeros((1, 1), dtype=types.intp) + else: + return np.zeros((0, 1), dtype=types.intp) return impl @@ -2544,10 +2552,10 @@ def impl(a): return np.nonzero(np.ravel(arr))[0] else: def impl(a): - if a is None: - data = [x for x in range(0)] - else: + if a is not None and bool(a): data = [0] + else: + data = [x for x in range(0)] return np.array(data, dtype=types.intp) return impl diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index ecaa5e9ecbd..44ada4bf2a1 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -805,12 +805,14 @@ def array_like_variations(): yield 0 yield 1 yield False + yield True yield (True, False, True) yield 2 + 1j # the following are not array-like, but numpy 1.15+ does not raise yield None if not sys.version_info < (3,): yield 'a_string' + yield '' @unittest.skipUnless(np_version >= (1, 15), "flatnonzero array-like handling per 1.15+") @@ -844,5 +846,14 @@ def test_flatnonzero_array_like_pre_115(self): self.assertIn("object has no attribute 'ravel'", str(e.exception)) + def test_argwhere_array_like(self): + pyfunc = numpy_argwhere + cfunc = jit(nopython=True)(pyfunc) + for a in self.array_like_variations(): + expected = pyfunc(a) + got = cfunc(a) + self.assertPreciseEqual(expected, got) + + if __name__ == '__main__': unittest.main() From 6082c0ac0afd4380a2c318e8d2d3e125dbc4da7c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 23 Oct 2019 15:13:55 -0600 Subject: [PATCH 014/595] Remove WIP get_thread_count stuff from the parfor reduction phase --- numba/npyufunc/parfor.py | 44 +--------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index baf96c914fc..da4c119e6aa 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -100,23 +100,6 @@ def _lower_parfor_parallel(lowerer, parfor): parfor_redvars, parfor_reddict = numba.parfor.get_parfor_reductions( parfor, parfor.params, lowerer.fndesc.calltypes) - get_num_threads = builder.module.get_or_insert_function( - lc.Type.function(lc.Type.int(types.intp.bitwidth), []), - name="get_num_threads") - - num_threads = builder.call(get_num_threads, []) - - # get_num_threads_sig = signature(types.intp) - # get_num_threads_intrinsic = ir.Intrinsic('get_num_threads', get_num_threads_sig, []) - # - # num_threads = ir.Expr.call(get_num_threads_intrinsic, (), (), loc) - # lowerer.fndesc.calltypes[num_threads] = get_num_threads_sig - - get_num_threads_var = ir.Var(scope, mk_unique_var('get_num_threads'), loc) - get_num_threads_assign = ir.Assign(ir.Const(num_threads, loc), get_num_threads_var, loc) - typemap[get_num_threads_var.name] = types.intp - lowerer.lower_inst(get_num_threads_assign) - # init reduction array allocation here. nredvars = len(parfor_redvars) redarrs = {} @@ -235,41 +218,16 @@ def _lower_parfor_parallel(lowerer, parfor): redtoset = redvar # For each thread, initialize the per-worker reduction array to the current reduction array value. - redblocks = [] for j in range(get_thread_count()): - block = ir.Block(scope, loc) - redblocks.append(block) index_var = ir.Var(scope, mk_unique_var("index_var"), loc) index_var_assign = ir.Assign(ir.Const(j, loc), index_var, loc) typemap[index_var.name] = types.uintp - block.body.append(index_var_assign) lowerer.lower_inst(index_var_assign) - cond = ir.Expr.binop(operator.gt, index_var, get_num_threads_var, loc) - cond_var = ir.Var(scope, mk_unique_var('cond'), loc) - cond_assign = ir.Assign(cond, cond_var, loc) - typemap[cond_var.name] = types.intp - lowerer.fndesc.calltypes[cond] = signature(types.i1, types.intp, types.intp) - lowerer.lower_inst(cond_assign) - - truebr = next_label() - true_block = ir.Block(scope, loc) - lowerer.blkmap[truebr] = true_block - # lowerer.blocks[truebr] = true_block - falsebr = next_label() - false_block = ir.Block(scope, loc) - lowerer.blkmap[falsebr] = false_block - # lowerer.blocks[falsebr] = false_block - redsetitem = ir.SetItem(redarr_var, index_var, redtoset, loc) lowerer.fndesc.calltypes[redsetitem] = signature(types.none, typemap[redarr_var.name], typemap[index_var.name], redvar_typ) - false_block.body.append(redsetitem) - - branch = ir.Branch(cond_var, truebr, falsebr, loc) - block.body.append(branch) - # lowerer.lower_inst(branch) - parfor.init_block.body.append(ir.Jump(redblocks[0], loc)) + lowerer.lower_inst(redsetitem) # compile parfor body as a separate function to be used with GUFuncWrapper flags = copy.copy(parfor.flags) From 2651ce7f9700846183e82329fbff5203ff080fa5 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 23 Oct 2019 15:15:08 -0600 Subject: [PATCH 015/595] Remove unused variable --- numba/npyufunc/parfor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index da4c119e6aa..0404b4084ed 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -60,7 +60,6 @@ def _lower_parfor_parallel(lowerer, parfor): lowerer.fndesc.typemap = copy.copy(orig_typemap) typemap = lowerer.fndesc.typemap varmap = lowerer.varmap - builder = lowerer.builder if config.DEBUG_ARRAY_OPT: print("_lower_parfor_parallel") From 63189ca9f567dc6ba35d59e860e2295959dc02a2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 23 Oct 2019 16:23:47 -0600 Subject: [PATCH 016/595] Make num_threads thread local in the tbb backend --- numba/npyufunc/tbbpool.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index b763e228a8f..db1ca3d8f38 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -37,7 +37,15 @@ Implement parallel vectorize workqueue on top of Intel TBB. static tbb::task_group *tg = NULL; static tbb::task_scheduler_init *tsi = NULL; static int tsi_count = 0; -int num_threads = 0; + +#ifdef _MSC_VER +#define THREAD_LOCAL(ty) __declspec(thread) ty +#else +/* Non-standard C99 extension that's understood by gcc and clang */ +#define THREAD_LOCAL(ty) __thread ty +#endif + +static THREAD_LOCAL(int) num_threads = 0; static void add_task(void *fn, void *args, void *dims, void *steps, void *data) From 8ee5652dddb66b2eb6e766c39ce1e7aa73266478 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 28 Oct 2019 12:50:55 -0600 Subject: [PATCH 017/595] Fix flake8 issues --- numba/npyufunc/parallel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 67324d7f45f..a7485f2f502 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -459,9 +459,11 @@ def raise_with_hint(required): def set_num_threads(n): if n > NUM_THREADS or n < 0: - raise ValueError("The number of threads must be between 0 and %s" % NUM_THREADS) + raise ValueError("The number of threads must be between 0 and %s" % + NUM_THREADS) _set_num_threads(n) + _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) From 2bc6dc2e6866a862aceda8105fa0f50ae29a987b Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 29 Oct 2019 17:25:19 +0000 Subject: [PATCH 018/595] Make type_callable return the decorated function This brings it in line with the behavior of `overload` and friends. --- numba/extending.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/extending.py b/numba/extending.py index e173d14ce6b..39b971d28d1 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -44,6 +44,7 @@ def generic(self): infer(template) if callable(func): infer_global(func, types.Function(template)) + return typing_func return decorate From 4eac9cf439c712245e7254047ad05efe803ef791 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 29 Oct 2019 13:46:08 -0600 Subject: [PATCH 019/595] Make sure threads are launched when calling set_num_threads() --- numba/npyufunc/parallel.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index a7485f2f502..aa48a595468 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -458,6 +458,8 @@ def raise_with_hint(required): def set_num_threads(n): + _launch_threads() + if n > NUM_THREADS or n < 0: raise ValueError("The number of threads must be between 0 and %s" % NUM_THREADS) From 5287cf8279c1c6bc6998c49d53acf818595f17e2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 29 Oct 2019 16:04:58 -0600 Subject: [PATCH 020/595] Add a jitted version of set_num_threads for testing purposes --- numba/npyufunc/parallel.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index aa48a595468..0e679c365c6 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -26,7 +26,7 @@ from numba.npyufunc import ufuncbuilder from numba.numpy_support import as_dtype -from numba import types, config, utils +from numba import types, config, utils, njit from numba.npyufunc.wrappers import _wrapper_info @@ -466,6 +466,16 @@ def set_num_threads(n): _set_num_threads(n) +@njit +def _set_num_threads_jit(n): + """ + Jitted version of set_num_threads for testing + + It does not check that n is in the right range and it will fail if + _launch_threads() has not already been called. + """ + _set_num_threads(n) + _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) From 464784b15bf4318c3b7d646e5efb6eb689fe44de Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 30 Oct 2019 15:28:57 -0600 Subject: [PATCH 021/595] Don't allow set_num_threads(0) --- numba/npyufunc/parallel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 0e679c365c6..c00e03301e2 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -460,8 +460,8 @@ def raise_with_hint(required): def set_num_threads(n): _launch_threads() - if n > NUM_THREADS or n < 0: - raise ValueError("The number of threads must be between 0 and %s" % + if n > NUM_THREADS or n < 1: + raise ValueError("The number of threads must be between 1 and %s" % NUM_THREADS) _set_num_threads(n) From fcd6cd136ee0887b3db36d04019d94a74686096e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 30 Oct 2019 15:31:16 -0600 Subject: [PATCH 022/595] Make set_num_threads() return the old number of threads --- numba/npyufunc/parallel.py | 6 +++--- numba/npyufunc/tbbpool.cpp | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index c00e03301e2..f99929b3b84 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -448,7 +448,7 @@ def raise_with_hint(required): launch_threads = CFUNCTYPE(None, c_int)(lib.launch_threads) launch_threads(NUM_THREADS) global _set_num_threads - _set_num_threads = CFUNCTYPE(None, c_int)(lib.set_num_threads) + _set_num_threads = CFUNCTYPE(c_int, c_int)(lib.set_num_threads) _set_num_threads(NUM_THREADS) # set library name so it can be queried @@ -463,7 +463,7 @@ def set_num_threads(n): if n > NUM_THREADS or n < 1: raise ValueError("The number of threads must be between 1 and %s" % NUM_THREADS) - _set_num_threads(n) + return _set_num_threads(n) @njit @@ -474,7 +474,7 @@ def _set_num_threads_jit(n): It does not check that n is in the right range and it will fail if _launch_threads() has not already been called. """ - _set_num_threads(n) + return _set_num_threads(n) _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index db1ca3d8f38..1eb77571f0a 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -215,9 +215,11 @@ static void ready(void) { } -static void set_num_threads(int count) +static int set_num_threads(int count) { + int old_num_threads = num_threads; num_threads = count; + return old_num_threads; } static int get_num_threads(void) From 9f0561faa2c81d2ef3d3780af6f44e9e2a946ae8 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 30 Oct 2019 16:11:45 -0600 Subject: [PATCH 023/595] Add some documentation for thread masking --- docs/source/user/threading-layer.rst | 18 ++++++++++++++++++ numba/npyufunc/parallel.py | 28 +++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index 576979e9592..dc00b7e5706 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -167,3 +167,21 @@ system level libraries, some additional things to note: threading layer. * For Windows users running Python 2.7, the ``tbb`` threading layer is not available. + +Masking Threads +--------------- + +The number of threads used by numba is based on the number of CPU cores +available (``multiprocessing.cpu_count()``), but it can be overridden with the +:envvar:`NUMBA_NUM_THREADS` environment variable. + +The total number of threads is in the variable +:obj:`numba.npyufunc.parallel.NUM_THREADS`: + +.. autodata:: numba.npyufunc.parallel.NUM_THREADS + :annotation: + +This total can be masked to a smaller number using +:func:`numba.npyufunc.parallel.set_num_threads`: + +.. autofunction:: numba.npyufunc.parallel.set_num_threads diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index f99929b3b84..daa424858f3 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -39,7 +39,10 @@ def get_thread_count(): raise ValueError("Number of threads specified must be > 0.") return t - +#: The total (maximum) number of threads used by numba parallel. +#: +#: Defaults to the number of cores but can be overridden with the +#: envvar:`NUMBA_NUM_THREADS` environment variable. NUM_THREADS = get_thread_count() @@ -458,6 +461,29 @@ def raise_with_hint(required): def set_num_threads(n): + """ + Set the number of threads to use for parallel execution + + This functionality works by masking out threads that are not used. + Therefore, the number of threads *n* must be less than or equal to the + total number of threads that are launched, which is set to the number of + cores by default but can be configured with the + :envvar:`NUMBA_NUM_THREADS` environment variable. See the + :func:`get_thread_count` function. + + Parameters + ---------- + n: The number of threads. Must be between 1 and :obj:`numba.npyufunc.parallel.NUM_THREADS`. + + Returns + ------- + The old number of threads. + + See Also + -------- + get_num_threads, NUM_THREADS + + """ _launch_threads() if n > NUM_THREADS or n < 1: From 87793a779c9c4cc7a954ab77efd497927bba8e3e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 30 Oct 2019 16:28:46 -0600 Subject: [PATCH 024/595] Add get_num_threads function to Python --- numba/npyufunc/parallel.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index daa424858f3..93998859ec8 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -450,10 +450,14 @@ def raise_with_hint(required): launch_threads = CFUNCTYPE(None, c_int)(lib.launch_threads) launch_threads(NUM_THREADS) + global _set_num_threads _set_num_threads = CFUNCTYPE(c_int, c_int)(lib.set_num_threads) _set_num_threads(NUM_THREADS) + global _get_num_threads + _get_num_threads = CFUNCTYPE(c_int)(lib.set_num_threads) + # set library name so it can be queried global _threading_layer _threading_layer = libname @@ -492,6 +496,29 @@ def set_num_threads(n): return _set_num_threads(n) +def get_num_threads(): + """ + Get the number of threads used for parallel execution. + + By default (if :func:`~.set_num_threads` is never called), all + :obj:`numba.npyufunc.parallel.NUM_THREADS` threads are used. + + This number is less than or equal to the total number of threads that are + launched, :obj:`numba.npyufunc.parallel.NUM_THREADS`. + + Returns + ------- + The number of threads. + + See Also + -------- + set_num_threads, NUM_THREADS + + """ + _launch_threads() + return _get_num_threads() + + @njit def _set_num_threads_jit(n): """ From 1ebef50f893692fcd443c2e8684e1f7663b7ec64 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 30 Oct 2019 16:29:06 -0600 Subject: [PATCH 025/595] Improved the documentation for thread masking --- docs/source/user/threading-layer.rst | 25 +++++++++++++++++++------ numba/npyufunc/parallel.py | 15 ++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index dc00b7e5706..81f950fbd2b 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -168,20 +168,33 @@ system level libraries, some additional things to note: * For Windows users running Python 2.7, the ``tbb`` threading layer is not available. -Masking Threads ---------------- +Setting the Number of Threads +----------------------------- The number of threads used by numba is based on the number of CPU cores available (``multiprocessing.cpu_count()``), but it can be overridden with the :envvar:`NUMBA_NUM_THREADS` environment variable. The total number of threads is in the variable -:obj:`numba.npyufunc.parallel.NUM_THREADS`: +:obj:`numba.npyufunc.parallel.NUM_THREADS`. + +For some use cases, it may be desirable to set the number of threads to a +lower value, so that numba can be used with higher level parallelism. + +The number of threads can be set dynamically at runtime using +:func:`numba.npyufunc.parallel.set_num_threads`. Note that +:func:`~.set_num_threads` only allows setting the number +of threads to a smaller value than :obj:`~.NUM_THREADS`. + +The number of threads can be accessed with +:func:`numba.npyufunc.parallel.get_num_threads`: + +API Reference +~~~~~~~~~~~~~ .. autodata:: numba.npyufunc.parallel.NUM_THREADS :annotation: -This total can be masked to a smaller number using -:func:`numba.npyufunc.parallel.set_num_threads`: - .. autofunction:: numba.npyufunc.parallel.set_num_threads + +.. autofunction:: numba.npyufunc.parallel.get_num_threads diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 93998859ec8..94e9505953e 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -466,18 +466,19 @@ def raise_with_hint(required): def set_num_threads(n): """ - Set the number of threads to use for parallel execution + Set the number of threads to use for parallel execution. + + By default, all :obj:`numba.npyufunc.parallel.NUM_THREADS` threads are + used. This functionality works by masking out threads that are not used. - Therefore, the number of threads *n* must be less than or equal to the - total number of threads that are launched, which is set to the number of - cores by default but can be configured with the - :envvar:`NUMBA_NUM_THREADS` environment variable. See the - :func:`get_thread_count` function. + Therefore, the number of threads *n* must be less than or equal to + :obj:`~.NUM_THREADS`, the total number of threads that are launched. See + its documentation for more details. Parameters ---------- - n: The number of threads. Must be between 1 and :obj:`numba.npyufunc.parallel.NUM_THREADS`. + n: The number of threads. Must be between 1 and NUM_THREADS. Returns ------- From 81292d1cc4bd99451c7baca3329e8f89e751e1c7 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 31 Oct 2019 12:36:44 -0600 Subject: [PATCH 026/595] Fix flake8 errors --- numba/npyufunc/parallel.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 94e9505953e..d1e95494f31 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -39,6 +39,7 @@ def get_thread_count(): raise ValueError("Number of threads specified must be > 0.") return t + #: The total (maximum) number of threads used by numba parallel. #: #: Defaults to the number of cores but can be overridden with the @@ -530,6 +531,7 @@ def _set_num_threads_jit(n): """ return _set_num_threads(n) + _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) From 86e70f9b215e41d644ccc66550e10f432b3d17f2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 12:22:15 -0700 Subject: [PATCH 027/595] Move get_num_threads and set_num_threads to their own C module --- numba/npyufunc/_num_threads.c | 39 +++++++++++++++++++++++++++++++++++ numba/npyufunc/omppool.cpp | 17 --------------- numba/npyufunc/parallel.py | 27 ++++++++++++++---------- numba/npyufunc/tbbpool.cpp | 25 +--------------------- numba/npyufunc/workqueue.c | 16 -------------- setup.py | 8 +++++-- 6 files changed, 62 insertions(+), 70 deletions(-) create mode 100644 numba/npyufunc/_num_threads.c diff --git a/numba/npyufunc/_num_threads.c b/numba/npyufunc/_num_threads.c new file mode 100644 index 00000000000..0ba43910474 --- /dev/null +++ b/numba/npyufunc/_num_threads.c @@ -0,0 +1,39 @@ +// Thread local num_threads variable for masking out the total number of +// launched threads. + +#include "../_pymodule.h" + +#ifdef _MSC_VER +#define THREAD_LOCAL(ty) __declspec(thread) ty +#else +/* Non-standard C99 extension that's understood by gcc and clang */ +#define THREAD_LOCAL(ty) __thread ty +#endif + +static THREAD_LOCAL(int) num_threads = 0; + +static int set_num_threads(int count) +{ + int old_num_threads = num_threads; + num_threads = count; + return old_num_threads; +} + +static int get_num_threads(void) +{ + return num_threads; +} + +MOD_INIT(_num_threads) +{ + PyObject *m; + MOD_DEF(m, "_num_threads", "No docs", NULL) + if (m == NULL) + return MOD_ERROR_VAL; + PyObject_SetAttrString(m, "set_num_threads", + PyLong_FromVoidPtr((void*)&set_num_threads)); + PyObject_SetAttrString(m, "get_num_threads", + PyLong_FromVoidPtr((void*)&get_num_threads)); + + return MOD_SUCCESS_VAL(m); +} diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index c8dd0d8d31c..32293fd94df 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -40,8 +40,6 @@ Threading layer on top of OpenMP. static pid_t parent_pid = 0; // 0 is not set, users can't own this anyway #endif -int num_threads = 0; - static void add_task(void *fn, void *args, void *dims, void *steps, void *data) { @@ -184,16 +182,6 @@ static void ready(void) { } -static void set_num_threads(int count) -{ - num_threads = count; -} - -static int get_num_threads(void) -{ - return num_threads; -} - MOD_INIT(omppool) { PyObject *m; @@ -217,10 +205,5 @@ MOD_INIT(omppool) PyLong_FromVoidPtr((void*)&do_scheduling_unsigned)); PyObject_SetAttrString(m, "openmp_vendor", PyString_FromString(_OMP_VENDOR)); - PyObject_SetAttrString(m, "set_num_threads", - PyLong_FromVoidPtr((void*)&set_num_threads)); - PyObject_SetAttrString(m, "get_num_threads", - PyLong_FromVoidPtr((void*)&get_num_threads)); - return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index d1e95494f31..9c1643114fa 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -18,6 +18,7 @@ from threading import RLock as threadRLock import multiprocessing from contextlib import contextmanager +from ctypes import CFUNCTYPE, c_int import numpy as np @@ -324,8 +325,6 @@ def _launch_threads(): if _is_initialized: return - from ctypes import CFUNCTYPE, c_int - def select_known_backend(backend): """ Loads a specific threading layer backend based on string @@ -446,25 +445,31 @@ def raise_with_hint(required): ll.add_symbol('numba_parallel_for', lib.parallel_for) ll.add_symbol('do_scheduling_signed', lib.do_scheduling_signed) ll.add_symbol('do_scheduling_unsigned', lib.do_scheduling_unsigned) - ll.add_symbol('get_num_threads', lib.get_num_threads) - ll.add_symbol('set_num_threads', lib.set_num_threads) launch_threads = CFUNCTYPE(None, c_int)(lib.launch_threads) launch_threads(NUM_THREADS) - global _set_num_threads - _set_num_threads = CFUNCTYPE(c_int, c_int)(lib.set_num_threads) - _set_num_threads(NUM_THREADS) - - global _get_num_threads - _get_num_threads = CFUNCTYPE(c_int)(lib.set_num_threads) - # set library name so it can be queried global _threading_layer _threading_layer = libname _is_initialized = True +def _load_num_threads_funcs(): + from . import _num_threads as lib + + ll.add_symbol('get_num_threads', lib.get_num_threads) + ll.add_symbol('set_num_threads', lib.set_num_threads) + + global _set_num_threads + _set_num_threads = CFUNCTYPE(c_int, c_int)(lib.set_num_threads) + _set_num_threads(NUM_THREADS) + + global _get_num_threads + _get_num_threads = CFUNCTYPE(c_int)(lib.set_num_threads) + +_load_num_threads_funcs() + def set_num_threads(n): """ Set the number of threads to use for parallel execution. diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index 1eb77571f0a..d976c8f8974 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -38,15 +38,6 @@ static tbb::task_group *tg = NULL; static tbb::task_scheduler_init *tsi = NULL; static int tsi_count = 0; -#ifdef _MSC_VER -#define THREAD_LOCAL(ty) __declspec(thread) ty -#else -/* Non-standard C99 extension that's understood by gcc and clang */ -#define THREAD_LOCAL(ty) __thread ty -#endif - -static THREAD_LOCAL(int) num_threads = 0; - static void add_task(void *fn, void *args, void *dims, void *steps, void *data) { @@ -215,17 +206,6 @@ static void ready(void) { } -static int set_num_threads(int count) -{ - int old_num_threads = num_threads; - num_threads = count; - return old_num_threads; -} - -static int get_num_threads(void) -{ - return num_threads; -} MOD_INIT(tbbpool) { @@ -255,10 +235,7 @@ MOD_INIT(tbbpool) PyLong_FromVoidPtr((void*)&do_scheduling_signed)); PyObject_SetAttrString(m, "do_scheduling_unsigned", PyLong_FromVoidPtr((void*)&do_scheduling_unsigned)); - PyObject_SetAttrString(m, "set_num_threads", - PyLong_FromVoidPtr((void*)&set_num_threads)); - PyObject_SetAttrString(m, "get_num_threads", - PyLong_FromVoidPtr((void*)&get_num_threads)); + return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index f1366bbe48a..17c29d22f87 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -51,8 +51,6 @@ typedef struct pthread_mutex_t mutex; } queue_condition_t; -int num_threads = 0; - static int queue_condition_init(queue_condition_t *qc) { @@ -452,16 +450,6 @@ static void reset_after_fork(void) NUM_THREADS = -1; } -static void set_num_threads(int count) -{ - num_threads = count; -} - -static int get_num_threads(void) -{ - return num_threads; -} - MOD_INIT(workqueue) { PyObject *m; @@ -483,10 +471,6 @@ MOD_INIT(workqueue) PyLong_FromVoidPtr(&do_scheduling_signed)); PyObject_SetAttrString(m, "do_scheduling_unsigned", PyLong_FromVoidPtr(&do_scheduling_unsigned)); - PyObject_SetAttrString(m, "set_num_threads", - PyLong_FromVoidPtr((void*)&set_num_threads)); - PyObject_SetAttrString(m, "get_num_threads", - PyLong_FromVoidPtr((void*)&get_num_threads)); return MOD_SUCCESS_VAL(m); } diff --git a/setup.py b/setup.py index b36604f6d9f..b86330a80eb 100644 --- a/setup.py +++ b/setup.py @@ -148,6 +148,10 @@ def get_ext_modules(): "numba/_pymodule.h"], **np_compile_args) + ext_npyufunc_num_threads = Extension(name="numba.npyufunc._num_threads", + sources=["numba/npyufunc/_num_threads.c"], + depends=["numba/_pymodule.h"], + ) ext_npyufunc_workqueue_impls = [] @@ -279,8 +283,8 @@ def check_file_at_path(path2file): include_dirs=["numba"]) ext_modules = [ext_dynfunc, ext_dispatcher, ext_helperlib, ext_typeconv, - ext_npyufunc_ufunc, ext_mviewbuf, ext_nrt_python, - ext_jitclass_box, ext_cuda_extras] + ext_npyufunc_ufunc, ext_npyufunc_num_threads, ext_mviewbuf, + ext_nrt_python, ext_jitclass_box, ext_cuda_extras] ext_modules += ext_npyufunc_workqueue_impls From 424202cb48e5f1c231a29ca9d0cb90f8cc61fc7e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 17:00:45 -0700 Subject: [PATCH 028/595] Remove the return value from set_num_threads --- numba/npyufunc/_num_threads.c | 4 +--- numba/npyufunc/parallel.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/numba/npyufunc/_num_threads.c b/numba/npyufunc/_num_threads.c index 0ba43910474..78156d78a77 100644 --- a/numba/npyufunc/_num_threads.c +++ b/numba/npyufunc/_num_threads.c @@ -12,11 +12,9 @@ static THREAD_LOCAL(int) num_threads = 0; -static int set_num_threads(int count) +static void set_num_threads(int count) { - int old_num_threads = num_threads; num_threads = count; - return old_num_threads; } static int get_num_threads(void) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 9c1643114fa..b332f394b8c 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -462,7 +462,7 @@ def _load_num_threads_funcs(): ll.add_symbol('set_num_threads', lib.set_num_threads) global _set_num_threads - _set_num_threads = CFUNCTYPE(c_int, c_int)(lib.set_num_threads) + _set_num_threads = CFUNCTYPE(None, c_int)(lib.set_num_threads) _set_num_threads(NUM_THREADS) global _get_num_threads From f353a6f9eab219c32539816ee02b312725cfb207 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 17:01:02 -0700 Subject: [PATCH 029/595] Fix a typo --- numba/npyufunc/parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index b332f394b8c..69e60cb1989 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -466,7 +466,7 @@ def _load_num_threads_funcs(): _set_num_threads(NUM_THREADS) global _get_num_threads - _get_num_threads = CFUNCTYPE(c_int)(lib.set_num_threads) + _get_num_threads = CFUNCTYPE(c_int)(lib.get_num_threads) _load_num_threads_funcs() From 1965c975040e247654438d44870e59a243c11146 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 17:01:10 -0700 Subject: [PATCH 030/595] Make get_num_threads and set_num_threads work in a jitted function --- numba/npyufunc/parallel.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 69e60cb1989..ede6d631c2a 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -29,6 +29,7 @@ from numba.numpy_support import as_dtype from numba import types, config, utils, njit from numba.npyufunc.wrappers import _wrapper_info +from numba.extending import overload def get_thread_count(): @@ -470,6 +471,23 @@ def _load_num_threads_funcs(): _load_num_threads_funcs() +# Some helpers to make set_num_threads jittable + +def snt_check(n): + from numba.config import NUMBA_NUM_THREADS + msg = "The number of threads must be between 1 and %s" % NUMBA_NUM_THREADS + if n > NUMBA_NUM_THREADS or n < 1: + raise ValueError(msg) + +@overload(snt_check) +def ol_snt_check(n): + from numba.config import NUMBA_NUM_THREADS + msg = "The number of threads must be between 1 and %s" % NUMBA_NUM_THREADS + def impl(n): + if n > NUMBA_NUM_THREADS or n < 1: + raise ValueError(msg) + return impl + def set_num_threads(n): """ Set the number of threads to use for parallel execution. @@ -497,11 +515,15 @@ def set_num_threads(n): """ _launch_threads() - if n > NUM_THREADS or n < 1: - raise ValueError("The number of threads must be between 1 and %s" % - NUM_THREADS) - return _set_num_threads(n) + snt_check(n) + _set_num_threads(n) +@overload(set_num_threads) +def ol_set_num_threads(n): + def impl(n): + snt_check(n) + _set_num_threads(n) + return impl def get_num_threads(): """ @@ -522,9 +544,13 @@ def get_num_threads(): set_num_threads, NUM_THREADS """ - _launch_threads() return _get_num_threads() +@overload(get_num_threads) +def ol_get_num_threads(): + def impl(): + return _get_num_threads() + return impl @njit def _set_num_threads_jit(n): From 8f06b5e910df9e6423fad99a3244ac503078d83a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 17:01:35 -0700 Subject: [PATCH 031/595] Remove _set_num_threads_jit --- numba/npyufunc/parallel.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index ede6d631c2a..4652b1da55b 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -552,17 +552,6 @@ def impl(): return _get_num_threads() return impl -@njit -def _set_num_threads_jit(n): - """ - Jitted version of set_num_threads for testing - - It does not check that n is in the right range and it will fail if - _launch_threads() has not already been called. - """ - return _set_num_threads(n) - - _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) From 538cc40bb30661075e2bbf76831041af44b39fd7 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 17:04:30 -0700 Subject: [PATCH 032/595] Add get_num_threads and set_num_threads to __init__.py --- numba/__init__.py | 3 ++- numba/npyufunc/__init__.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index aabe97fc99a..5887cb33718 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -31,7 +31,8 @@ jit_module) # Re-export vectorize decorators and the thread layer querying function -from .npyufunc import vectorize, guvectorize, threading_layer +from .npyufunc import (vectorize, guvectorize, threading_layer, + get_num_threads, set_num_threads) # Re-export Numpy helpers from .numpy_support import carray, farray, from_dtype diff --git a/numba/npyufunc/__init__.py b/numba/npyufunc/__init__.py index b1736268832..2f44fc80f02 100644 --- a/numba/npyufunc/__init__.py +++ b/numba/npyufunc/__init__.py @@ -4,7 +4,7 @@ from .decorators import Vectorize, GUVectorize, vectorize, guvectorize from ._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One from . import _internal, array_exprs, parfor -from .parallel import threading_layer +from .parallel import threading_layer, get_num_threads, set_num_threads if hasattr(_internal, 'PyUFunc_ReorderableNone'): PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone del _internal, array_exprs From 74abf6d3260ce449e5e74b7e580d7a96f7adb999 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 17:09:48 -0700 Subject: [PATCH 033/595] Remove an unused import --- numba/npyufunc/parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 5185cbd8fb3..e903c9df4df 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -27,7 +27,7 @@ from numba.npyufunc import ufuncbuilder from numba.numpy_support import as_dtype -from numba import types, config, utils, njit +from numba import types, config, utils from numba.npyufunc.wrappers import _wrapper_info from numba.extending import overload From bf40093cf99e0fb4709fe355fdd16c7cc6a448aa Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 5 Nov 2019 17:41:43 -0700 Subject: [PATCH 034/595] Update the documentation on set_num_threads and friends --- docs/source/reference/envvars.rst | 6 ++-- docs/source/user/threading-layer.rst | 42 +++++++++++++++++++--------- numba/npyufunc/parallel.py | 31 ++++++++++---------- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/docs/source/reference/envvars.rst b/docs/source/reference/envvars.rst index 8b0645ea3c0..fd4f3ba4ea4 100644 --- a/docs/source/reference/envvars.rst +++ b/docs/source/reference/envvars.rst @@ -342,7 +342,10 @@ Threading Control of ``OMP_NUM_THREADS`` and ``MKL_NUM_THREADS``. *Default value:* The number of CPU cores on the system as determined at run - time, this can be accessed via ``numba.config.NUMBA_DEFAULT_NUM_THREADS``. + time. This can be accessed via :obj:`numba.config.NUMBA_DEFAULT_NUM_THREADS`. + + See also the section on :ref:`setting_the_number_of_threads` for + information on how to set the number of threads at runtime. .. envvar:: NUMBA_THREADING_LAYER @@ -363,4 +366,3 @@ Threading Control * ``tbb`` - A threading layer backed by Intel TBB. * ``omp`` - A threading layer backed by OpenMP. * ``workqueue`` - A simple built-in work-sharing task scheduler. - diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index 81f950fbd2b..9e8fcf2b9a2 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -168,33 +168,49 @@ system level libraries, some additional things to note: * For Windows users running Python 2.7, the ``tbb`` threading layer is not available. +.. _setting_the_number_of_threads: + Setting the Number of Threads ----------------------------- The number of threads used by numba is based on the number of CPU cores -available (``multiprocessing.cpu_count()``), but it can be overridden with the -:envvar:`NUMBA_NUM_THREADS` environment variable. +available (see :obj:`numba.config.NUMBA_DEFAULT_NUM_THREADS`), but it can be +overridden with the :envvar:`NUMBA_NUM_THREADS` environment variable. -The total number of threads is in the variable -:obj:`numba.npyufunc.parallel.NUM_THREADS`. +The total number of threads that numba launches is in the variable +:obj:`numba.config.NUMBA_NUM_THREADS`. For some use cases, it may be desirable to set the number of threads to a lower value, so that numba can be used with higher level parallelism. The number of threads can be set dynamically at runtime using -:func:`numba.npyufunc.parallel.set_num_threads`. Note that -:func:`~.set_num_threads` only allows setting the number -of threads to a smaller value than :obj:`~.NUM_THREADS`. +:func:`numba.set_num_threads`. Note that :func:`~.set_num_threads` only allows +setting the number of threads to a smaller value than +:obj:`~.NUMBA_NUM_THREADS`. Numba always launches +:obj:`numba.config.NUMBA_NUM_THREADS` threads, but :func:`~.set_num_threads` +causes it to mask out unused threads so they aren't used in computations. -The number of threads can be accessed with -:func:`numba.npyufunc.parallel.get_num_threads`: +The current number of threads used by numba can be accessed with +:func:`numba.get_num_threads`. Both functions work inside of a jitted +function. API Reference ~~~~~~~~~~~~~ -.. autodata:: numba.npyufunc.parallel.NUM_THREADS - :annotation: +.. py:data:: numba.config.NUMBA_NUM_THREADS + + The total (maximum) number of threads launched by numba. + + Defaults :obj:`numba.config.NUMBA_DEFAULT_NUM_THREADS`, but can be + overridden with the :envvar:`NUMBA_NUM_THREADS` environment variable. + +.. py:data:: numba.config.NUMBA_DEFAULT_NUM_THREADS + + The number of CPU cores on the system (as determined by + ``multiprocessing.cpu_count()``). This is the default value for + :obj:`numba.config.NUMBA_NUM_THREADS` unless the + :envvar:`NUMBA_NUM_THREADS` environment variable is set. -.. autofunction:: numba.npyufunc.parallel.set_num_threads +.. autofunction:: numba.set_num_threads -.. autofunction:: numba.npyufunc.parallel.get_num_threads +.. autofunction:: numba.get_num_threads diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index e903c9df4df..8ea3363fe55 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -42,10 +42,6 @@ def get_thread_count(): return t -#: The total (maximum) number of threads used by numba parallel. -#: -#: Defaults to the number of cores but can be overridden with the -#: envvar:`NUMBA_NUM_THREADS` environment variable. NUM_THREADS = get_thread_count() @@ -492,25 +488,23 @@ def set_num_threads(n): """ Set the number of threads to use for parallel execution. - By default, all :obj:`numba.npyufunc.parallel.NUM_THREADS` threads are - used. + By default, all :obj:`numba.config.NUMBA_NUM_THREADS` threads are used. This functionality works by masking out threads that are not used. Therefore, the number of threads *n* must be less than or equal to - :obj:`~.NUM_THREADS`, the total number of threads that are launched. See - its documentation for more details. + :obj:`~.NUMBA_NUM_THREADS`, the total number of threads that are launched. + See its documentation for more details. + + This function can be used inside of a jitted function. Parameters ---------- - n: The number of threads. Must be between 1 and NUM_THREADS. - - Returns - ------- - The old number of threads. + n: The number of threads. Must be between 1 and NUMBA_NUM_THREADS. See Also -------- - get_num_threads, NUM_THREADS + get_num_threads, numba.config.NUMBA_NUM_THREADS, + numba.config.NUMBA_DEFAULT_NUM_THREADS, :envvar:`NUMBA_NUM_THREADS` """ _launch_threads() @@ -530,10 +524,12 @@ def get_num_threads(): Get the number of threads used for parallel execution. By default (if :func:`~.set_num_threads` is never called), all - :obj:`numba.npyufunc.parallel.NUM_THREADS` threads are used. + :obj:`numba.config.NUMBA_NUM_THREADS` threads are used. This number is less than or equal to the total number of threads that are - launched, :obj:`numba.npyufunc.parallel.NUM_THREADS`. + launched, :obj:`numba.config.NUMBA_NUM_THREADS`. + + This function can be used inside of a jitted function. Returns ------- @@ -541,7 +537,8 @@ def get_num_threads(): See Also -------- - set_num_threads, NUM_THREADS + set_num_threads, numba.config.NUMBA_NUM_THREADS, + numba.config.NUMBA_DEFAULT_NUM_THREADS, :envvar:`NUMBA_NUM_THREADS` """ return _get_num_threads() From a3f416003a67d9798a9a294177b0a3a077ba3c8e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 6 Nov 2019 15:10:23 -0700 Subject: [PATCH 035/595] Fix flake8 issues --- numba/npyufunc/parallel.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 8ea3363fe55..075c4d95321 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -465,25 +465,30 @@ def _load_num_threads_funcs(): global _get_num_threads _get_num_threads = CFUNCTYPE(c_int)(lib.get_num_threads) + _load_num_threads_funcs() # Some helpers to make set_num_threads jittable + def snt_check(n): from numba.config import NUMBA_NUM_THREADS msg = "The number of threads must be between 1 and %s" % NUMBA_NUM_THREADS if n > NUMBA_NUM_THREADS or n < 1: raise ValueError(msg) + @overload(snt_check) def ol_snt_check(n): from numba.config import NUMBA_NUM_THREADS msg = "The number of threads must be between 1 and %s" % NUMBA_NUM_THREADS + def impl(n): if n > NUMBA_NUM_THREADS or n < 1: raise ValueError(msg) return impl + def set_num_threads(n): """ Set the number of threads to use for parallel execution. @@ -512,6 +517,7 @@ def set_num_threads(n): snt_check(n) _set_num_threads(n) + @overload(set_num_threads) def ol_set_num_threads(n): def impl(n): @@ -519,6 +525,7 @@ def impl(n): _set_num_threads(n) return impl + def get_num_threads(): """ Get the number of threads used for parallel execution. @@ -543,12 +550,14 @@ def get_num_threads(): """ return _get_num_threads() + @overload(get_num_threads) def ol_get_num_threads(): def impl(): return _get_num_threads() return impl + _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) From cb5d7cef0acb09a582e93612915ab3ffe9f53b23 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 8 Nov 2019 16:14:41 -0700 Subject: [PATCH 036/595] Start writing tests for get_num_threads and set_num_threads --- numba/tests/test_num_threads.py | 107 ++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 numba/tests/test_num_threads.py diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py new file mode 100644 index 00000000000..fb7d7b6e161 --- /dev/null +++ b/numba/tests/test_num_threads.py @@ -0,0 +1,107 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function, absolute_import, division + +import numpy as np + +from numba import njit, set_num_threads, get_num_threads, prange, config +from numba import unittest_support as unittest +from .support import TestCase, skip_parfors_unsupported + +class TestNumThreads(TestCase): + _numba_parallel_test_ = False + + def setUp(self): + # Make sure the num_threads is set to the max. This also makes sure + # the threads are launched. + set_num_threads(config.NUMBA_NUM_THREADS) + + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_set_num_threads_basic(self): + max_threads = config.NUMBA_NUM_THREADS + + self.assertEqual(get_num_threads(), max_threads) + set_num_threads(2) + self.assertEqual(get_num_threads(), 2) + set_num_threads(max_threads) + self.assertEqual(get_num_threads(), max_threads) + + with self.assertRaises(ValueError): + set_num_threads(0) + + with self.assertRaises(ValueError): + set_num_threads(max_threads + 1) + + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_set_num_threads_basic_jit(self): + max_threads = config.NUMBA_NUM_THREADS + + @njit + def get_n(): + return get_num_threads() + + @njit + def set_n(n): + set_num_threads(n) + + self.assertEqual(get_n(), max_threads) + set_n(2) + self.assertEqual(get_n(), 2) + set_n(max_threads) + self.assertEqual(get_n(), max_threads) + + @njit + def set_get_n(n): + set_num_threads(n) + return get_num_threads() + + self.assertEqual(set_get_n(2), 2) + self.assertEqual(set_get_n(max_threads), max_threads) + + with self.assertRaises(ValueError): + set_n(0) + + with self.assertRaises(ValueError): + set_n(max_threads + 1) + + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_set_num_threads_outside_jit(self): + + # Test set_num_threads outside a jitted function + set_num_threads(2) + + @njit(parallel=True) + def test_func(): + x = 5 + buf = np.empty((x,)) + for i in prange(x): + buf[i] = get_num_threads() + return buf + + out = test_func() + self.assertTrue(np.all(out == 2)) + + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_set_num_threads_inside_jit(self): + # Test set_num_threads inside a jitted function + @njit(parallel=True) + def test_func(nthreads): + x = 5 + buf = np.empty((x,)) + set_num_threads(nthreads) + for i in prange(x): + buf[i] = get_num_threads() + return buf + + mask = 2 + out = test_func(mask) + self.assertTrue(np.all(out == mask)) + + def tearDown(self): + set_num_threads(config.NUMBA_NUM_THREADS) + +if __name__ == '__main__': + unittest.main() From ff17bf8555ef14b280abbd6a42caac3085cf3332 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 15 Nov 2019 13:44:07 -0700 Subject: [PATCH 037/595] Use numpy.testing.assert_equal instead of self.assertEqual(np.all(...)) --- numba/tests/test_num_threads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index fb7d7b6e161..461ba90bc53 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -81,7 +81,7 @@ def test_func(): return buf out = test_func() - self.assertTrue(np.all(out == 2)) + np.testing.assert_equal(out, 2) @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") @@ -98,7 +98,7 @@ def test_func(nthreads): mask = 2 out = test_func(mask) - self.assertTrue(np.all(out == mask)) + np.testing.assert_equal(out, mask) def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) From 8502b0354ef2756a00a56cef65e64870b0529ebf Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 18 Nov 2019 15:33:42 -0700 Subject: [PATCH 038/595] Make set_num_threads() affect guvectorized functions This requires setting the number of threads in the backends themselves. This is not yet implemented for workqueue. --- numba/npyufunc/omppool.cpp | 4 +- numba/npyufunc/parallel.py | 10 ++++- numba/npyufunc/tbbpool.cpp | 89 +++++++++++++++++++++----------------- numba/npyufunc/workqueue.c | 2 +- numba/npyufunc/workqueue.h | 2 +- 5 files changed, 62 insertions(+), 45 deletions(-) diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index 32293fd94df..3d1c6a4d66a 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -51,7 +51,7 @@ add_task(void *fn, void *args, void *dims, void *steps, void *data) static void parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *data, - size_t inner_ndim, size_t array_count) + size_t inner_ndim, size_t array_count, int num_threads) { typedef void (*func_ptr_t)(char **args, size_t *dims, size_t *steps, void *data); func_ptr_t func = reinterpret_cast(fn); @@ -107,6 +107,8 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat printf("\n"); } + omp_set_num_threads(num_threads); + #pragma omp parallel { size_t * count_space = (size_t *)alloca(sizeof(size_t) * arg_len); diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 075c4d95321..aa6c435f292 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -132,7 +132,7 @@ def as_void_ptr(arg): array_count = len(sig.args) + 1 parallel_for_ty = lc.Type.function(lc.Type.void(), - [byte_ptr_t] * 5 + [intp_t, ] * 2) + [byte_ptr_t] * 5 + [intp_t, ] * 3) parallel_for = mod.get_or_insert_function(parallel_for_ty, name='numba_parallel_for') @@ -146,12 +146,18 @@ def as_void_ptr(arg): ) wrapperlib.add_linking_library(info.library) + get_num_threads = builder.module.get_or_insert_function( + lc.Type.function(lc.Type.int(types.intp.bitwidth), []), + name="get_num_threads") + + num_threads = builder.call(get_num_threads, []) + # Prepare call fnptr = builder.bitcast(tmp_voidptr, byte_ptr_t) innerargs = [as_void_ptr(x) for x in [args, dimensions, steps, data]] builder.call(parallel_for, [fnptr] + innerargs + - [intp_t(x) for x in (inner_ndim, array_count)]) + [intp_t(x) for x in (inner_ndim, array_count)] + [num_threads]) # Release the GIL pyapi.restore_thread(thread_state) diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index d976c8f8974..5bcc1029ae0 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -50,7 +50,7 @@ add_task(void *fn, void *args, void *dims, void *steps, void *data) static void parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *data, - size_t inner_ndim, size_t array_count) + size_t inner_ndim, size_t array_count, int num_threads) { static bool printed = false; if(!printed && _DEBUG) @@ -83,49 +83,58 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat printf("\n"); } - using range_t = tbb::blocked_range; - tbb::parallel_for(range_t(0, dimensions[0]), [=](const range_t &range) - { - size_t * count_space = (size_t *)alloca(sizeof(size_t) * arg_len); - char ** array_arg_space = (char**)alloca(sizeof(char*) * array_count); - memcpy(count_space, dimensions, arg_len * sizeof(size_t)); - count_space[0] = range.size(); + tbb::task_arena limited(num_threads); - if(_DEBUG && _TRACE_SPLIT > 1) - { - printf("THREAD %p:", count_space); - printf("count_space: "); - for(size_t j = 0; j < arg_len; j++) - printf("%lu, ", count_space[j]); - printf("\n"); - } - for(size_t j = 0; j < array_count; j++) + limited.execute([&] + { + tg->run([=] { - char * base = args[j]; - size_t step = steps[j]; - ptrdiff_t offset = step * range.begin(); - array_arg_space[j] = base + offset; - - if(_DEBUG && _TRACE_SPLIT > 2) + using range_t = tbb::blocked_range; + tbb::parallel_for(range_t(0, dimensions[0]), [=](const range_t &range) { - printf("Index %ld\n", j); - printf("-->Got base %p\n", (void *)base); - printf("-->Got step %lu\n", step); - printf("-->Got offset %ld\n", offset); - printf("-->Got addr %p\n", (void *)array_arg_space[j]); - } - } - - if(_DEBUG && _TRACE_SPLIT > 2) - { - printf("array_arg_space: "); - for(size_t j = 0; j < array_count; j++) - printf("%p, ", (void *)array_arg_space[j]); - printf("\n"); - } - auto func = reinterpret_cast(fn); - func(array_arg_space, count_space, steps, data); + size_t * count_space = (size_t *)alloca(sizeof(size_t) * arg_len); + char ** array_arg_space = (char**)alloca(sizeof(char*) * array_count); + memcpy(count_space, dimensions, arg_len * sizeof(size_t)); + count_space[0] = range.size(); + + if(_DEBUG && _TRACE_SPLIT > 1) + { + printf("THREAD %p:", count_space); + printf("count_space: "); + for(size_t j = 0; j < arg_len; j++) + printf("%lu, ", count_space[j]); + printf("\n"); + } + for(size_t j = 0; j < array_count; j++) + { + char * base = args[j]; + size_t step = steps[j]; + ptrdiff_t offset = step * range.begin(); + array_arg_space[j] = base + offset; + + if(_DEBUG && _TRACE_SPLIT > 2) + { + printf("Index %ld\n", j); + printf("-->Got base %p\n", (void *)base); + printf("-->Got step %lu\n", step); + printf("-->Got offset %ld\n", offset); + printf("-->Got addr %p\n", (void *)array_arg_space[j]); + } + } + + if(_DEBUG && _TRACE_SPLIT > 2) + { + printf("array_arg_space: "); + for(size_t j = 0; j < array_count; j++) + printf("%p, ", (void *)array_arg_space[j]); + printf("\n"); + } + auto func = reinterpret_cast(fn); + func(array_arg_space, count_space, steps, data); + }); + }); }); + limited.execute([&]{ tg->wait(); }); } void ignore_blocking_terminate_assertion( const char*, int, const char*, const char * ) diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 17c29d22f87..428b21845b6 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -246,7 +246,7 @@ void nopfn(void *args, void *dims, void *steps, void *data) {}; static void parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *data, - size_t inner_ndim, size_t array_count) + size_t inner_ndim, size_t array_count, int num_threads) { // args = , diff --git a/numba/npyufunc/workqueue.h b/numba/npyufunc/workqueue.h index cfb805c55fd..32f78480bd6 100644 --- a/numba/npyufunc/workqueue.h +++ b/numba/npyufunc/workqueue.h @@ -53,4 +53,4 @@ void ready(void); */ static void parallel_for(void *fn, char **args, size_t *dims, size_t *steps, void *data,\ - size_t inner_ndim, size_t array_count); + size_t inner_ndim, size_t array_count, int num_threads); From 179ce8daff2eac6d15af9343e9f88bdabd768d9a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 25 Nov 2019 13:01:50 +0000 Subject: [PATCH 039/595] Fix issues in #4615 (thread masking). This does the following: * Adds the function `get_thread_num()` to the API, this returns a unique id for the calling thread in the current execution context. This is not to be part of the public API but is useful in testing. * Fixes the TBB backend: * removes potential nested parallelism deadlock * adds TLS synchronisation in tbb::task_arena usage * Fixes the OpenMP backend: * Permits nested parallelism * Adds TLS sychronisation in the OMP PARALLEL region * Prevents potential race condition in parallel for launch * Remove global OMP DSO state mutation * Fixes the workqueue backend: * Limits the active queue size based on num_threads * Adds TLS sychronisation as a prequistite task set prior to submitting the distributed kernel work. * Adds some tests (more work needed). --- numba/__init__.py | 2 +- numba/npyufunc/__init__.py | 3 +- numba/npyufunc/omppool.cpp | 50 ++++++++- numba/npyufunc/parallel.py | 24 +++- numba/npyufunc/tbbpool.cpp | 141 ++++++++++++++++-------- numba/npyufunc/workqueue.c | 78 +++++++++++-- numba/npyufunc/workqueue.h | 9 ++ numba/tests/test_num_threads.py | 189 +++++++++++++++++++++++++++++++- 8 files changed, 436 insertions(+), 60 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index 5887cb33718..30d75fb15f5 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -32,7 +32,7 @@ # Re-export vectorize decorators and the thread layer querying function from .npyufunc import (vectorize, guvectorize, threading_layer, - get_num_threads, set_num_threads) + get_num_threads, set_num_threads, get_thread_num) # Re-export Numpy helpers from .numpy_support import carray, farray, from_dtype diff --git a/numba/npyufunc/__init__.py b/numba/npyufunc/__init__.py index 2f44fc80f02..97448d43597 100644 --- a/numba/npyufunc/__init__.py +++ b/numba/npyufunc/__init__.py @@ -4,7 +4,8 @@ from .decorators import Vectorize, GUVectorize, vectorize, guvectorize from ._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One from . import _internal, array_exprs, parfor -from .parallel import threading_layer, get_num_threads, set_num_threads +from .parallel import (threading_layer, get_num_threads, set_num_threads, + get_thread_num) if hasattr(_internal, 'PyUFunc_ReorderableNone'): PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone del _internal, array_exprs diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index 3d1c6a4d66a..79b61b80576 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -40,6 +40,34 @@ Threading layer on top of OpenMP. static pid_t parent_pid = 0; // 0 is not set, users can't own this anyway #endif + +#ifdef _MSC_VER +#define THREAD_LOCAL(ty) __declspec(thread) ty +#else +/* Non-standard C99 extension that's understood by gcc and clang */ +#define THREAD_LOCAL(ty) __thread ty +#endif + +static THREAD_LOCAL(int) num_threads = 0; + +static void +set_num_threads(int count) +{ + num_threads = count; +} + +static int +get_num_threads(void) +{ + return num_threads; +} + +static int +get_thread_num(void) +{ + return omp_get_thread_num(); +} + static void add_task(void *fn, void *args, void *dims, void *steps, void *data) { @@ -90,6 +118,10 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat // index variable in OpenMP 'for' statement must have signed integral type for MSVC const ptrdiff_t size = (ptrdiff_t)dimensions[0]; + // holds the shared variable for `num_threads`, this is a bit superfluous + // but present to force thinking about the scope of validity + int agreed_nthreads = num_threads; + if(_DEBUG) { printf("inner_ndim: %lu\n",inner_ndim); @@ -107,12 +139,17 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat printf("\n"); } - omp_set_num_threads(num_threads); - - #pragma omp parallel + // Set the thread mask on the pragma such that the state is scope limited + // and passed via a register on the OMP region call site, this limiting + // global state and racing + #pragma omp parallel num_threads(num_threads), shared(agreed_nthreads) { size_t * count_space = (size_t *)alloca(sizeof(size_t) * arg_len); char ** array_arg_space = (char**)alloca(sizeof(char*) * array_count); + + // tell the active thread team about the number of threads + set_num_threads(agreed_nthreads); + #pragma omp for for(ptrdiff_t r = 0; r < size; r++) { @@ -174,6 +211,7 @@ static void launch_threads(int count) if(count < 1) return; omp_set_num_threads(count); + omp_set_nested(0x1); // enable nesting, control depth with OMP env var } static void synchronize(void) @@ -207,5 +245,11 @@ MOD_INIT(omppool) PyLong_FromVoidPtr((void*)&do_scheduling_unsigned)); PyObject_SetAttrString(m, "openmp_vendor", PyString_FromString(_OMP_VENDOR)); + PyObject_SetAttrString(m, "set_num_threads", + PyLong_FromVoidPtr((void*)&set_num_threads)); + PyObject_SetAttrString(m, "get_num_threads", + PyLong_FromVoidPtr((void*)&get_num_threads)); + PyObject_SetAttrString(m, "get_thread_num", + PyLong_FromVoidPtr((void*)&get_thread_num)); return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index aa6c435f292..0a3dfc1e599 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -452,17 +452,19 @@ def raise_with_hint(required): launch_threads = CFUNCTYPE(None, c_int)(lib.launch_threads) launch_threads(NUM_THREADS) + _load_num_threads_funcs(lib) # load late + # set library name so it can be queried global _threading_layer _threading_layer = libname _is_initialized = True -def _load_num_threads_funcs(): - from . import _num_threads as lib +def _load_num_threads_funcs(lib): ll.add_symbol('get_num_threads', lib.get_num_threads) ll.add_symbol('set_num_threads', lib.set_num_threads) + ll.add_symbol('get_thread_num', lib.get_thread_num) global _set_num_threads _set_num_threads = CFUNCTYPE(None, c_int)(lib.set_num_threads) @@ -471,8 +473,9 @@ def _load_num_threads_funcs(): global _get_num_threads _get_num_threads = CFUNCTYPE(c_int)(lib.get_num_threads) + global _get_thread_num + _get_thread_num = CFUNCTYPE(c_int)(lib.get_thread_num) -_load_num_threads_funcs() # Some helpers to make set_num_threads jittable @@ -519,13 +522,13 @@ def set_num_threads(n): """ _launch_threads() - snt_check(n) _set_num_threads(n) @overload(set_num_threads) def ol_set_num_threads(n): + _launch_threads() def impl(n): snt_check(n) _set_num_threads(n) @@ -554,15 +557,28 @@ def get_num_threads(): numba.config.NUMBA_DEFAULT_NUM_THREADS, :envvar:`NUMBA_NUM_THREADS` """ + _launch_threads() return _get_num_threads() @overload(get_num_threads) def ol_get_num_threads(): + _launch_threads() def impl(): return _get_num_threads() return impl +def get_thread_num(): + """ + docs + """ + return _get_thread_num() + +@overload(get_thread_num) +def ol_get_thread_num(): + def impl(): + return _get_thread_num() + return impl _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index 5bcc1029ae0..157b069d253 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -38,6 +38,49 @@ static tbb::task_group *tg = NULL; static tbb::task_scheduler_init *tsi = NULL; static int tsi_count = 0; +#ifdef _MSC_VER +#define THREAD_LOCAL(ty) __declspec(thread) ty +#else +/* Non-standard C99 extension that's understood by gcc and clang */ +#define THREAD_LOCAL(ty) __thread ty +#endif + +static THREAD_LOCAL(int) num_threads = 0; + +static void +set_num_threads(int count) +{ + num_threads = count; +} + +static int +get_num_threads(void) +{ + return num_threads; +} + +static int +get_thread_num(void) +{ + return tbb::task_arena::current_thread_index(); +} + +// watch the arena, if it decides to create more threads/add threads into the +// arena then make sure they get the right thread count +class fix_tls_observer: public tbb::task_scheduler_observer { + int mask_val; + void on_scheduler_entry( bool is_worker ) override; +public: + fix_tls_observer(tbb::task_arena &arena, int mask) : tbb::task_scheduler_observer(arena), mask_val(mask) + { + observe(true); + } +}; + +void fix_tls_observer::on_scheduler_entry(bool worker) { + set_num_threads(mask_val); +} + static void add_task(void *fn, void *args, void *dims, void *steps, void *data) { @@ -83,58 +126,65 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat printf("\n"); } + // This is making the assumption that the calling thread knows the truth + // about num_threads, which should be correct via the following: + // program starts/reinits and the threadpool launches, num_threads TLS is + // set as default. Any thread spawned on init making a call to this function + // will have a valid num_threads TLS slot and so the task_arena is sized + // appropriately and it's value is used in the observer that fixes the TLS + // slots of any subsequent threads joining the task_arena. This leads to + // all threads in a task_arena having valid num_threads TLS slots prior to + // doing any work. Any further call to query the TLS slot value made by any + // thread in the arena is then safe and were any thread to create a nested + // parallel region the same logic applies as per program start/reinit. tbb::task_arena limited(num_threads); + fix_tls_observer observer(limited, num_threads); - limited.execute([&] - { - tg->run([=] + limited.execute([&]{ + using range_t = tbb::blocked_range; + tbb::parallel_for(range_t(0, dimensions[0]), [=](const range_t &range) { - using range_t = tbb::blocked_range; - tbb::parallel_for(range_t(0, dimensions[0]), [=](const range_t &range) - { - size_t * count_space = (size_t *)alloca(sizeof(size_t) * arg_len); - char ** array_arg_space = (char**)alloca(sizeof(char*) * array_count); - memcpy(count_space, dimensions, arg_len * sizeof(size_t)); - count_space[0] = range.size(); + size_t * count_space = (size_t *)alloca(sizeof(size_t) * arg_len); + char ** array_arg_space = (char**)alloca(sizeof(char*) * array_count); + memcpy(count_space, dimensions, arg_len * sizeof(size_t)); + count_space[0] = range.size(); - if(_DEBUG && _TRACE_SPLIT > 1) - { - printf("THREAD %p:", count_space); - printf("count_space: "); - for(size_t j = 0; j < arg_len; j++) - printf("%lu, ", count_space[j]); - printf("\n"); - } - for(size_t j = 0; j < array_count; j++) - { - char * base = args[j]; - size_t step = steps[j]; - ptrdiff_t offset = step * range.begin(); - array_arg_space[j] = base + offset; - - if(_DEBUG && _TRACE_SPLIT > 2) - { - printf("Index %ld\n", j); - printf("-->Got base %p\n", (void *)base); - printf("-->Got step %lu\n", step); - printf("-->Got offset %ld\n", offset); - printf("-->Got addr %p\n", (void *)array_arg_space[j]); - } - } + if(_DEBUG && _TRACE_SPLIT > 1) + { + printf("THREAD %p:", count_space); + printf("count_space: "); + for(size_t j = 0; j < arg_len; j++) + printf("%lu, ", count_space[j]); + printf("\n"); + } + for(size_t j = 0; j < array_count; j++) + { + char * base = args[j]; + size_t step = steps[j]; + ptrdiff_t offset = step * range.begin(); + array_arg_space[j] = base + offset; if(_DEBUG && _TRACE_SPLIT > 2) { - printf("array_arg_space: "); - for(size_t j = 0; j < array_count; j++) - printf("%p, ", (void *)array_arg_space[j]); - printf("\n"); + printf("Index %ld\n", j); + printf("-->Got base %p\n", (void *)base); + printf("-->Got step %lu\n", step); + printf("-->Got offset %ld\n", offset); + printf("-->Got addr %p\n", (void *)array_arg_space[j]); } - auto func = reinterpret_cast(fn); - func(array_arg_space, count_space, steps, data); - }); + } + + if(_DEBUG && _TRACE_SPLIT > 2) + { + printf("array_arg_space: "); + for(size_t j = 0; j < array_count; j++) + printf("%p, ", (void *)array_arg_space[j]); + printf("\n"); + } + auto func = reinterpret_cast(fn); + func(array_arg_space, count_space, steps, data); }); }); - limited.execute([&]{ tg->wait(); }); } void ignore_blocking_terminate_assertion( const char*, int, const char*, const char * ) @@ -244,7 +294,12 @@ MOD_INIT(tbbpool) PyLong_FromVoidPtr((void*)&do_scheduling_signed)); PyObject_SetAttrString(m, "do_scheduling_unsigned", PyLong_FromVoidPtr((void*)&do_scheduling_unsigned)); - + PyObject_SetAttrString(m, "set_num_threads", + PyLong_FromVoidPtr((void*)&set_num_threads)); + PyObject_SetAttrString(m, "get_num_threads", + PyLong_FromVoidPtr((void*)&get_num_threads)); + PyObject_SetAttrString(m, "get_thread_num", + PyLong_FromVoidPtr((void*)&get_thread_num)); return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 428b21845b6..8267e6621cf 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -114,6 +114,12 @@ numba_new_thread(void *worker, void *arg) return (thread_pointer)th; } +static int +get_thread_num(void) +{ + return pthread_self(); +} + #endif /* Win Thread */ @@ -199,6 +205,12 @@ numba_new_thread(void *worker, void *arg) return (thread_pointer)handle; } +static int +get_thread_num(void) +{ + return GetCurrentThreadId(); +} + #endif typedef struct Task @@ -239,10 +251,41 @@ queue_state_wait(Queue *queue, int old, int repl) void debug_marker(void); void debug_marker() {}; + +#ifdef _MSC_VER +#define THREAD_LOCAL(ty) __declspec(thread) ty +#else +/* Non-standard C99 extension that's understood by gcc and clang */ +#define THREAD_LOCAL(ty) __thread ty +#endif + +static THREAD_LOCAL(int) num_threads = 0; + +static void +set_num_threads(int count) +{ + num_threads = count; +} + +static int +get_num_threads(void) +{ + return num_threads; +} + + // this complies to a launchable function from `add_task` like: // add_task(nopfn, NULL, NULL, NULL, NULL) // useful if you want to limit the number of threads locally -void nopfn(void *args, void *dims, void *steps, void *data) {}; +// static void nopfn(void *args, void *dims, void *steps, void *data) {}; + + +// synchronize the TLS num_threads slot to value args[0] +static void sync_tls(void *args, void *dims, void *steps, void *data) { + int nthreads = *((int *)(args)); + num_threads = nthreads; +}; + static void parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *data, @@ -257,17 +300,19 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat size_t * count_space = NULL; char ** array_arg_space = NULL; const size_t arg_len = (inner_ndim + 1); - size_t i, j, count, remain, total; + int i; // induction var for chunking, thread count unlikely to overflow int + size_t j, count, remain, total; ptrdiff_t offset; char * base; + int old_queue_count = -1; size_t step; debug_marker(); total = *((size_t *)dimensions); - count = total / NUM_THREADS; + count = total / num_threads; remain = total; if(_DEBUG) @@ -298,12 +343,24 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat } } - + // sync the thread pool TLS slots, sync all slots, we don't know which + // threads will end up running. for (i = 0; i < NUM_THREADS; i++) + { + add_task(sync_tls, (void *)(&num_threads), NULL, NULL, NULL); + } + ready(); + synchronize(); + + // This backend isn't threadsafe so just mutate the global + old_queue_count = queue_count; + queue_count = num_threads; + + for (i = 0; i < num_threads; i++) { count_space = (size_t *)alloca(sizeof(size_t) * arg_len); memcpy(count_space, dimensions, arg_len * sizeof(size_t)); - if(i == NUM_THREADS - 1) + if(i == num_threads - 1) { // Last thread takes all leftover count_space[0] = remain; @@ -316,7 +373,7 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat if(_DEBUG) { - printf("\n=================== THREAD %ld ===================\n", i); + printf("\n=================== THREAD %d ===================\n", i); printf("\ncount_space: "); for(j = 0; j < arg_len; j++) { @@ -357,6 +414,8 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat ready(); synchronize(); + + queue_count = old_queue_count; } static void @@ -471,6 +530,11 @@ MOD_INIT(workqueue) PyLong_FromVoidPtr(&do_scheduling_signed)); PyObject_SetAttrString(m, "do_scheduling_unsigned", PyLong_FromVoidPtr(&do_scheduling_unsigned)); - + PyObject_SetAttrString(m, "set_num_threads", + PyLong_FromVoidPtr((void*)&set_num_threads)); + PyObject_SetAttrString(m, "get_num_threads", + PyLong_FromVoidPtr((void*)&get_num_threads)); + PyObject_SetAttrString(m, "get_thread_num", + PyLong_FromVoidPtr((void*)&get_thread_num)); return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/workqueue.h b/numba/npyufunc/workqueue.h index 32f78480bd6..865a082116a 100644 --- a/numba/npyufunc/workqueue.h +++ b/numba/npyufunc/workqueue.h @@ -54,3 +54,12 @@ void ready(void); static void parallel_for(void *fn, char **args, size_t *dims, size_t *steps, void *data,\ size_t inner_ndim, size_t array_count, int num_threads); + + +/* Masking API cf. OpenMP */ +static void +set_num_threads(int count); +static int +get_num_threads(void); +static int +get_thread_num(void); diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 461ba90bc53..bc4bbd229c3 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -3,7 +3,8 @@ import numpy as np -from numba import njit, set_num_threads, get_num_threads, prange, config +from numba import (njit, set_num_threads, get_num_threads, get_thread_num, + prange, config) from numba import unittest_support as unittest from .support import TestCase, skip_parfors_unsupported @@ -100,6 +101,192 @@ def test_func(nthreads): out = test_func(mask) np.testing.assert_equal(out, mask) + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_get_num_threads_truth_outside_jit(self): + + for mask in range(2, min(6, config.NUMBA_NUM_THREADS + 1)): + set_num_threads(mask) + + # a lot of work, hopefully will trigger "mask" count of threads to + # join the parallel region (for those backends with dynamic threads) + @njit(parallel=True) + def test_func(): + x = 5000000 + buf = np.empty((x,)) + for i in prange(x): + buf[i] = get_thread_num() + return len(np.unique(buf)), get_num_threads() + + out = test_func() + self.assertEqual(out, (mask, mask)) + + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_get_num_threads_truth_inside_jit(self): + + for mask in range(2, min(6, config.NUMBA_NUM_THREADS + 1)): + + # a lot of work, hopefully will trigger "mask" count of threads to + # join the parallel region (for those backends with dynamic threads) + @njit(parallel=True) + def test_func(): + set_num_threads(mask) + x = 5000000 + buf = np.empty((x,)) + for i in prange(x): + buf[i] = get_thread_num() + return len(np.unique(buf)), get_num_threads() + + out = test_func() + self.assertEqual(out, (mask, mask)) + + # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not + # set or >= 2) and TBB backends + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_nested_parallelism_1(self): + # check that get_thread_num is ok in nesting + mask = config.NUMBA_NUM_THREADS - 1 + + N = 4 + M = 8 + + def gen(fid): + @njit(parallel=True) + def child_func(buf): + M, N = buf.shape + for i in prange(N): + buf[fid, i] = get_num_threads() + return child_func + + child1 = gen(1) + child2 = gen(2) + child3 = gen(3) + + @njit(parallel=True) + def test_func(nthreads): + acc = 0 + buf = np.zeros((M, N)) + set_num_threads(nthreads) + for i in prange(M): + local_mask = 1 + i % mask + set_num_threads(local_mask) # set threads in parent function + if local_mask == 1: + child1(buf) + elif local_mask == 2: + child2(buf) + elif local_mask == 3: + child3(buf) + acc += get_num_threads() + return acc, buf + + got_acc, got_arr = test_func(mask) + exp_acc, exp_arr = test_func.py_func(mask) + self.assertEqual(exp_acc, got_acc) + np.testing.assert_equal(exp_arr, got_arr) + + # check the maths reconciles + math_acc = np.sum(1 + np.arange(M) % mask) + self.assertEqual(math_acc, got_acc) + math_arr = np.zeros((M, N)) + for i in range(1, 4): # there's branches on 1, 2, 3 + math_arr[i, :] = i + np.testing.assert_equal(math_arr, got_arr) + + + # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not + # set or >= 2) and TBB backends + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_nested_parallelism_2(self): + # check that get_thread_num is ok in nesting + + N = 4 + M = 8 + def gen(fid): + @njit(parallel=True) + def child_func(buf): + M, N = buf.shape + set_num_threads(fid) # set threads in child function + for i in prange(N): + buf[fid, i] = get_num_threads() + return child_func + + child1 = gen(1) + child2 = gen(2) + child3 = gen(3) + + @njit(parallel=True) + def test_func(nthreads): + acc = 0 + buf = np.zeros((M, N)) + set_num_threads(nthreads) + for i in prange(M): + local_mask = 1 + i % mask + if local_mask == 1: + child1(buf) + elif local_mask == 2: + child2(buf) + elif local_mask == 3: + child3(buf) + acc += get_num_threads() + return acc, buf + + mask = config.NUMBA_NUM_THREADS - 1 + got_acc, got_arr = test_func(mask) + exp_acc, exp_arr = test_func.py_func(mask) + self.assertEqual(exp_acc, got_acc) + np.testing.assert_equal(exp_arr, got_arr) + + # check the maths reconciles + math_acc = np.sum(1 + np.arange(M) % mask) + self.assertEqual(math_acc, got_acc) + math_arr = np.zeros((M, N)) + for i in range(1, 4): # there's branches on 1, 2, 3 + math_arr[i, :] = i + np.testing.assert_equal(math_arr, got_arr) + + + # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not + # set or >= 2) and TBB backends + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_nested_parallelism_3(self): + # check that the right number of threads are present in nesting + # this relies on there being a load of cores present + BIG = 1000000 + + @njit(parallel=True) + def work(local_nt): + tid = np.zeros(BIG) + acc = 0 + set_num_threads(local_nt) + for i in prange(BIG): + acc += 1 + tid[i] = get_thread_num() + return acc, np.unique(tid) + + @njit(parallel=True) + def test_func(nthreads): + acc = 0 + set_num_threads(nthreads) + lens = np.zeros(nthreads) + total = 0 + for i in prange(nthreads): + my_acc, tids = work(nthreads + 1) + lens[i] = len(tids) + total += my_acc + return total, np.unique(lens) + + NT = 2 + expected_acc = BIG * NT + expected_thread_count = NT + 1 + + got_acc, got_tc = test_func(NT) + self.assertEqual(expected_acc, got_acc) + np.testing.assert_equal(expected_thread_count, got_tc) + def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) From 74bf5f84f03dc488d9f4e7044b547e9679f2e8ee Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 9 Dec 2019 11:03:05 +0000 Subject: [PATCH 040/595] Fix problematic test design. As title. --- numba/tests/test_num_threads.py | 102 +++++++++++++++++++------------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index bc4bbd229c3..e23e8f60625 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -8,6 +8,7 @@ from numba import unittest_support as unittest from .support import TestCase, skip_parfors_unsupported + class TestNumThreads(TestCase): _numba_parallel_test_ = False @@ -171,7 +172,7 @@ def test_func(nthreads): set_num_threads(nthreads) for i in prange(M): local_mask = 1 + i % mask - set_num_threads(local_mask) # set threads in parent function + set_num_threads(local_mask) # set threads in parent function if local_mask == 1: child1(buf) elif local_mask == 2: @@ -190,11 +191,10 @@ def test_func(nthreads): math_acc = np.sum(1 + np.arange(M) % mask) self.assertEqual(math_acc, got_acc) math_arr = np.zeros((M, N)) - for i in range(1, 4): # there's branches on 1, 2, 3 + for i in range(1, 4): # there's branches on 1, 2, 3 math_arr[i, :] = i np.testing.assert_equal(math_arr, got_arr) - # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @skip_parfors_unsupported @@ -202,51 +202,70 @@ def test_func(nthreads): def test_nested_parallelism_2(self): # check that get_thread_num is ok in nesting - N = 4 - M = 8 - def gen(fid): - @njit(parallel=True) - def child_func(buf): - M, N = buf.shape - set_num_threads(fid) # set threads in child function - for i in prange(N): - buf[fid, i] = get_num_threads() - return child_func - - child1 = gen(1) - child2 = gen(2) - child3 = gen(3) - - @njit(parallel=True) - def test_func(nthreads): - acc = 0 - buf = np.zeros((M, N)) - set_num_threads(nthreads) - for i in prange(M): - local_mask = 1 + i % mask - if local_mask == 1: - child1(buf) - elif local_mask == 2: - child2(buf) - elif local_mask == 3: - child3(buf) - acc += get_num_threads() - return acc, buf + N = 5 + M = 17 + def get_impl(flag): + + if flag == True: + dec = njit(parallel=True) + elif flag == False: + dec = njit(parallel=False) + else: + def dec(x): return x + + def gen(fid): + @dec + def child_func(buf): + M, N = buf.shape + set_num_threads(fid) # set threads in child function + for i in prange(N): + buf[fid, i] = get_num_threads() + return child_func + + child1 = gen(1) + child2 = gen(2) + child3 = gen(3) + + @dec + def test_func(nthreads): + acc = 0 + buf = np.zeros((M, N)) + set_num_threads(nthreads) + for i in prange(M): + local_mask = 1 + i % mask + # when the threads exit the child functions they should have + # a TLS slot value of the local mask as it was set in + # child + if local_mask == 1: + child1(buf) + assert get_num_threads() == local_mask + elif local_mask == 2: + child2(buf) + assert get_num_threads() == local_mask + elif local_mask == 3: + child3(buf) + assert get_num_threads() == local_mask + return buf + return test_func mask = config.NUMBA_NUM_THREADS - 1 - got_acc, got_arr = test_func(mask) - exp_acc, exp_arr = test_func.py_func(mask) - self.assertEqual(exp_acc, got_acc) - np.testing.assert_equal(exp_arr, got_arr) + set_num_threads(mask) + pf_arr = get_impl(True)(mask) + set_num_threads(mask) + nj_arr = get_impl(False)(mask) + set_num_threads(mask) + py_arr = get_impl(None)(mask) + + np.testing.assert_equal(pf_arr, py_arr) + np.testing.assert_equal(nj_arr, py_arr) # check the maths reconciles - math_acc = np.sum(1 + np.arange(M) % mask) - self.assertEqual(math_acc, got_acc) math_arr = np.zeros((M, N)) - for i in range(1, 4): # there's branches on 1, 2, 3 + for i in range( + 1, 4): # there's branches on modulo mask but only 3 funcs math_arr[i, :] = i - np.testing.assert_equal(math_arr, got_arr) + np.testing.assert_equal(math_arr, pf_arr) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @@ -290,5 +309,6 @@ def test_func(nthreads): def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) + if __name__ == '__main__': unittest.main() From 86897dbbf39bd8796f5147c4796ae6d18b00f4b0 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 10 Dec 2019 11:10:44 -0700 Subject: [PATCH 041/595] Skip tests that deadlock in workqueue test_nested_parallelism_2 doesn't deadlock for me, so I haven't skipped it, although I'm not sure if that's just a coincidence. --- numba/tests/test_num_threads.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index e23e8f60625..3e623690d4d 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -4,11 +4,10 @@ import numpy as np from numba import (njit, set_num_threads, get_num_threads, get_thread_num, - prange, config) + prange, config, threading_layer) from numba import unittest_support as unittest from .support import TestCase, skip_parfors_unsupported - class TestNumThreads(TestCase): _numba_parallel_test_ = False @@ -147,6 +146,9 @@ def test_func(): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_nested_parallelism_1(self): + if threading_layer() == 'workqueue': + return unittest.skip("workqueue is not threadsafe") + # check that get_thread_num is ok in nesting mask = config.NUMBA_NUM_THREADS - 1 @@ -272,6 +274,9 @@ def test_func(nthreads): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_nested_parallelism_3(self): + if threading_layer() == 'workqueue': + return unittest.skip("workqueue is not threadsafe") + # check that the right number of threads are present in nesting # this relies on there being a load of cores present BIG = 1000000 From 63589f937f35dc3c97e2fb636313bb61c55f4ea5 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 10 Dec 2019 11:13:40 -0700 Subject: [PATCH 042/595] Use the correct mechanism for skipping a test in unittest --- numba/tests/test_num_threads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 3e623690d4d..470d342f4ca 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -147,7 +147,7 @@ def test_func(): @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_nested_parallelism_1(self): if threading_layer() == 'workqueue': - return unittest.skip("workqueue is not threadsafe") + self.skipTest("workqueue is not threadsafe") # check that get_thread_num is ok in nesting mask = config.NUMBA_NUM_THREADS - 1 @@ -275,7 +275,7 @@ def test_func(nthreads): @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_nested_parallelism_3(self): if threading_layer() == 'workqueue': - return unittest.skip("workqueue is not threadsafe") + self.skipTest("workqueue is not threadsafe") # check that the right number of threads are present in nesting # this relies on there being a load of cores present From a604ee5c625aa5a6d27fc5bb60fb842a7b73e341 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 10 Dec 2019 11:16:24 -0700 Subject: [PATCH 043/595] Also skip test_nested_parallelism_2 with the workqueue backend --- numba/tests/test_num_threads.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 470d342f4ca..b365ae8ed77 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -202,6 +202,9 @@ def test_func(nthreads): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_nested_parallelism_2(self): + if threading_layer() == 'workqueue': + self.skipTest("workqueue is not threadsafe") + # check that get_thread_num is ok in nesting N = 5 From d6a8262906d9805965056182efbbc25afa907085 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 10 Dec 2019 13:32:52 -0700 Subject: [PATCH 044/595] Fix thread requirement for test_nested_parallelism_3 The nested function uses nthreads + 1, where nthreads is set to 2, so at least 3 cores are required. --- numba/tests/test_num_threads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index b365ae8ed77..16dcc8b7b92 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -275,7 +275,7 @@ def test_func(nthreads): # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @skip_parfors_unsupported - @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + @unittest.skipIf(config.NUMBA_NUM_THREADS < 3, "Not enough CPU cores") def test_nested_parallelism_3(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") From a45fce4b30555145db5c2e81826efadb242a40ea Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 10 Dec 2019 13:35:02 -0700 Subject: [PATCH 045/595] Remove unused variables --- numba/tests/test_num_threads.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 16dcc8b7b92..e7ed1fe1ee0 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -233,7 +233,6 @@ def child_func(buf): @dec def test_func(nthreads): - acc = 0 buf = np.zeros((M, N)) set_num_threads(nthreads) for i in prange(M): @@ -296,7 +295,6 @@ def work(local_nt): @njit(parallel=True) def test_func(nthreads): - acc = 0 set_num_threads(nthreads) lens = np.zeros(nthreads) total = 0 From 03c28707c0dbf4d305c2ace9aad22b93a6efbb6e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 10 Dec 2019 15:25:16 -0700 Subject: [PATCH 046/595] Skip nested parallelism tests if there are fewer than 4 cores --- numba/tests/test_num_threads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index e7ed1fe1ee0..4574eff09eb 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -144,7 +144,7 @@ def test_func(): # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @skip_parfors_unsupported - @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + @unittest.skipIf(config.NUMBA_NUM_THREADS < 4, "Not enough CPU cores") def test_nested_parallelism_1(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") @@ -200,7 +200,7 @@ def test_func(nthreads): # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @skip_parfors_unsupported - @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + @unittest.skipIf(config.NUMBA_NUM_THREADS < 4, "Not enough CPU cores") def test_nested_parallelism_2(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") From fcf7c7caf6ee16ab75a6c94e28905129f1556fa3 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 10 Dec 2019 16:33:13 -0700 Subject: [PATCH 047/595] Add some test_num_threads for guvectorize Note that some of these tests don't actually work yet - The test of calling set_num_threads inside of a guvectorized function does not work in workqueue - The test to check how many threads are used by reading get_thread_num() does not work, presumably because the function is only called once. I'm unsure how to test this properly. --- numba/tests/test_num_threads.py | 115 +++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 4574eff09eb..3165a879196 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -4,7 +4,7 @@ import numpy as np from numba import (njit, set_num_threads, get_num_threads, get_thread_num, - prange, config, threading_layer) + prange, config, threading_layer, guvectorize) from numba import unittest_support as unittest from .support import TestCase, skip_parfors_unsupported @@ -66,6 +66,60 @@ def set_get_n(n): with self.assertRaises(ValueError): set_n(max_threads + 1) + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_set_num_threads_basic_guvectorize(self): + max_threads = config.NUMBA_NUM_THREADS + + @guvectorize(['void(int64[:])'], + '(n)', + nopython=True, + target='parallel') + def get_n(x): + x[:] = get_num_threads() + + @guvectorize(['void(int64[:])'], + '(n)', + nopython=True, + target='parallel') + def set_n(n): + set_num_threads(n[0]) + + x = np.zeros((5000000,), dtype=np.int64) + get_n(x) + np.testing.assert_equal(x, max_threads) + set_n(np.array([2])) + x = np.zeros((5000000,), dtype=np.int64) + get_n(x) + np.testing.assert_equal(x, 2) + set_n(np.array([max_threads])) + x = np.zeros((5000000,), dtype=np.int64) + get_n(x) + np.testing.assert_equal(x, max_threads) + + @guvectorize(['void(int64[:])'], + '(n)', + nopython=True, + target='parallel') + def set_get_n(n): + set_num_threads(n[0]) + n[:] = get_num_threads() + + x = np.zeros((5000000,), dtype=np.int64) + x[0] = 2 + set_get_n(x) + np.testing.assert_equal(x, 2) + x = np.zeros((5000000,), dtype=np.int64) + x[0] = max_threads + set_get_n(x) + np.testing.assert_equal(x, max_threads) + + with self.assertRaises(ValueError): + set_n(np.array([0])) + + with self.assertRaises(ValueError): + set_n(np.array([max_threads + 1])) + @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_set_num_threads_outside_jit(self): @@ -81,9 +135,21 @@ def test_func(): buf[i] = get_num_threads() return buf + @guvectorize(['void(int64[:])'], + '(n)', + nopython=True, + target='parallel') + def test_gufunc(x): + x[:] = get_num_threads() + + out = test_func() np.testing.assert_equal(out, 2) + x = np.zeros((5000000,), dtype=np.int64) + test_gufunc(x) + np.testing.assert_equal(x, 2) + @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_set_num_threads_inside_jit(self): @@ -101,6 +167,24 @@ def test_func(nthreads): out = test_func(mask) np.testing.assert_equal(out, mask) + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + def test_set_num_threads_inside_guvectorize(self): + # Test set_num_threads inside a jitted guvectorize function + @guvectorize(['void(int64[:])'], + '(n)', + nopython=True, + target='parallel') + def test_func(x): + set_num_threads(x[0]) + x[:] = get_num_threads() + + x = np.zeros((5000000,), dtype=np.int64) + mask = 2 + x[0] = mask + test_func(x) + np.testing.assert_equal(x, mask) + @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_get_num_threads_truth_outside_jit(self): @@ -121,6 +205,20 @@ def test_func(): out = test_func() self.assertEqual(out, (mask, mask)) + @guvectorize(['void(int64[:], int64[:])'], + '(n), (m)', + nopython=True, + target='parallel') + def test_gufunc(x, out): + x[:] = get_thread_num() # XXX: Doesn't actually work + out[0] = len(np.unique(x)) + out[1] = get_num_threads() + + x = np.full((5000000,), -1, dtype=np.int64) + out = np.zeros((mask,), dtype=np.int64) + test_gufunc(x, out) + np.testing.assert_equal(out, np.array([mask, mask]), str(x[0])) + @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_get_num_threads_truth_inside_jit(self): @@ -141,6 +239,21 @@ def test_func(): out = test_func() self.assertEqual(out, (mask, mask)) + @guvectorize(['void(int64[:], int64[:])'], + '(n), (m)', + nopython=True, + target='parallel') + def test_gufunc(x, out): + set_num_threads(mask) + x[:] = get_thread_num() # XXX: Doesn't actually work + out[0] = len(np.unique(x)) + out[1] = get_num_threads() + + x = np.full((5000000,), -1, dtype=np.int64) + out = np.zeros((mask,), dtype=np.int64) + test_gufunc(x, out) + np.testing.assert_equal(out, np.array([mask, mask]), str(x[0])) + # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @skip_parfors_unsupported From 4925df38ea28423d54677807a66ae789b4e83c2b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 12 Dec 2019 15:35:46 -0700 Subject: [PATCH 048/595] Make sure threads are launched when calling get_thread_num() Otherwise it will reference the C implementation from the threading library which hasn't been loaded yet. --- numba/npyufunc/parallel.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 3a3664a4b29..043527e3bf6 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -576,10 +576,12 @@ def get_thread_num(): """ docs """ + _launch_threads() return _get_thread_num() @overload(get_thread_num) def ol_get_thread_num(): + _launch_threads() def impl(): return _get_thread_num() return impl From 28ade30a48a2008939509a96d8a714325aea0a0a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 12 Dec 2019 15:36:59 -0700 Subject: [PATCH 049/595] Fix the guvectorize tests to properly test parallelism vectorized kernels aren't parallelized unless they have to do broadcasting over a higher number of dimensions than they were compiled for. --- numba/tests/test_num_threads.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 3165a879196..610b2dbae95 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -210,14 +210,15 @@ def test_func(): nopython=True, target='parallel') def test_gufunc(x, out): - x[:] = get_thread_num() # XXX: Doesn't actually work - out[0] = len(np.unique(x)) - out[1] = get_num_threads() + x[:] = get_thread_num() + out[0] = get_num_threads() - x = np.full((5000000,), -1, dtype=np.int64) - out = np.zeros((mask,), dtype=np.int64) + # Reshape to force parallelism + x = np.full((5000000,), -1, dtype=np.int64).reshape((100, 50000)) + out = np.zeros((1,), dtype=np.int64) test_gufunc(x, out) - np.testing.assert_equal(out, np.array([mask, mask]), str(x[0])) + np.testing.assert_equal(out, np.array([mask])) + self.assertEqual(len(np.unique(x)), mask) @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") @@ -239,20 +240,22 @@ def test_func(): out = test_func() self.assertEqual(out, (mask, mask)) + @guvectorize(['void(int64[:], int64[:])'], '(n), (m)', nopython=True, target='parallel') def test_gufunc(x, out): set_num_threads(mask) - x[:] = get_thread_num() # XXX: Doesn't actually work - out[0] = len(np.unique(x)) - out[1] = get_num_threads() + x[:] = get_thread_num() + out[0] = get_num_threads() - x = np.full((5000000,), -1, dtype=np.int64) - out = np.zeros((mask,), dtype=np.int64) + # Reshape to force parallelism + x = np.full((5000000,), -1, dtype=np.int64).reshape((100, 50000)) + out = np.zeros((1,), dtype=np.int64) test_gufunc(x, out) - np.testing.assert_equal(out, np.array([mask, mask]), str(x[0])) + np.testing.assert_equal(out, np.array([mask])) + self.assertEqual(len(np.unique(x)), mask) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends From b9914d2821715a0ceff7a7f7dfdb40d5916a4f9f Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Thu, 12 Dec 2019 15:26:42 -0800 Subject: [PATCH 050/595] Add notes on overwriting gufunc inputs to docs It is possible to write gufuncs that overwrite input arrays, but the new values may not be visible outside the gufunc execution, for example if a temporary array is passed in. This commit adds notes to the documentation warning the user of this case. --- docs/source/reference/jit-compilation.rst | 5 ++- docs/source/user/vectorize.rst | 43 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/source/reference/jit-compilation.rst b/docs/source/reference/jit-compilation.rst index d037b78a642..ddcba3d6b1a 100644 --- a/docs/source/reference/jit-compilation.rst +++ b/docs/source/reference/jit-compilation.rst @@ -316,7 +316,10 @@ Vectorized functions (ufuncs and DUFuncs) for the function you are implementing. If your function doesn't take an output array, you should omit the "arrow" - in the layout string (e.g. ``"(n),(n)"``). + in the layout string (e.g. ``"(n),(n)"``). When doing this, it is important + to be aware that changes to the input arrays cannot always be relied on to be + visible outside the execution of the ufunc, as Numpy may pass in temporary + arrays as inputs (for example, if a cast is required). .. seealso:: Specification of the `layout string `_ diff --git a/docs/source/user/vectorize.rst b/docs/source/user/vectorize.rst index 784f32eef06..4a887cca6ea 100644 --- a/docs/source/user/vectorize.rst +++ b/docs/source/user/vectorize.rst @@ -203,6 +203,49 @@ complicated inputs, depending on their shapes:: Use it to ensure the generated code does not fallback to :term:`object mode`. +.. _overwriting-input-values: + +Overwriting input values +------------------------ + +In most cases, writing to inputs may also appear to work - however, this +behaviour cannot be relied on. Consider the following example function:: + + @guvectorize([(float64[:], float64[:])], '()->()') + def init_values(invals, outvals): + invals[0] = 6.5 + outvals[0] = 4.2 + +Calling the `init_values` function with an array of `float64` type results in +visible changes to the input:: + + >>> invals = np.zeros(shape=(3, 3), dtype=np.float64) + >>> outvals = init_values(invals) + >>> invals + array([[6.5, 6.5, 6.5], + [6.5, 6.5, 6.5], + [6.5, 6.5, 6.5]]) + >>> outvals + array([[4.2, 4.2, 4.2], + [4.2, 4.2, 4.2], + [4.2, 4.2, 4.2]]) + +This works because Numpy passes a pointer to the input data directly into the +`init_values` function. However, it may also create and pass in a temporary +array, in which case changes to the input are lost. For example, this can occur +when casting is required. To demonstrate this, we can use an array of `float32` +with the `init_values` function:: + + >>> invals = np.zeros(shape=(3, 3), dtype=np.float32) + >>> outvals = init_values(invals) + >>> invals + array([[0., 0., 0.], + [0., 0., 0.], + [0., 0., 0.]], dtype=float32) + +In this case, there is no change to the `invals` array because the temporary +casted array was mutated instead. + .. _dynamic-universal-functions: Dynamic universal functions From 2e7636443bf8e44f9e1ca4c43f226ff63971e58f Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 12 Dec 2019 16:38:43 -0700 Subject: [PATCH 051/595] Rename get_thread_num() to get_thread_id() --- numba/__init__.py | 2 +- numba/npyufunc/__init__.py | 2 +- numba/npyufunc/omppool.cpp | 6 +++--- numba/npyufunc/parallel.py | 16 ++++++++-------- numba/npyufunc/tbbpool.cpp | 6 +++--- numba/npyufunc/workqueue.c | 8 ++++---- numba/npyufunc/workqueue.h | 2 +- numba/tests/test_num_threads.py | 16 ++++++++-------- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index 3ae810fa994..643354bee0d 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -32,7 +32,7 @@ # Re-export vectorize decorators and the thread layer querying function from .npyufunc import (vectorize, guvectorize, threading_layer, - get_num_threads, set_num_threads, get_thread_num) + get_num_threads, set_num_threads, get_thread_id) # Re-export Numpy helpers from .numpy_support import carray, farray, from_dtype diff --git a/numba/npyufunc/__init__.py b/numba/npyufunc/__init__.py index 97448d43597..48217324f8a 100644 --- a/numba/npyufunc/__init__.py +++ b/numba/npyufunc/__init__.py @@ -5,7 +5,7 @@ from ._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One from . import _internal, array_exprs, parfor from .parallel import (threading_layer, get_num_threads, set_num_threads, - get_thread_num) + get_thread_id) if hasattr(_internal, 'PyUFunc_ReorderableNone'): PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone del _internal, array_exprs diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index 79b61b80576..12e0ee88f70 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -63,7 +63,7 @@ get_num_threads(void) } static int -get_thread_num(void) +get_thread_id(void) { return omp_get_thread_num(); } @@ -249,7 +249,7 @@ MOD_INIT(omppool) PyLong_FromVoidPtr((void*)&set_num_threads)); PyObject_SetAttrString(m, "get_num_threads", PyLong_FromVoidPtr((void*)&get_num_threads)); - PyObject_SetAttrString(m, "get_thread_num", - PyLong_FromVoidPtr((void*)&get_thread_num)); + PyObject_SetAttrString(m, "get_thread_id", + PyLong_FromVoidPtr((void*)&get_thread_id)); return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 043527e3bf6..108b0f7d5d5 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -468,7 +468,7 @@ def _load_num_threads_funcs(lib): ll.add_symbol('get_num_threads', lib.get_num_threads) ll.add_symbol('set_num_threads', lib.set_num_threads) - ll.add_symbol('get_thread_num', lib.get_thread_num) + ll.add_symbol('get_thread_id', lib.get_thread_id) global _set_num_threads _set_num_threads = CFUNCTYPE(None, c_int)(lib.set_num_threads) @@ -477,8 +477,8 @@ def _load_num_threads_funcs(lib): global _get_num_threads _get_num_threads = CFUNCTYPE(c_int)(lib.get_num_threads) - global _get_thread_num - _get_thread_num = CFUNCTYPE(c_int)(lib.get_thread_num) + global _get_thread_id + _get_thread_id = CFUNCTYPE(c_int)(lib.get_thread_id) # Some helpers to make set_num_threads jittable @@ -572,18 +572,18 @@ def impl(): return _get_num_threads() return impl -def get_thread_num(): +def get_thread_id(): """ docs """ _launch_threads() - return _get_thread_num() + return _get_thread_id() -@overload(get_thread_num) -def ol_get_thread_num(): +@overload(get_thread_id) +def ol_get_thread_id(): _launch_threads() def impl(): - return _get_thread_num() + return _get_thread_id() return impl _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index 157b069d253..49c2ff0b2f7 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -60,7 +60,7 @@ get_num_threads(void) } static int -get_thread_num(void) +get_thread_id(void) { return tbb::task_arena::current_thread_index(); } @@ -298,8 +298,8 @@ MOD_INIT(tbbpool) PyLong_FromVoidPtr((void*)&set_num_threads)); PyObject_SetAttrString(m, "get_num_threads", PyLong_FromVoidPtr((void*)&get_num_threads)); - PyObject_SetAttrString(m, "get_thread_num", - PyLong_FromVoidPtr((void*)&get_thread_num)); + PyObject_SetAttrString(m, "get_thread_id", + PyLong_FromVoidPtr((void*)&get_thread_id)); return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 8267e6621cf..ba7786ff3df 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -115,7 +115,7 @@ numba_new_thread(void *worker, void *arg) } static int -get_thread_num(void) +get_thread_id(void) { return pthread_self(); } @@ -206,7 +206,7 @@ numba_new_thread(void *worker, void *arg) } static int -get_thread_num(void) +get_thread_id(void) { return GetCurrentThreadId(); } @@ -534,7 +534,7 @@ MOD_INIT(workqueue) PyLong_FromVoidPtr((void*)&set_num_threads)); PyObject_SetAttrString(m, "get_num_threads", PyLong_FromVoidPtr((void*)&get_num_threads)); - PyObject_SetAttrString(m, "get_thread_num", - PyLong_FromVoidPtr((void*)&get_thread_num)); + PyObject_SetAttrString(m, "get_thread_id", + PyLong_FromVoidPtr((void*)&get_thread_id)); return MOD_SUCCESS_VAL(m); } diff --git a/numba/npyufunc/workqueue.h b/numba/npyufunc/workqueue.h index 865a082116a..80558a0e534 100644 --- a/numba/npyufunc/workqueue.h +++ b/numba/npyufunc/workqueue.h @@ -62,4 +62,4 @@ set_num_threads(int count); static int get_num_threads(void); static int -get_thread_num(void); +get_thread_id(void); diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 610b2dbae95..5fc7f6b5a07 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -3,7 +3,7 @@ import numpy as np -from numba import (njit, set_num_threads, get_num_threads, get_thread_num, +from numba import (njit, set_num_threads, get_num_threads, get_thread_id, prange, config, threading_layer, guvectorize) from numba import unittest_support as unittest from .support import TestCase, skip_parfors_unsupported @@ -199,7 +199,7 @@ def test_func(): x = 5000000 buf = np.empty((x,)) for i in prange(x): - buf[i] = get_thread_num() + buf[i] = get_thread_id() return len(np.unique(buf)), get_num_threads() out = test_func() @@ -210,7 +210,7 @@ def test_func(): nopython=True, target='parallel') def test_gufunc(x, out): - x[:] = get_thread_num() + x[:] = get_thread_id() out[0] = get_num_threads() # Reshape to force parallelism @@ -234,7 +234,7 @@ def test_func(): x = 5000000 buf = np.empty((x,)) for i in prange(x): - buf[i] = get_thread_num() + buf[i] = get_thread_id() return len(np.unique(buf)), get_num_threads() out = test_func() @@ -247,7 +247,7 @@ def test_func(): target='parallel') def test_gufunc(x, out): set_num_threads(mask) - x[:] = get_thread_num() + x[:] = get_thread_id() out[0] = get_num_threads() # Reshape to force parallelism @@ -265,7 +265,7 @@ def test_nested_parallelism_1(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") - # check that get_thread_num is ok in nesting + # check that get_thread_id is ok in nesting mask = config.NUMBA_NUM_THREADS - 1 N = 4 @@ -321,7 +321,7 @@ def test_nested_parallelism_2(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") - # check that get_thread_num is ok in nesting + # check that get_thread_id is ok in nesting N = 5 M = 17 @@ -406,7 +406,7 @@ def work(local_nt): set_num_threads(local_nt) for i in prange(BIG): acc += 1 - tid[i] = get_thread_num() + tid[i] = get_thread_id() return acc, np.unique(tid) @njit(parallel=True) From 0af2d58022c7aac3d9dc5d44e8f2d3e3a3f47252 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 12 Dec 2019 16:41:03 -0700 Subject: [PATCH 052/595] Rename get_thread_id() to _get_thread_id() This also removes it from the main numba.__all__. --- numba/__init__.py | 2 +- numba/npyufunc/__init__.py | 2 +- numba/npyufunc/parallel.py | 4 ++-- numba/tests/test_num_threads.py | 19 ++++++++++--------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index 643354bee0d..b77773749ec 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -32,7 +32,7 @@ # Re-export vectorize decorators and the thread layer querying function from .npyufunc import (vectorize, guvectorize, threading_layer, - get_num_threads, set_num_threads, get_thread_id) + get_num_threads, set_num_threads) # Re-export Numpy helpers from .numpy_support import carray, farray, from_dtype diff --git a/numba/npyufunc/__init__.py b/numba/npyufunc/__init__.py index 48217324f8a..680141aa9ea 100644 --- a/numba/npyufunc/__init__.py +++ b/numba/npyufunc/__init__.py @@ -5,7 +5,7 @@ from ._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One from . import _internal, array_exprs, parfor from .parallel import (threading_layer, get_num_threads, set_num_threads, - get_thread_id) + _get_thread_id) if hasattr(_internal, 'PyUFunc_ReorderableNone'): PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone del _internal, array_exprs diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 108b0f7d5d5..333684d1bdf 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -572,14 +572,14 @@ def impl(): return _get_num_threads() return impl -def get_thread_id(): +def _get_thread_id(): """ docs """ _launch_threads() return _get_thread_id() -@overload(get_thread_id) +@overload(_get_thread_id) def ol_get_thread_id(): _launch_threads() def impl(): diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 5fc7f6b5a07..2ef76336c6d 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -3,8 +3,9 @@ import numpy as np -from numba import (njit, set_num_threads, get_num_threads, get_thread_id, - prange, config, threading_layer, guvectorize) +from numba import (njit, set_num_threads, get_num_threads, prange, config, + threading_layer, guvectorize) +from numba.npyufunc.parallel import _get_thread_id from numba import unittest_support as unittest from .support import TestCase, skip_parfors_unsupported @@ -199,7 +200,7 @@ def test_func(): x = 5000000 buf = np.empty((x,)) for i in prange(x): - buf[i] = get_thread_id() + buf[i] = _get_thread_id() return len(np.unique(buf)), get_num_threads() out = test_func() @@ -210,7 +211,7 @@ def test_func(): nopython=True, target='parallel') def test_gufunc(x, out): - x[:] = get_thread_id() + x[:] = _get_thread_id() out[0] = get_num_threads() # Reshape to force parallelism @@ -234,7 +235,7 @@ def test_func(): x = 5000000 buf = np.empty((x,)) for i in prange(x): - buf[i] = get_thread_id() + buf[i] = _get_thread_id() return len(np.unique(buf)), get_num_threads() out = test_func() @@ -247,7 +248,7 @@ def test_func(): target='parallel') def test_gufunc(x, out): set_num_threads(mask) - x[:] = get_thread_id() + x[:] = _get_thread_id() out[0] = get_num_threads() # Reshape to force parallelism @@ -265,7 +266,7 @@ def test_nested_parallelism_1(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") - # check that get_thread_id is ok in nesting + # check that _get_thread_id is ok in nesting mask = config.NUMBA_NUM_THREADS - 1 N = 4 @@ -321,7 +322,7 @@ def test_nested_parallelism_2(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") - # check that get_thread_id is ok in nesting + # check that _get_thread_id is ok in nesting N = 5 M = 17 @@ -406,7 +407,7 @@ def work(local_nt): set_num_threads(local_nt) for i in prange(BIG): acc += 1 - tid[i] = get_thread_id() + tid[i] = _get_thread_id() return acc, np.unique(tid) @njit(parallel=True) From deb7ff37118b10d43e1b0bda48ce080555a0b526 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 12 Dec 2019 16:58:05 -0700 Subject: [PATCH 053/595] Don't assume that set_num_threads inside a jitted function will propogate outside of it See https://github.com/numba/numba/pull/4615#issuecomment-564503993 --- numba/tests/test_num_threads.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 2ef76336c6d..4fbae485d7b 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -43,14 +43,10 @@ def test_set_num_threads_basic_jit(self): def get_n(): return get_num_threads() - @njit - def set_n(n): - set_num_threads(n) - self.assertEqual(get_n(), max_threads) - set_n(2) + set_num_threads(2) self.assertEqual(get_n(), 2) - set_n(max_threads) + set_num_threads(max_threads) self.assertEqual(get_n(), max_threads) @njit @@ -62,10 +58,10 @@ def set_get_n(n): self.assertEqual(set_get_n(max_threads), max_threads) with self.assertRaises(ValueError): - set_n(0) + set_get_n(0) with self.assertRaises(ValueError): - set_n(max_threads + 1) + set_get_n(max_threads + 1) @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") @@ -79,21 +75,14 @@ def test_set_num_threads_basic_guvectorize(self): def get_n(x): x[:] = get_num_threads() - @guvectorize(['void(int64[:])'], - '(n)', - nopython=True, - target='parallel') - def set_n(n): - set_num_threads(n[0]) - x = np.zeros((5000000,), dtype=np.int64) get_n(x) np.testing.assert_equal(x, max_threads) - set_n(np.array([2])) + set_num_threads(2) x = np.zeros((5000000,), dtype=np.int64) get_n(x) np.testing.assert_equal(x, 2) - set_n(np.array([max_threads])) + set_num_threads(max_threads) x = np.zeros((5000000,), dtype=np.int64) get_n(x) np.testing.assert_equal(x, max_threads) @@ -116,10 +105,10 @@ def set_get_n(n): np.testing.assert_equal(x, max_threads) with self.assertRaises(ValueError): - set_n(np.array([0])) + set_get_n(np.array([0])) with self.assertRaises(ValueError): - set_n(np.array([max_threads + 1])) + set_get_n(np.array([max_threads + 1])) @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") From 94020e9ebee234cd7850b901f3eaf67b32c9e347 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 13 Dec 2019 14:05:38 -0700 Subject: [PATCH 054/595] Generalize the nested parallelism tests to work with any number of cores --- numba/tests/test_num_threads.py | 74 ++++++++++++--------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 4fbae485d7b..b971a972ac9 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -250,28 +250,22 @@ def test_gufunc(x, out): # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @skip_parfors_unsupported - @unittest.skipIf(config.NUMBA_NUM_THREADS < 4, "Not enough CPU cores") + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_nested_parallelism_1(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") - # check that _get_thread_id is ok in nesting + # check that get_num_threads is ok in nesting mask = config.NUMBA_NUM_THREADS - 1 - N = 4 - M = 8 - - def gen(fid): - @njit(parallel=True) - def child_func(buf): - M, N = buf.shape - for i in prange(N): - buf[fid, i] = get_num_threads() - return child_func + N = config.NUMBA_NUM_THREADS + M = 2*config.NUMBA_NUM_THREADS - child1 = gen(1) - child2 = gen(2) - child3 = gen(3) + @njit(parallel=True) + def child_func(buf, fid): + M, N = buf.shape + for i in prange(N): + buf[fid, i] = get_num_threads() @njit(parallel=True) def test_func(nthreads): @@ -281,12 +275,8 @@ def test_func(nthreads): for i in prange(M): local_mask = 1 + i % mask set_num_threads(local_mask) # set threads in parent function - if local_mask == 1: - child1(buf) - elif local_mask == 2: - child2(buf) - elif local_mask == 3: - child3(buf) + if local_mask < N: + child_func(buf, local_mask) acc += get_num_threads() return acc, buf @@ -299,22 +289,23 @@ def test_func(nthreads): math_acc = np.sum(1 + np.arange(M) % mask) self.assertEqual(math_acc, got_acc) math_arr = np.zeros((M, N)) - for i in range(1, 4): # there's branches on 1, 2, 3 + for i in range(1, N): # there's branches on 1, ..., num_threads - 1 math_arr[i, :] = i np.testing.assert_equal(math_arr, got_arr) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @skip_parfors_unsupported - @unittest.skipIf(config.NUMBA_NUM_THREADS < 4, "Not enough CPU cores") + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_nested_parallelism_2(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") - # check that _get_thread_id is ok in nesting + # check that get_num_threads is ok in nesting + + N = config.NUMBA_NUM_THREADS + 1 + M = 4*config.NUMBA_NUM_THREADS + 1 - N = 5 - M = 17 def get_impl(flag): if flag == True: @@ -324,18 +315,12 @@ def get_impl(flag): else: def dec(x): return x - def gen(fid): - @dec - def child_func(buf): - M, N = buf.shape - set_num_threads(fid) # set threads in child function - for i in prange(N): - buf[fid, i] = get_num_threads() - return child_func - - child1 = gen(1) - child2 = gen(2) - child3 = gen(3) + @dec + def child(buf, fid): + M, N = buf.shape + set_num_threads(fid) # set threads in child function + for i in prange(N): + buf[fid, i] = get_num_threads() @dec def test_func(nthreads): @@ -346,14 +331,8 @@ def test_func(nthreads): # when the threads exit the child functions they should have # a TLS slot value of the local mask as it was set in # child - if local_mask == 1: - child1(buf) - assert get_num_threads() == local_mask - elif local_mask == 2: - child2(buf) - assert get_num_threads() == local_mask - elif local_mask == 3: - child3(buf) + if local_mask < config.NUMBA_NUM_THREADS: + child(buf, local_mask) assert get_num_threads() == local_mask return buf return test_func @@ -371,8 +350,7 @@ def test_func(nthreads): # check the maths reconciles math_arr = np.zeros((M, N)) - for i in range( - 1, 4): # there's branches on modulo mask but only 3 funcs + for i in range(1, config.NUMBA_NUM_THREADS): # there's branches on modulo mask but only NUMBA_NUM_THREADS funcs math_arr[i, :] = i np.testing.assert_equal(math_arr, pf_arr) From 39815fb1ccb406340c3ace4c515ef27b68499c43 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 13 Dec 2019 15:51:57 -0700 Subject: [PATCH 055/595] Make test_nested_parallelism_1 test nesting from a guvectorized function as well --- numba/tests/test_num_threads.py | 82 +++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index b971a972ac9..9a4aa0955bf 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -267,31 +267,65 @@ def child_func(buf, fid): for i in prange(N): buf[fid, i] = get_num_threads() - @njit(parallel=True) - def test_func(nthreads): - acc = 0 - buf = np.zeros((M, N)) - set_num_threads(nthreads) - for i in prange(M): - local_mask = 1 + i % mask - set_num_threads(local_mask) # set threads in parent function - if local_mask < N: - child_func(buf, local_mask) - acc += get_num_threads() - return acc, buf - - got_acc, got_arr = test_func(mask) - exp_acc, exp_arr = test_func.py_func(mask) - self.assertEqual(exp_acc, got_acc) - np.testing.assert_equal(exp_arr, got_arr) + def get_test(test_type): + if test_type == 'njit': + def test_func(nthreads, py_func=False): + @njit(parallel=True) + def _test_func(nthreads): + acc = 0 + buf = np.zeros((M, N)) + set_num_threads(nthreads) + for i in prange(M): + local_mask = 1 + i % mask + set_num_threads(local_mask) # set threads in parent function + if local_mask < N: + child_func(buf, local_mask) + acc += get_num_threads() + return acc, buf + if py_func: + return _test_func.py_func(nthreads) + else: + return _test_func(nthreads) + + elif test_type == 'guvectorize': + def test_func(nthreads, py_func=False): + def _test_func(acc, buf, local_mask): + set_num_threads(nthreads) + set_num_threads(local_mask[0]) # set threads in parent function + if local_mask[0] < N: + child_func(buf, local_mask[0]) + acc[0] += get_num_threads() + + buf = np.zeros((M, N), dtype=np.int64) + acc = np.array([0]) + local_mask = (1 + np.arange(M) % mask).reshape((M, 1)) + if not py_func: + _test_func = guvectorize(['void(int64[:], int64[:, :], int64[:])'], + '(k), (n, m), (p)', nopython=True, + target='parallel')(_test_func) + else: + _test_func = guvectorize(['void(int64[:], int64[:, :], int64[:])'], + '(k), (n, m), (p)', forceobj=True)(_test_func) + _test_func(acc, buf, local_mask) + return acc, buf - # check the maths reconciles - math_acc = np.sum(1 + np.arange(M) % mask) - self.assertEqual(math_acc, got_acc) - math_arr = np.zeros((M, N)) - for i in range(1, N): # there's branches on 1, ..., num_threads - 1 - math_arr[i, :] = i - np.testing.assert_equal(math_arr, got_arr) + return test_func + + for test_type in ['njit', 'guvectorize']: + test_func = get_test(test_type) + + got_acc, got_arr = test_func(mask) + exp_acc, exp_arr = test_func(mask, py_func=True) + self.assertEqual(exp_acc, got_acc, test_type) + np.testing.assert_equal(exp_arr, got_arr) + + # check the maths reconciles + math_acc = np.sum(1 + np.arange(M) % mask) + self.assertEqual(math_acc, got_acc) + math_arr = np.zeros((M, N)) + for i in range(1, N): # there's branches on 1, ..., num_threads - 1 + math_arr[i, :] = i + np.testing.assert_equal(math_arr, got_arr) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends From fe0af898ce6c8aaedaa699fccadbb77907572dc0 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 13 Dec 2019 16:09:34 -0700 Subject: [PATCH 056/595] Test guvectorize combinations in test_nested_parallelism_2 --- numba/tests/test_num_threads.py | 97 +++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 30 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 9a4aa0955bf..ef4fea87cb0 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -340,54 +340,91 @@ def test_nested_parallelism_2(self): N = config.NUMBA_NUM_THREADS + 1 M = 4*config.NUMBA_NUM_THREADS + 1 - def get_impl(flag): + def get_impl(child_type, test_type): - if flag == True: - dec = njit(parallel=True) - elif flag == False: - dec = njit(parallel=False) - else: - def dec(x): return x + if child_type == 'parallel': + child_dec = njit(parallel=True) + elif child_type == 'njit': + child_dec = njit(parallel=False) + elif child_type == 'none': + def child_dec(x): return x - @dec + @child_dec def child(buf, fid): M, N = buf.shape set_num_threads(fid) # set threads in child function for i in prange(N): buf[fid, i] = get_num_threads() - @dec - def test_func(nthreads): - buf = np.zeros((M, N)) - set_num_threads(nthreads) - for i in prange(M): - local_mask = 1 + i % mask - # when the threads exit the child functions they should have - # a TLS slot value of the local mask as it was set in - # child - if local_mask < config.NUMBA_NUM_THREADS: - child(buf, local_mask) - assert get_num_threads() == local_mask - return buf + + if test_type in ['parallel', 'njit', 'none']: + if test_type == 'parallel': + test_dec = njit(parallel=True) + elif test_type == 'njit': + test_dec = njit(parallel=False) + elif test_type == 'none': + def test_dec(x): return x + + @test_dec + def test_func(nthreads): + buf = np.zeros((M, N)) + set_num_threads(nthreads) + for i in prange(M): + local_mask = 1 + i % mask + # when the threads exit the child functions they should have + # a TLS slot value of the local mask as it was set in + # child + if local_mask < config.NUMBA_NUM_THREADS: + child(buf, local_mask) + assert get_num_threads() == local_mask + return buf + else: + if test_type == 'guvectorize': + test_dec = guvectorize(['int64[:,:], int64[:]'], + '(n, m), (k)', nopython=True, + target='parallel') + elif test_type == 'guvectorize-obj': + test_dec = guvectorize(['int64[:,:], int64[:]'], + '(n, m), (k)', forceobj=True) + + def test_func(nthreads): + @test_dec + def _test_func(buf, local_mask): + set_num_threads(nthreads) + # when the threads exit the child functions they should have + # a TLS slot value of the local mask as it was set in + # child + if local_mask[0] < config.NUMBA_NUM_THREADS: + child(buf, local_mask[0]) + assert get_num_threads() == local_mask[0] + + buf = np.zeros((M, N), dtype=np.int64) + local_mask = (1 + np.arange(M) % mask).reshape((M, 1)) + _test_func(buf, local_mask) + return buf + return test_func mask = config.NUMBA_NUM_THREADS - 1 - set_num_threads(mask) - pf_arr = get_impl(True)(mask) - set_num_threads(mask) - nj_arr = get_impl(False)(mask) - set_num_threads(mask) - py_arr = get_impl(None)(mask) - np.testing.assert_equal(pf_arr, py_arr) - np.testing.assert_equal(nj_arr, py_arr) + res_arrays = {} + for test_type in ['parallel', 'njit', 'none', 'guvectorize', 'guvectorize-obj']: + for child_type in ['parallel', 'njit', 'none']: + if child_type == 'none' and test_type != 'none': + continue + set_num_threads(mask) + res_arrays[test_type, child_type] = get_impl(child_type, test_type)(mask) + + py_arr = res_arrays['none', 'none'] + for arr in res_arrays.values(): + np.testing.assert_equal(arr, py_arr) # check the maths reconciles math_arr = np.zeros((M, N)) for i in range(1, config.NUMBA_NUM_THREADS): # there's branches on modulo mask but only NUMBA_NUM_THREADS funcs math_arr[i, :] = i - np.testing.assert_equal(math_arr, pf_arr) + np.testing.assert_equal(math_arr, py_arr) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends From 35b69f72f6dbc3b74f463664ae4f15781e1c498f Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 13 Dec 2019 16:20:22 -0700 Subject: [PATCH 057/595] Add guvectorize to test_nested_parallelism_3 --- numba/tests/test_num_threads.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index ef4fea87cb0..d436713611c 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -449,7 +449,7 @@ def work(local_nt): return acc, np.unique(tid) @njit(parallel=True) - def test_func(nthreads): + def test_func_jit(nthreads): set_num_threads(nthreads) lens = np.zeros(nthreads) total = 0 @@ -463,10 +463,31 @@ def test_func(nthreads): expected_acc = BIG * NT expected_thread_count = NT + 1 - got_acc, got_tc = test_func(NT) + got_acc, got_tc = test_func_jit(NT) + self.assertEqual(expected_acc, got_acc) + np.testing.assert_equal(expected_thread_count, got_tc) + + def test_guvectorize(nthreads): + @guvectorize(['int64[:], int64[:]'], + '(n), (m)', + nopython=True, + target='parallel') + def test_func_guvectorize(total, lens): + my_acc, tids = work(nthreads + 1) + lens[:] = len(tids) + total += my_acc + + total = np.array([0]) + lens = np.zeros(nthreads, dtype=np.int64).reshape((nthreads, 1)) + + test_func_guvectorize(total, lens) + return total, np.unique(lens) + + got_acc, got_tc = test_guvectorize(NT) self.assertEqual(expected_acc, got_acc) np.testing.assert_equal(expected_thread_count, got_tc) + def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) From 5f2bd38ee9031dedaa5e302befde611b86cf3893 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 13 Dec 2019 16:25:42 -0700 Subject: [PATCH 058/595] Remove raises tests for set_num_threads inside of a jitted function The exception is only raised if the jitted function happens to be called on the main thread, which is not the case for the workqueue backend, and is an implementation detail that it happens on openmp and tbb. --- numba/tests/test_num_threads.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index d436713611c..380ac41f34e 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -57,12 +57,6 @@ def set_get_n(n): self.assertEqual(set_get_n(2), 2) self.assertEqual(set_get_n(max_threads), max_threads) - with self.assertRaises(ValueError): - set_get_n(0) - - with self.assertRaises(ValueError): - set_get_n(max_threads + 1) - @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_set_num_threads_basic_guvectorize(self): @@ -104,12 +98,6 @@ def set_get_n(n): set_get_n(x) np.testing.assert_equal(x, max_threads) - with self.assertRaises(ValueError): - set_get_n(np.array([0])) - - with self.assertRaises(ValueError): - set_get_n(np.array([max_threads + 1])) - @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def test_set_num_threads_outside_jit(self): From 78b2dd1f4f2da6bc73f742b574579da76b567654 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 13 Dec 2019 16:28:12 -0700 Subject: [PATCH 059/595] Add get_num_threads and set_num_threads to numba.__all__ --- numba/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/__init__.py b/numba/__init__.py index b77773749ec..6ec2aded9f0 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -72,6 +72,8 @@ vectorize objmode literal_unroll + get_num_threads + set_num_threads """.split() + types.__all__ + errors.__all__ From e489e1018451a975906821d0bb8b2102ffb3c918 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 16 Dec 2019 17:13:33 -0700 Subject: [PATCH 060/595] Run the num_threads tests in all backends This reuses the machinery from test_parallel_backend.py, which has been refactored slightly to make it more reusable. --- numba/tests/test_num_threads.py | 56 ++++++++++++++++++++++------ numba/tests/test_parallel_backend.py | 23 ++++++------ 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 380ac41f34e..da3186664d9 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import print_function, absolute_import, division +import sys + import numpy as np from numba import (njit, set_num_threads, get_num_threads, prange, config, @@ -8,6 +10,7 @@ from numba.npyufunc.parallel import _get_thread_id from numba import unittest_support as unittest from .support import TestCase, skip_parfors_unsupported +from .test_parallel_backend import TestInSubprocess class TestNumThreads(TestCase): _numba_parallel_test_ = False @@ -19,7 +22,7 @@ def setUp(self): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_set_num_threads_basic(self): + def _test_set_num_threads_basic(self): max_threads = config.NUMBA_NUM_THREADS self.assertEqual(get_num_threads(), max_threads) @@ -36,7 +39,7 @@ def test_set_num_threads_basic(self): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_set_num_threads_basic_jit(self): + def _test_set_num_threads_basic_jit(self): max_threads = config.NUMBA_NUM_THREADS @njit @@ -59,7 +62,7 @@ def set_get_n(n): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_set_num_threads_basic_guvectorize(self): + def _test_set_num_threads_basic_guvectorize(self): max_threads = config.NUMBA_NUM_THREADS @guvectorize(['void(int64[:])'], @@ -100,7 +103,7 @@ def set_get_n(n): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_set_num_threads_outside_jit(self): + def _test_set_num_threads_outside_jit(self): # Test set_num_threads outside a jitted function set_num_threads(2) @@ -130,7 +133,7 @@ def test_gufunc(x): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_set_num_threads_inside_jit(self): + def _test_set_num_threads_inside_jit(self): # Test set_num_threads inside a jitted function @njit(parallel=True) def test_func(nthreads): @@ -147,7 +150,7 @@ def test_func(nthreads): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_set_num_threads_inside_guvectorize(self): + def _test_set_num_threads_inside_guvectorize(self): # Test set_num_threads inside a jitted guvectorize function @guvectorize(['void(int64[:])'], '(n)', @@ -165,7 +168,7 @@ def test_func(x): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_get_num_threads_truth_outside_jit(self): + def _test_get_num_threads_truth_outside_jit(self): for mask in range(2, min(6, config.NUMBA_NUM_THREADS + 1)): set_num_threads(mask) @@ -200,7 +203,7 @@ def test_gufunc(x, out): @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_get_num_threads_truth_inside_jit(self): + def _test_get_num_threads_truth_inside_jit(self): for mask in range(2, min(6, config.NUMBA_NUM_THREADS + 1)): @@ -239,7 +242,7 @@ def test_gufunc(x, out): # set or >= 2) and TBB backends @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_nested_parallelism_1(self): + def _test_nested_parallelism_1(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") @@ -319,7 +322,7 @@ def _test_func(acc, buf, local_mask): # set or >= 2) and TBB backends @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") - def test_nested_parallelism_2(self): + def _test_nested_parallelism_2(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") @@ -418,7 +421,7 @@ def _test_func(buf, local_mask): # set or >= 2) and TBB backends @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 3, "Not enough CPU cores") - def test_nested_parallelism_3(self): + def _test_nested_parallelism_3(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") @@ -480,5 +483,36 @@ def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) +class TestNumThreadsBackends(TestInSubprocess, TestCase): + _class = TestNumThreads + _DEBUG = False + + @classmethod + def _inject(cls, name, backend, backend_guard): + themod = cls.__module__ + thecls = cls._class.__name__ + injected_method = '%s.%s.%s' % (themod, thecls, name) + + def test_template(self): + o, e = self.run_test_in_separate_process(injected_method, backend) + if self._DEBUG: + print('stdout:\n "%s"\n stderr:\n "%s"' % (o, e)) + self.assertIn('OK', e) + self.assertTrue('FAIL' not in e) + self.assertTrue('ERROR' not in e) + injected_test = "%s_%s" % (name[1:], backend) + setattr(cls, injected_test, + backend_guard(test_template)) + + @classmethod + def generate(cls): + for name in cls._class.__dict__.copy(): + for backend, backend_guard in cls.backends.items(): + if not name.startswith('_test_'): + continue + cls._inject(name, backend, backend_guard) + +TestNumThreadsBackends.generate() + if __name__ == '__main__': unittest.main() diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 1204a7c5879..6f82de7e6ba 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -337,17 +337,7 @@ def test_method(self): TestParallelBackend.generate() -class TestSpecificBackend(TestParallelBackendBase): - """ - This is quite contrived, for each test in the TestParallelBackend tests it - generates a test that will run the TestParallelBackend test in a new python - process with an environment modified to ensure a specific threadsafe backend - is used. This is with view of testing the backends independently and in an - isolated manner such that if they hang/crash/have issues, it doesn't kill - the test suite. - """ - _DEBUG = False - +class TestInSubprocess(object): backends = {'tbb': skip_no_tbb, 'omp': skip_no_omp, 'workqueue': unittest.skipIf(False, '')} @@ -377,6 +367,17 @@ def run_test_in_separate_process(self, test, threading_layer): cmdline = [sys.executable, "-m", "numba.runtests", test] return self.run_cmd(cmdline, env_copy) +class TestSpecificBackend(TestInSubprocess, TestParallelBackendBase): + """ + This is quite contrived, for each test in the TestParallelBackend tests it + generates a test that will run the TestParallelBackend test in a new python + process with an environment modified to ensure a specific threadsafe backend + is used. This is with view of testing the backends independently and in an + isolated manner such that if they hang/crash/have issues, it doesn't kill + the test suite. + """ + _DEBUG = False + @classmethod def _inject(cls, p, name, backend, backend_guard): themod = cls.__module__ From 8fba01b1d29aed680b4e52055f6e5bb59fb41afc Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 16 Dec 2019 17:24:18 -0700 Subject: [PATCH 061/595] Parameterize the num_threads tests over NUMBA_NUM_THREADS --- numba/tests/test_num_threads.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index da3186664d9..093c12097c6 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -2,6 +2,7 @@ from __future__ import print_function, absolute_import, division import sys +import os import numpy as np @@ -487,20 +488,31 @@ class TestNumThreadsBackends(TestInSubprocess, TestCase): _class = TestNumThreads _DEBUG = False + # 1 is mainly here to ensure tests skip correctly + num_threads = [i for i in [1, 2, 4, 8, 16] if i <= config.NUMBA_NUM_THREADS] + + def run_test_in_separate_process(self, test, threading_layer, num_threads): + env_copy = os.environ.copy() + env_copy['NUMBA_THREADING_LAYER'] = str(threading_layer) + env_copy['NUMBA_NUM_THREADS'] = str(num_threads) + cmdline = [sys.executable, "-m", "numba.runtests", test] + return self.run_cmd(cmdline, env_copy) + @classmethod - def _inject(cls, name, backend, backend_guard): + def _inject(cls, name, backend, backend_guard, num_threads): themod = cls.__module__ thecls = cls._class.__name__ injected_method = '%s.%s.%s' % (themod, thecls, name) def test_template(self): - o, e = self.run_test_in_separate_process(injected_method, backend) + o, e = self.run_test_in_separate_process(injected_method, backend, + num_threads) if self._DEBUG: print('stdout:\n "%s"\n stderr:\n "%s"' % (o, e)) self.assertIn('OK', e) self.assertTrue('FAIL' not in e) self.assertTrue('ERROR' not in e) - injected_test = "%s_%s" % (name[1:], backend) + injected_test = "%s_%s_%s_threads" % (name[1:], backend, num_threads) setattr(cls, injected_test, backend_guard(test_template)) @@ -508,9 +520,10 @@ def test_template(self): def generate(cls): for name in cls._class.__dict__.copy(): for backend, backend_guard in cls.backends.items(): - if not name.startswith('_test_'): - continue - cls._inject(name, backend, backend_guard) + for num_threads in cls.num_threads: + if not name.startswith('_test_'): + continue + cls._inject(name, backend, backend_guard, num_threads) TestNumThreadsBackends.generate() From 980b550e160d96b3965d63162778a3b93266da0a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 16 Dec 2019 17:36:41 -0700 Subject: [PATCH 062/595] Propagate the skip message from the subprocess in the num_threads tests --- numba/tests/test_num_threads.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 093c12097c6..abb2e07910d 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -3,6 +3,7 @@ import sys import os +import re import numpy as np @@ -495,7 +496,7 @@ def run_test_in_separate_process(self, test, threading_layer, num_threads): env_copy = os.environ.copy() env_copy['NUMBA_THREADING_LAYER'] = str(threading_layer) env_copy['NUMBA_NUM_THREADS'] = str(num_threads) - cmdline = [sys.executable, "-m", "numba.runtests", test] + cmdline = [sys.executable, "-m", "numba.runtests", "-v", test] return self.run_cmd(cmdline, env_copy) @classmethod @@ -512,6 +513,10 @@ def test_template(self): self.assertIn('OK', e) self.assertTrue('FAIL' not in e) self.assertTrue('ERROR' not in e) + m = re.search(r"\.\.\. skipped '(.*?)'", e) + if m: + self.skipTest(m.group(1)) + injected_test = "%s_%s_%s_threads" % (name[1:], backend, num_threads) setattr(cls, injected_test, backend_guard(test_template)) From 35c92ba373b81c20fc03423834f15304cd07a87a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 16 Dec 2019 17:37:11 -0700 Subject: [PATCH 063/595] Tag the num_threads tests as long running --- numba/tests/test_num_threads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index abb2e07910d..1df85ea2943 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -11,7 +11,7 @@ threading_layer, guvectorize) from numba.npyufunc.parallel import _get_thread_id from numba import unittest_support as unittest -from .support import TestCase, skip_parfors_unsupported +from .support import TestCase, skip_parfors_unsupported, tag from .test_parallel_backend import TestInSubprocess class TestNumThreads(TestCase): @@ -519,7 +519,7 @@ def test_template(self): injected_test = "%s_%s_%s_threads" % (name[1:], backend, num_threads) setattr(cls, injected_test, - backend_guard(test_template)) + tag('long_running')(backend_guard(test_template))) @classmethod def generate(cls): From 413fd3dd3df45242c5e710fe04b5639e95ca335b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Jan 2020 16:21:13 -0700 Subject: [PATCH 064/595] Raise an exception if get_num_threads() returns 0 This means it is called before set_num_threads, which shouldn't happen. This will make identifying bugs with it easier, such as the one with mkl. This should probably be modified to be raised inside of the C implementation rather than in every place where it is called. --- numba/npyufunc/parallel.py | 14 ++++++++++---- numba/npyufunc/parfor.py | 8 ++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 333684d1bdf..6aed51d5ae5 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -538,7 +538,6 @@ def impl(n): _set_num_threads(n) return impl - def get_num_threads(): """ Get the number of threads used for parallel execution. @@ -562,14 +561,21 @@ def get_num_threads(): """ _launch_threads() - return _get_num_threads() - + num_threads = _get_num_threads() + if num_threads == 0: + raise RuntimeError("Invalid number of threads. " + "This likely indicates a bug in numba.") + return num_threads @overload(get_num_threads) def ol_get_num_threads(): _launch_threads() def impl(): - return _get_num_threads() + num_threads = _get_num_threads() + if num_threads == 0: + raise RuntimeError("Invalid number of threads. " + "This likely indicates a bug in numba.") + return num_threads return impl def _get_thread_id(): diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index bf9dcbce284..cd24b6dc3a9 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1343,6 +1343,14 @@ def load_range(v): num_threads = builder.call(get_num_threads, []) + with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, + num_threads.type(0))): + context.call_conv.return_user_exc(builder, RuntimeError, + ("Invalid number of threads. " + "This likely indicates a bug in numba.",)) + + cgutils.printf(builder, "num_threads: %d\n", num_threads) + builder.call( do_scheduling, [ context.get_constant( From 0435f2d547af870e85212f9497f68f52f517d012 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Jan 2020 16:22:54 -0700 Subject: [PATCH 065/595] Remove debug printf --- numba/npyufunc/parfor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index cd24b6dc3a9..3b03ea5ac82 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1349,8 +1349,6 @@ def load_range(v): ("Invalid number of threads. " "This likely indicates a bug in numba.",)) - cgutils.printf(builder, "num_threads: %d\n", num_threads) - builder.call( do_scheduling, [ context.get_constant( From d6922c6472a513f0bd37c1249ba73c368c435816 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 7 Jan 2020 15:51:35 +0000 Subject: [PATCH 066/595] Rename TLS var --- numba/npyufunc/omppool.cpp | 6 +++--- numba/npyufunc/tbbpool.cpp | 6 +++--- numba/npyufunc/workqueue.c | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index 12e0ee88f70..91f9352aad2 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -48,18 +48,18 @@ static pid_t parent_pid = 0; // 0 is not set, users can't own this anyway #define THREAD_LOCAL(ty) __thread ty #endif -static THREAD_LOCAL(int) num_threads = 0; +static THREAD_LOCAL(int) _TLS_num_threads = 0; static void set_num_threads(int count) { - num_threads = count; + _TLS_num_threads = count; } static int get_num_threads(void) { - return num_threads; + return _TLS_num_threads; } static int diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index 49c2ff0b2f7..81b6bfd9e98 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -45,18 +45,18 @@ static int tsi_count = 0; #define THREAD_LOCAL(ty) __thread ty #endif -static THREAD_LOCAL(int) num_threads = 0; +static THREAD_LOCAL(int) _TLS_num_threads = 0; static void set_num_threads(int count) { - num_threads = count; + _TLS_num_threads = count; } static int get_num_threads(void) { - return num_threads; + return _TLS_num_threads; } static int diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index ba7786ff3df..57d0c442854 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -259,18 +259,18 @@ void debug_marker() {}; #define THREAD_LOCAL(ty) __thread ty #endif -static THREAD_LOCAL(int) num_threads = 0; +static THREAD_LOCAL(int) _TLS_num_threads = 0; static void set_num_threads(int count) { - num_threads = count; + _TLS_num_threads = count; } static int get_num_threads(void) { - return num_threads; + return _TLS_num_threads; } @@ -283,7 +283,7 @@ get_num_threads(void) // synchronize the TLS num_threads slot to value args[0] static void sync_tls(void *args, void *dims, void *steps, void *data) { int nthreads = *((int *)(args)); - num_threads = nthreads; + _TLS_num_threads = nthreads; }; From 5110d7331b555a6ab68d847b9f8b00d849dfa083 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 6 Jan 2020 16:45:43 -0600 Subject: [PATCH 067/595] Drop old np but keep np1.11 --- azure-pipelines.yml | 32 ++++++++++------------------ buildscripts/azure/azure-windows.yml | 4 ++-- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7c1d596b609..ea5deb44764 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,7 +3,7 @@ trigger: variables: # Change the following along with adding new TEST_START_INDEX. - TEST_COUNT: 18 + TEST_COUNT: 16 jobs: # Mac and Linux use the same template with different matrixes @@ -46,68 +46,58 @@ jobs: RUN_COVERAGE: yes RUN_FLAKE8: yes TEST_START_INDEX: 4 - py36_np112_doc: + py36_np117_doc: PYTHON: '3.6' - NUMPY: '1.12' + NUMPY: '1.17' CONDA_ENV: travisci BUILD_DOC: yes TEST_START_INDEX: 5 - py36_np113: - PYTHON: '3.6' - NUMPY: '1.13' - CONDA_ENV: travisci - TEST_START_INDEX: 6 - py37_np114: - PYTHON: '3.7' - NUMPY: '1.14' - CONDA_ENV: travisci - TEST_START_INDEX: 7 py37_np115: PYTHON: '3.7' NUMPY: '1.15' CONDA_ENV: travisci - TEST_START_INDEX: 8 + TEST_START_INDEX: 6 py37_np116_svml: PYTHON: '3.7' NUMPY: '1.16' CONDA_ENV: travisci TEST_SVML: yes - TEST_START_INDEX: 9 + TEST_START_INDEX: 7 py37_np116_vanilla: PYTHON: '3.7' NUMPY: '1.16' CONDA_ENV: travisci VANILLA_INSTALL: yes - TEST_START_INDEX: 10 + TEST_START_INDEX: 8 py36_np111_32bit: PYTHON: '3.6' NUMPY: '1.11' CONDA_ENV: travisci BITS32: yes - TEST_START_INDEX: 11 + TEST_START_INDEX: 9 py37_np115_32bit: PYTHON: '3.7' NUMPY: '1.15' CONDA_ENV: travisci BITS32: yes - TEST_START_INDEX: 12 + TEST_START_INDEX: 10 py37_np116_omp: PYTHON: '3.7' NUMPY: '1.16' CONDA_ENV: travisci TEST_THREADING: omp - TEST_START_INDEX: 13 + TEST_START_INDEX: 11 py37_np116_workqueue: PYTHON: '3.7' NUMPY: '1.16' CONDA_ENV: travisci TEST_THREADING: workqueue - TEST_START_INDEX: 14 + TEST_START_INDEX: 12 py38_np117: PYTHON: '3.8' NUMPY: '1.17' CONDA_ENV: travisci - TEST_START_INDEX: 15 + TEST_START_INDEX: 13 - template: buildscripts/azure/azure-windows.yml parameters: diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index f3fe8cc49ed..51860a379b3 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -12,12 +12,12 @@ jobs: PYTHON: '3.8' NUMPY: '1.17' CONDA_ENV: 'testenv' - TEST_START_INDEX: 16 + TEST_START_INDEX: 14 py37_np115: PYTHON: '3.7' NUMPY: '1.15' CONDA_ENV: 'testenv' - TEST_START_INDEX: 17 + TEST_START_INDEX: 15 steps: - task: CondaEnvironment@1 From 051bb50ca20f1850550428622134d6f59795097f Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 7 Jan 2020 09:44:03 -0600 Subject: [PATCH 068/595] Update setup.py set python and numpy requirement, use setuptools --- setup.py | 99 ++++++++++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/setup.py b/setup.py index af4af1470a9..89893ba78fb 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,8 @@ -try: - # Try to use setuptools so as to enable support of the special - # "Microsoft Visual C++ Compiler for Python 2.7" (http://aka.ms/vcpython27) - # for building under Windows. - # Note setuptools >= 6.0 is required for this. - from setuptools import setup, Extension -except ImportError: - from distutils.core import setup, Extension - +# NOTE: for building under Windows. +# Use setuptools so as to enable support of the special +# "Microsoft Visual C++ Compiler for Python 2.7" (http://aka.ms/vcpython27) +# Note setuptools >= 6.0 is required for this. +from setuptools import setup, Extension, find_packages from distutils.command import build from distutils.spawn import spawn from distutils import sysconfig @@ -16,6 +12,11 @@ import versioneer +min_python_version = "3.6" +min_numpy_build_version = "1.11" +min_numpy_run_version = "1.15" +min_llvmlite_version = "0.31.0dev0" + if sys.platform.startswith('linux'): # Patch for #2555 to make wheels without libpython sysconfig.get_config_vars()['Py_ENABLE_SHARED'] = 0 @@ -99,7 +100,6 @@ def get_ext_modules(): # C API (include dirs, library dirs etc.) np_compile_args = np_misc.get_info('npymath') - ext_dynfunc = Extension(name='numba._dynfunc', sources=['numba/_dynfuncmod.c'], extra_compile_args=CFLAGS, @@ -216,16 +216,23 @@ def check_file_at_path(path2file): print("Using Intel TBB from:", tbb_root) ext_npyufunc_tbb_workqueue = Extension( name='numba.npyufunc.tbbpool', - sources=['numba/npyufunc/tbbpool.cpp', 'numba/npyufunc/gufunc_scheduler.cpp'], + sources=[ + 'numba/npyufunc/tbbpool.cpp', + 'numba/npyufunc/gufunc_scheduler.cpp', + ], depends=['numba/npyufunc/workqueue.h'], include_dirs=[os.path.join(tbb_root, 'include')], extra_compile_args=cpp11flags, - libraries =['tbb'], # TODO: if --debug or -g, use 'tbb_debug' - library_dirs=[os.path.join(tbb_root, 'lib', 'intel64', 'gcc4.4'), # for Linux - os.path.join(tbb_root, 'lib'), # for MacOS - os.path.join(tbb_root, 'lib', 'intel64', 'vc_mt'), # for Windows - ], - ) + libraries=['tbb'], # TODO: if --debug or -g, use 'tbb_debug' + library_dirs=[ + # for Linux + os.path.join(tbb_root, 'lib', 'intel64', 'gcc4.4'), + # for MacOS + os.path.join(tbb_root, 'lib'), + # for Windows + os.path.join(tbb_root, 'lib', 'intel64', 'vc_mt'), + ], + ) ext_npyufunc_workqueue_impls.append(ext_npyufunc_tbb_workqueue) else: print("TBB not found") @@ -237,12 +244,16 @@ def check_file_at_path(path2file): elif have_openmp: print("Using OpenMP from:", have_openmp) # OpenMP backed work queue - ext_npyufunc_omppool = Extension( name='numba.npyufunc.omppool', - sources=['numba/npyufunc/omppool.cpp', - 'numba/npyufunc/gufunc_scheduler.cpp'], - depends=['numba/npyufunc/workqueue.h'], - extra_compile_args=ompcompileflags + cpp11flags, - extra_link_args = omplinkflags) + ext_npyufunc_omppool = Extension( + name='numba.npyufunc.omppool', + sources=[ + 'numba/npyufunc/omppool.cpp', + 'numba/npyufunc/gufunc_scheduler.cpp', + ], + depends=['numba/npyufunc/workqueue.h'], + extra_compile_args=ompcompileflags + cpp11flags, + extra_link_args=omplinkflags, + ) ext_npyufunc_workqueue_impls.append(ext_npyufunc_omppool) else: @@ -252,11 +263,11 @@ def check_file_at_path(path2file): # version is built. Users can select a backend via env vars. ext_npyufunc_workqueue = Extension( name='numba.npyufunc.workqueue', - sources=['numba/npyufunc/workqueue.c', 'numba/npyufunc/gufunc_scheduler.cpp'], + sources=['numba/npyufunc/workqueue.c', + 'numba/npyufunc/gufunc_scheduler.cpp'], depends=['numba/npyufunc/workqueue.h']) ext_npyufunc_workqueue_impls.append(ext_npyufunc_workqueue) - ext_mviewbuf = Extension(name='numba.mviewbuf', extra_link_args=install_name_tool_fixer, sources=['numba/mviewbuf.c']) @@ -288,45 +299,26 @@ def check_file_at_path(path2file): return ext_modules -def find_packages(root_dir, root_name): - """ - Recursively find packages in *root_dir*. - """ - packages = [] - def rec(path, pkg_name): - packages.append(pkg_name) - for fn in sorted(os.listdir(path)): - subpath = os.path.join(path, fn) - if os.path.exists(os.path.join(subpath, "__init__.py")): - subname = "%s.%s" % (pkg_name, fn) - rec(subpath, subname) - rec(root_dir, root_name) - return packages - - -packages = find_packages("numba", "numba") +packages = find_packages(include=["numba", "numba.*"]) -build_requires = ['numpy'] - -install_requires = ['llvmlite>=0.31.0dev0', 'numpy', 'setuptools'] -install_requires.extend(['enum34; python_version < "3.4"']) -install_requires.extend(['singledispatch; python_version < "3.4"']) -install_requires.extend(['funcsigs; python_version < "3.3"']) +build_requires = [f'numpy >={min_numpy_build_version}'] +install_requires = [ + f'llvmlite >={min_llvmlite_version}', + f'numpy >={min_numpy_run_version}', + 'setuptools', +] metadata = dict( name='numba', description="compiling Python code using LLVM", version=versioneer.get_version(), - classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", @@ -353,9 +345,10 @@ def rec(path, pkg_name): packages=packages, setup_requires=build_requires, install_requires=install_requires, + python_requires=f">={min_python_version}", license="BSD", cmdclass=cmdclass, - ) +) with open('README.rst') as f: metadata['long_description'] = f.read() From 851437184d0de1dbdd425aee3896bbe01da7670e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 7 Jan 2020 18:09:53 +0000 Subject: [PATCH 069/595] Sync TLS slot on main thread with launch default --- numba/npyufunc/omppool.cpp | 13 +++++++++++++ numba/npyufunc/parallel.py | 5 ++++- numba/npyufunc/parfor.py | 2 +- numba/npyufunc/tbbpool.cpp | 15 +++++++++++++++ numba/npyufunc/workqueue.c | 18 ++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index 91f9352aad2..b1830a9e94f 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -48,6 +48,11 @@ static pid_t parent_pid = 0; // 0 is not set, users can't own this anyway #define THREAD_LOCAL(ty) __thread ty #endif +// This is the number of threads that is default, it is set on initialisation of +// the threading backend via the launch_threads() call +static int _INIT_NUM_THREADS = -1; + +// This is the per-thread thread mask, each thread can carry its own mask. static THREAD_LOCAL(int) _TLS_num_threads = 0; static void @@ -59,6 +64,13 @@ set_num_threads(int count) static int get_num_threads(void) { + if (_TLS_num_threads == 0) + { + // This is a thread that did not call launch_threads() but is still a + // "main" thread, probably from e.g. threading.Thread() use, it still + // has a TLS slot which is 0 from the lack of launch_threads() call + _TLS_num_threads = _INIT_NUM_THREADS; + } return _TLS_num_threads; } @@ -212,6 +224,7 @@ static void launch_threads(int count) return; omp_set_num_threads(count); omp_set_nested(0x1); // enable nesting, control depth with OMP env var + _INIT_NUM_THREADS = count; } static void synchronize(void) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 6aed51d5ae5..9c351a5469f 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -464,6 +464,7 @@ def raise_with_hint(required): _is_initialized = True + def _load_num_threads_funcs(lib): ll.add_symbol('get_num_threads', lib.get_num_threads) @@ -563,8 +564,9 @@ def get_num_threads(): _launch_threads() num_threads = _get_num_threads() if num_threads == 0: + print("Broken: ", _get_thread_id()) raise RuntimeError("Invalid number of threads. " - "This likely indicates a bug in numba.") + "This likely indicates a bug in numba.", _get_thread_id()) return num_threads @overload(get_num_threads) @@ -573,6 +575,7 @@ def ol_get_num_threads(): def impl(): num_threads = _get_num_threads() if num_threads == 0: + print("Broken: ", _get_thread_id()) raise RuntimeError("Invalid number of threads. " "This likely indicates a bug in numba.") return num_threads diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 3b03ea5ac82..7ea65fdb32f 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1346,7 +1346,7 @@ def load_range(v): with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, num_threads.type(0))): context.call_conv.return_user_exc(builder, RuntimeError, - ("Invalid number of threads. " + ("3 Invalid number of threads. " "This likely indicates a bug in numba.",)) builder.call( diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index 81b6bfd9e98..b7fc8a9f0b1 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -45,8 +45,14 @@ static int tsi_count = 0; #define THREAD_LOCAL(ty) __thread ty #endif +// This is the number of threads that is default, it is set on initialisation of +// the threading backend via the launch_threads() call +static int _INIT_NUM_THREADS = -1; + +// This is the per-thread thread mask, each thread can carry its own mask. static THREAD_LOCAL(int) _TLS_num_threads = 0; + static void set_num_threads(int count) { @@ -56,6 +62,13 @@ set_num_threads(int count) static int get_num_threads(void) { + if (_TLS_num_threads == 0) + { + // This is a thread that did not call launch_threads() but is still a + // "main" thread, probably from e.g. threading.Thread() use, it still + // has a TLS slot which is 0 from the lack of launch_threads() call + _TLS_num_threads = _INIT_NUM_THREADS; + } return _TLS_num_threads; } @@ -251,6 +264,8 @@ static void launch_threads(int count) tg = new tbb::task_group; tg->run([] {}); // start creating threads asynchronously + _INIT_NUM_THREADS = count; + #ifndef _MSC_VER pthread_atfork(prepare_fork, reset_after_fork, reset_after_fork); #endif diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 57d0c442854..b2981db48b5 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -259,6 +259,11 @@ void debug_marker() {}; #define THREAD_LOCAL(ty) __thread ty #endif +// This is the number of threads that is default, it is set on initialisation of +// the threading backend via the launch_threads() call +static int _INIT_NUM_THREADS = -1; + +// This is the per-thread thread mask, each thread can carry its own mask. static THREAD_LOCAL(int) _TLS_num_threads = 0; static void @@ -270,6 +275,16 @@ set_num_threads(int count) static int get_num_threads(void) { + // This is purely to permit the implementation to survive to the point + // where it can exit cleanly as multiple threads cannot be used with this + // backend + if (_TLS_num_threads == 0) + { + // This is a thread that did not call launch_threads() but is still a + // "main" thread, probably from e.g. threading.Thread() use, it still + // has a TLS slot which is 0 from the lack of launch_threads() call + _TLS_num_threads = _INIT_NUM_THREADS; + } return _TLS_num_threads; } @@ -481,6 +496,8 @@ static void launch_threads(int count) queue_condition_init(&queues[i].cond); numba_new_thread(thread_worker, &queues[i]); } + + _INIT_NUM_THREADS = count; } } @@ -507,6 +524,7 @@ static void reset_after_fork(void) free(queues); queues = NULL; NUM_THREADS = -1; + _INIT_NUM_THREADS = -1; } MOD_INIT(workqueue) From ec366c8ee5a5c60fd4da5cba169e7f0d63a7c41e Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 7 Jan 2020 13:58:11 -0600 Subject: [PATCH 070/595] Stop running on np1.11 --- azure-pipelines.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ea5deb44764..c4497f73d5a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -39,9 +39,9 @@ jobs: NUMPY: '1.17' CONDA_ENV: travisci TEST_START_INDEX: 3 - py36_np111_cov: + py36_np115_cov: PYTHON: '3.6' - NUMPY: '1.11' + NUMPY: '1.15' CONDA_ENV: travisci RUN_COVERAGE: yes RUN_FLAKE8: yes @@ -69,15 +69,15 @@ jobs: CONDA_ENV: travisci VANILLA_INSTALL: yes TEST_START_INDEX: 8 - py36_np111_32bit: + py36_np115_32bit: PYTHON: '3.6' - NUMPY: '1.11' + NUMPY: '1.15' CONDA_ENV: travisci BITS32: yes TEST_START_INDEX: 9 - py37_np115_32bit: + py37_np117_32bit: PYTHON: '3.7' - NUMPY: '1.15' + NUMPY: '1.17' CONDA_ENV: travisci BITS32: yes TEST_START_INDEX: 10 From 9c202703613e059f8d7292c33b3584c99206473a Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 7 Jan 2020 14:37:59 -0600 Subject: [PATCH 071/595] Fix --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c4497f73d5a..30de3753557 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -75,9 +75,9 @@ jobs: CONDA_ENV: travisci BITS32: yes TEST_START_INDEX: 9 - py37_np117_32bit: + py37_np115_32bit: PYTHON: '3.7' - NUMPY: '1.17' + NUMPY: '1.15' CONDA_ENV: travisci BITS32: yes TEST_START_INDEX: 10 From 01d76bc7eec99646af90ca65463f01d5cdd68f0d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 11:45:21 +0000 Subject: [PATCH 072/595] Fix up flake8 As title --- numba/npyufunc/parallel.py | 15 ++++++-- numba/npyufunc/tbbpool.cpp | 2 ++ numba/tests/test_num_threads.py | 52 ++++++++++++++++------------ numba/tests/test_parallel_backend.py | 1 + 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 9c351a5469f..a85169464ad 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -276,6 +276,7 @@ def build_gufunc_wrapper(py_func, cres, sin, sout, cache, is_parfors): class _nop(object): """A no-op contextmanager """ + def __enter__(self): pass @@ -456,7 +457,7 @@ def raise_with_hint(required): launch_threads = CFUNCTYPE(None, c_int)(lib.launch_threads) launch_threads(NUM_THREADS) - _load_num_threads_funcs(lib) # load late + _load_num_threads_funcs(lib) # load late # set library name so it can be queried global _threading_layer @@ -464,7 +465,6 @@ def raise_with_hint(required): _is_initialized = True - def _load_num_threads_funcs(lib): ll.add_symbol('get_num_threads', lib.get_num_threads) @@ -534,11 +534,13 @@ def set_num_threads(n): @overload(set_num_threads) def ol_set_num_threads(n): _launch_threads() + def impl(n): snt_check(n) _set_num_threads(n) return impl + def get_num_threads(): """ Get the number of threads used for parallel execution. @@ -566,12 +568,15 @@ def get_num_threads(): if num_threads == 0: print("Broken: ", _get_thread_id()) raise RuntimeError("Invalid number of threads. " - "This likely indicates a bug in numba.", _get_thread_id()) + "This likely indicates a bug in numba.", + _get_thread_id()) return num_threads + @overload(get_num_threads) def ol_get_num_threads(): _launch_threads() + def impl(): num_threads = _get_num_threads() if num_threads == 0: @@ -581,6 +586,7 @@ def impl(): return num_threads return impl + def _get_thread_id(): """ docs @@ -588,13 +594,16 @@ def _get_thread_id(): _launch_threads() return _get_thread_id() + @overload(_get_thread_id) def ol_get_thread_id(): _launch_threads() + def impl(): return _get_thread_id() return impl + _DYLD_WORKAROUND_SET = 'NUMBA_DYLD_WORKAROUND' in os.environ _DYLD_WORKAROUND_VAL = int(os.environ.get('NUMBA_DYLD_WORKAROUND', 0)) diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index b7fc8a9f0b1..08e1e48a48b 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -2,6 +2,8 @@ Implement parallel vectorize workqueue on top of Intel TBB. */ +#define TBB_USE_DEBUG 1 +#define __TBB_EXTRA_DEBUG 1 #define TBB_PREVIEW_WAITING_FOR_WORKERS 1 /* tbb.h redefines these */ #include "../_pymodule.h" diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 1df85ea2943..9158132b0b5 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -14,6 +14,7 @@ from .support import TestCase, skip_parfors_unsupported, tag from .test_parallel_backend import TestInSubprocess + class TestNumThreads(TestCase): _numba_parallel_test_ = False @@ -125,7 +126,6 @@ def test_func(): def test_gufunc(x): x[:] = get_num_threads() - out = test_func() np.testing.assert_equal(out, 2) @@ -223,7 +223,6 @@ def test_func(): out = test_func() self.assertEqual(out, (mask, mask)) - @guvectorize(['void(int64[:], int64[:])'], '(n), (m)', nopython=True, @@ -252,7 +251,7 @@ def _test_nested_parallelism_1(self): mask = config.NUMBA_NUM_THREADS - 1 N = config.NUMBA_NUM_THREADS - M = 2*config.NUMBA_NUM_THREADS + M = 2 * config.NUMBA_NUM_THREADS @njit(parallel=True) def child_func(buf, fid): @@ -270,7 +269,8 @@ def _test_func(nthreads): set_num_threads(nthreads) for i in prange(M): local_mask = 1 + i % mask - set_num_threads(local_mask) # set threads in parent function + # set threads in parent function + set_num_threads(local_mask) if local_mask < N: child_func(buf, local_mask) acc += get_num_threads() @@ -284,7 +284,8 @@ def _test_func(nthreads): def test_func(nthreads, py_func=False): def _test_func(acc, buf, local_mask): set_num_threads(nthreads) - set_num_threads(local_mask[0]) # set threads in parent function + # set threads in parent function + set_num_threads(local_mask[0]) if local_mask[0] < N: child_func(buf, local_mask[0]) acc[0] += get_num_threads() @@ -292,13 +293,14 @@ def _test_func(acc, buf, local_mask): buf = np.zeros((M, N), dtype=np.int64) acc = np.array([0]) local_mask = (1 + np.arange(M) % mask).reshape((M, 1)) + sig = ['void(int64[:], int64[:, :], int64[:])'] if not py_func: - _test_func = guvectorize(['void(int64[:], int64[:, :], int64[:])'], - '(k), (n, m), (p)', nopython=True, + _test_func = guvectorize(sig, '(k), (n, m), (p)', + nopython=True, target='parallel')(_test_func) else: - _test_func = guvectorize(['void(int64[:], int64[:, :], int64[:])'], - '(k), (n, m), (p)', forceobj=True)(_test_func) + _test_func = guvectorize(sig, '(k), (n, m), (p)', + forceobj=True)(_test_func) _test_func(acc, buf, local_mask) return acc, buf @@ -331,7 +333,7 @@ def _test_nested_parallelism_2(self): # check that get_num_threads is ok in nesting N = config.NUMBA_NUM_THREADS + 1 - M = 4*config.NUMBA_NUM_THREADS + 1 + M = 4 * config.NUMBA_NUM_THREADS + 1 def get_impl(child_type, test_type): @@ -340,7 +342,8 @@ def get_impl(child_type, test_type): elif child_type == 'njit': child_dec = njit(parallel=False) elif child_type == 'none': - def child_dec(x): return x + def child_dec(x): + return x @child_dec def child(buf, fid): @@ -349,14 +352,14 @@ def child(buf, fid): for i in prange(N): buf[fid, i] = get_num_threads() - if test_type in ['parallel', 'njit', 'none']: if test_type == 'parallel': test_dec = njit(parallel=True) elif test_type == 'njit': test_dec = njit(parallel=False) elif test_type == 'none': - def test_dec(x): return x + def test_dec(x): + return x @test_dec def test_func(nthreads): @@ -364,9 +367,9 @@ def test_func(nthreads): set_num_threads(nthreads) for i in prange(M): local_mask = 1 + i % mask - # when the threads exit the child functions they should have - # a TLS slot value of the local mask as it was set in - # child + # when the threads exit the child functions they should + # have a TLS slot value of the local mask as it was set + # in child if local_mask < config.NUMBA_NUM_THREADS: child(buf, local_mask) assert get_num_threads() == local_mask @@ -384,9 +387,9 @@ def test_func(nthreads): @test_dec def _test_func(buf, local_mask): set_num_threads(nthreads) - # when the threads exit the child functions they should have - # a TLS slot value of the local mask as it was set in - # child + # when the threads exit the child functions they should + # have a TLS slot value of the local mask as it was set + # in child if local_mask[0] < config.NUMBA_NUM_THREADS: child(buf, local_mask[0]) assert get_num_threads() == local_mask[0] @@ -401,12 +404,14 @@ def _test_func(buf, local_mask): mask = config.NUMBA_NUM_THREADS - 1 res_arrays = {} - for test_type in ['parallel', 'njit', 'none', 'guvectorize', 'guvectorize-obj']: + for test_type in ['parallel', 'njit', 'none', + 'guvectorize', 'guvectorize-obj']: for child_type in ['parallel', 'njit', 'none']: if child_type == 'none' and test_type != 'none': continue set_num_threads(mask) - res_arrays[test_type, child_type] = get_impl(child_type, test_type)(mask) + res_arrays[test_type, child_type] = get_impl( + child_type, test_type)(mask) py_arr = res_arrays['none', 'none'] for arr in res_arrays.values(): @@ -414,7 +419,8 @@ def _test_func(buf, local_mask): # check the maths reconciles math_arr = np.zeros((M, N)) - for i in range(1, config.NUMBA_NUM_THREADS): # there's branches on modulo mask but only NUMBA_NUM_THREADS funcs + # there's branches on modulo mask but only NUMBA_NUM_THREADS funcs + for i in range(1, config.NUMBA_NUM_THREADS): math_arr[i, :] = i np.testing.assert_equal(math_arr, py_arr) @@ -480,7 +486,6 @@ def test_func_guvectorize(total, lens): self.assertEqual(expected_acc, got_acc) np.testing.assert_equal(expected_thread_count, got_tc) - def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) @@ -530,6 +535,7 @@ def generate(cls): continue cls._inject(name, backend, backend_guard, num_threads) + TestNumThreadsBackends.generate() if __name__ == '__main__': diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 6f82de7e6ba..1ec3379211f 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -367,6 +367,7 @@ def run_test_in_separate_process(self, test, threading_layer): cmdline = [sys.executable, "-m", "numba.runtests", test] return self.run_cmd(cmdline, env_copy) + class TestSpecificBackend(TestInSubprocess, TestParallelBackendBase): """ This is quite contrived, for each test in the TestParallelBackend tests it From 9a99a119d82a79c90389514ab52c3c83e92a8bca Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 12:09:45 +0000 Subject: [PATCH 073/595] Work around TBB scheduler not guaranteeing full mask use. As title --- numba/tests/test_num_threads.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 9158132b0b5..5d4bb43a401 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -433,6 +433,16 @@ def _test_nested_parallelism_3(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") + def check_mask(expected, result): + # There's no guarantee that TBB will use a full mask worth of + # threads if it deems it inefficient to do so + if threading_layer() == 'tbb': + self.assertTrue(np.all(result <= expected)) + elif threading_layer() == 'omp': + np.testing.assert_equal(expected, result) + else: + assert 0, 'unreachable' + # check that the right number of threads are present in nesting # this relies on there being a load of cores present BIG = 1000000 @@ -464,7 +474,7 @@ def test_func_jit(nthreads): got_acc, got_tc = test_func_jit(NT) self.assertEqual(expected_acc, got_acc) - np.testing.assert_equal(expected_thread_count, got_tc) + check_mask(expected_thread_count, got_tc) def test_guvectorize(nthreads): @guvectorize(['int64[:], int64[:]'], @@ -484,7 +494,7 @@ def test_func_guvectorize(total, lens): got_acc, got_tc = test_guvectorize(NT) self.assertEqual(expected_acc, got_acc) - np.testing.assert_equal(expected_thread_count, got_tc) + check_mask(expected_thread_count, got_tc) def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) From 48ffe548f3007cdf2eddff3b6795d146df052f72 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 12:19:51 +0000 Subject: [PATCH 074/595] Add OpenMP vendor string to numba -s As title --- numba/numba_entry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/numba_entry.py b/numba/numba_entry.py index 3747b234f45..5264dcd1fe0 100644 --- a/numba/numba_entry.py +++ b/numba/numba_entry.py @@ -280,6 +280,7 @@ def parse_error(e, backend): try: from numba.npyufunc import omppool print(fmt % ("OpenMP Threading layer available", True)) + print(fmt % ("+--> Vendor: ", omppool.openmp_vendor)) except ImportError as e: print(fmt % ("OpenMP Threading layer available", False)) print(fmt % ("+--> Disabled due to", From 5b323b615c960a84813b99929fe43349601296e9 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 13:30:01 +0000 Subject: [PATCH 075/595] Fix up OMP vendor ordering and test. As title. --- numba/npyufunc/omppool.cpp | 4 ++-- numba/tests/test_parallel_backend.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index b1830a9e94f..1002d2c9741 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -30,10 +30,10 @@ Threading layer on top of OpenMP. // OpenMP vendor strings #if defined(_MSC_VER) #define _OMP_VENDOR "MS" -#elif defined(__GNUC__) -#define _OMP_VENDOR "GNU" #elif defined(__clang__) #define _OMP_VENDOR "Intel" +#elif defined(__GNUC__) // NOTE: clang also defines this, but it's checked above +#define _OMP_VENDOR "GNU" #endif #if defined(__GNUC__) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 1ec3379211f..ecbb2a64017 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -858,5 +858,25 @@ def run_cmd(cmdline): print("ERR:", err) +@parfors_skip_unsupported +@skip_no_omp +class TestOpenMPVendors(TestCase): + + def test_vendors(self): + """ + Checks the OpenMP vendor strings are correct + """ + expected = dict() + expected['win32'] = "MS" + expected['darwin'] = "Intel" + expected['linux'] = "GNU" + + # only check OS that are supported, custom toolchains may well work as + # may other OS + for k in expected.keys(): + if sys.platform.startswith(k): + self.assertEqual(expected[k], omppool.openmp_vendor) + + if __name__ == '__main__': unittest.main() From 6b8338e1cf05f7245a03529907ac3e95d3d97696 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 13:49:36 +0000 Subject: [PATCH 076/595] Update forksafe definition site As title --- numba/npyufunc/omppool.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/numba/npyufunc/omppool.cpp b/numba/npyufunc/omppool.cpp index 1002d2c9741..ade5d93aeb8 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/npyufunc/omppool.cpp @@ -33,10 +33,11 @@ Threading layer on top of OpenMP. #elif defined(__clang__) #define _OMP_VENDOR "Intel" #elif defined(__GNUC__) // NOTE: clang also defines this, but it's checked above +#define _NOT_FORKSAFE 1 // GNU OpenMP Not forksafe #define _OMP_VENDOR "GNU" #endif -#if defined(__GNUC__) +#if defined(_NOT_FORKSAFE) static pid_t parent_pid = 0; // 0 is not set, users can't own this anyway #endif @@ -102,7 +103,7 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat printed = true; } -#if defined(__GNUC__) +#if defined(_NOT_FORKSAFE) // Handle GNU OpenMP not being forksafe... // This checks if the pid set by the process that initialized this library // matches the parent of this pid. If they do match this is a fork() from @@ -209,7 +210,7 @@ static void launch_threads(int count) { // this must be called in a fork+thread safe region from Python static bool initialized = false; -#ifdef __GNUC__ +#ifdef _NOT_FORKSAFE parent_pid = getpid(); // record the parent PID for use later if(_DEBUG_FORK) { From ce196b3bd0b184e4b157db3f3f64aeee2763af4b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 14:32:27 +0000 Subject: [PATCH 077/595] TMP: Add conda-forge TBB for windows --- buildscripts/azure/azure-windows.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index f3fe8cc49ed..acf639ba307 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -43,22 +43,18 @@ jobs: call activate %CONDA_ENV% conda remove -y tbb tbb-devel displayName: 'Remove TBB' - condition: eq(variables['PYTHON'], '2.7') - script: | - buildscripts\\incremental\\build.cmd - displayName: 'Build' + # temporarily patch this in to get a recent TBB + call activate %CONDA_ENV% + conda install -c conda-forge -y tbb tbb-devel + displayName: 'Add in conda-forge TBB' - script: | - # One of the tbb tests is failing on Azure. Removing tbb before - # testing until we can figure out why. Only do this for Python 3 - # because we already removed TBB before build on Python 2. - call activate %CONDA_ENV% - conda remove -y tbb tbb-devel - displayName: 'Remove TBB' - condition: ne(variables['PYTHON'], '2.7') + buildscripts\\incremental\\build.cmd + displayName: 'Build' - # not working on windows? + # not working on windows? #- script: | # call activate %CONDA_ENV% # numba.exe -s From 234a88e4c8f95d0911a978de676bc368cd5def0e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 15:21:35 +0000 Subject: [PATCH 078/595] Get test type in feedback message --- numba/tests/test_num_threads.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 5d4bb43a401..cd12d8c9146 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -311,16 +311,21 @@ def _test_func(acc, buf, local_mask): got_acc, got_arr = test_func(mask) exp_acc, exp_arr = test_func(mask, py_func=True) - self.assertEqual(exp_acc, got_acc, test_type) - np.testing.assert_equal(exp_arr, got_arr) - - # check the maths reconciles - math_acc = np.sum(1 + np.arange(M) % mask) - self.assertEqual(math_acc, got_acc) - math_arr = np.zeros((M, N)) - for i in range(1, N): # there's branches on 1, ..., num_threads - 1 - math_arr[i, :] = i - np.testing.assert_equal(math_arr, got_arr) + try: + self.assertEqual(exp_acc, got_acc, test_type) + np.testing.assert_equal(exp_arr, got_arr) + + # check the maths reconciles + math_acc = np.sum(1 + np.arange(M) % mask) + self.assertEqual(math_acc, got_acc) + math_arr = np.zeros((M, N)) + for i in range(1, N): + # there's branches on 1, ..., num_threads - 1 + math_arr[i, :] = i + np.testing.assert_equal(math_arr, got_arr) + except Exception as e: + msg = "TYPE: %s, error: %s" % (test_type, e.args[0]) + raise type(e)(msg, *e.args[1:]) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends From f23a38521b481279c1968aa81aeeec0a8deb29a2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 15:33:52 +0000 Subject: [PATCH 079/595] Extend TBB flexible testing to other tests --- numba/tests/test_num_threads.py | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index cd12d8c9146..5b3abdb8c8e 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -23,6 +23,16 @@ def setUp(self): # the threads are launched. set_num_threads(config.NUMBA_NUM_THREADS) + def check_mask(self, expected, result): + # There's no guarantee that TBB will use a full mask worth of + # threads if it deems it inefficient to do so + if threading_layer() == 'tbb': + self.assertTrue(np.all(result <= expected)) + elif threading_layer() in ('omp', 'workqueue'): + np.testing.assert_equal(expected, result) + else: + assert 0, 'unreachable' + @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def _test_set_num_threads_basic(self): @@ -186,7 +196,7 @@ def test_func(): return len(np.unique(buf)), get_num_threads() out = test_func() - self.assertEqual(out, (mask, mask)) + self.check_mask((mask, mask), out) @guvectorize(['void(int64[:], int64[:])'], '(n), (m)', @@ -200,8 +210,8 @@ def test_gufunc(x, out): x = np.full((5000000,), -1, dtype=np.int64).reshape((100, 50000)) out = np.zeros((1,), dtype=np.int64) test_gufunc(x, out) - np.testing.assert_equal(out, np.array([mask])) - self.assertEqual(len(np.unique(x)), mask) + self.check_mask(mask, out) + self.check_mask(mask, len(np.unique(x))) @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") @@ -221,7 +231,7 @@ def test_func(): return len(np.unique(buf)), get_num_threads() out = test_func() - self.assertEqual(out, (mask, mask)) + self.check_mask((mask, mask), out) @guvectorize(['void(int64[:], int64[:])'], '(n), (m)', @@ -236,8 +246,8 @@ def test_gufunc(x, out): x = np.full((5000000,), -1, dtype=np.int64).reshape((100, 50000)) out = np.zeros((1,), dtype=np.int64) test_gufunc(x, out) - np.testing.assert_equal(out, np.array([mask])) - self.assertEqual(len(np.unique(x)), mask) + self.check_mask(mask, out) + self.check_mask(mask, len(np.unique(x))) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends @@ -438,16 +448,6 @@ def _test_nested_parallelism_3(self): if threading_layer() == 'workqueue': self.skipTest("workqueue is not threadsafe") - def check_mask(expected, result): - # There's no guarantee that TBB will use a full mask worth of - # threads if it deems it inefficient to do so - if threading_layer() == 'tbb': - self.assertTrue(np.all(result <= expected)) - elif threading_layer() == 'omp': - np.testing.assert_equal(expected, result) - else: - assert 0, 'unreachable' - # check that the right number of threads are present in nesting # this relies on there being a load of cores present BIG = 1000000 @@ -479,7 +479,7 @@ def test_func_jit(nthreads): got_acc, got_tc = test_func_jit(NT) self.assertEqual(expected_acc, got_acc) - check_mask(expected_thread_count, got_tc) + self.check_mask(expected_thread_count, got_tc) def test_guvectorize(nthreads): @guvectorize(['int64[:], int64[:]'], @@ -499,7 +499,7 @@ def test_func_guvectorize(total, lens): got_acc, got_tc = test_guvectorize(NT) self.assertEqual(expected_acc, got_acc) - check_mask(expected_thread_count, got_tc) + self.check_mask(expected_thread_count, got_tc) def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) From 57360128be35bdd7770665e567d3d66f3ca76c78 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 8 Jan 2020 11:21:52 -0600 Subject: [PATCH 080/595] Update buildscript pinning --- buildscripts/condarecipe.local/meta.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildscripts/condarecipe.local/meta.yaml b/buildscripts/condarecipe.local/meta.yaml index 82231aafff6..59b4ef0ac42 100644 --- a/buildscripts/condarecipe.local/meta.yaml +++ b/buildscripts/condarecipe.local/meta.yaml @@ -29,7 +29,7 @@ requirements: - intel-openmp # [osx] host: - python - - numpy x.x + - numpy - setuptools # On channel https://anaconda.org/numba/ - llvmlite 0.31.* @@ -38,8 +38,8 @@ requirements: # TBB devel version is to match TBB libs - tbb-devel >=2018.0.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] run: - - python - - numpy x.x + - python >=3.6 + - numpy >=1.15 - setuptools # On channel https://anaconda.org/numba/ - llvmlite 0.31.* From 09a0239cfe86790355368f5d7b68910ad47d4715 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 8 Jan 2020 15:34:44 -0600 Subject: [PATCH 081/595] Ensure fork context is used as needed by the test --- numba/tests/test_parallel_backend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 1204a7c5879..2b0f4a3e5e2 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -629,15 +629,16 @@ def test_par_parent_implicit_mp_fork_par_child(self): pattern for GNU OpenMP """ body = """if 1: + mp = multiprocessing.get_context('fork') X = np.arange(1000000.) Y = np.arange(1000000.) - q = multiprocessing.Queue() + q = mp.Queue() # Start OpenMP runtime on parent via parallel function Z = busy_func(X, Y, q) # fork() underneath with no exec, will abort - proc = multiprocessing.Process(target = busy_func, args=(X, Y, q)) + proc = mp.Process(target = busy_func, args=(X, Y, q)) proc.start() err = q.get() From 05536255ce52c70c16ad8388311c8c24155c5ac2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 22:11:10 +0000 Subject: [PATCH 082/595] Add numba -s to azure --- buildscripts/azure/azure-windows.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index acf639ba307..050ec64379a 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -54,11 +54,10 @@ jobs: buildscripts\\incremental\\build.cmd displayName: 'Build' - # not working on windows? - #- script: | - # call activate %CONDA_ENV% - # numba.exe -s - # displayName: 'Display numba system information' + - script: | + call activate %CONDA_ENV% + python -m numba -s + displayName: 'Display numba system information' - script: | call activate %CONDA_ENV% From 5dd3bbc7ca141b7c2ad8d9bca9421291ce4a6df2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 8 Jan 2020 22:20:22 +0000 Subject: [PATCH 083/595] Debug output --- numba/tests/test_num_threads.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 5b3abdb8c8e..df0b8c2a013 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -318,9 +318,11 @@ def _test_func(acc, buf, local_mask): for test_type in ['njit', 'guvectorize']: test_func = get_test(test_type) - got_acc, got_arr = test_func(mask) exp_acc, exp_arr = test_func(mask, py_func=True) + print(test_type.center(80, '-')) + print(got_acc, '\n', got_arr) + print(exp_acc, '\n', exp_arr) try: self.assertEqual(exp_acc, got_acc, test_type) np.testing.assert_equal(exp_arr, got_arr) @@ -328,6 +330,7 @@ def _test_func(acc, buf, local_mask): # check the maths reconciles math_acc = np.sum(1 + np.arange(M) % mask) self.assertEqual(math_acc, got_acc) + print(math_acc, '\n', got_acc) math_arr = np.zeros((M, N)) for i in range(1, N): # there's branches on 1, ..., num_threads - 1 From 9116ce22861ec3eeed5bc3478302646cf22948a7 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 8 Jan 2020 17:30:54 -0600 Subject: [PATCH 084/595] Constrain llvmlite version --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 89893ba78fb..4f3b46f00e3 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ min_numpy_build_version = "1.11" min_numpy_run_version = "1.15" min_llvmlite_version = "0.31.0dev0" +max_llvmlite_version = "0.32.0" if sys.platform.startswith('linux'): # Patch for #2555 to make wheels without libpython @@ -303,7 +304,7 @@ def check_file_at_path(path2file): build_requires = [f'numpy >={min_numpy_build_version}'] install_requires = [ - f'llvmlite >={min_llvmlite_version}', + f'llvmlite >={min_llvmlite_version},<{max_llvmlite_version}', f'numpy >={min_numpy_run_version}', 'setuptools', ] From de9a8b303be38e11931aeb3d5758faee83eadcd2 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 8 Jan 2020 17:32:14 -0600 Subject: [PATCH 085/595] Constrain scipy --- buildscripts/condarecipe.local/meta.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildscripts/condarecipe.local/meta.yaml b/buildscripts/condarecipe.local/meta.yaml index 59b4ef0ac42..90dcffdb898 100644 --- a/buildscripts/condarecipe.local/meta.yaml +++ b/buildscripts/condarecipe.local/meta.yaml @@ -53,6 +53,8 @@ requirements: - libopenblas !=0.3.6 # [x86_64] # CUDA 8.0 or later is required for CUDA support - cudatoolkit >=8.0 + # scipy 1.0 or later + - scipy >=1.0 test: requires: - jinja2 From 001e23acacdbe661445432107d1efaa63e5528a3 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 8 Jan 2020 15:50:40 -0800 Subject: [PATCH 086/595] insert_equiv now returns True if some change was made to the equivalence sets, False otherwise. If no change is made then we can safely allow multiple defs of the variable since the equivalence set stays the same. --- numba/array_analysis.py | 78 ++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/numba/array_analysis.py b/numba/array_analysis.py index 258e344c408..8ceab6270e7 100644 --- a/numba/array_analysis.py +++ b/numba/array_analysis.py @@ -291,7 +291,7 @@ def insert_equiv(self, *objs): """Insert a set of equivalent objects by modifying self. This method can be overloaded to transform object type before insertion. """ - self._insert(objs) + return self._insert(objs) def intersect(self, equiv_set): """ Return the intersection of self and the given equiv_set, @@ -375,6 +375,9 @@ def _get_names(self, obj): """ if isinstance(obj, ir.Var) or isinstance(obj, str): name = obj if isinstance(obj, str) else obj.name + if name not in self.typemap: + return (name,) + typ = self.typemap[name] if (isinstance(typ, types.BaseTuple) or isinstance(typ, types.ArrayCompatible)): @@ -524,9 +527,14 @@ def insert_equiv(self, *objs): self.ind_to_const[self.next_ind] = const self.next_ind += 1 + some_change = False + for i in range(ndim): names = [obj_name[i] for obj_name in obj_names] - super(ShapeEquivSet, self).insert_equiv(*names) + ie_res = super(ShapeEquivSet, self).insert_equiv(*names) + some_change = some_change or ie_res + + return some_change def has_shape(self, name): """Return true if the shape of the given variable is available. @@ -612,28 +620,30 @@ def define(self, name, redefined): name = name.name if name in self.defs: self.defs[name] += 1 - # NOTE: variable being redefined, must invalidate previous - # equivalences. Believe it is a rare case, and only happens to - # scalar accumuators. - if name in self.obj_to_ind: - redefined.add(name) # remove this var from all equiv sets - i = self.obj_to_ind[name] - del self.obj_to_ind[name] - self.ind_to_obj[i].remove(name) - if self.ind_to_obj[i] == []: - del self.ind_to_obj[i] - assert(i in self.ind_to_var) - names = [x.name for x in self.ind_to_var[i]] - if name in names: - j = names.index(name) - del self.ind_to_var[i][j] - if self.ind_to_var[i] == []: - del self.ind_to_var[i] - # no more size variables, remove equivalence too - if i in self.ind_to_obj: - for obj in self.ind_to_obj[i]: - del self.obj_to_ind[obj] - del self.ind_to_obj[i] + name_res = list(self._get_names(name)) + for one_name in name_res: + # NOTE: variable being redefined, must invalidate previous + # equivalences. Believe it is a rare case, and only happens to + # scalar accumuators. + if one_name in self.obj_to_ind: + redefined.add(one_name) # remove this var from all equiv sets + i = self.obj_to_ind[one_name] + del self.obj_to_ind[one_name] + self.ind_to_obj[i].remove(one_name) + if self.ind_to_obj[i] == []: + del self.ind_to_obj[i] + assert(i in self.ind_to_var) + names = [x.name for x in self.ind_to_var[i]] + if name in names: + j = names.index(name) + del self.ind_to_var[i][j] + if self.ind_to_var[i] == []: + del self.ind_to_var[i] + # no more size variables, remove equivalence too + if i in self.ind_to_obj: + for obj in self.ind_to_obj[i]: + del self.obj_to_ind[obj] + del self.ind_to_obj[i] else: self.defs[name] = 1 @@ -835,7 +845,7 @@ def define(self, var, redefined, func_ir=None, typ=None): def _insert(self, objs): """Overload _insert method to handle ind changes between relative - objects. + objects. Returns True if some change is made, false otherwise. """ indset = set() uniqs = set() @@ -847,7 +857,7 @@ def _insert(self, objs): uniqs.add(obj) indset.add(ind) if len(uniqs) <= 1: - return + return False uniqs = list(uniqs) super(SymbolicEquivSet, self)._insert(uniqs) objs = self.ind_to_obj[self._get_ind(uniqs[0])] @@ -875,6 +885,7 @@ def get_or_set(d, k): get_or_set(offset_dict, offset).append(name) for names in offset_dict.values(): self._insert(names) + return True def set_shape_setitem(self, obj, shape): """remember shapes of SetItem IR nodes. @@ -1015,11 +1026,17 @@ def run(self, blocks=None, equiv_set=None): # Go through each incoming edge, process prepended instructions and # calculate beginning equiv_set of current block as an intersection # of incoming ones. + if config.DEBUG_ARRAY_OPT >= 2: + print("preds:", preds) for (p, q) in preds: + if config.DEBUG_ARRAY_OPT >= 2: + print("p, q:", p, q) if p in pruned: continue if p in self.equiv_sets: from_set = self.equiv_sets[p].clone() + if config.DEBUG_ARRAY_OPT >= 2: + print("p in equiv_sets", from_set) if (p, label) in self.prepends: instrs = self.prepends[(p, label)] for inst in instrs: @@ -1052,7 +1069,8 @@ def run(self, blocks=None, equiv_set=None): self.calltypes[inst] = orig_calltype pre, post = self._analyze_inst(label, scope, equiv_set, inst, redefined) # Remove anything multiply defined in this block from every block equivs. - self.remove_redefineds(redefined) + if len(redefined) > 0: + self.remove_redefineds(redefined) for instr in pre: new_body.append(instr) new_body.append(inst) @@ -1143,9 +1161,11 @@ def _analyze_inst(self, label, scope, equiv_set, inst, redefined): (shape, post) = self._gen_shape_call(equiv_set, lhs, len(typ), shape) + needs_define = True if shape != None: - equiv_set.insert_equiv(lhs, shape) - equiv_set.define(lhs, redefined, self.func_ir, typ) + needs_define = equiv_set.insert_equiv(lhs, shape) + if needs_define: + equiv_set.define(lhs, redefined, self.func_ir, typ) elif isinstance(inst, ir.StaticSetItem) or isinstance(inst, ir.SetItem): index = inst.index if isinstance(inst, ir.SetItem) else inst.index_var result = guard(self._index_to_shape, From acf660cbb24ec3f044f12ea050760cd8b94ece8f Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 8 Jan 2020 15:50:57 -0800 Subject: [PATCH 087/595] Add test for issue5031. --- numba/tests/test_parfors.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index fbc755b6162..fd7551dc3e6 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -1532,6 +1532,19 @@ def test_impl(n): return np.sum(n) + np.prod(n) + np.min(n) + np.max(n) + np.var(n) self.check(test_impl, np.array(7), check_scheduling=False) + @skip_unsupported + def test_array_analysis_optional_def(self): + def test_impl(x, half): + size = len(x) + parr = x[0:size] + + if half: + parr = x[0:size//2] + + return parr.sum() + x = np.ones(20) + self.check(test_impl, x, True, check_scheduling=False) + class TestParforsLeaks(MemoryLeakMixin, TestParforsBase): def check(self, pyfunc, *args, **kwargs): From 74b81d3ff9f1f7e4ab717fcb6d707173a3532cfb Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 11:39:13 +0000 Subject: [PATCH 088/595] Fix up guvectorize race condition. As title. --- numba/tests/test_num_threads.py | 44 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index df0b8c2a013..376d82bc68a 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -301,15 +301,15 @@ def _test_func(acc, buf, local_mask): acc[0] += get_num_threads() buf = np.zeros((M, N), dtype=np.int64) - acc = np.array([0]) + acc = np.zeros((M, 1), dtype=np.int64) local_mask = (1 + np.arange(M) % mask).reshape((M, 1)) sig = ['void(int64[:], int64[:, :], int64[:])'] + layout = '(p), (n, m), (p)' if not py_func: - _test_func = guvectorize(sig, '(k), (n, m), (p)', - nopython=True, + _test_func = guvectorize(sig, layout, nopython=True, target='parallel')(_test_func) else: - _test_func = guvectorize(sig, '(k), (n, m), (p)', + _test_func = guvectorize(sig, layout, forceobj=True)(_test_func) _test_func(acc, buf, local_mask) return acc, buf @@ -320,25 +320,23 @@ def _test_func(acc, buf, local_mask): test_func = get_test(test_type) got_acc, got_arr = test_func(mask) exp_acc, exp_arr = test_func(mask, py_func=True) - print(test_type.center(80, '-')) - print(got_acc, '\n', got_arr) - print(exp_acc, '\n', exp_arr) - try: - self.assertEqual(exp_acc, got_acc, test_type) - np.testing.assert_equal(exp_arr, got_arr) - - # check the maths reconciles - math_acc = np.sum(1 + np.arange(M) % mask) - self.assertEqual(math_acc, got_acc) - print(math_acc, '\n', got_acc) - math_arr = np.zeros((M, N)) - for i in range(1, N): - # there's branches on 1, ..., num_threads - 1 - math_arr[i, :] = i - np.testing.assert_equal(math_arr, got_arr) - except Exception as e: - msg = "TYPE: %s, error: %s" % (test_type, e.args[0]) - raise type(e)(msg, *e.args[1:]) + np.testing.assert_equal(exp_acc, got_acc) + np.testing.assert_equal(exp_arr, got_arr) + + # check the maths reconciles, guvectorize does not reduce, njit does + math_acc_exp = 1 + np.arange(M) % mask + if test_type == 'guvectorize': + math_acc = math_acc_exp.reshape((M, 1)) + else: + math_acc = np.sum(math_acc_exp) + + np.testing.assert_equal(math_acc, got_acc) + + math_arr = np.zeros((M, N)) + for i in range(1, N): + # there's branches on 1, ..., num_threads - 1 + math_arr[i, :] = i + np.testing.assert_equal(math_arr, got_arr) # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends From 8eb2a09aa12884425afadb8f81da970c972005dd Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 11:58:20 +0000 Subject: [PATCH 089/595] Fix another race condition --- numba/tests/test_num_threads.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 376d82bc68a..a734c0a1a46 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -443,6 +443,8 @@ def _test_func(buf, local_mask): # this test can only run on OpenMP (providing OMP_MAX_ACTIVE_LEVELS is not # set or >= 2) and TBB backends + # This test needs at least 3 threads to run, N>=2 for the launch, M>=N+1 for + # the nested function @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 3, "Not enough CPU cores") def _test_nested_parallelism_3(self): @@ -454,10 +456,10 @@ def _test_nested_parallelism_3(self): BIG = 1000000 @njit(parallel=True) - def work(local_nt): + def work(local_nt): # arg is value 3 tid = np.zeros(BIG) acc = 0 - set_num_threads(local_nt) + set_num_threads(local_nt) # set to 3 threads for i in prange(BIG): acc += 1 tid[i] = _get_thread_id() @@ -465,11 +467,11 @@ def work(local_nt): @njit(parallel=True) def test_func_jit(nthreads): - set_num_threads(nthreads) + set_num_threads(nthreads) # set to 2 threads lens = np.zeros(nthreads) total = 0 for i in prange(nthreads): - my_acc, tids = work(nthreads + 1) + my_acc, tids = work(nthreads + 1) # call with value 3 lens[i] = len(tids) total += my_acc return total, np.unique(lens) @@ -484,21 +486,23 @@ def test_func_jit(nthreads): def test_guvectorize(nthreads): @guvectorize(['int64[:], int64[:]'], - '(n), (m)', + '(n), (n)', nopython=True, target='parallel') def test_func_guvectorize(total, lens): my_acc, tids = work(nthreads + 1) - lens[:] = len(tids) - total += my_acc + lens[0] = len(tids) + total[0] += my_acc - total = np.array([0]) + total = np.zeros((nthreads, 1), dtype=np.int64) lens = np.zeros(nthreads, dtype=np.int64).reshape((nthreads, 1)) test_func_guvectorize(total, lens) - return total, np.unique(lens) + # vectorize does not reduce, so total is summed + return total.sum(), np.unique(lens) got_acc, got_tc = test_guvectorize(NT) + self.assertEqual(expected_acc, got_acc) self.check_mask(expected_thread_count, got_tc) From 1fa4da7c1599bd4e7cb7bb9a7bb9ac851dfacbc4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 13:14:50 +0000 Subject: [PATCH 090/595] Trying out nested parallelism prevention in workqueue --- numba/npyufunc/tbbpool.cpp | 2 -- numba/npyufunc/workqueue.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index 08e1e48a48b..b7fc8a9f0b1 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -2,8 +2,6 @@ Implement parallel vectorize workqueue on top of Intel TBB. */ -#define TBB_USE_DEBUG 1 -#define __TBB_EXTRA_DEBUG 1 #define TBB_PREVIEW_WAITING_FOR_WORKERS 1 /* tbb.h redefines these */ #include "../_pymodule.h" diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index b2981db48b5..1cf4798d8fd 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -21,12 +21,16 @@ race condition. #include #include #include +#include #define NUMBA_WINTHREAD #else /* PThread */ #include #include #include +#include +#include +#include #define NUMBA_PTHREAD #endif @@ -38,6 +42,16 @@ race condition. #define _DEBUG 0 +/* workqueue is not threadsafe, so we use DSO globals to flag and update various + * states. + */ +/* This variable is the nesting level, it's incremented at the start of each + * parallel region and decremented at the end, if parallel regions are nested + * on entry the value == 1 and workqueue will abort (this in preference to just + * hanging or segfaulting). + */ +static int _nesting_level = 0; + /* As the thread-pool isn't inherited by children, free the task-queue, too. */ static void reset_after_fork(void); @@ -312,6 +326,20 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat // steps = // data = + // check the nesting level, if it's already 1, abort, workqueue cannot + // handle nesting. + if (_nesting_level >= 1){ + fprintf(stderr, "%s", "Terminating: Nested parallel kernel launch " + "detected, the workqueue threading layer does " + "not supported nested parallelism. Try the TBB " + "threading layer.\n"); + raise(SIGTERM); + return; + } + + // increment the nest level + _nesting_level += 1; + size_t * count_space = NULL; char ** array_arg_space = NULL; const size_t arg_len = (inner_ndim + 1); @@ -431,6 +459,8 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat synchronize(); queue_count = old_queue_count; + // decrement the nest level + _nesting_level -= 1; } static void @@ -525,6 +555,7 @@ static void reset_after_fork(void) queues = NULL; NUM_THREADS = -1; _INIT_NUM_THREADS = -1; + _nesting_level = 0; } MOD_INIT(workqueue) From 3c33a0b8c765ff65b5cd70d2f998e3908dd58a5d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 13:41:58 +0000 Subject: [PATCH 091/595] Add test for sigterm on nested workqueue use --- numba/npyufunc/workqueue.c | 2 +- numba/tests/test_parallel_backend.py | 40 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 1cf4798d8fd..92940a46139 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -333,7 +333,7 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat "detected, the workqueue threading layer does " "not supported nested parallelism. Try the TBB " "threading layer.\n"); - raise(SIGTERM); + raise(SIGABRT); return; } diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index ecbb2a64017..c01af21ca11 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -8,6 +8,7 @@ import multiprocessing import random import os +import signal import sys import subprocess @@ -579,6 +580,45 @@ def foo(n): print(out, err) self.assertIn("@tbb@", out) + def test_workqueue_aborts_on_nested_parallelism(self): + """ + Tests workqueue raises sigabrt if a nested parallel call is performed + """ + runme = """if 1: + from numba import njit, prange + import numpy as np + + @njit(parallel=True) + def nested(x): + for i in prange(len(x)): + x[i] += 1 + + + @njit(parallel=True) + def main(): + Z = np.zeros((5, 10)) + for i in prange(Z.shape[0]): + nested(Z[i]) + return Z + + main() + """ + cmdline = [sys.executable, '-c', runme] + env = os.environ.copy() + env['NUMBA_THREADING_LAYER'] = "workqueue" + env['NUMBA_NUM_THREADS'] = "4" + + try: + out, err = self.run_cmd(cmdline, env=env) + except AssertionError as e: + if self._DEBUG: + print(out, err) + e_msg = str(e) + self.assertIn("failed with code", e_msg) + self.assertIn(str(signal.SIGTERM.value), e_msg) + self.assertIn("Terminating: Nested parallel kernel launch detected", + e_msg) + # 32bit or windows py27 (not that this runs on windows) @parfors_skip_unsupported From 3f080fbaa5b01111aadb2c6fb451719b7441b6ce Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 14:20:07 +0000 Subject: [PATCH 092/595] Update signal --- numba/npyufunc/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 92940a46139..1cf4798d8fd 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -333,7 +333,7 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat "detected, the workqueue threading layer does " "not supported nested parallelism. Try the TBB " "threading layer.\n"); - raise(SIGABRT); + raise(SIGTERM); return; } From 2bcf552685ed9edcbf571097b0004e64bfedcadb Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 15:35:41 +0000 Subject: [PATCH 093/595] Update signal for windows --- numba/tests/test_parallel_backend.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index c01af21ca11..00fde72a57d 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -615,7 +615,13 @@ def main(): print(out, err) e_msg = str(e) self.assertIn("failed with code", e_msg) - self.assertIn(str(signal.SIGTERM.value), e_msg) + # raised a SIGTERM, on windows in practise this seems to + # materialise as a SIGQUIT + # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=vs-2019 + if _windows: + self.assertIn(str(signal.SIGQUIT.value), e_msg) + else: + self.assertIn(str(signal.SIGTERM.value), e_msg) self.assertIn("Terminating: Nested parallel kernel launch detected", e_msg) From 5f5179739ae7228f979a3151eae8302992b9ee0d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 15:43:12 +0000 Subject: [PATCH 094/595] Fix flake8 --- numba/tests/test_parallel_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 00fde72a57d..7767738acfe 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -615,9 +615,9 @@ def main(): print(out, err) e_msg = str(e) self.assertIn("failed with code", e_msg) - # raised a SIGTERM, on windows in practise this seems to + # raised a SIGTERM, on windows in practise this seems to # materialise as a SIGQUIT - # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=vs-2019 + # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=vs-2019 # noqa: E501 if _windows: self.assertIn(str(signal.SIGQUIT.value), e_msg) else: From b95da892283367614560b417411563c92ca8f113 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 16:07:14 +0000 Subject: [PATCH 095/595] Move to SIGABRT as all OS have that?! --- numba/npyufunc/workqueue.c | 2 +- numba/tests/test_parallel_backend.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 1cf4798d8fd..92940a46139 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -333,7 +333,7 @@ parallel_for(void *fn, char **args, size_t *dimensions, size_t *steps, void *dat "detected, the workqueue threading layer does " "not supported nested parallelism. Try the TBB " "threading layer.\n"); - raise(SIGTERM); + raise(SIGABRT); return; } diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 7767738acfe..7c11dc67559 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -615,13 +615,9 @@ def main(): print(out, err) e_msg = str(e) self.assertIn("failed with code", e_msg) - # raised a SIGTERM, on windows in practise this seems to - # materialise as a SIGQUIT + # raised a SIGABRT, this seems to exist everywhere # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=vs-2019 # noqa: E501 - if _windows: - self.assertIn(str(signal.SIGQUIT.value), e_msg) - else: - self.assertIn(str(signal.SIGTERM.value), e_msg) + self.assertIn(str(signal.SIGABRT.value), e_msg) self.assertIn("Terminating: Nested parallel kernel launch detected", e_msg) From d5bd678d09f18ac1fd30e9dfe22083d6ba6dcfe6 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Thu, 9 Jan 2020 08:47:37 -0800 Subject: [PATCH 096/595] Add comments describing logical behind invalidating a variable from an equivalence set only if multiple definitions are not known to be consistent with one another. --- numba/array_analysis.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/numba/array_analysis.py b/numba/array_analysis.py index 8ceab6270e7..758727953ac 100644 --- a/numba/array_analysis.py +++ b/numba/array_analysis.py @@ -613,8 +613,27 @@ def define(self, name, redefined): defined. Most variables in Numba IR are SSA, i.e., defined only once, but not all of them. When a variable is being re-defined, it must be removed from the equivalence relation and added to the redefined - set. Those variables redefined are removed from all the blocks' - equivalence sets later. + set but only if that redefinition is not known to have the same + equivalence classes. Those variables redefined are removed from all + the blocks' equivalence sets later. + + Arrays passed to define() use their whole name but these do not + appear in the equivalence sets since they are stored there per + dimension. Calling _get_names() here converts array names to + dimensional names. + + This function would previously invalidate if there were any multiple + definitions of a variable. However, we realized that this behavior + is overly restrictive. You need only invalidate on multiple + definitions if they are not known to be equivalent. So, the + equivalence insertion functions now return True if some change was + made (meaning the definition was not equivalent) and False + otherwise. If no change was made, then define() need not be + called. For no change to have been made, the variable must + already be present. If the new definition of the var has the + case where lhs and rhs are in the same equivalence class then + again, no change will be made and define() need not be called + or the variable invalidated. """ if isinstance(name, ir.Var): name = name.name @@ -1161,6 +1180,20 @@ def _analyze_inst(self, label, scope, equiv_set, inst, redefined): (shape, post) = self._gen_shape_call(equiv_set, lhs, len(typ), shape) + """ See the comment on the define() function. + + We need only call define(), which will invalidate a variable + from being in the equivalence sets on multiple definitions, + if the variable was not previously defined or if the new + definition would be in a conflicting equivalence class to the + original equivalence class for the variable. + + insert_equiv() returns True if either of these conditions are + True and then we call define() in those cases. If insert_equiv() + returns False then no changes were made and all equivalence + classes are consistent upon a redefinition so no invalidation + is needed and we don't call define(). + """ needs_define = True if shape != None: needs_define = equiv_set.insert_equiv(lhs, shape) From 370b73279a7e0703d553185c150d1e071ef5bb13 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 17:32:00 +0000 Subject: [PATCH 097/595] Stop checking signal value --- numba/tests/test_parallel_backend.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 7c11dc67559..b23807c4777 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -8,7 +8,6 @@ import multiprocessing import random import os -import signal import sys import subprocess @@ -615,9 +614,8 @@ def main(): print(out, err) e_msg = str(e) self.assertIn("failed with code", e_msg) - # raised a SIGABRT, this seems to exist everywhere - # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=vs-2019 # noqa: E501 - self.assertIn(str(signal.SIGABRT.value), e_msg) + # raised a SIGABRT, but the value is platform specific so just check + # the error message self.assertIn("Terminating: Nested parallel kernel launch detected", e_msg) From 0b2e22220a0f8dddce7c776aed88d6f73cc58e54 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 9 Jan 2020 20:56:20 +0000 Subject: [PATCH 098/595] Cast pthread_self() to int. This is not ideal, but is likely sufficient given the use case (testing and debug). --- numba/npyufunc/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/workqueue.c b/numba/npyufunc/workqueue.c index 92940a46139..e732a3c368c 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/npyufunc/workqueue.c @@ -131,7 +131,7 @@ numba_new_thread(void *worker, void *arg) static int get_thread_id(void) { - return pthread_self(); + return (int)pthread_self(); } #endif From d67b21fb65a9f1455b9eba7e40b113283209459c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 9 Jan 2020 15:26:11 -0700 Subject: [PATCH 099/595] Add thread mask tests to test_parallel_backend --- numba/tests/test_parallel_backend.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index b23807c4777..4c64a8e2d9d 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -16,7 +16,7 @@ from numba import config, utils from numba import unittest_support as unittest -from numba import jit, vectorize, guvectorize +from numba import jit, vectorize, guvectorize, set_num_threads from .support import temp_directory, override_config, TestCase, tag @@ -110,6 +110,17 @@ def __call__(self): got = cfunc(a, b) np.testing.assert_allclose(expected, got) +class mask_runner(object): + def __init__(self, runner, mask, **options): + self.runner = runner + self.mask = mask + + def __call__(self): + if self.mask: + # Tests are all run in isolated subprocesses, so we + # don't have to worry about this affecting other tests + set_num_threads(self.mask) + self.runner() class linalg_runner(runnable): @@ -243,6 +254,13 @@ class TestParallelBackendBase(TestCase): ] all_impls.extend(parfor_impls) + masks = [i for i in [1, 2, 4, 8, 16] if i <= config.NUMBA_NUM_THREADS] + + mask_impls = [] + for impl in all_impls: + for mask in masks: + mask_impls.append(mask_runner(impl, mask)) + parallelism = ['threading', 'random'] if utils.PYVERSION > (3, 0): parallelism.append('multiprocessing_spawn') @@ -263,6 +281,7 @@ class TestParallelBackendBase(TestCase): guvectorize_runner(nopython=True, target='parallel'), ], 'concurrent_mix_use': all_impls, + 'concurrent_mix_use_masks': mask_impls, } safe_backends = {'omp', 'tbb'} From 20167f395e117fca39522f267fad8c42263a4bc0 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 9 Jan 2020 16:20:13 -0700 Subject: [PATCH 100/595] Somewhat improved the error messages if get_num_threads() gets an invalid value --- numba/npyufunc/parallel.py | 13 +++++++------ numba/npyufunc/parfor.py | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index a85169464ad..5f368cf9ec4 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -565,11 +565,11 @@ def get_num_threads(): """ _launch_threads() num_threads = _get_num_threads() - if num_threads == 0: - print("Broken: ", _get_thread_id()) + if num_threads <= 0: raise RuntimeError("Invalid number of threads. " - "This likely indicates a bug in numba.", - _get_thread_id()) + "This likely indicates a bug in numba. " + "(thread_id=%s, num_threads=%s)" % + (_get_thread_id(), num_threads)) return num_threads @@ -579,8 +579,9 @@ def ol_get_num_threads(): def impl(): num_threads = _get_num_threads() - if num_threads == 0: - print("Broken: ", _get_thread_id()) + if num_threads <= 0: + print("Broken thread_id: ", _get_thread_id()) + print("num_threads: ", num_threads) raise RuntimeError("Invalid number of threads. " "This likely indicates a bug in numba.") return num_threads diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 7ea65fdb32f..096c4eb595e 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1345,8 +1345,9 @@ def load_range(v): with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, num_threads.type(0))): + cgutils.printf(builder, "num_threads: %d\n", num_threads) context.call_conv.return_user_exc(builder, RuntimeError, - ("3 Invalid number of threads. " + ("Invalid number of threads. " "This likely indicates a bug in numba.",)) builder.call( From 3135b9078740baff968f7e70a5a475d07bb01e8b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 9 Jan 2020 18:59:17 -0700 Subject: [PATCH 101/595] Use fewer masks in the parallel_backend tests --- numba/tests/test_parallel_backend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 4c64a8e2d9d..f0e59ddf7e4 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -254,7 +254,10 @@ class TestParallelBackendBase(TestCase): ] all_impls.extend(parfor_impls) - masks = [i for i in [1, 2, 4, 8, 16] if i <= config.NUMBA_NUM_THREADS] + if config.NUMBA_NUM_THREADS < 2: + # Not enough cores + masks = [] + masks = [1, 2] mask_impls = [] for impl in all_impls: From ef7c32123b72e2d686010d0f5474d83556502f04 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 10 Jan 2020 09:23:27 +0000 Subject: [PATCH 102/595] Permit mixed int types in wrap_index As title. Fixes #5056 --- numba/array_analysis.py | 25 +++++++------------------ numba/tests/test_array_analysis.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/numba/array_analysis.py b/numba/array_analysis.py index 258e344c408..d165c9571f2 100644 --- a/numba/array_analysis.py +++ b/numba/array_analysis.py @@ -68,27 +68,16 @@ def wrap_index(typingctx, idx, size): where idx > size due to the way indices are calculated during slice/range analysis. """ - if idx != size: + unified_ty = typingctx.unify_types(idx, size) + if not unified_ty: raise ValueError("Argument types for wrap_index must match") def codegen(context, builder, sig, args): - """ - assert(len(args) == 2) - idx = args[0] - size = args[1] - rem = builder.srem(idx, size) - zero = llvmlite.ir.Constant(idx.type, 0) - is_negative = builder.icmp_signed('<', rem, zero) - wrapped_rem = builder.add(rem, size) - is_oversize = builder.icmp_signed('>=', wrapped_rem, size) - mod = builder.select(is_negative, wrapped_rem, - builder.select(is_oversize, rem, wrapped_rem)) - return mod - """ - idx = args[0] - size = args[1] + ll_unified_ty = context.get_data_type(unified_ty) + idx = builder.sext(args[0], ll_unified_ty) + size = builder.sext(args[1], ll_unified_ty) neg_size = builder.neg(size) - zero = llvmlite.ir.Constant(idx.type, 0) + zero = llvmlite.ir.Constant(ll_unified_ty, 0) idx_negative = builder.icmp_signed('<', idx, zero) pos_oversize = builder.icmp_signed('>=', idx, size) neg_oversize = builder.icmp_signed('<=', idx, neg_size) @@ -97,7 +86,7 @@ def codegen(context, builder, sig, args): mod = builder.select(idx_negative, neg_res, pos_res) return mod - return signature(idx, idx, size), codegen + return signature(unified_ty, idx, size), codegen def wrap_index_literal(idx, size): if idx < 0: diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 91c6a4c84e5..a98d15eacfd 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -993,6 +993,21 @@ def test_impl2(A, a): np.testing.assert_array_equal( njit(test_impl2, parallel=True)(A, a), test_impl2(A, a)) + @skip_unsupported + def test_slice_dtype_issue_5056(self): + # see issue 5056 + + @njit(parallel=True) + def test_impl(data): + N = data.shape[0] + sums = np.zeros(N) + for i in prange(N): + sums[i] = np.sum(data[np.int32(0):np.int32(1)]) + return sums + + data = np.arange(10.) + np.testing.assert_array_equal(test_impl(data), test_impl.py_func(data)) + if __name__ == '__main__': unittest.main() From b4ee055760206cc795a2e6b1f748bbda5c2d11ff Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Tue, 7 Jan 2020 08:55:46 -0800 Subject: [PATCH 103/595] Document the use of Memcheck and add suppressions --- contrib/valgrind-numba.supp | 21 +++++ docs/source/developer/debugging.rst | 130 ++++++++++++++++++++++++++++ docs/source/developer/index.rst | 1 + 3 files changed, 152 insertions(+) create mode 100644 contrib/valgrind-numba.supp create mode 100644 docs/source/developer/debugging.rst diff --git a/contrib/valgrind-numba.supp b/contrib/valgrind-numba.supp new file mode 100644 index 00000000000..26271eb4ef0 --- /dev/null +++ b/contrib/valgrind-numba.supp @@ -0,0 +1,21 @@ +{ + + Memcheck:Cond + fun:_ZN4llvm3sys14getHostCPUNameEv + fun:LLVMPY_GetHostCPUName +} + +{ + + Memcheck:Value8 + fun:_ZN4llvm3sys14getHostCPUNameEv + fun:LLVMPY_GetHostCPUName +} + +{ + + Memcheck:Cond + fun:__intel_sse2_strrchr + fun:_ZN67_INTERNAL_45_______src_thirdparty_tbb_omp_dynamic_link_cpp_c306cade5__kmp12init_dl_dataEv + fun:__sti__$E +} diff --git a/docs/source/developer/debugging.rst b/docs/source/developer/debugging.rst new file mode 100644 index 00000000000..da9dd057434 --- /dev/null +++ b/docs/source/developer/debugging.rst @@ -0,0 +1,130 @@ +.. _developer-debugging: + +================== +Notes on Debugging +================== + +This section describes techniques that can be useful in debugging the +compilation and execution of generated code. + +Memcheck +-------- + +Memcheck_ is a memory error detector implemented using Valgrind_. It is useful +for detecting memory errors in compiled code, particularly out-of-bounds +accesses and use-after-free errors. Buggy or miscompiled native code can +generate these kinds of errors. The `Memcheck documentation +`_ explains its usage; here, we +discuss only the specifics of using it with Numba. + +.. _Memcheck: https://valgrind.org/docs/manual/mc-manual.html +.. _Valgrind: https://valgrind.org/ + +The Python interpreter, and some of the libraries used by Numba can generate +false positives with Memcheck - see `this section of the manual +`_ for more +information on why false positives occur. The false positives can make it +difficult to determine when an actual error has occurred, so it is helpful to +suppress known false positives. This can be done by supplying a suppressions +file, which instructs Memcheck to ignore errors that match the suppressions +defined in it. + +The CPython source distribution includes a suppressions file, in the file +``Misc/valgrind-python.supp``. Using this file prevents a lot of spurious errors +generated by Python's memory allocation implementation. Additionally, the Numba +repository includes a suppressions file in ``contrib/valgrind-numba.supp``. + +To run the Python interpreter under Memcheck with both suppressions +files, it is invoked with the following command:: + + valgrind --tool=memcheck \ + --suppressions=${CPYTHON_SRC_DIR}/Misc/valgrind-python.supp \ + --suppressions=${NUMBA_SRC_DIR}/contrib/valgrind-numba.supp \ + python ${PYTHON_ARGS} + +where ``${CPYTHON_SRC_DIR}`` is set to the location of the CPython source +distribution, ``${NUMBA_SRC_DIR}`` is the location of the Numba source dir, and +``${PYTHON_ARGS}`` are the arguments to the Python interpreter. + +If there are errors, then messages describing them will be printed to standard +error. An example of an error is:: + + ==77113== at 0x24169A: PyLong_FromLong (longobject.c:251) + ==77113== by 0x241881: striter_next (bytesobject.c:3084) + ==77113== by 0x2D3C95: _PyEval_EvalFrameDefault (ceval.c:2809) + ==77113== by 0x21B499: _PyEval_EvalCodeWithName (ceval.c:3930) + ==77113== by 0x26B436: _PyFunction_FastCallKeywords (call.c:433) + ==77113== by 0x2D3605: call_function (ceval.c:4616) + ==77113== by 0x2D3605: _PyEval_EvalFrameDefault (ceval.c:3124) + ==77113== by 0x21B977: _PyEval_EvalCodeWithName (ceval.c:3930) + ==77113== by 0x21C2A4: _PyFunction_FastCallDict (call.c:376) + ==77113== by 0x2D5129: do_call_core (ceval.c:4645) + ==77113== by 0x2D5129: _PyEval_EvalFrameDefault (ceval.c:3191) + ==77113== by 0x21B499: _PyEval_EvalCodeWithName (ceval.c:3930) + ==77113== by 0x26B436: _PyFunction_FastCallKeywords (call.c:433) + ==77113== by 0x2D46DA: call_function (ceval.c:4616) + ==77113== by 0x2D46DA: _PyEval_EvalFrameDefault (ceval.c:3139) + ==77113== + ==77113== Use of uninitialised value of size 8 + +The traceback provided only outlines the C call stack, which can make it +difficult to determine what the Python interpreter was doing at the time of the +error. One can learn more about the state of the stack by looking at the +backtrace in GDB. Launch ``valgrind`` with an additional argument, +``--vgdb-error=0`` and attach to the process using GDB as instructed by the +output. Once an error is encountered, GDB will stop at the error and the stack +can be inspected. + +GDB does provide support for backtracing through the Python stack, but this +requires symbols which may not be easily available in your Python distribution. +In this case, it is still possible to determine some information about what was +happening in Python, but this depends on examining the backtrace closely. For +example, in a backtrace corresponding to the above error, we see items in the +backtrace such as: + +.. code-block:: + + #18 0x00000000002722da in slot_tp_call ( + self=<_wrap_impl(_callable=<_wrap_missing_loc(func=) at remote 0x1d200bd0>, _imp=, + _context=, , , , , , , , , , , , , , , , , , , , , ], attributes=[, , , , , + , identified_types={}) at remote + 0xbb5add0>, name='cuconstRecAlign$7', + data_layout='e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64', + scope=, triple='nvptx64-nvidia-cuda', + globals={'_ZN08NumbaEnv5numba4cuda5tests6cudapy13test_constmem19cuconstRecAlign$247E5ArrayIdLi1E1C7mutable7ali...(truncated), + kwds=0x0) + +We can see some of the arguments, in particular the names of the compiled functions, e.g:: + + _ZN5numba4cuda5tests6cudapy13test_constmem19cuconstRecAlign$247E5ArrayIdLi1E1C7mutable7alignedE5ArrayIdLi1E1C7mutable7alignedE5ArrayIdLi1E1C7mutable7alignedE5ArrayIdLi1E1C7mutable7alignedE5ArrayIdLi1E1C7mutable7alignedE + +We can run this through ``c++filt`` to see a more human-readable representation:: + + numba::cuda::tests::cudapy::test_constmem::cuconstRecAlign$247( + Array, + Array, + Array, + Array, + Array) + +which is the fully qualified name of a jitted function and the types with which +it was called. + diff --git a/docs/source/developer/index.rst b/docs/source/developer/index.rst index 1a01e1e0067..89c48be7815 100644 --- a/docs/source/developer/index.rst +++ b/docs/source/developer/index.rst @@ -23,4 +23,5 @@ Developer Manual hashing.rst caching.rst literal.rst + debugging.rst roadmap.rst From c9c07692c567f106284a9c5843a8448592582028 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Fri, 10 Jan 2020 11:59:41 +0000 Subject: [PATCH 104/595] Fix various issues in CUDA documentation - cudapysupported.rst: Remove non-existent `math.arctan`, and Python 2-only `div` and `idiv` operators. - device-management.rst: Fix broken references to `numba.cuda.gpus` and the ``DeviceList`` class. - intrinsics.rst: Remove non-resolving reference to `numba.cuda.atomic`. and adjust grammar accordingly. - decorators.py: Remove a trailing "If" in docstring and fix references to the `AutoJitCUDAKernel` class. Remove the type of `func_or_sig`, because it doesn't refer to a particular type. This resolves most, but not all, issues in the CUDA documentation that cause Sphinx to complain in nit-picky mode. The remainder come from docstings in the `numba.cuda.random` module, which will require some creativity to resolve as the types of parameters cause an issue - e.g. they are things such as `uint64`, which is a Numba type but not a Python class. Ideally these would link back to the table of types in the reference manual, but some custom solution may be needed to do this in a non-ugly way. --- docs/source/cuda/cudapysupported.rst | 3 --- docs/source/cuda/device-management.rst | 4 ++-- docs/source/cuda/intrinsics.rst | 6 ++---- numba/cuda/decorators.py | 10 +++++----- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/docs/source/cuda/cudapysupported.rst b/docs/source/cuda/cudapysupported.rst index 23901cd870d..ddf9ad17bec 100644 --- a/docs/source/cuda/cudapysupported.rst +++ b/docs/source/cuda/cudapysupported.rst @@ -111,7 +111,6 @@ The following functions from the :mod:`math` module are supported: * :func:`math.acos` * :func:`math.asin` * :func:`math.atan` -* :func:`math.arctan` * :func:`math.acosh` * :func:`math.asinh` * :func:`math.atanh` @@ -150,14 +149,12 @@ The following functions from the :mod:`operator` module are supported: * :func:`operator.add` * :func:`operator.and_` -* :func:`operator.div` (Python 2 only) * :func:`operator.eq` * :func:`operator.floordiv` * :func:`operator.ge` * :func:`operator.gt` * :func:`operator.iadd` * :func:`operator.iand` -* :func:`operator.idiv` (Python 2 only) * :func:`operator.ifloordiv` * :func:`operator.ilshift` * :func:`operator.imod` diff --git a/docs/source/cuda/device-management.rst b/docs/source/cuda/device-management.rst index 605db5a2bd8..5eba71e7f57 100644 --- a/docs/source/cuda/device-management.rst +++ b/docs/source/cuda/device-management.rst @@ -67,8 +67,8 @@ obtain a context manager that ensures execution on the selected GPU. :noindex: .. attribute:: numba.cuda.cudadrv.devices.gpus -:py:data:`.gpus` is an instance of the :class:`_DeviceList` class, from which -the current GPU context can also be retrieved: +:py:data:`numba.cuda.gpus` is an instance of the ``_DeviceList`` class, from +which the current GPU context can also be retrieved: .. autoclass:: numba.cuda.cudadrv.devices._DeviceList :members: current diff --git a/docs/source/cuda/intrinsics.rst b/docs/source/cuda/intrinsics.rst index c1033eef38a..521c1d918f7 100644 --- a/docs/source/cuda/intrinsics.rst +++ b/docs/source/cuda/intrinsics.rst @@ -2,10 +2,8 @@ Supported Atomic Operations =========================== -Numba provides access to some of the atomic operations supported in CUDA, in the -:class:`numba.cuda.atomic` class. - -Those that are presently implemented are as follows: +Numba provides access to some of the atomic operations supported in CUDA. Those +that are presently implemented are as follows: .. automodule:: numba.cuda :members: atomic diff --git a/numba/cuda/decorators.py b/numba/cuda/decorators.py index fc64df83a84..9aaf2f519e1 100644 --- a/numba/cuda/decorators.py +++ b/numba/cuda/decorators.py @@ -20,16 +20,16 @@ def jit(func_or_sig=None, argtypes=None, device=False, inline=False, bind=True, """ JIT compile a python function conforming to the CUDA Python specification. If a signature is supplied, then a function is returned that takes a - function to compile. If + function to compile. :param func_or_sig: A function to JIT compile, or a signature of a function - to compile. If a function is supplied, then an :class:`AutoJitCUDAKernel` - is returned. If a signature is supplied, then a function which takes a - function to compile and returns an :class:`AutoJitCUDAKernel` is + to compile. If a function is supplied, then an + :class:`numba.cuda.compiler.AutoJitCUDAKernel` is returned. If a + signature is supplied, then a function which takes a function to compile + and returns an :class:`numba.cuda.compiler.AutoJitCUDAKernel` is returned. .. note:: A kernel cannot have any return value. - :type func_or_sig: function or numba.typing.Signature :param device: Indicates whether this is a device function. :type device: bool :param bind: Force binding to CUDA context immediately From e3e9bad9c2c7402bc88b8e8f375644c83ba01d5a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 9 Jan 2020 15:26:11 -0700 Subject: [PATCH 105/595] Add thread mask tests to test_parallel_backend --- numba/tests/test_parallel_backend.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index b23807c4777..4c64a8e2d9d 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -16,7 +16,7 @@ from numba import config, utils from numba import unittest_support as unittest -from numba import jit, vectorize, guvectorize +from numba import jit, vectorize, guvectorize, set_num_threads from .support import temp_directory, override_config, TestCase, tag @@ -110,6 +110,17 @@ def __call__(self): got = cfunc(a, b) np.testing.assert_allclose(expected, got) +class mask_runner(object): + def __init__(self, runner, mask, **options): + self.runner = runner + self.mask = mask + + def __call__(self): + if self.mask: + # Tests are all run in isolated subprocesses, so we + # don't have to worry about this affecting other tests + set_num_threads(self.mask) + self.runner() class linalg_runner(runnable): @@ -243,6 +254,13 @@ class TestParallelBackendBase(TestCase): ] all_impls.extend(parfor_impls) + masks = [i for i in [1, 2, 4, 8, 16] if i <= config.NUMBA_NUM_THREADS] + + mask_impls = [] + for impl in all_impls: + for mask in masks: + mask_impls.append(mask_runner(impl, mask)) + parallelism = ['threading', 'random'] if utils.PYVERSION > (3, 0): parallelism.append('multiprocessing_spawn') @@ -263,6 +281,7 @@ class TestParallelBackendBase(TestCase): guvectorize_runner(nopython=True, target='parallel'), ], 'concurrent_mix_use': all_impls, + 'concurrent_mix_use_masks': mask_impls, } safe_backends = {'omp', 'tbb'} From 81ea4fb3ad1b041e0bdfe434162aeb97f73be619 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 9 Jan 2020 16:20:13 -0700 Subject: [PATCH 106/595] Somewhat improved the error messages if get_num_threads() gets an invalid value --- numba/npyufunc/parallel.py | 13 +++++++------ numba/npyufunc/parfor.py | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index a85169464ad..5f368cf9ec4 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -565,11 +565,11 @@ def get_num_threads(): """ _launch_threads() num_threads = _get_num_threads() - if num_threads == 0: - print("Broken: ", _get_thread_id()) + if num_threads <= 0: raise RuntimeError("Invalid number of threads. " - "This likely indicates a bug in numba.", - _get_thread_id()) + "This likely indicates a bug in numba. " + "(thread_id=%s, num_threads=%s)" % + (_get_thread_id(), num_threads)) return num_threads @@ -579,8 +579,9 @@ def ol_get_num_threads(): def impl(): num_threads = _get_num_threads() - if num_threads == 0: - print("Broken: ", _get_thread_id()) + if num_threads <= 0: + print("Broken thread_id: ", _get_thread_id()) + print("num_threads: ", num_threads) raise RuntimeError("Invalid number of threads. " "This likely indicates a bug in numba.") return num_threads diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 7ea65fdb32f..096c4eb595e 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1345,8 +1345,9 @@ def load_range(v): with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, num_threads.type(0))): + cgutils.printf(builder, "num_threads: %d\n", num_threads) context.call_conv.return_user_exc(builder, RuntimeError, - ("3 Invalid number of threads. " + ("Invalid number of threads. " "This likely indicates a bug in numba.",)) builder.call( From eb44a96085a4a16fbd7335889547c5c997e22740 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 9 Jan 2020 18:59:17 -0700 Subject: [PATCH 107/595] Use fewer masks in the parallel_backend tests --- numba/tests/test_parallel_backend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 4c64a8e2d9d..f0e59ddf7e4 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -254,7 +254,10 @@ class TestParallelBackendBase(TestCase): ] all_impls.extend(parfor_impls) - masks = [i for i in [1, 2, 4, 8, 16] if i <= config.NUMBA_NUM_THREADS] + if config.NUMBA_NUM_THREADS < 2: + # Not enough cores + masks = [] + masks = [1, 2] mask_impls = [] for impl in all_impls: From 547fd1a3b3f7c599010e14b567cf38d66471a0ab Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 10 Jan 2020 12:51:06 +0000 Subject: [PATCH 108/595] fix flake8 --- numba/tests/test_parallel_backend.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index f0e59ddf7e4..4dcf1ef5a8a 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -110,6 +110,7 @@ def __call__(self): got = cfunc(a, b) np.testing.assert_allclose(expected, got) + class mask_runner(object): def __init__(self, runner, mask, **options): self.runner = runner @@ -122,6 +123,7 @@ def __call__(self): set_num_threads(self.mask) self.runner() + class linalg_runner(runnable): def __call__(self): From d787cfb09613ddf0b11ef636d03ae0dcc3db86d1 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 10 Jan 2020 13:12:43 +0000 Subject: [PATCH 109/595] Fix issue in masked testing when cores=1 --- numba/tests/test_parallel_backend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 4dcf1ef5a8a..d6bb016adb8 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -259,7 +259,8 @@ class TestParallelBackendBase(TestCase): if config.NUMBA_NUM_THREADS < 2: # Not enough cores masks = [] - masks = [1, 2] + else: + masks = [1, 2] mask_impls = [] for impl in all_impls: From cbd1c45548140bb68e98297f9077cf4ff300a949 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 10 Jan 2020 13:46:37 +0000 Subject: [PATCH 110/595] refactor snt checker --- numba/npyufunc/parallel.py | 25 ++++++++++++------------- numba/npyufunc/parfor.py | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 5f368cf9ec4..9be186af8fa 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -484,23 +484,22 @@ def _load_num_threads_funcs(lib): # Some helpers to make set_num_threads jittable - -def snt_check(n): +def gen_snt_check(): from numba.config import NUMBA_NUM_THREADS msg = "The number of threads must be between 1 and %s" % NUMBA_NUM_THREADS - if n > NUMBA_NUM_THREADS or n < 1: - raise ValueError(msg) + + def snt_check(n): + if n > NUMBA_NUM_THREADS or n < 1: + raise ValueError(msg) + return snt_check + + +snt_check = gen_snt_check() @overload(snt_check) def ol_snt_check(n): - from numba.config import NUMBA_NUM_THREADS - msg = "The number of threads must be between 1 and %s" % NUMBA_NUM_THREADS - - def impl(n): - if n > NUMBA_NUM_THREADS or n < 1: - raise ValueError(msg) - return impl + return snt_check def set_num_threads(n): @@ -567,7 +566,7 @@ def get_num_threads(): num_threads = _get_num_threads() if num_threads <= 0: raise RuntimeError("Invalid number of threads. " - "This likely indicates a bug in numba. " + "This likely indicates a bug in Numba. " "(thread_id=%s, num_threads=%s)" % (_get_thread_id(), num_threads)) return num_threads @@ -583,7 +582,7 @@ def impl(): print("Broken thread_id: ", _get_thread_id()) print("num_threads: ", num_threads) raise RuntimeError("Invalid number of threads. " - "This likely indicates a bug in numba.") + "This likely indicates a bug in Numba.") return num_threads return impl diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 096c4eb595e..68925d306c8 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1348,7 +1348,7 @@ def load_range(v): cgutils.printf(builder, "num_threads: %d\n", num_threads) context.call_conv.return_user_exc(builder, RuntimeError, ("Invalid number of threads. " - "This likely indicates a bug in numba.",)) + "This likely indicates a bug in Numba.",)) builder.call( do_scheduling, [ From b9e11a3e2bc5143f2682f5c17f50a01e7a41ab49 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 10 Jan 2020 16:17:46 +0000 Subject: [PATCH 111/595] Assert int type in set_num_threads --- numba/npyufunc/parallel.py | 7 ++++++- numba/tests/test_num_threads.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 9be186af8fa..5534dcbf7ac 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -26,7 +26,7 @@ from numba.npyufunc import ufuncbuilder from numba.numpy_support import as_dtype -from numba import types, config, utils +from numba import types, config, utils, errors from numba.npyufunc.wrappers import _wrapper_info from numba.extending import overload @@ -526,6 +526,8 @@ def set_num_threads(n): """ _launch_threads() + if not isinstance(n, int): + raise TypeError("The number of threads specified must be an integer") snt_check(n) _set_num_threads(n) @@ -533,6 +535,9 @@ def set_num_threads(n): @overload(set_num_threads) def ol_set_num_threads(n): _launch_threads() + if not isinstance(n, types.Integer): + msg = "The number of threads specified must be an integer" + raise errors.TypingError(msg) def impl(n): snt_check(n) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index a734c0a1a46..56f2e970b19 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -11,6 +11,7 @@ threading_layer, guvectorize) from numba.npyufunc.parallel import _get_thread_id from numba import unittest_support as unittest +from numba.errors import TypingError from .support import TestCase, skip_parfors_unsupported, tag from .test_parallel_backend import TestInSubprocess @@ -33,6 +34,19 @@ def check_mask(self, expected, result): else: assert 0, 'unreachable' + @skip_parfors_unsupported + def test_set_num_threads_type(self): + + @njit + def foo(): + set_num_threads('wrong_type') + + expected = "The number of threads specified must be an integer" + for fn, errty in ((foo, TypingError), (foo.py_func, TypeError)): + with self.assertRaises(errty) as raises: + fn() + self.assertIn(expected, str(raises.exception)) + @skip_parfors_unsupported @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") def _test_set_num_threads_basic(self): From 0f3fa8fcb1955ea94e0420557356d48422ec7309 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 10 Jan 2020 10:46:49 -0600 Subject: [PATCH 112/595] Update docs for updated version requirements for python, llvmlite, numpy and scipy --- README.rst | 28 +++++++++++------------- docs/source/cuda/cudapysupported.rst | 5 +---- docs/source/cuda/kernels.rst | 2 -- docs/source/developer/hashing.rst | 3 --- docs/source/reference/fpsemantics.rst | 4 ---- docs/source/reference/numpysupported.rst | 7 +++--- docs/source/reference/pysupported.rst | 13 +++-------- docs/source/user/5minguide.rst | 10 ++++----- docs/source/user/installing.rst | 10 ++------- docs/source/user/threading-layer.rst | 5 ++--- 10 files changed, 29 insertions(+), 58 deletions(-) diff --git a/README.rst b/README.rst index ae45a3b74af..ac347abeaa5 100644 --- a/README.rst +++ b/README.rst @@ -18,16 +18,9 @@ NumPy functions. Additionally, Numba has support for automatic parallelization of loops, generation of GPU-accelerated code, and creation of ufuncs and C callbacks. -For more information about Numba, see the Numba homepage: +For more information about Numba, see the Numba homepage: http://numba.pydata.org -Dependencies -============ - -* llvmlite (version 0.31.0 or higher) -* NumPy (version 1.9 or higher) -* funcsigs (for Python 2) - Supported Platforms =================== @@ -37,13 +30,18 @@ Supported Platforms ARMv8 (64-bit) - Windows: x86, x86_64 - macOS: x86_64 - -* Python versions: 2.7, 3.5-3.7 -* NumPy: >= 1.11 -* NVIDIA GPUs (Kepler architecture or later) via CUDA driver on Linux, Windows, - macOS (< 10.14) -* AMD GPUs via ROCm driver on Linux -* llvmlite: >= 0.31.0 + +* (Optional) Accelerators and GPUs: + * NVIDIA GPUs (Kepler architecture or later) via CUDA driver on Linux, Windows, + macOS (< 10.14) + * AMD GPUs via ROCm driver on Linux + +Dependencies +============ + +* Python versions: 3.6-3.8 +* llvmlite 0.31.* +* NumPy >=1.15 (can build with 1.11 for ABI compatibility) Installing diff --git a/docs/source/cuda/cudapysupported.rst b/docs/source/cuda/cudapysupported.rst index 23901cd870d..5b678977a33 100644 --- a/docs/source/cuda/cudapysupported.rst +++ b/docs/source/cuda/cudapysupported.rst @@ -65,8 +65,7 @@ The following built-in functions are supported: * :func:`len` * :func:`min`: only the multiple-argument form * :func:`max`: only the multiple-argument form -* :class:`range`: semantics are similar to those of Python 3 even in Python 2: - a range object is returned instead of an array of values. +* :class:`range` * :func:`round` * :func:`zip` @@ -150,14 +149,12 @@ The following functions from the :mod:`operator` module are supported: * :func:`operator.add` * :func:`operator.and_` -* :func:`operator.div` (Python 2 only) * :func:`operator.eq` * :func:`operator.floordiv` * :func:`operator.ge` * :func:`operator.gt` * :func:`operator.iadd` * :func:`operator.iand` -* :func:`operator.idiv` (Python 2 only) * :func:`operator.ifloordiv` * :func:`operator.ilshift` * :func:`operator.imod` diff --git a/docs/source/cuda/kernels.rst b/docs/source/cuda/kernels.rst index 0f0780c6cd4..5d59e6afa97 100644 --- a/docs/source/cuda/kernels.rst +++ b/docs/source/cuda/kernels.rst @@ -210,8 +210,6 @@ The same example for a 2D array and grid of threads would be:: Note the grid computation when instantiating the kernel must still be done manually, for example:: - from __future__ import division # for Python 2 - threadsperblock = (16, 16) blockspergrid_x = math.ceil(an_array.shape[0] / threadsperblock[0]) blockspergrid_y = math.ceil(an_array.shape[1] / threadsperblock[1]) diff --git a/docs/source/developer/hashing.rst b/docs/source/developer/hashing.rst index 69eeab63141..eafe4af0305 100644 --- a/docs/source/developer/hashing.rst +++ b/docs/source/developer/hashing.rst @@ -25,9 +25,6 @@ Python 3. The only exception to this is that for hashing Unicode and bytes (for content longer than ``sys.hash_info.cutoff``) the only supported algorithm is ``siphash24`` (default in CPython 3). As a result Numba will match Python 3 hash values for all supported types under the default conditions described. -Python 2 hashing support is set up to follow Python 3 and similar defaults are -hard coded for this purpose, including, perhaps most noticeably, -``sys.hash_info.cutoff`` is set to zero. Unicode hash cache differences ------------------------------ diff --git a/docs/source/reference/fpsemantics.rst b/docs/source/reference/fpsemantics.rst index c9b6071216f..7973d4e500b 100644 --- a/docs/source/reference/fpsemantics.rst +++ b/docs/source/reference/fpsemantics.rst @@ -28,10 +28,6 @@ These are provided with reference to the IEEE 754 and C99 standards and are often implemented in Numba in a manner similar to equivalent CPython functions. -In particular, math library issues are known to affect Python 2.7 builds -on Windows, since Python 2.7 requires the use of an obsolete version of -the Microsoft Visual Studio compiler. - Linear algebra '''''''''''''' diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index f31732552b4..bb173d013f2 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -279,7 +279,7 @@ floating-point and complex numbers: * :func:`numpy.linalg.svd` (only the 2 first arguments). .. note:: - The implementation of these functions needs Scipy 0.16+ to be installed. + The implementation of these functions needs Scipy to be installed. Reductions ---------- @@ -330,11 +330,10 @@ The following top-level functions are supported: * :func:`numpy.concatenate` * :func:`numpy.convolve` (only the 2 first arguments) * :func:`numpy.copy` (only the first argument) -* :func:`numpy.corrcoef` (only the 3 first arguments, requires NumPy >= 1.10 and - SciPy >= 0.16; extreme value handling per NumPy 1.11+) +* :func:`numpy.corrcoef` (only the 3 first arguments) * :func:`numpy.correlate` (only the 2 first arguments) * :func:`numpy.count_nonzero` (axis only supports scalar values) -* :func:`numpy.cov` (only the 5 first arguments, requires NumPy >= 1.10 and SciPy >= 0.16) +* :func:`numpy.cov` (only the 5 first arguments) * :func:`numpy.cross` (only the 2 first arguments; at least one of the input arrays should have ``shape[-1] == 3``) diff --git a/docs/source/reference/pysupported.rst b/docs/source/reference/pysupported.rst index d1b835c2075..53da3b7e06f 100644 --- a/docs/source/reference/pysupported.rst +++ b/docs/source/reference/pysupported.rst @@ -757,10 +757,9 @@ The following built-in functions are supported: * :func:`max` * :func:`next`: only the one-argument form * :func:`print`: only numbers and strings; no ``file`` or ``sep`` argument -* :class:`range`: semantics are similar to those of Python 3 even in Python 2: - a range object is returned instead of an array of values. The only permitted - use of range is as a callable function (cannot pass range as an argument to a - jitted function or return a range from a jitted function). +* :class:`range`: The only permitted use of range is as a callable function + (cannot pass range as an argument to a jitted function or return a range from + a jitted function). * :func:`round` * :func:`sorted`: the ``key`` argument is not supported * :func:`type`: only the one-argument form, and only on some types @@ -779,10 +778,6 @@ Under Python 3, hash values computed by Numba will exactly match those computed in CPython under the condition that the :attr:`sys.hash_info.algorithm` is ``siphash24`` (default). -Under Python 2, hash values computed by Numba will follow the behavior -described for Python 3 with the :attr:`sys.hash_info.algorithm` emulated as -``siphash24``. No attempt is made to replicate Python 2 hashing behavior. - The ``PYTHONHASHSEED`` environment variable influences the hashing behavior in precisely the manner described in the CPython documentation. @@ -911,14 +906,12 @@ The following functions from the :mod:`operator` module are supported: * :func:`operator.add` * :func:`operator.and_` -* :func:`operator.div` (Python 2 only) * :func:`operator.eq` * :func:`operator.floordiv` * :func:`operator.ge` * :func:`operator.gt` * :func:`operator.iadd` * :func:`operator.iand` -* :func:`operator.idiv` (Python 2 only) * :func:`operator.ifloordiv` * :func:`operator.ilshift` * :func:`operator.imatmul` (Python 3.5 and above) diff --git a/docs/source/user/5minguide.rst b/docs/source/user/5minguide.rst index a782e14bf1c..c4854769ed5 100644 --- a/docs/source/user/5minguide.rst +++ b/docs/source/user/5minguide.rst @@ -8,7 +8,7 @@ NumPy arrays and functions, and loops. The most common way to use Numba is through its collection of decorators that can be applied to your functions to instruct Numba to compile them. When a call is made to a Numba decorated function it is compiled to machine code "just-in-time" for execution and all or -part of your code can subsequently run at native machine code speed! +part of your code can subsequently run at native machine code speed! Out of the box Numba works with the following: @@ -16,11 +16,11 @@ Out of the box Numba works with the following: * Architecture: x86, x86_64, ppc64le. Experimental on armv7l, armv8l (aarch64). * GPUs: Nvidia CUDA. Experimental on AMD ROC. * CPython -* NumPy 1.10 - latest +* NumPy 1.15 - latest How do I get it? ---------------- -Numba is available as a `conda `_ package for the +Numba is available as a `conda `_ package for the `Anaconda Python distribution `_:: $ conda install numba @@ -157,7 +157,7 @@ using the `timeit `_ module functions, these measure multiple iterations of execution and, as a result, can be made to accommodate for the compilation time in the first execution. -As a side note, if compilation time is an issue, Numba JIT supports +As a side note, if compilation time is an issue, Numba JIT supports :ref:`on-disk caching ` of compiled functions and also has an :ref:`Ahead-Of-Time ` compilation mode. @@ -199,7 +199,7 @@ also: Extra options available in some decorators: -* ``parallel = True`` - :ref:`enable ` the +* ``parallel = True`` - :ref:`enable ` the :ref:`automatic parallelization ` of the function. * ``fastmath = True`` - enable :ref:`fast-math ` behaviour for the function. diff --git a/docs/source/user/installing.rst b/docs/source/user/installing.rst index ee54bf93e9a..3748d46615d 100644 --- a/docs/source/user/installing.rst +++ b/docs/source/user/installing.rst @@ -5,8 +5,7 @@ Installation Compatibility ------------- -Numba is compatible with Python 2.7 and 3.5 or later, and Numpy versions 1.7 to -1.16. +Numba is compatible with 3.6 or later, and Numpy versions 1.15 or later. Our supported platforms are: @@ -19,8 +18,7 @@ Our supported platforms are: * ARMv7 (32-bit little-endian, such as Raspberry Pi 2 and 3) * ARMv8 (64-bit little-endian, such as the NVIDIA Jetson) -:ref:`numba-parallel` is only available on 64-bit platforms, -and is not supported in Python 2.7 on Windows. +:ref:`numba-parallel` is only available on 64-bit platforms. Installing using conda on x86/x86_64/POWER Platforms ---------------------------------------------------- @@ -186,8 +184,6 @@ vary with target operating system and hardware. The following lists them all * ``setuptools`` * ``numpy`` * ``llvmlite`` - * ``funcsigs`` (Python 2) - * ``singledispatch`` (Python 2) * Compiler toolchain mentioned above * Optional build time: @@ -204,8 +200,6 @@ vary with target operating system and hardware. The following lists them all * ``setuptools`` * ``numpy`` * ``llvmlite`` - * ``funcsigs`` (Python 2) - * ``singledispatch`` (Python 2) * Optional runtime are: diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index 576979e9592..4aa11aca31e 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -70,7 +70,7 @@ means!): * ``spawn`` ing processes from the ``multiprocessing`` module via ``spawn`` (default on Windows, only available in Python 3.4+ on Unix) * ``fork`` ing processes from the ``multiprocessing`` module via ``fork`` - (default on Unix and the only option available for Python 2 on Unix). + (default on Unix). * ``fork`` ing processes from the ``multiprocessing`` module through the use of a ``forkserver`` (only available in Python 3 on Unix). Essentially a new process is spawned and then forks are made from this new process on request. @@ -165,5 +165,4 @@ system level libraries, some additional things to note: error message to ``STDERR``. * On OSX, the ``intel-openmp`` package is required to enable the OpenMP based threading layer. -* For Windows users running Python 2.7, the ``tbb`` threading layer is not - available. + From 10cca0008a59bd89f9e93883d6d5cfb1045c9ddb Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 10 Jan 2020 10:52:48 -0600 Subject: [PATCH 113/595] Add optional depedency in readme --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index ac347abeaa5..6d5da15ea4f 100644 --- a/README.rst +++ b/README.rst @@ -43,6 +43,10 @@ Dependencies * llvmlite 0.31.* * NumPy >=1.15 (can build with 1.11 for ABI compatibility) +Optionally: + +* Scipy >=1.0.0 (for ``numpy.linalg`` support) + Installing ========== From fd55a90875e908ae14bce71a893f239ba9a02660 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 10 Jan 2020 10:46:55 -0700 Subject: [PATCH 114/595] Remove duplicated class --- numba/tests/test_parallel_backend.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 477e918ab19..9ec8fb1ec7e 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -122,19 +122,6 @@ def __call__(self): set_num_threads(self.mask) self.runner() -class mask_runner(object): - def __init__(self, runner, mask, **options): - self.runner = runner - self.mask = mask - - def __call__(self): - if self.mask: - # Tests are all run in isolated subprocesses, so we - # don't have to worry about this affecting other tests - set_num_threads(self.mask) - self.runner() - - class linalg_runner(runnable): def __call__(self): From 36295d959b985ebc3f8f811ec949063d1a04a72e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 10 Jan 2020 10:55:11 -0700 Subject: [PATCH 115/595] Allow numpy integers in set_num_threads() --- numba/npyufunc/parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 5534dcbf7ac..14c82d2e970 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -526,7 +526,7 @@ def set_num_threads(n): """ _launch_threads() - if not isinstance(n, int): + if not isinstance(n, (int, np.integer)): raise TypeError("The number of threads specified must be an integer") snt_check(n) _set_num_threads(n) From 9c5e0c43c5d3ea10cb77360b3fd498f8c238518c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 10 Jan 2020 14:19:45 -0700 Subject: [PATCH 116/595] Fix flake8 --- numba/tests/test_parallel_backend.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 9ec8fb1ec7e..d6bb016adb8 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -110,6 +110,7 @@ def __call__(self): got = cfunc(a, b) np.testing.assert_allclose(expected, got) + class mask_runner(object): def __init__(self, runner, mask, **options): self.runner = runner @@ -122,6 +123,7 @@ def __call__(self): set_num_threads(self.mask) self.runner() + class linalg_runner(runnable): def __call__(self): From 1ee0a49440ab8c34e169c3f18ef0afd1c0a9578f Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 10 Jan 2020 17:22:50 -0700 Subject: [PATCH 117/595] Add an example of thread masking to the documentation --- docs/source/user/threading-layer.rst | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index 9e8fcf2b9a2..0c887256377 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -194,6 +194,61 @@ The current number of threads used by numba can be accessed with :func:`numba.get_num_threads`. Both functions work inside of a jitted function. +Example of Limiting the Number of Threads +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In this example, suppose the machine we are running on has 8 cores (so +:obj:`numba.config.NUMBA_NUM_THREADS` would be ``8``). Suppose we want to run +some code with ``@njit(parallel=True)``, but we also want to run our code +concurrently in 4 different processes. With the default number of threads, +each Python process would run 8 threads, for a total in 4*8 = 32 threads, +which is oversubscription for our 8 cores. We should rather limit each process +to 2 threads, so that the total will be 4*2 = 8, which matches our number of +physical cores. + +There are two ways to do this. One is to set the :envvar:`NUMBA_NUM_THREADS` +environment variable to ``2``. + +.. code:: bash + + $ NUMBA_NUM_THREADS=2 python ourcode.py + +However, there are two downsides to this approach: + +1. :envvar:`NUMBA_NUM_THREADS` must be set before Numba is imported, and + ideally before Python is launched. As soon as Numba is imported the + environment variable is read and that number of threads is locked in as the + number of threads Numba launches. + +2. If we want to later increase the number of threads used by the process, we + cannot. :envvar:`NUMBA_NUM_THREADS` sets the *maximum* number of threads + that are launched for a process. Calling :func:`~.set_num_threads()` with a + value greater than :obj:`numba.config.NUMBA_NUM_THREADS` results in an + error. + +The advantage of this approach is that we can do it from outside of the +process without changing the code. + +Another approach is to use the :func:`numba.set_num_threads` function in our code + +.. code:: python + + from numba import njit, set_num_threads + + @njit(parallel=True) + def func(): + ... + + set_num_threads(2) + func() + +If we call ``set_num_threads(2)`` before executing our parallel code, it has +the same effect as calling the process with ``NUMBA_NUM_THREADS=2``, in that +the parallel code will only execute on 2 threads. However, we can later call +``set_num_threads(8)`` to increase the number of threads back to the default +size. And we do not have to worry about setting it before Numba gets imported. +It only needs to be called before the parallel function is run. + API Reference ~~~~~~~~~~~~~ From 225ce1348b8c7ff47c4dc9bd78203f0bcbd92b2e Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Mon, 13 Jan 2020 03:45:40 -0800 Subject: [PATCH 118/595] utils: remove finalize backported from weakref Uses are replaced with the standard library weakref.finalize now that all supported platforms (Python 3.6 onwards) provide it. --- numba/cuda/cudadrv/driver.py | 14 +-- numba/dispatcher.py | 2 +- numba/roc/hlc/libhlc.py | 5 +- numba/roc/hsadrv/driver.py | 8 +- numba/runtime/nrt.py | 2 +- numba/targets/codegen.py | 2 +- numba/utils.py | 160 +++-------------------------------- 7 files changed, 28 insertions(+), 165 deletions(-) diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index 5f0da733a80..4d949d1eb98 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -1252,7 +1252,7 @@ def __init__(self, context, pointer, size, finalizer=None, owner=None): self._owner = owner if finalizer is not None: - self._finalizer = utils.finalize(self, finalizer) + self._finalizer = weakref.finalize(self, finalizer) @property def owner(self): @@ -1359,7 +1359,7 @@ def __init__(self, context, owner, pointer, size, finalizer=None): self._bufptr_ = self.host_pointer.value if finalizer is not None: - utils.finalize(self, finalizer) + weakref.finalize(self, finalizer) def own(self): return self @@ -1388,7 +1388,7 @@ def deref(): pass self._mem.refct += 1 - utils.finalize(self, deref) + weakref.finalize(self, deref) def __getattr__(self, fname): """Proxy MemoryPointer methods @@ -1405,7 +1405,7 @@ def __init__(self, context, handle, finalizer): self.context = context self.handle = handle if finalizer is not None: - utils.finalize(self, finalizer) + weakref.finalize(self, finalizer) def __int__(self): return self.handle.value @@ -1435,7 +1435,7 @@ def __init__(self, context, handle, finalizer=None): self.context = context self.handle = handle if finalizer is not None: - utils.finalize(self, finalizer) + weakref.finalize(self, finalizer) def query(self): """ @@ -1497,7 +1497,7 @@ def __init__(self, context, handle, info_log, finalizer=None): self.handle = handle self.info_log = info_log if finalizer is not None: - self._finalizer = utils.finalize(self, finalizer) + self._finalizer = weakref.finalize(self, finalizer) def unload(self): self.context.unload_module(self) @@ -1658,7 +1658,7 @@ def __init__(self, max_registers=0): driver.cuLinkCreate(len(raw_keys), option_keys, option_vals, byref(self.handle)) - utils.finalize(self, driver.cuLinkDestroy, handle) + weakref.finalize(self, driver.cuLinkDestroy, handle) self.linker_info_buf = linkerinfo self.linker_errors_buf = linkererrors diff --git a/numba/dispatcher.py b/numba/dispatcher.py index 260d8790042..7cedecb727c 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -224,7 +224,7 @@ def __init__(self, arg_count, py_func, pysig, can_fallback, self.doc = py_func.__doc__ self._compiling_counter = _CompilingCounter() - utils.finalize(self, self._make_finalizer()) + weakref.finalize(self, self._make_finalizer()) def _reset_overloads(self): self._clear() diff --git a/numba/roc/hlc/libhlc.py b/numba/roc/hlc/libhlc.py index f0bdf7c4e2a..b78733bc80d 100644 --- a/numba/roc/hlc/libhlc.py +++ b/numba/roc/hlc/libhlc.py @@ -9,7 +9,8 @@ import tempfile import os import re -from numba import utils, config +import weakref +from numba import config from numba.roc.hsadrv import devices from .common import AMDGCNModule @@ -72,7 +73,7 @@ def __init__(self): hlc.ROC_ParseBitcode.restype = moduleref_ptr hlc.ROC_ModuleEmitBRIG.restype = c_size_t hlc.ROC_Initialize() - utils.finalize(hlc, hlc.ROC_Finalize) + weakref.finalize(hlc, hlc.ROC_Finalize) hlc.ROC_SetCommandLineOption.argtypes = [ c_int, diff --git a/numba/roc/hsadrv/driver.py b/numba/roc/hsadrv/driver.py index 12591025611..6c6b0c56035 100644 --- a/numba/roc/hsadrv/driver.py +++ b/numba/roc/hsadrv/driver.py @@ -892,7 +892,7 @@ class Signal(object): def __init__(self, signal_id): self._id = signal_id self._as_parameter_ = self._id - utils.finalize(self, hsa.hsa_signal_destroy, self._id) + weakref.finalize(self, hsa.hsa_signal_destroy, self._id) def load_relaxed(self): return hsa.hsa_signal_load_relaxed(self._id) @@ -985,7 +985,7 @@ def check_fptr_return(hsa_status): check_fptr_return(ret) self._as_parameter_ = self._id - utils.finalize(self, self._ftabl.hsa_ext_program_destroy, + weakref.finalize(self, self._ftabl.hsa_ext_program_destroy, self._id) def add_module(self, module): @@ -1013,7 +1013,7 @@ class CodeObject(object): def __init__(self, code_object): self._id = code_object self._as_parameter_ = self._id - utils.finalize(self, hsa.hsa_code_object_destroy, self._id) + weakref.finalize(self, hsa.hsa_code_object_destroy, self._id) class Executable(object): @@ -1025,7 +1025,7 @@ def __init__(self): ctypes.byref(ex)) self._id = ex self._as_parameter_ = self._id - utils.finalize(self, hsa.hsa_executable_destroy, self._id) + weakref.finalize(self, hsa.hsa_executable_destroy, self._id) def load(self, agent, code_object): hsa.hsa_executable_load_code_object(self._id, agent._id, diff --git a/numba/runtime/nrt.py b/numba/runtime/nrt.py index ab9c0f9ef38..482d7f0335c 100644 --- a/numba/runtime/nrt.py +++ b/numba/runtime/nrt.py @@ -1,11 +1,11 @@ from __future__ import print_function, absolute_import, division from collections import namedtuple +from weakref import finalize as _finalize from . import nrtdynmod from llvmlite import binding as ll -from numba.utils import finalize as _finalize from numba.compiler_lock import global_compiler_lock from numba.typing.typeof import typeof_impl from numba import types diff --git a/numba/targets/codegen.py b/numba/targets/codegen.py index 4cceef51630..5f9fdc3c087 100644 --- a/numba/targets/codegen.py +++ b/numba/targets/codegen.py @@ -270,7 +270,7 @@ def _finalize_final_module(self): # could fail. cleanup = self._codegen._add_module(self._final_module) if cleanup: - utils.finalize(self, cleanup) + weakref.finalize(self, cleanup) self._finalize_specific() self._finalized = True diff --git a/numba/utils.py b/numba/utils.py index c0fcb46c8d7..387602778e2 100644 --- a/numba/utils.py +++ b/numba/utils.py @@ -11,6 +11,7 @@ import math import sys import traceback +import weakref from types import ModuleType import numpy as np @@ -270,8 +271,6 @@ def _c3_merge(sequences): INPLACE_BINOPS_TO_OPERATORS['@='] = operator.imatmul - - _shutting_down = False def _at_shutdown(): @@ -291,6 +290,16 @@ def shutting_down(globals=globals): return v is True or v is None +# weakref.finalize registers an exit function that runs all finalizers for +# which atexit is True. Some of these finalizers may call shutting_down() to +# check whether the interpreter is shutting down. For this to behave correctly, +# we need to make sure that _at_shutdown is called before the finalizer exit +# function. Since atexit operates as a LIFO stack, we first contruct a dummy +# finalizer then register atexit to ensure this ordering. +weakref.finalize(lambda: None, lambda: None) +atexit.register(_at_shutdown) + + class ConfigOptions(object): OPTIONS = {} @@ -620,153 +629,6 @@ def logger_hasHandlers(logger): _dynamic_module.__builtins__ = moves.builtins -# Backported from Python 3.4: weakref.finalize() - -from weakref import ref - -class finalize: - """Class for finalization of weakrefable objects - - finalize(obj, func, *args, **kwargs) returns a callable finalizer - object which will be called when obj is garbage collected. The - first time the finalizer is called it evaluates func(*arg, **kwargs) - and returns the result. After this the finalizer is dead, and - calling it just returns None. - - When the program exits any remaining finalizers for which the - atexit attribute is true will be run in reverse order of creation. - By default atexit is true. - """ - - # Finalizer objects don't have any state of their own. They are - # just used as keys to lookup _Info objects in the registry. This - # ensures that they cannot be part of a ref-cycle. - - __slots__ = () - _registry = {} - _shutdown = False - _index_iter = itertools.count() - _dirty = False - _registered_with_atexit = False - - class _Info: - __slots__ = ("weakref", "func", "args", "kwargs", "atexit", "index") - - def __init__(self, obj, func, *args, **kwargs): - if not self._registered_with_atexit: - # We may register the exit function more than once because - # of a thread race, but that is harmless - import atexit - atexit.register(self._exitfunc) - finalize._registered_with_atexit = True - atexit.register(_at_shutdown) - info = self._Info() - info.weakref = ref(obj, self) - info.func = func - info.args = args - info.kwargs = kwargs or None - info.atexit = True - info.index = next(self._index_iter) - self._registry[self] = info - finalize._dirty = True - - def __call__(self, _=None): - """If alive then mark as dead and return func(*args, **kwargs); - otherwise return None""" - info = self._registry.pop(self, None) - if info and not self._shutdown: - return info.func(*info.args, **(info.kwargs or {})) - - def detach(self): - """If alive then mark as dead and return (obj, func, args, kwargs); - otherwise return None""" - info = self._registry.get(self) - obj = info and info.weakref() - if obj is not None and self._registry.pop(self, None): - return (obj, info.func, info.args, info.kwargs or {}) - - def peek(self): - """If alive then return (obj, func, args, kwargs); - otherwise return None""" - info = self._registry.get(self) - obj = info and info.weakref() - if obj is not None: - return (obj, info.func, info.args, info.kwargs or {}) - - @property - def alive(self): - """Whether finalizer is alive""" - return self in self._registry - - @property - def atexit(self): - """Whether finalizer should be called at exit""" - info = self._registry.get(self) - return bool(info) and info.atexit - - @atexit.setter - def atexit(self, value): - info = self._registry.get(self) - if info: - info.atexit = bool(value) - - def __repr__(self): - info = self._registry.get(self) - obj = info and info.weakref() - if obj is None: - return '<%s object at %#x; dead>' % (type(self).__name__, id(self)) - else: - return '<%s object at %#x; for %r at %#x>' % \ - (type(self).__name__, id(self), type(obj).__name__, id(obj)) - - @classmethod - def _select_for_exit(cls): - # Return live finalizers marked for exit, oldest first - L = [(f,i) for (f,i) in cls._registry.items() if i.atexit] - L.sort(key=lambda item:item[1].index) - return [f for (f,i) in L] - - @classmethod - def _exitfunc(cls): - # At shutdown invoke finalizers for which atexit is true. - # This is called once all other non-daemonic threads have been - # joined. - reenable_gc = False - try: - if cls._registry: - import gc - if gc.isenabled(): - reenable_gc = True - gc.disable() - pending = None - while True: - if pending is None or finalize._dirty: - pending = cls._select_for_exit() - finalize._dirty = False - if not pending: - break - f = pending.pop() - try: - # gc is disabled, so (assuming no daemonic - # threads) the following is the only line in - # this function which might trigger creation - # of a new finalizer - f() - except Exception: - sys.excepthook(*sys.exc_info()) - assert f not in cls._registry - finally: - # prevent any more finalizers from executing during shutdown - finalize._shutdown = True - if reenable_gc: - gc.enable() - - -# dummy invocation to force _at_shutdown() to be registered -finalize(lambda: None, lambda: None) -assert finalize._registered_with_atexit - - def chain_exception(new_exc, old_exc): """Set the __cause__ attribute on *new_exc* for explicit exception chaining. Returns the inplace modified *new_exc*. From b7bd78b2edfe9fc3a67a3319470bad3ee0c514b2 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Mon, 13 Jan 2020 04:18:14 -0800 Subject: [PATCH 119/595] utils: remove backported total_ordering from functools Uses are replaced with the standard library functools.total_ordering now that all supported platforms (Python 3.6 onwards) provide it. As test_utils is removed (it tested only the total_ordering backport) the test_module test in test_runtests needed modifying since it checks the test infrastructure by counting the number of tests in test_utils - instead it counts the tests in test_storeslice. --- numba/roc/hsadrv/driver.py | 2 +- numba/tests/test_runtests.py | 6 +- numba/tests/test_utils.py | 85 --------------------------- numba/typeconv/castgraph.py | 3 +- numba/types/scalars.py | 11 ++-- numba/utils.py | 110 ----------------------------------- 6 files changed, 11 insertions(+), 206 deletions(-) delete mode 100644 numba/tests/test_utils.py diff --git a/numba/roc/hsadrv/driver.py b/numba/roc/hsadrv/driver.py index 6c6b0c56035..788b3e9c918 100644 --- a/numba/roc/hsadrv/driver.py +++ b/numba/roc/hsadrv/driver.py @@ -15,7 +15,7 @@ from contextlib import contextmanager from collections import defaultdict, deque -from numba.utils import total_ordering +from functools import total_ordering from numba import mviewbuf from numba import utils from numba import config diff --git a/numba/tests/test_runtests.py b/numba/tests/test_runtests.py index ddc3856837d..58e4cd5debd 100755 --- a/numba/tests/test_runtests.py +++ b/numba/tests/test_runtests.py @@ -67,11 +67,11 @@ def test_cuda_submodules(self): self.check_listing_prefix('numba.cuda.tests.cudasim') def test_module(self): - self.check_testsuite_size(['numba.tests.test_utils'], 3) - self.check_testsuite_size(['numba.tests.test_nested_calls'], 5) + self.check_testsuite_size(['numba.tests.test_storeslice'], 2) + self.check_testsuite_size(['numba.tests.test_nested_calls'], 10) # Several modules self.check_testsuite_size(['numba.tests.test_nested_calls', - 'numba.tests.test_utils'], 13) + 'numba.tests.test_storeslice'], 12) def test_subpackage(self): self.check_testsuite_size(['numba.tests.npyufunc'], 50) diff --git a/numba/tests/test_utils.py b/numba/tests/test_utils.py deleted file mode 100644 index 0500401a868..00000000000 --- a/numba/tests/test_utils.py +++ /dev/null @@ -1,85 +0,0 @@ -""" -Tests for numba.utils. -""" - -from __future__ import print_function, absolute_import - -import threading -import time - -from numba import utils -from numba import unittest_support as unittest - - -class C(object): - def __init__(self, value): - self.value = value - - def __eq__(self, o): - return self.value == o.value - - def __ne__(self, o): - return self.value != o.value - - def __gt__(self, o): - return self.value > o.value - -class D(C): - pass - - -class TestTotalOrdering(unittest.TestCase): - - def test_is_inherited(self): - f = utils._is_inherited_from_object - for cls in (C, D): - self.assertFalse(f(cls, '__eq__')) - self.assertFalse(f(cls, '__gt__')) - self.assertFalse(f(cls, '__ne__')) - self.assertTrue(f(cls, '__ge__')) - self.assertTrue(f(cls, '__le__')) - self.assertTrue(f(cls, '__lt__')) - - def check_total_ordering(self, cls): - # Duplicate the class-under-test, to avoid mutating the original - cls = type(cls.__name__, cls.__bases__, dict(cls.__dict__)) - cls = utils.total_ordering(cls) - - a, b, c, d = cls(10), cls(5), cls(15), cls(10) - self.assertFalse(a < b) - self.assertTrue(a < c) - self.assertFalse(a < d) - self.assertTrue(b < c) - self.assertTrue(b < d) - self.assertFalse(c < d) - - self.assertFalse(a <= b) - self.assertTrue(a <= c) - self.assertTrue(a <= d) - self.assertTrue(b <= c) - self.assertTrue(b <= d) - self.assertFalse(c <= d) - - self.assertTrue(a > b) - self.assertFalse(a > c) - self.assertFalse(a > d) - self.assertFalse(b > c) - self.assertFalse(b > d) - self.assertTrue(c > d) - - self.assertTrue(a >= b) - self.assertFalse(a >= c) - self.assertTrue(a >= d) - self.assertFalse(b >= c) - self.assertFalse(b >= d) - self.assertTrue(c >= d) - - def test_total_ordering(self): - self.check_total_ordering(C) - - def test_total_ordering_derived(self): - self.check_total_ordering(D) - - -if __name__ == '__main__': - unittest.main() diff --git a/numba/typeconv/castgraph.py b/numba/typeconv/castgraph.py index 6d3b7637d6d..1a93535c9a2 100644 --- a/numba/typeconv/castgraph.py +++ b/numba/typeconv/castgraph.py @@ -1,10 +1,9 @@ from __future__ import print_function, absolute_import from collections import defaultdict +from functools import total_ordering import enum -from numba.utils import total_ordering - class Conversion(enum.IntEnum): """ diff --git a/numba/types/scalars.py b/numba/types/scalars.py index 8c92db84a13..46d0b1ce5e8 100644 --- a/numba/types/scalars.py +++ b/numba/types/scalars.py @@ -5,6 +5,7 @@ import numpy as np from .abstract import Dummy, Hashable, Literal, Number, Type +from functools import total_ordering from .. import npdatetime, utils from ..typeconv import Conversion @@ -27,7 +28,7 @@ def parse_integer_signed(name): return signed -@utils.total_ordering +@total_ordering class Integer(Number): def __init__(self, name, bitwidth=None, signed=None): super(Integer, self).__init__(name) @@ -95,7 +96,7 @@ def can_convert_to(self, typingctx, other): Literal.ctor_map[int] = IntegerLiteral -@utils.total_ordering +@total_ordering class Float(Number): def __init__(self, *args, **kws): super(Float, self).__init__(*args, **kws) @@ -113,7 +114,7 @@ def __lt__(self, other): return self.bitwidth < other.bitwidth -@utils.total_ordering +@total_ordering class Complex(Number): def __init__(self, name, underlying_float, **kwargs): super(Complex, self).__init__(name, **kwargs) @@ -159,11 +160,11 @@ def cast_python_value(self, value): return cls(value) -@utils.total_ordering +@total_ordering class NPTimedelta(_NPDatetimeBase): type_name = 'timedelta64' -@utils.total_ordering +@total_ordering class NPDatetime(_NPDatetimeBase): type_name = 'datetime64' diff --git a/numba/utils.py b/numba/utils.py index 387602778e2..5e5cfceccd9 100644 --- a/numba/utils.py +++ b/numba/utils.py @@ -498,116 +498,6 @@ def benchmark(func, maxsec=1): pass -# Backported from Python 3.4: functools.total_ordering() - -def _not_op(op, other): - # "not a < b" handles "a >= b" - # "not a <= b" handles "a > b" - # "not a >= b" handles "a < b" - # "not a > b" handles "a <= b" - op_result = op(other) - if op_result is NotImplemented: - return NotImplemented - return not op_result - - -def _op_or_eq(op, self, other): - # "a < b or a == b" handles "a <= b" - # "a > b or a == b" handles "a >= b" - op_result = op(other) - if op_result is NotImplemented: - return NotImplemented - return op_result or self == other - - -def _not_op_and_not_eq(op, self, other): - # "not (a < b or a == b)" handles "a > b" - # "not a < b and a != b" is equivalent - # "not (a > b or a == b)" handles "a < b" - # "not a > b and a != b" is equivalent - op_result = op(other) - if op_result is NotImplemented: - return NotImplemented - return not op_result and self != other - - -def _not_op_or_eq(op, self, other): - # "not a <= b or a == b" handles "a >= b" - # "not a >= b or a == b" handles "a <= b" - op_result = op(other) - if op_result is NotImplemented: - return NotImplemented - return not op_result or self == other - - -def _op_and_not_eq(op, self, other): - # "a <= b and not a == b" handles "a < b" - # "a >= b and not a == b" handles "a > b" - op_result = op(other) - if op_result is NotImplemented: - return NotImplemented - return op_result and self != other - - -def _is_inherited_from_object(cls, op): - """ - Whether operator *op* on *cls* is inherited from the root object type. - """ - if PYVERSION >= (3,): - object_op = getattr(object, op) - cls_op = getattr(cls, op) - return object_op is cls_op - else: - # In 2.x, the inherited operator gets a new descriptor, so identity - # doesn't work. OTOH, dir() doesn't list methods inherited from - # object (which it does in 3.x). - return op not in dir(cls) - - -def total_ordering(cls): - """Class decorator that fills in missing ordering methods""" - convert = { - '__lt__': [('__gt__', - lambda self, other: _not_op_and_not_eq(self.__lt__, self, - other)), - ('__le__', - lambda self, other: _op_or_eq(self.__lt__, self, other)), - ('__ge__', lambda self, other: _not_op(self.__lt__, other))], - '__le__': [('__ge__', - lambda self, other: _not_op_or_eq(self.__le__, self, - other)), - ('__lt__', - lambda self, other: _op_and_not_eq(self.__le__, self, - other)), - ('__gt__', lambda self, other: _not_op(self.__le__, other))], - '__gt__': [('__lt__', - lambda self, other: _not_op_and_not_eq(self.__gt__, self, - other)), - ('__ge__', - lambda self, other: _op_or_eq(self.__gt__, self, other)), - ('__le__', lambda self, other: _not_op(self.__gt__, other))], - '__ge__': [('__le__', - lambda self, other: _not_op_or_eq(self.__ge__, self, - other)), - ('__gt__', - lambda self, other: _op_and_not_eq(self.__ge__, self, - other)), - ('__lt__', lambda self, other: _not_op(self.__ge__, other))] - } - # Find user-defined comparisons (not those inherited from object). - roots = [op for op in convert if not _is_inherited_from_object(cls, op)] - if not roots: - raise ValueError( - 'must define at least one ordering operation: < > <= >=') - root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__ - for opname, opfunc in convert[root]: - if opname not in roots: - opfunc.__name__ = opname - opfunc.__doc__ = getattr(int, opname).__doc__ - setattr(cls, opname, opfunc) - return cls - - def logger_hasHandlers(logger): # Backport from python3.5 logging implementation of `.hasHandlers()` c = logger From 87bb526d962243fbb05f694e347004cde1389081 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Mon, 13 Jan 2020 04:19:36 -0800 Subject: [PATCH 120/595] test_boundscheck: fix test_no_cuda_boundscheck This test used CUDA functionality, so it needs the SerialMixin to prevent it running in a child process after the test runner already initialized CUDA in the parent process. It is moved into its own class to add the SerialMixin, to preserve the ability to run other tests from the same class to run in parallel. It also uses a CUDA kernel without a launch configuration, which will soon (pending PR #5061) be an error, so we add a launch configuration to it. --- numba/tests/test_boundscheck.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index 8ee117a8ffa..e2769d3e9e1 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -3,6 +3,7 @@ import numpy as np from numba.compiler import compile_isolated, DEFAULT_FLAGS +from numba.cuda.testing import SerialMixin from numba import typeof, config, cuda, njit from numba.types import float64 from numba import unittest_support as unittest @@ -104,6 +105,15 @@ def test_fancy_indexing_boundscheck(self): # Doesn't raise boundscheck(b) + def tearDown(self): + config.BOUNDSCHECK = self.old_boundscheck + + +class TestNoCudaBoundsCheck(SerialMixin, unittest.TestCase): + def setUp(self): + self.old_boundscheck = config.BOUNDSCHECK + config.BOUNDSCHECK = None + @unittest.skipIf(not cuda.is_available(), "NO CUDA") def test_no_cuda_boundscheck(self): with self.assertRaises(NotImplementedError): @@ -121,7 +131,7 @@ def func2(x, a): # Out of bounds but doesn't raise (it does raise in the simulator, # so skip there) if not config.ENABLE_CUDASIM: - func2(x, a) + func2[1, 1](x, a) def tearDown(self): config.BOUNDSCHECK = self.old_boundscheck From e049e41047a9dbd88cfc4dbb4d7f084ea036946c Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Mon, 13 Jan 2020 09:01:36 -0800 Subject: [PATCH 121/595] Add some comments to explain why this approach works. --- numba/parfor.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/numba/parfor.py b/numba/parfor.py index 410f42fbbe4..1addb44c12a 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -3529,8 +3529,14 @@ def remove_dead_parfor(parfor, lives, lives_n_aliases, arg_aliases, alias_map, f typemap.pop(tuple_var.name) # remove dummy tuple type blocks[last_label].body.pop() # remove jump - - # process parfor body recursively + """ + Process parfor body recursively. + Note that this is the only place in this function that uses the + argument lives instead of lives_n_aliases. The former does not + include the aliases of live variables but only the live variable + names themselves. See a comment in this function for how that + is used. + """ remove_dead_parfor_recursive( parfor, lives, arg_aliases, alias_map, func_ir, typemap) @@ -3586,6 +3592,17 @@ def remove_dead_parfor_recursive(parfor, lives, arg_aliases, alias_map, assert first_body_block > 0 # we are using 0 for init block here last_label = max(blocks.keys()) + """ + Previously, this statement used lives_n_aliases. That had the effect of + keeping variables in the init_block alive if they aliased an array that + was later written to. By using just lives to indicate which variables + names are live at exit of the parfor but then using alias_map for the + actual recursive dead code removal, we keep any writes to aliased arrays + alive but also allow aliasing assignments (i.e., a = b) to be eliminated + so long as 'a' is not written to through the variable 'a' later on. + This makes assignment handling of remove_dead_block work properly since + it allows distinguishing between live variables and their aliases. + """ return_label, tuple_var = _add_liveness_return_block(blocks, lives, typemap) # branch back to first body label to simulate loop From 416d65653cb566c128a1789807328135c1299b06 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 13 Jan 2020 11:38:41 -0600 Subject: [PATCH 122/595] Fix SciPy spelling and corrcoef still requires Scipy --- docs/source/reference/numpysupported.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index bb173d013f2..2765a9149c7 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -279,7 +279,7 @@ floating-point and complex numbers: * :func:`numpy.linalg.svd` (only the 2 first arguments). .. note:: - The implementation of these functions needs Scipy to be installed. + The implementation of these functions needs SciPy to be installed. Reductions ---------- @@ -330,7 +330,7 @@ The following top-level functions are supported: * :func:`numpy.concatenate` * :func:`numpy.convolve` (only the 2 first arguments) * :func:`numpy.copy` (only the first argument) -* :func:`numpy.corrcoef` (only the 3 first arguments) +* :func:`numpy.corrcoef` (only the 3 first arguments, requires SciPy) * :func:`numpy.correlate` (only the 2 first arguments) * :func:`numpy.count_nonzero` (axis only supports scalar values) * :func:`numpy.cov` (only the 5 first arguments) From 5ed37c52fd3b766530d3afabf3442397d0cd629e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 10 Jan 2020 17:22:50 -0700 Subject: [PATCH 123/595] Add an example of thread masking to the documentation --- docs/source/user/threading-layer.rst | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index 9e8fcf2b9a2..0c887256377 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -194,6 +194,61 @@ The current number of threads used by numba can be accessed with :func:`numba.get_num_threads`. Both functions work inside of a jitted function. +Example of Limiting the Number of Threads +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In this example, suppose the machine we are running on has 8 cores (so +:obj:`numba.config.NUMBA_NUM_THREADS` would be ``8``). Suppose we want to run +some code with ``@njit(parallel=True)``, but we also want to run our code +concurrently in 4 different processes. With the default number of threads, +each Python process would run 8 threads, for a total in 4*8 = 32 threads, +which is oversubscription for our 8 cores. We should rather limit each process +to 2 threads, so that the total will be 4*2 = 8, which matches our number of +physical cores. + +There are two ways to do this. One is to set the :envvar:`NUMBA_NUM_THREADS` +environment variable to ``2``. + +.. code:: bash + + $ NUMBA_NUM_THREADS=2 python ourcode.py + +However, there are two downsides to this approach: + +1. :envvar:`NUMBA_NUM_THREADS` must be set before Numba is imported, and + ideally before Python is launched. As soon as Numba is imported the + environment variable is read and that number of threads is locked in as the + number of threads Numba launches. + +2. If we want to later increase the number of threads used by the process, we + cannot. :envvar:`NUMBA_NUM_THREADS` sets the *maximum* number of threads + that are launched for a process. Calling :func:`~.set_num_threads()` with a + value greater than :obj:`numba.config.NUMBA_NUM_THREADS` results in an + error. + +The advantage of this approach is that we can do it from outside of the +process without changing the code. + +Another approach is to use the :func:`numba.set_num_threads` function in our code + +.. code:: python + + from numba import njit, set_num_threads + + @njit(parallel=True) + def func(): + ... + + set_num_threads(2) + func() + +If we call ``set_num_threads(2)`` before executing our parallel code, it has +the same effect as calling the process with ``NUMBA_NUM_THREADS=2``, in that +the parallel code will only execute on 2 threads. However, we can later call +``set_num_threads(8)`` to increase the number of threads back to the default +size. And we do not have to worry about setting it before Numba gets imported. +It only needs to be called before the parallel function is run. + API Reference ~~~~~~~~~~~~~ From 4b06a0faca076f354a68c7c60be3f5933b579afc Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 10 Jan 2020 10:55:11 -0700 Subject: [PATCH 124/595] Allow numpy integers in set_num_threads() --- numba/npyufunc/parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 5534dcbf7ac..14c82d2e970 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -526,7 +526,7 @@ def set_num_threads(n): """ _launch_threads() - if not isinstance(n, int): + if not isinstance(n, (int, np.integer)): raise TypeError("The number of threads specified must be an integer") snt_check(n) _set_num_threads(n) From 000d68443e5935390108827db9892f5ffe175e43 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Tue, 14 Jan 2020 12:28:28 +0100 Subject: [PATCH 125/595] Catch the use of global typed-list in JITed functions As Numba treats globals as compile time constants, we detect the use of a global typed-list inside a JITed function early on during type-inference and emit an appropriate error. The previous behaviour was to error out during lowering with a less informative error message. Includes test. Fixes: 5041 --- numba/ir_utils.py | 2 +- numba/tests/test_typedlist.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 2dea66345a2..5a27b3aea5a 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -1987,7 +1987,7 @@ def raise_on_unsupported_feature(func_ir, typemap): "compile-time constants and there is no known way to " "compile a %s type as a constant.") if (getattr(ty, 'reflected', False) or - isinstance(ty, types.DictType)): + isinstance(ty, (types.DictType, types.ListType))): raise TypingError(msg % (ty, stmt.value.name, ty), loc=stmt.loc) # checks for generator expressions (yield in use when func_ir has diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 5fb393a7625..f7cb05ca809 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -9,6 +9,7 @@ from numba import jitclass, typeof from numba.typed import List, Dict from numba.utils import IS_PY3 +from numba.errors import TypingError from .support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) @@ -18,6 +19,11 @@ skip_py2 = unittest.skipUnless(IS_PY3, reason='not supported in py2') +# global typed-list for testing purposes +global_typed_list = List.empty_list(int32) +for i in (int32(1), int32(2), int32(3)): + global_typed_list.append(i) + def to_tl(l): """ Convert cpython list to typed-list. """ @@ -459,6 +465,25 @@ def test_list_create_no_jit_using_List(self): l = List() self.assertEqual(type(l), list) + def test_catch_global_typed_list(self): + @njit() + def foo(): + x = List() + for i in global_typed_list: + x.append(i) + + expected_message = ("The use of a ListType[int32] type, assigned to " + "variable 'global_typed_list' in globals, is not " + "supported as globals are considered compile-time " + "constants and there is no known way to compile " + "a ListType[int32] type as a constant.") + with self.assertRaises(TypingError) as raises: + foo() + self.assertIn( + expected_message, + str(raises.exception), + ) + class TestAllocation(MemoryLeakMixin, TestCase): From a65067544b37bffe08cfac985094859a8db7b430 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 14 Jan 2020 14:09:39 +0000 Subject: [PATCH 126/595] Initial draft of developer docs for the thread masking impl. As title. --- docs/source/developer/index.rst | 1 + .../developer/threading_implementation.rst | 114 ++++++++++++++++++ docs/source/user/threading-layer.rst | 2 + 3 files changed, 117 insertions(+) create mode 100644 docs/source/developer/threading_implementation.rst diff --git a/docs/source/developer/index.rst b/docs/source/developer/index.rst index 1a01e1e0067..b1efc6defa1 100644 --- a/docs/source/developer/index.rst +++ b/docs/source/developer/index.rst @@ -22,5 +22,6 @@ Developer Manual environment.rst hashing.rst caching.rst + threading_implementation.rst literal.rst roadmap.rst diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst new file mode 100644 index 00000000000..48eaeb879d4 --- /dev/null +++ b/docs/source/developer/threading_implementation.rst @@ -0,0 +1,114 @@ + +========================================= +Notes on Numba's threading implementation +========================================= + +The execution of the work presented by the Numba ``parallel`` targets is +undertaken by the Numba threading layer. Practically, the "threading layer" +is a Numba built-in library that can perform the required concurrent execution. +At the time of writing there are three threading layers available, each +implemented via a different lower level native threading library. More +information on the threading layers and appropriate selection of a threading +layer for a given application/system can be found in the +:ref:`threading layer documentation `. + +The pertinent information to note for the following sections is that the +function in the threading library that performs the parallel execution is the +``parallel_for`` function. The job of this function is to both orchestrate and +execute the parallel tasks. + +Thread masking +-------------- +:ref:`Thread masking ` was added to make +it possible for a user to programmatically alter the number of threads +performing work in the threading layer. Thread masking proved challenging to +implement as it required the development of a programming model that is suitable +for users, easy to reason about, and could be implemented safely, with +consistent behaviour across the various threading layers. + +Programming model +~~~~~~~~~~~~~~~~~ +The programming model chosen is similar to that found in OpenMP. The reasons for +this choice were that it is familiar to a lot of users, restricted in scope and +also simple. The number of threads in use is specified by calling +``set_num_threads`` and the number of threads in use can be queried by calling +``get_num_threads``.These two functions are synonymous with their OpenMP +counterparts. The execution semantic is also similar to OpenmP in that once a +parallel region is launched altering the thread mask has no impact on the +currently executing region but will have an impact on parallel regions executed +subsequently. + + +The Implementation +~~~~~~~~~~~~~~~~~~ + +So as to place no further restrictions on user code other than those that +already existed in the threading layer libraries, careful consideration of the +design of thread masking was required. The "thread mask" cannot be stored in a +global value as concurrent use of the threading layer may result in classic +forms of race conditions on the value itself. Numerous designs were discussed +involving various types of mutex on such a global value, all of which were +eventually broken through thought experiment alone. It eventually transpired +that, following some OpenMP implementations, the "thread mask" is best +implemented as a ``thread local``. This means each thread that executes a Numba +parallel function will have a thread local storage (TLS) slot that contains the +value of the thread mask to use when scheduling threads in the ``parallel_for`` +function. + +The above notion of TLS use for a thread mask is relatively easy to implement, +``get_num_threads`` and ``set_num_threads`` simply need to address the TLS slot +in a given threading layer. This also means that the execution schedule for a +parallel region can be derived from a run time call to ``get_num_threads``. This +is achieved via a well known and relatively easy to implement pattern of a ``C`` +library function registration and wrapping it in the internal Numba +implementation. + +In addition to satisfying the original upfront thread masking requirements, a +few more complicated scenarios needed consideration as follows. + +Nested parallelism +****************** + +In all threading layers a "main thread" will invoke the ``parallel_for`` +function and then in the parallel region, depending on the threading layer, +some number of additional threads will assist in doing the actual work. +If the work contains a call to another parallel function (i.e. nested +parallelism) it is necessary for the thread making the call to know what the +"thread mask" of the main thread is so that it can propagate it into the +``parallel_for`` call it makes when executing the nested parallel function. +The implementation of this behaviour is threading layer specific but the general +principle is for the "main thread" to always "send" the value of the thread mask +from its TLS slot to all threads in the threading layer that are active in the +parallel region. These active threads then update their TLS slots with this +value prior to performing any work. The net result of this implementation detail +is that: + +* thread masks correctly propagate into nested functions +* it's still possible for each thread in a parallel region to safely have a + different mask with which to call nested functions, if it's not set explicitly + then the inherited mask from the "main thread" is used +* threading layers which have dynamic scheduling with threads potentially + joining and leaving the active pool during a ``parallel_for`` execution are + successfully accommodated +* any "main thread" thread mask is entirely decoupled from the in-flux nature + of the thread masks of the threads in the active thread pool + +Python threads independently invoking parallel functions +******************************************************** + +The threading layer launch sequence is heavily guarded to ensure that the +launch is both thread and process safe and run once per process. In a system +with numerous Python ``threading`` module threads all using Numba, the first +thread through the launch sequence will get its thread mask set +appropriately, but no further threads can run the launch sequence. This means +that other threads will need their initial thread mask set some other way, +this is achieved when ``get_num_threads`` is called and no thread mask is +present, in this case the thread mask will be set to the default. + +OS ``fork()`` calls +******************* + +The use of TLS was also in part driven by the Linux (the most popular +platform for Numba use by far) having a ``fork(2, 3P)`` call that will do TLS +propagation into child processes, see ``clone(2)``'s ``CLONE_SETTLS``. + diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index 0c887256377..30a52e35909 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -194,6 +194,8 @@ The current number of threads used by numba can be accessed with :func:`numba.get_num_threads`. Both functions work inside of a jitted function. +.. _numba-threading-layer-thread-masking: + Example of Limiting the Number of Threads ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 58641147259fce0fa0bcf349382ad5607c94253d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 14 Jan 2020 14:56:14 +0000 Subject: [PATCH 127/595] Add fork test --- numba/tests/test_num_threads.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/numba/tests/test_num_threads.py b/numba/tests/test_num_threads.py index 56f2e970b19..de44f2b93ff 100644 --- a/numba/tests/test_num_threads.py +++ b/numba/tests/test_num_threads.py @@ -4,6 +4,7 @@ import sys import os import re +import multiprocessing import numpy as np @@ -520,6 +521,29 @@ def test_func_guvectorize(total, lens): self.assertEqual(expected_acc, got_acc) self.check_mask(expected_thread_count, got_tc) + @skip_parfors_unsupported + @unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores") + @unittest.skipIf(not sys.platform.startswith('linux'), "Linux only") + def _test_threadmask_across_fork(self): + forkctx = multiprocessing.get_context('fork') + @njit + def foo(): + return get_num_threads() + + def wrap(queue): + queue.put(foo()) + + mask = 1 + self.assertEqual(foo(), config.NUMBA_NUM_THREADS) + set_num_threads(mask) + self.assertEqual(foo(), mask) + shared_queue = forkctx.Queue() + # check TLS slot inheritance in fork + p = forkctx.Process(target=wrap, args=(shared_queue,)) + p.start() + p.join() + self.assertEqual(shared_queue.get(), mask) + def tearDown(self): set_num_threads(config.NUMBA_NUM_THREADS) From 66841727fa309cb2b64fb6c101cc501fc8756311 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Tue, 14 Jan 2020 11:14:19 -0800 Subject: [PATCH 128/595] Improve comment. --- numba/parfor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/parfor.py b/numba/parfor.py index 543d6079066..309eda84c45 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -3744,7 +3744,7 @@ def remove_dead_parfor_recursive(parfor, lives, arg_aliases, alias_map, names are live at exit of the parfor but then using alias_map for the actual recursive dead code removal, we keep any writes to aliased arrays alive but also allow aliasing assignments (i.e., a = b) to be eliminated - so long as 'a' is not written to through the variable 'a' later on. + so long as 'b' is not written to through the variable 'a' later on. This makes assignment handling of remove_dead_block work properly since it allows distinguishing between live variables and their aliases. """ From 3284d11f46c573849815d699039ab3f799b2d3fb Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Wed, 15 Jan 2020 15:31:04 +0100 Subject: [PATCH 129/595] refactor for loop to make it shorter As title. --- numba/tests/test_typedlist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index f7cb05ca809..8c48d199f08 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -21,8 +21,8 @@ # global typed-list for testing purposes global_typed_list = List.empty_list(int32) -for i in (int32(1), int32(2), int32(3)): - global_typed_list.append(i) +for i in (1, 2, 3): + global_typed_list.append(int32(i)) def to_tl(l): From 07d92aebbd0ee03cb68a751d2438cbb8c360fbb5 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 15 Jan 2020 09:53:16 -0600 Subject: [PATCH 130/595] Update docs/source/user/installing.rst Co-Authored-By: stuartarchibald --- docs/source/user/installing.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/source/user/installing.rst b/docs/source/user/installing.rst index 3748d46615d..2be5342369d 100644 --- a/docs/source/user/installing.rst +++ b/docs/source/user/installing.rst @@ -5,7 +5,7 @@ Installation Compatibility ------------- -Numba is compatible with 3.6 or later, and Numpy versions 1.15 or later. +Numba is compatible with Python 3.6 or later, and Numpy versions 1.15 or later. Our supported platforms are: @@ -290,4 +290,3 @@ further information. (output truncated due to length) - From c34d12ee6d5e98f6874a6a5653f013e99fd4dbd0 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Tue, 10 Dec 2019 09:57:45 -0800 Subject: [PATCH 131/595] copy function definitions in _arrayexpr_tree_to_ir to prevent IR aliasing. When copying a definition to a block so that it can be inlined in a parfor to prevent having to pass a function type to a gufunc, rename the function definition var so that typing won't try a recursive lock on a global var. Then, do renaming in the effected block. --- numba/parfor.py | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/numba/parfor.py b/numba/parfor.py index c49b259ba43..622de3dc427 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -77,7 +77,8 @@ is_get_setitem, index_var_of_get_setitem, set_index_var_of_get_setitem, - find_potential_aliases) + find_potential_aliases, + replace_var_names) from numba.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) @@ -1547,7 +1548,7 @@ def run(self): simplify(self.func_ir, self.typemap, self.calltypes) # push function call variables inside parfors so gufunc function # wouldn't need function variables as argument - push_call_vars(self.func_ir.blocks, {}, {}) + push_call_vars(self.func_ir.blocks, {}, {}, self.typemap) # simplify again simplify(self.func_ir, self.typemap, self.calltypes) dprint_func_ir(self.func_ir, "after optimization") @@ -2676,7 +2677,7 @@ def _arrayexpr_tree_to_ir( func_var_name = _find_func_var(typemap, op, avail_vars) func_var = ir.Var(scope, mk_unique_var(func_var_name), loc) typemap[func_var.name] = typemap[func_var_name] - func_var_def = func_ir.get_definition(func_var_name) + func_var_def = copy.deepcopy(func_ir.get_definition(func_var_name)) if isinstance(func_var_def, ir.Expr) and func_var_def.op == 'getattr' and func_var_def.attr == 'sqrt': g_math_var = ir.Var(scope, mk_unique_var("$math_g_var"), loc) typemap[g_math_var.name] = types.misc.Module(math) @@ -3909,7 +3910,7 @@ def apply_copies_parfor(parfor, var_dict, name_var_table, ir_utils.apply_copy_propagate_extensions[Parfor] = apply_copies_parfor -def push_call_vars(blocks, saved_globals, saved_getattrs, nested=False): +def push_call_vars(blocks, saved_globals, saved_getattrs, typemap, nested=False): """push call variables to right before their call site. assuming one global/getattr is created for each call site and control flow doesn't change it. @@ -3919,6 +3920,12 @@ def push_call_vars(blocks, saved_globals, saved_getattrs, nested=False): # global/attr variables that are defined in this block already, # no need to reassign them block_defs = set() + # Some definitions are copied right before the call but then we + # need to rename that symbol in that block so that typing won't + # generate an error trying to lock the save var twice. + # In rename_dict, we collect the symbols that must be renamed in + # this block. We collect them then apply the renaming at the end. + rename_dict = {} for stmt in block.body: def process_assign(stmt): if isinstance(stmt, ir.Assign): @@ -3937,32 +3944,50 @@ def process_assign(stmt): for s in stmt.init_block.body: process_assign(s) pblocks = stmt.loop_body.copy() - push_call_vars(pblocks, saved_globals, saved_getattrs, nested=True) + push_call_vars(pblocks, saved_globals, saved_getattrs, typemap, nested=True) new_body.append(stmt) continue else: process_assign(stmt) for v in stmt.list_vars(): new_body += _get_saved_call_nodes(v.name, saved_globals, - saved_getattrs, block_defs) + saved_getattrs, block_defs, rename_dict) new_body.append(stmt) block.body = new_body + # If there is anything to rename then apply the renaming here. + if len(rename_dict) > 0: + # Fix-up the typing for the renamed vars. + for k,v in rename_dict.items(): + typemap[v] = typemap[k] + # This is only to call replace_var_names which takes a dict. + temp_blocks = {0:block} + replace_var_names(temp_blocks, rename_dict) return -def _get_saved_call_nodes(fname, saved_globals, saved_getattrs, block_defs): +def _get_saved_call_nodes(fname, saved_globals, saved_getattrs, block_defs, rename_dict): nodes = [] while (fname not in block_defs and (fname in saved_globals or fname in saved_getattrs)): if fname in saved_globals: - nodes.append(saved_globals[fname]) - block_defs.add(saved_globals[fname].target.name) + assert(isinstance(saved_globals[fname], ir.Assign)) + saved_global = saved_globals[fname] + renamed_var = ir.Var(saved_global.target.scope, mk_unique_var("$push_global_to_block"), saved_global.target.loc) + renamed_assign = ir.Assign(copy.deepcopy(saved_global.value), renamed_var, saved_global.loc) + nodes.append(renamed_assign) + block_defs.add(saved_global.target.name) + rename_dict[saved_global.target.name] = renamed_assign.target.name fname = '_PA_DONE' elif fname in saved_getattrs: + assert(isinstance(saved_getattrs[fname], ir.Assign)) up_name = saved_getattrs[fname].value.value.name - nodes.append(saved_getattrs[fname]) - block_defs.add(saved_getattrs[fname].target.name) + saved_getattr = saved_getattrs[fname] + renamed_var = ir.Var(saved_getattr.target.scope, mk_unique_var("$push_getattr_to_block"), saved_getattr.target.loc) + renamed_assign = ir.Assign(copy.deepcopy(saved_getattr.value), renamed_var, saved_getattr.loc) + nodes.append(renamed_assign) + block_defs.add(saved_getattr.target.name) + rename_dict[saved_getattr.target.name] = renamed_assign.target.name fname = up_name nodes.reverse() return nodes From 32d9f78226d3bf7cccb913c0da96096b9481312f Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Tue, 10 Dec 2019 13:50:09 -0800 Subject: [PATCH 132/595] Add test for issue4903. --- numba/tests/test_parfors.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index fbc755b6162..0066a106a4c 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -2320,6 +2320,30 @@ def test_impl(): return B self.prange_tester(test_impl) + @skip_unsupported + def test_copy_global_for_parfor(self): + """ issue4903: a global is copied next to a parfor so that + it can be inlined into the parfor and thus not have to be + passed to the parfor (i.e., an unsupported function type). + This global needs to be renamed in the block into which + it is copied. + """ + def test_impl(zz, tc): + lh = np.zeros(len(tc)) + lc = np.zeros(len(tc)) + for i in range(1): + nt = tc[i] + for t in range(nt): + lh += np.exp(zz[i, t]) + for t in range(nt): + lc += np.exp(zz[i, t]) + return lh, lc + + m = 2 + zz = np.ones((m, m, m)) + tc = np.ones(m, dtype=np.int_) + self.prange_tester(test_impl, zz, tc, patch_instance=[0]) + @skip_unsupported def test_multiple_call_getattr_object(self): def test_impl(n): From f7a661e009cf81e1a6f6313d83884c5c321482ee Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 15 Jan 2020 08:26:49 -0800 Subject: [PATCH 133/595] Update numba/parfor.py Co-Authored-By: stuartarchibald --- numba/parfor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/parfor.py b/numba/parfor.py index 622de3dc427..dc25bf4e30a 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -3960,7 +3960,7 @@ def process_assign(stmt): for k,v in rename_dict.items(): typemap[v] = typemap[k] # This is only to call replace_var_names which takes a dict. - temp_blocks = {0:block} + temp_blocks = {0: block} replace_var_names(temp_blocks, rename_dict) return From a0876ce9af15c0c8e17b483a06998360f8fecc84 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 15 Jan 2020 08:27:03 -0800 Subject: [PATCH 134/595] Update numba/parfor.py Co-Authored-By: stuartarchibald --- numba/parfor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/parfor.py b/numba/parfor.py index dc25bf4e30a..e5801c92389 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -3957,7 +3957,7 @@ def process_assign(stmt): # If there is anything to rename then apply the renaming here. if len(rename_dict) > 0: # Fix-up the typing for the renamed vars. - for k,v in rename_dict.items(): + for k, v in rename_dict.items(): typemap[v] = typemap[k] # This is only to call replace_var_names which takes a dict. temp_blocks = {0: block} From a5ea360b17a84198590f4db5865d029d1e39870d Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 15 Jan 2020 09:13:29 -0800 Subject: [PATCH 135/595] Extract common code to an inner function. --- numba/parfor.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/numba/parfor.py b/numba/parfor.py index e5801c92389..81f6abe13ce 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -3967,28 +3967,35 @@ def process_assign(stmt): def _get_saved_call_nodes(fname, saved_globals, saved_getattrs, block_defs, rename_dict): + """ Implement the copying of globals or getattrs for the purposes noted in + push_call_vars. We make a new var and assign to it a copy of the + global or getattr. We remember this new assignment node and add an + entry in the renaming dictionary so that for this block the original + var name is replaced by the new var name we created. + """ nodes = [] while (fname not in block_defs and (fname in saved_globals or fname in saved_getattrs)): - if fname in saved_globals: - assert(isinstance(saved_globals[fname], ir.Assign)) - saved_global = saved_globals[fname] - renamed_var = ir.Var(saved_global.target.scope, mk_unique_var("$push_global_to_block"), saved_global.target.loc) - renamed_assign = ir.Assign(copy.deepcopy(saved_global.value), renamed_var, saved_global.loc) + def rename_global_or_getattr(obj, var_base, nodes, block_defs, rename_dict): + assert(isinstance(obj, ir.Assign)) + renamed_var = ir.Var(obj.target.scope, + mk_unique_var(var_base), + obj.target.loc) + renamed_assign = ir.Assign(copy.deepcopy(obj.value), + renamed_var, + obj.loc) nodes.append(renamed_assign) - block_defs.add(saved_global.target.name) - rename_dict[saved_global.target.name] = renamed_assign.target.name + block_defs.add(obj.target.name) + rename_dict[obj.target.name] = renamed_assign.target.name + + if fname in saved_globals: + rename_global_or_getattr(saved_globals[fname], "$push_global_to_block", + nodes, block_defs, rename_dict) fname = '_PA_DONE' elif fname in saved_getattrs: - assert(isinstance(saved_getattrs[fname], ir.Assign)) - up_name = saved_getattrs[fname].value.value.name - saved_getattr = saved_getattrs[fname] - renamed_var = ir.Var(saved_getattr.target.scope, mk_unique_var("$push_getattr_to_block"), saved_getattr.target.loc) - renamed_assign = ir.Assign(copy.deepcopy(saved_getattr.value), renamed_var, saved_getattr.loc) - nodes.append(renamed_assign) - block_defs.add(saved_getattr.target.name) - rename_dict[saved_getattr.target.name] = renamed_assign.target.name - fname = up_name + rename_global_or_getattr(saved_getattrs[fname], "$push_getattr_to_block", + nodes, block_defs, rename_dict) + fname = saved_getattrs[fname].value.value.name nodes.reverse() return nodes From 73681fe28810626c83640607eaed9a20f76139e0 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 13:36:41 -0700 Subject: [PATCH 136/595] Guard against get_num_threads being -1 as well --- numba/npyufunc/parfor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 68925d306c8..0fd904d0790 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1343,7 +1343,7 @@ def load_range(v): num_threads = builder.call(get_num_threads, []) - with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, + with cgutils.if_unlikely(builder, builder.icmp_signed('<=', num_threads, num_threads.type(0))): cgutils.printf(builder, "num_threads: %d\n", num_threads) context.call_conv.return_user_exc(builder, RuntimeError, From 4bc33d338b8a5ef5d2056308867b784c55c2cb68 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:30:21 -0700 Subject: [PATCH 137/595] Add a short docstring to _get_thread_id() --- numba/npyufunc/parallel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 14c82d2e970..cb5bc488c29 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -594,7 +594,9 @@ def impl(): def _get_thread_id(): """ - docs + Returns a unique ID for each thread + + This function is private and should only be used for testing purposes. """ _launch_threads() return _get_thread_id() From b08e0918378e724cd1fe7e5add701e038f8ba7cb Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:30:48 -0700 Subject: [PATCH 138/595] Add some stuff to the threading implementation documentation --- .../developer/threading_implementation.rst | 98 +++++++++++++++++-- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index 48eaeb879d4..e34587ab574 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -1,4 +1,3 @@ - ========================================= Notes on Numba's threading implementation ========================================= @@ -19,15 +18,29 @@ execute the parallel tasks. Thread masking -------------- + +In order to simplify the design, it was decided that Numba should never launch +new threads beyond the threads that are launched initially with +``_launch_threads`` when the first parallel execution is run. Consequently, +the programmatic setting of the number of threads can only be done by setting +the number of threads to a number less than the total number that have already +been launched. This is done by "masking" out unused threads, causing them to +do no work. For example, on a 16 core machine, if the user were to call +``set_num_threads(4)``, numba would always have 16 threads present, but 12 of +them would sit idle for parallel computations. A further call to +``set_num_threads(16)`` would cause those same threads to do work in later +computations. + :ref:`Thread masking ` was added to make it possible for a user to programmatically alter the number of threads performing work in the threading layer. Thread masking proved challenging to implement as it required the development of a programming model that is suitable for users, easy to reason about, and could be implemented safely, with -consistent behaviour across the various threading layers. +consistent behavior across the various threading layers. Programming model ~~~~~~~~~~~~~~~~~ + The programming model chosen is similar to that found in OpenMP. The reasons for this choice were that it is familiar to a lot of users, restricted in scope and also simple. The number of threads in use is specified by calling @@ -76,7 +89,7 @@ If the work contains a call to another parallel function (i.e. nested parallelism) it is necessary for the thread making the call to know what the "thread mask" of the main thread is so that it can propagate it into the ``parallel_for`` call it makes when executing the nested parallel function. -The implementation of this behaviour is threading layer specific but the general +The implementation of this behavior is threading layer specific but the general principle is for the "main thread" to always "send" the value of the thread mask from its TLS slot to all threads in the threading layer that are active in the parallel region. These active threads then update their TLS slots with this @@ -99,11 +112,16 @@ Python threads independently invoking parallel functions The threading layer launch sequence is heavily guarded to ensure that the launch is both thread and process safe and run once per process. In a system with numerous Python ``threading`` module threads all using Numba, the first -thread through the launch sequence will get its thread mask set -appropriately, but no further threads can run the launch sequence. This means -that other threads will need their initial thread mask set some other way, -this is achieved when ``get_num_threads`` is called and no thread mask is -present, in this case the thread mask will be set to the default. +thread through the launch sequence will get its thread mask set appropriately, +but no further threads can run the launch sequence. This means that other +threads will need their initial thread mask set some other way. This is +achieved when ``get_num_threads`` is called and no thread mask is present, in +this case the thread mask will be set to the default. In the implementation, +"no thread mask is present" is represented by the value -1 and the "default +thread mask" (unset) is represented by the value 0. The implementation also +immediately calls ``set_num_threads(NUMBA_NUM_THREADS)`` after doing this, so +if either -1 or 0 is encountered as a result from ``get_num_threads()`` it +indicates a bug in the above processes. OS ``fork()`` calls ******************* @@ -112,3 +130,67 @@ The use of TLS was also in part driven by the Linux (the most popular platform for Numba use by far) having a ``fork(2, 3P)`` call that will do TLS propagation into child processes, see ``clone(2)``'s ``CLONE_SETTLS``. +Thread ID +********* + +A private ``get_thread_id()`` function was added to each threading backend, +which returns a unique ID for each thread. This can be accessed from Python by +``numba.npyufunc.parallel._get_thread_id()`` (it can also be used inside of an +njitted function). The thread ID function is useful for testing that the +thread masking behavior is correct, but it should not be used outside of the +tests. For example, one can call ``set_num_threads(4)`` and then collect all +unique ``_get_thread_id()``s in a parallel region to verify that only 4 +threads are run. + +Caveats +~~~~~~~ + +Some caveats to be aware of when testing this: + +- The TBB backend may choose to schedule fewer than the given mask number of + threads. Thus a test such as the one described above may return fewer than 4 + unique threads. + +- The workqueue backend is not threadsafe, so attempts to do nested + parallelism with it may result in deadlocks or other undefined behavior. + +- Certain backends may reuse the main thread for computation, but this + behavior shouldn't be relied on (for instance, for exceptions propagating). + +Use in Code Generation +~~~~~~~~~~~~~~~~~~~~~~ + +The general pattern for using ``get_num_threads`` in code generation is + +.. code:: python + + import llvmlite.llvmpy.core as lc + + get_num_threads = builder.module.get_or_insert_function( + lc.Type.function(lc.Type.int(types.intp.bitwidth), []), + name="get_num_threads") + + num_threads = builder.call(get_num_threads, []) + + with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, + num_threads.type(0))): + cgutils.printf(builder, "num_threads: %d\n", num_threads) + context.call_conv.return_user_exc(builder, RuntimeError, + ("Invalid number of threads. " + "This likely indicates a bug in Numba.",)) + + # Pass num_threads through to the appropriate backend function + +See the code in ``numba/npyufunc/parfor.py``. Here ``builder.module`` is the thread pool backend library, e.g., ``tbbpool``. + +The guard against ``num_threads`` being <= 0 is not strictly necessary, but it +can protect against accidentally incorrect behavior in case the thread masking +logic contains a bug. + +The ``num_threads`` variable should be passed through to the appropriate +backend function, such as ``do_scheduling`` or ``parallel_for``. If it's used +in some way other than passing it through to the backend function, the above +considerations should be taken into account to ensure the use of the +``num_threads`` variable is safe. It would probably be better to keep such +logic in the threading backends, rather than trying to do it in code +generation. From 2a7ae35f6795acfd4eac267ffcbe6308e5d9af02 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:34:27 -0700 Subject: [PATCH 139/595] Clarify some bits about OpenMP in the threading implementation docs --- .../developer/threading_implementation.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index e34587ab574..660ed2767d0 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -41,16 +41,16 @@ consistent behavior across the various threading layers. Programming model ~~~~~~~~~~~~~~~~~ -The programming model chosen is similar to that found in OpenMP. The reasons for -this choice were that it is familiar to a lot of users, restricted in scope and -also simple. The number of threads in use is specified by calling +The programming model chosen is similar to that found in OpenMP. The reasons +for this choice were that it is familiar to a lot of users, restricted in +scope and also simple. The number of threads in use is specified by calling ``set_num_threads`` and the number of threads in use can be queried by calling ``get_num_threads``.These two functions are synonymous with their OpenMP -counterparts. The execution semantic is also similar to OpenmP in that once a -parallel region is launched altering the thread mask has no impact on the -currently executing region but will have an impact on parallel regions executed -subsequently. - +counterparts (with the above restriction that the mask must be <= the number +of launched threads). The execution semantics are also similar to OpenmP in +that once a parallel region is launched altering the thread mask, it has no +impact on the currently executing region but will have an impact on parallel +regions executed subsequently. The Implementation ~~~~~~~~~~~~~~~~~~ From aab11a097623404b116997a58aad4488083e844a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:38:11 -0700 Subject: [PATCH 140/595] Fix docs build errors --- docs/source/developer/threading_implementation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index 660ed2767d0..a0b19e4ac31 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -128,7 +128,7 @@ OS ``fork()`` calls The use of TLS was also in part driven by the Linux (the most popular platform for Numba use by far) having a ``fork(2, 3P)`` call that will do TLS -propagation into child processes, see ``clone(2)``'s ``CLONE_SETTLS``. +propagation into child processes, see ``clone(2)``\ 's ``CLONE_SETTLS``. Thread ID ********* @@ -139,7 +139,7 @@ which returns a unique ID for each thread. This can be accessed from Python by njitted function). The thread ID function is useful for testing that the thread masking behavior is correct, but it should not be used outside of the tests. For example, one can call ``set_num_threads(4)`` and then collect all -unique ``_get_thread_id()``s in a parallel region to verify that only 4 +unique ``_get_thread_id()``\ 's in a parallel region to verify that only 4 threads are run. Caveats From a59a199abadca917c6a7b76b1d5edb7d80191037 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:38:56 -0700 Subject: [PATCH 141/595] Small fix in the threading implementation docs --- docs/source/developer/threading_implementation.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index a0b19e4ac31..aff452ed38c 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -172,7 +172,7 @@ The general pattern for using ``get_num_threads`` in code generation is num_threads = builder.call(get_num_threads, []) - with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, + with cgutils.if_unlikely(builder, builder.icmp_signed('<=', num_threads, num_threads.type(0))): cgutils.printf(builder, "num_threads: %d\n", num_threads) context.call_conv.return_user_exc(builder, RuntimeError, @@ -181,7 +181,8 @@ The general pattern for using ``get_num_threads`` in code generation is # Pass num_threads through to the appropriate backend function -See the code in ``numba/npyufunc/parfor.py``. Here ``builder.module`` is the thread pool backend library, e.g., ``tbbpool``. +See the code in ``numba/npyufunc/parfor.py``. Here ``builder.module`` is the +thread pool backend library, e.g., ``tbbpool``. The guard against ``num_threads`` being <= 0 is not strictly necessary, but it can protect against accidentally incorrect behavior in case the thread masking From 03a37aac3950d5e5adc02e6ab770469116a2a4d7 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Wed, 15 Jan 2020 15:09:30 -0800 Subject: [PATCH 142/595] Raise `ValueError` when `view`ing bad `dtype` NumPy raises a `ValueError` instead of a `TypeError`. So do the same in Numba. --- numba/cuda/cudadrv/devicearray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index cb8f38b9564..9324e5e125b 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -355,7 +355,7 @@ def view(self, dtype): """ dtype = np.dtype(dtype) if dtype.itemsize != self.dtype.itemsize: - raise TypeError("new dtype itemsize doesn't match") + raise ValueError("new dtype itemsize doesn't match") return DeviceNDArray( shape=self.shape, strides=self.strides, From d00cce4ccf2327a55f49ac777296a6d887107e0e Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Wed, 15 Jan 2020 15:11:01 -0800 Subject: [PATCH 143/595] Relax the error to allow for type casting --- numba/cuda/cudadrv/devicearray.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 9324e5e125b..270865db14a 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -354,8 +354,10 @@ def view(self, dtype): copy of the data. """ dtype = np.dtype(dtype) - if dtype.itemsize != self.dtype.itemsize: - raise ValueError("new dtype itemsize doesn't match") + if self.shape[-1] * self.dtype.itemsize % dtype.itemsize != 0: + raise ValueError( + "new dtype's itemsize must evenly divide the last dimension" + ) return DeviceNDArray( shape=self.shape, strides=self.strides, From 4dc7cc5599be1e5eeea5ceb54f31290cfa205772 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Wed, 15 Jan 2020 15:21:33 -0800 Subject: [PATCH 144/595] Compute the `shape` when `itemsize` changes --- numba/cuda/cudadrv/devicearray.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 270865db14a..b73fc1c2ff1 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -354,12 +354,21 @@ def view(self, dtype): copy of the data. """ dtype = np.dtype(dtype) - if self.shape[-1] * self.dtype.itemsize % dtype.itemsize != 0: + + shape = list(shape) + shape[-1], rem = divmod( + dtype.itemsize, + shape[-1] * self.dtype.itemsize + ) + shape = tuple(shape) + + if rem != 0: raise ValueError( "new dtype's itemsize must evenly divide the last dimension" ) + return DeviceNDArray( - shape=self.shape, + shape=shape, strides=self.strides, dtype=dtype, stream=self.stream, From 4c4b742e62873714d1aca18613205f939a3b8aec Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Thu, 16 Jan 2020 16:44:27 +0100 Subject: [PATCH 145/595] revert changes to np.flatnonzero Reverted due to lack of tests. --- numba/targets/arraymath.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 1ee5cf79ab5..75fdef30ce4 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -2694,10 +2694,10 @@ def impl(a): return np.nonzero(np.ravel(arr))[0] else: def impl(a): - if a is not None and bool(a): - data = [0] - else: + if a is None: data = [x for x in range(0)] + else: + data = [0] return np.array(data, dtype=types.intp) return impl From 6d699cd46ae4987112cadd78acaa6c16c0bf9010 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Thu, 16 Jan 2020 17:27:43 +0100 Subject: [PATCH 146/595] Revert "revert changes to np.flatnonzero" This reverts commit 4c4b742e62873714d1aca18613205f939a3b8aec. The test for np.flatnonzero started failing after the empty string was addeed to the array_variations. The changes to np.flatnonzero were designed to fix this bug and so we revert the revert at this stage. --- numba/targets/arraymath.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 75fdef30ce4..1ee5cf79ab5 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -2694,10 +2694,10 @@ def impl(a): return np.nonzero(np.ravel(arr))[0] else: def impl(a): - if a is None: - data = [x for x in range(0)] - else: + if a is not None and bool(a): data = [0] + else: + data = [x for x in range(0)] return np.array(data, dtype=types.intp) return impl From ac42ceac6c03221286d44ce1c954dc1b82f667c0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 16 Jan 2020 16:33:07 +0000 Subject: [PATCH 147/595] Update deprecation notices for 0.48.0 As title. --- docs/source/reference/deprecation.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/reference/deprecation.rst b/docs/source/reference/deprecation.rst index 267c85f6b33..ab4b58118bc 100644 --- a/docs/source/reference/deprecation.rst +++ b/docs/source/reference/deprecation.rst @@ -100,8 +100,8 @@ Schedule This feature will be removed with respect to this schedule: * Pending-deprecation warnings will be issued in version 0.44.0 -* Deprecation warnings and replacements will be issued in version 0.48.0 -* Support will be removed in version 0.49.0 +* Deprecation warnings and replacements will be issued in version 0.49.0 +* Support will be removed in version 0.50.0 Recommendations --------------- @@ -205,7 +205,7 @@ Schedule This feature will be removed with respect to this schedule: * Deprecation warnings will be issued in version 0.44.0 -* Support will be removed in version 0.48.0 +* Support will be removed in version 0.50.0 Recommendations --------------- From eb332f668b81a3bb0639656d86bfd6c8de974dea Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 16 Jan 2020 10:30:27 -0600 Subject: [PATCH 148/595] Add test that type_callable retains the decorated function --- numba/tests/test_extending.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index b6692243943..0e822fb9a86 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -119,8 +119,7 @@ def unbox_index(typ, obj, c): def func1(x=None): raise NotImplementedError -@type_callable(func1) -def type_func1(context): +def type_func1_(context): def typer(x=None): if x in (None, types.none): # 0-arg or 1-arg with None @@ -131,6 +130,10 @@ def typer(x=None): return typer + +type_func1 = type_callable(func1)(type_func1_) + + @lower_builtin(func1) @lower_builtin(func1, types.none) def func1_nullary(context, builder, sig, args): @@ -449,6 +452,10 @@ def test_func1_isolated(self): cr = compile_isolated(pyfunc, (types.float64,)) self.assertPreciseEqual(cr.entry_point(18.0), 6.0) + def test_type_callable_keeps_function(self): + self.assertIs(type_func1, type_func1_) + self.assertIsNotNone(type_func1) + def test_cast_mydummy(self): pyfunc = get_dummy cr = compile_isolated(pyfunc, (), types.float64) From f79ddbc895435fa24ec513e768e58c448bebcb89 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 16 Jan 2020 09:59:44 -0800 Subject: [PATCH 149/595] Test `DeviceNDArray`'s `view` --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index cc68b6305e8..3f548777ac6 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -142,6 +142,28 @@ def test_devicearray_transpose_wrongaxis(self): 'axis 2 is out of bounds for array of dimension 2', # sim ]) + def test_devicearray_view_ok(self): + original = np.array(np.arange(12), dtype="i2").reshape(3, 4) + array = cuda.to_device(original) + self.assertTrue(np.all( + array.view("i4").copy_to_host() == original.view("i4") + )) + self.assertTrue(np.all( + array.view("u4").copy_to_host() == original.view("i4") + )) + self.assertTrue(np.all( + array.view("i8").copy_to_host() == original.view("i8") + )) + self.assertTrue(np.all( + array.view("f8").copy_to_host() == original.view("f8") + )) + + def test_devicearray_view_err(self): + original = np.array(np.arange(12), dtype="i2").reshape(4, 3) + array = cuda.to_device(original) + with self.assertRaises(ValueError) as e: + original.view("i4") + def test_devicearray_transpose_ok(self): original = np.array(np.arange(12)).reshape(3, 4) array = np.transpose(cuda.to_device(original)).copy_to_host() From d08f27f38d90485fcacb510a80da89db251ef3d0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 16 Jan 2020 18:42:02 +0000 Subject: [PATCH 150/595] Change log update for 0.48.0 As title. --- CHANGE_LOG | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-) diff --git a/CHANGE_LOG b/CHANGE_LOG index fafc092c7e0..68cbdb69b11 100644 --- a/CHANGE_LOG +++ b/CHANGE_LOG @@ -1,9 +1,132 @@ -Version 0.48.0dev +Version 0.49.0dev ----------------- In development +Version 0.48.0 (Jan 16, 2020) +----------------------------- + +This release is particularly small as it was present to catch anything that +missed the 0.47.0 deadline (the deadline deliberately coincided with the end of +support for Python 2.7). The next release will be considerable larger. + +The core changes in this release are dominated by the start of the clean up +needed for the end of Python 2.7 support, improvements to the CUDA target and +support for numerous additional unicode string methods. + +Enhancements from user contributed PRs (with thanks!): + +* Brian Wignall fixed more spelling typos in #4998. +* Denis Smirnov added support for string methods ``capitalize`` (#4823), + ``casefold`` (#4824), ``swapcase`` (#4825), ``rsplit`` (#4834), ``partition`` + (#4845) and ``splitlines`` (#4849). +* Elena Totmenina extended support for string methods ``startswith`` (#4867) and + added ``endswith`` (#4868). +* Eric Wieser made ``type_callable`` return the decorated function itself in + #4760 +* Ethan Pronovost added support for ``np.argwhere`` in #4617 +* Graham Markall contributed a large number of CUDA enhancements and fixes, + namely: + + * #5068: Remove Python 3.4 backports from utils + * #4975: Make ``device_array_like`` create contiguous arrays (Fixes #4832) + * #5023: Don't launch ForAll kernels with 0 elements (Fixes #5017) + * #5016: Fix various issues in CUDA library search (Fixes #4979) + * #5014: Enable use of records and bools for shared memory, remove ddt, add + additional transpose tests + * #4964: Fix #4628: Add more appropriate typing for CUDA device arrays + * #5007: test_consuming_strides: Keep dev array alive + * #4997: State that CUDA Toolkit 8.0 required in docs + +* James Bourbeau added the Python 3.8 classifier to setup.py in #5027. +* John Kirkham added a clarification to the ``__cuda_array_interface__`` + documentation in #5049. +* Leo Fang Fixed an indexing problem in ``dummyarray`` in #5012. +* Marcel Bargull fixed a build and test issue for Python 3.8 in #5029. +* Maria Rubtsov added support for string methods ``isdecimal`` (#4842), + ``isdigit`` (#4843), ``isnumeric`` (#4844) and ``replace`` (#4865). + +General Enhancements: + +* PR #4760: Make type_callable return the decorated function +* PR #5010: merge string prs + + This merge PR included the following: + + * PR #4823: Implement str.capitalize() based on CPython + * PR #4824: Implement str.casefold() based on CPython + * PR #4825: Implement str.swapcase() based on CPython + * PR #4834: Implement str.rsplit() based on CPython + * PR #4842: Implement str.isdecimal + * PR #4843: Implement str.isdigit + * PR #4844: Implement str.isnumeric + * PR #4845: Implement str.partition() based on CPython + * PR #4849: Implement str.splitlines() based on CPython + * PR #4865: Implement str.replace + * PR #4867: Functionality extension str.startswith() based on CPython + * PR #4868: Add functionality for str.endswith() + +* PR #5039: Disable help messages. +* PR #4617: Add coverage for ``np.argwhere`` + +Fixes: + +* PR #4724: Only use lives (and not aliases) to create post parfor live set. +* PR #4998: Fix more spelling typos +* PR #5024: Propagate semantic constants ahead of static rewrites. +* PR #5027: Add Python 3.8 classifier to setup.py +* PR #5046: Update setup.py and buildscripts for dependency requirements +* PR #5053: Convert from arrays to names in define() and don't invalidate for + multiple consistent defines. +* PR #5058: Permit mixed int types in wrap_index +* PR #5078: Catch the use of global typed-list in JITed functions + +CUDA Enhancements/Fixes: + +* PR #4964: Fix #4628: Add more appropriate typing for CUDA device arrays +* PR #4975: Make ``device_array_like`` create contiguous arrays (Fixes #4832) +* PR #4997: State that CUDA Toolkit 8.0 required in docs +* PR #5007: test_consuming_strides: Keep dev array alive +* PR #5012: Fix IndexError when accessing the "-1" element of dummyarray +* PR #5014: Enable use of records and bools for shared memory, remove ddt, add + additional transpose tests +* PR #5016: Fix various issues in CUDA library search (Fixes #4979) +* PR #5023: Don't launch ForAll kernels with 0 elements (Fixes #5017) +* PR #5068: Remove Python 3.4 backports from utils + +Documentation Updates: + +* PR #5049: Clarify what dictionary means +* PR #5062: Update docs for updated version requirements +* PR #5090: Update deprecation notices for 0.48.0 + +CI updates: + +* PR #5029: Install optional dependencies for Python 3.8 tests +* PR #5040: Drop Py2.7 and Py3.5 from public CI +* PR #5048: Fix CI py38 + +Authors: + +* Brian Wignall +* Denis Smirnov +* Elena Totmenina +* Eric Wieser +* Ethan Pronovost +* Graham Markall +* James Bourbeau +* John Kirkham +* Leo Fang +* Marcel Bargull +* Maria Rubtsov +* Siu Kwan Lam (core dev) +* Stan Seibert (core dev) +* Stuart Archibald (core dev) +* Todd A. Anderson (core dev) +* Valentin Haenel (core dev) + + Version 0.47.0 (Jan 2, 2020) ----------------------------- From 0ddd1c454367707d9f40db66cb2f215945afcccd Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 16 Jan 2020 13:34:23 -0600 Subject: [PATCH 151/595] Attempt to fix #5087 --- numba/byteflow.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/numba/byteflow.py b/numba/byteflow.py index 01799f7bc25..688b072683b 100644 --- a/numba/byteflow.py +++ b/numba/byteflow.py @@ -194,15 +194,20 @@ def propagate_phi_map(phismap): """An iterative dataflow algorithm to find the definition (the source) of each PHI node. """ + blacklist = defaultdict(set) + while True: changing = False for phi, defsites in sorted(list(phismap.items())): for rhs, state in sorted(list(defsites)): if rhs in phi_set: - old = frozenset(defsites) defsites |= phismap[rhs] - defsites.discard((rhs, state)) - changing = old != defsites + blacklist[id(defsites)].add((rhs, state)) + to_remove = blacklist[id(defsites)] + if to_remove & defsites: + defsites -= to_remove + changing = True + _logger.debug("changing phismap: %s", _lazy_pformat(phismap)) if not changing: break From f2883dda5c0dde5a17486212f5203973f123133c Mon Sep 17 00:00:00 2001 From: stuartarchibald Date: Thu, 16 Jan 2020 19:52:15 +0000 Subject: [PATCH 152/595] Update CHANGE_LOG Co-Authored-By: Siu Kwan Lam --- CHANGE_LOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGE_LOG b/CHANGE_LOG index 68cbdb69b11..8f1166364a5 100644 --- a/CHANGE_LOG +++ b/CHANGE_LOG @@ -9,7 +9,7 @@ Version 0.48.0 (Jan 16, 2020) This release is particularly small as it was present to catch anything that missed the 0.47.0 deadline (the deadline deliberately coincided with the end of -support for Python 2.7). The next release will be considerable larger. +support for Python 2.7). The next release will be considerably larger. The core changes in this release are dominated by the start of the clean up needed for the end of Python 2.7 support, improvements to the CUDA target and From f3928f99bde3df7c5bd0189a52d844b1b33243e4 Mon Sep 17 00:00:00 2001 From: jakirkham Date: Thu, 16 Jan 2020 16:27:03 -0800 Subject: [PATCH 153/595] Update numba/cuda/cudadrv/devicearray.py Co-Authored-By: Graham Markall <535640+gmarkall@users.noreply.github.com> --- numba/cuda/cudadrv/devicearray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index b73fc1c2ff1..0b52c699c75 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -355,7 +355,7 @@ def view(self, dtype): """ dtype = np.dtype(dtype) - shape = list(shape) + shape = list(self.shape) shape[-1], rem = divmod( dtype.itemsize, shape[-1] * self.dtype.itemsize From e7c4cb977fbc1440b802ccb01d3b00ff472bb785 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 16 Jan 2020 16:41:02 -0800 Subject: [PATCH 154/595] Check error message matches --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index 3f548777ac6..8b5eb00c5b7 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -163,6 +163,9 @@ def test_devicearray_view_err(self): array = cuda.to_device(original) with self.assertRaises(ValueError) as e: original.view("i4") + self.assertEqual( + "new dtype's itemsize must evenly divide the last dimension", + str(e.exception)) def test_devicearray_transpose_ok(self): original = np.array(np.arange(12)).reshape(3, 4) From 5fcdeec437b915a4cf7284d96c0edcd6b4e20aad Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 16 Jan 2020 16:41:13 -0800 Subject: [PATCH 155/595] Rename test to clarify error checked --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index 8b5eb00c5b7..ea2286a4c60 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -158,7 +158,7 @@ def test_devicearray_view_ok(self): array.view("f8").copy_to_host() == original.view("f8") )) - def test_devicearray_view_err(self): + def test_devicearray_view_bad_itemsize(self): original = np.array(np.arange(12), dtype="i2").reshape(4, 3) array = cuda.to_device(original) with self.assertRaises(ValueError) as e: From 6f9b8d3cdd10e28a4efa3b614bf6f698732032e1 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 16 Jan 2020 16:50:34 -0800 Subject: [PATCH 156/595] Ensure array is C-contiguous when itemsize changes --- numba/cuda/cudadrv/devicearray.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 0b52c699c75..551917f26ab 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -355,6 +355,11 @@ def view(self, dtype): """ dtype = np.dtype(dtype) + if self.dtype.itemsize != dtype.itemsize and not self.is_c_contiguous(): + raise ValueError( + "array must be C-contiguous when changing itemsize" + ) + shape = list(self.shape) shape[-1], rem = divmod( dtype.itemsize, From 32547357d8e42e64ab72c472465f907a1a10981d Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 16 Jan 2020 16:52:16 -0800 Subject: [PATCH 157/595] Test itemsize change on non-contiguous array fail --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index ea2286a4c60..9191505944a 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -158,6 +158,15 @@ def test_devicearray_view_ok(self): array.view("f8").copy_to_host() == original.view("f8") )) + def test_devicearray_view_bad_not_c_contig(self): + original = np.array(np.arange(32), dtype="i2").reshape(4, 8)[:, ::2] + array = cuda.to_device(original) + with self.assertRaises(ValueError) as e: + original.view("i4") + self.assertEqual( + "array must be C-contiguous when changing itemsize", + str(e.exception)) + def test_devicearray_view_bad_itemsize(self): original = np.array(np.arange(12), dtype="i2").reshape(4, 3) array = cuda.to_device(original) From e33cc578a444fdc7ef5c28c017703eb33ad969e5 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 16 Jan 2020 16:53:29 -0800 Subject: [PATCH 158/595] Test itemsize preserving changes allowed --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index 9191505944a..1062317aef1 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -158,6 +158,13 @@ def test_devicearray_view_ok(self): array.view("f8").copy_to_host() == original.view("f8") )) + def test_devicearray_view_ok_not_c_contig(self): + original = np.array(np.arange(32), dtype="i2").reshape(4, 8)[:, ::2] + array = cuda.to_device(original) + self.assertTrue(np.all( + array.view("u2").copy_to_host() == original.view("u2") + )) + def test_devicearray_view_bad_not_c_contig(self): original = np.array(np.arange(32), dtype="i2").reshape(4, 8)[:, ::2] array = cuda.to_device(original) From 59df2f82475e4aac70310b8cf522165a141b2513 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Thu, 16 Jan 2020 16:55:14 -0800 Subject: [PATCH 159/595] Rewrap viewed arrays for use with simulator --- numba/cuda/simulator/cudadrv/devicearray.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numba/cuda/simulator/cudadrv/devicearray.py b/numba/cuda/simulator/cudadrv/devicearray.py index b0006be40cd..b0c474c2475 100644 --- a/numba/cuda/simulator/cudadrv/devicearray.py +++ b/numba/cuda/simulator/cudadrv/devicearray.py @@ -128,6 +128,9 @@ def ravel(self, *args, **kwargs): def reshape(self, *args, **kwargs): return FakeCUDAArray(self._ary.reshape(*args, **kwargs)) + def view(self, *args, **kwargs): + return FakeCUDAArray(self._ary.view(*args, **kwargs)) + def is_c_contiguous(self): return self._ary.flags.c_contiguous From 7b31decaf1b4843991ed4b2cc812e1a92d6754f2 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 16 Jan 2020 17:33:11 -0800 Subject: [PATCH 160/595] Test with the device array --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index 1062317aef1..2714bc70b3a 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -169,7 +169,7 @@ def test_devicearray_view_bad_not_c_contig(self): original = np.array(np.arange(32), dtype="i2").reshape(4, 8)[:, ::2] array = cuda.to_device(original) with self.assertRaises(ValueError) as e: - original.view("i4") + array.view("i4") self.assertEqual( "array must be C-contiguous when changing itemsize", str(e.exception)) @@ -178,7 +178,7 @@ def test_devicearray_view_bad_itemsize(self): original = np.array(np.arange(12), dtype="i2").reshape(4, 3) array = cuda.to_device(original) with self.assertRaises(ValueError) as e: - original.view("i4") + array.view("i4") self.assertEqual( "new dtype's itemsize must evenly divide the last dimension", str(e.exception)) From ef90d089518ff47cdc0ede3f13cd1d311e0fcd68 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 13:36:41 -0700 Subject: [PATCH 161/595] Guard against get_num_threads being -1 as well --- numba/npyufunc/parfor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 68925d306c8..0fd904d0790 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1343,7 +1343,7 @@ def load_range(v): num_threads = builder.call(get_num_threads, []) - with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, + with cgutils.if_unlikely(builder, builder.icmp_signed('<=', num_threads, num_threads.type(0))): cgutils.printf(builder, "num_threads: %d\n", num_threads) context.call_conv.return_user_exc(builder, RuntimeError, From 99212851bf4167bb39e6bbd060f78b3bb934cbe4 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:30:21 -0700 Subject: [PATCH 162/595] Add a short docstring to _get_thread_id() --- numba/npyufunc/parallel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 14c82d2e970..cb5bc488c29 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -594,7 +594,9 @@ def impl(): def _get_thread_id(): """ - docs + Returns a unique ID for each thread + + This function is private and should only be used for testing purposes. """ _launch_threads() return _get_thread_id() From fac8c4db2e8fa23dcec41f7b7f87f00a2976d963 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:30:48 -0700 Subject: [PATCH 163/595] Add some stuff to the threading implementation documentation --- .../developer/threading_implementation.rst | 98 +++++++++++++++++-- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index 48eaeb879d4..e34587ab574 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -1,4 +1,3 @@ - ========================================= Notes on Numba's threading implementation ========================================= @@ -19,15 +18,29 @@ execute the parallel tasks. Thread masking -------------- + +In order to simplify the design, it was decided that Numba should never launch +new threads beyond the threads that are launched initially with +``_launch_threads`` when the first parallel execution is run. Consequently, +the programmatic setting of the number of threads can only be done by setting +the number of threads to a number less than the total number that have already +been launched. This is done by "masking" out unused threads, causing them to +do no work. For example, on a 16 core machine, if the user were to call +``set_num_threads(4)``, numba would always have 16 threads present, but 12 of +them would sit idle for parallel computations. A further call to +``set_num_threads(16)`` would cause those same threads to do work in later +computations. + :ref:`Thread masking ` was added to make it possible for a user to programmatically alter the number of threads performing work in the threading layer. Thread masking proved challenging to implement as it required the development of a programming model that is suitable for users, easy to reason about, and could be implemented safely, with -consistent behaviour across the various threading layers. +consistent behavior across the various threading layers. Programming model ~~~~~~~~~~~~~~~~~ + The programming model chosen is similar to that found in OpenMP. The reasons for this choice were that it is familiar to a lot of users, restricted in scope and also simple. The number of threads in use is specified by calling @@ -76,7 +89,7 @@ If the work contains a call to another parallel function (i.e. nested parallelism) it is necessary for the thread making the call to know what the "thread mask" of the main thread is so that it can propagate it into the ``parallel_for`` call it makes when executing the nested parallel function. -The implementation of this behaviour is threading layer specific but the general +The implementation of this behavior is threading layer specific but the general principle is for the "main thread" to always "send" the value of the thread mask from its TLS slot to all threads in the threading layer that are active in the parallel region. These active threads then update their TLS slots with this @@ -99,11 +112,16 @@ Python threads independently invoking parallel functions The threading layer launch sequence is heavily guarded to ensure that the launch is both thread and process safe and run once per process. In a system with numerous Python ``threading`` module threads all using Numba, the first -thread through the launch sequence will get its thread mask set -appropriately, but no further threads can run the launch sequence. This means -that other threads will need their initial thread mask set some other way, -this is achieved when ``get_num_threads`` is called and no thread mask is -present, in this case the thread mask will be set to the default. +thread through the launch sequence will get its thread mask set appropriately, +but no further threads can run the launch sequence. This means that other +threads will need their initial thread mask set some other way. This is +achieved when ``get_num_threads`` is called and no thread mask is present, in +this case the thread mask will be set to the default. In the implementation, +"no thread mask is present" is represented by the value -1 and the "default +thread mask" (unset) is represented by the value 0. The implementation also +immediately calls ``set_num_threads(NUMBA_NUM_THREADS)`` after doing this, so +if either -1 or 0 is encountered as a result from ``get_num_threads()`` it +indicates a bug in the above processes. OS ``fork()`` calls ******************* @@ -112,3 +130,67 @@ The use of TLS was also in part driven by the Linux (the most popular platform for Numba use by far) having a ``fork(2, 3P)`` call that will do TLS propagation into child processes, see ``clone(2)``'s ``CLONE_SETTLS``. +Thread ID +********* + +A private ``get_thread_id()`` function was added to each threading backend, +which returns a unique ID for each thread. This can be accessed from Python by +``numba.npyufunc.parallel._get_thread_id()`` (it can also be used inside of an +njitted function). The thread ID function is useful for testing that the +thread masking behavior is correct, but it should not be used outside of the +tests. For example, one can call ``set_num_threads(4)`` and then collect all +unique ``_get_thread_id()``s in a parallel region to verify that only 4 +threads are run. + +Caveats +~~~~~~~ + +Some caveats to be aware of when testing this: + +- The TBB backend may choose to schedule fewer than the given mask number of + threads. Thus a test such as the one described above may return fewer than 4 + unique threads. + +- The workqueue backend is not threadsafe, so attempts to do nested + parallelism with it may result in deadlocks or other undefined behavior. + +- Certain backends may reuse the main thread for computation, but this + behavior shouldn't be relied on (for instance, for exceptions propagating). + +Use in Code Generation +~~~~~~~~~~~~~~~~~~~~~~ + +The general pattern for using ``get_num_threads`` in code generation is + +.. code:: python + + import llvmlite.llvmpy.core as lc + + get_num_threads = builder.module.get_or_insert_function( + lc.Type.function(lc.Type.int(types.intp.bitwidth), []), + name="get_num_threads") + + num_threads = builder.call(get_num_threads, []) + + with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, + num_threads.type(0))): + cgutils.printf(builder, "num_threads: %d\n", num_threads) + context.call_conv.return_user_exc(builder, RuntimeError, + ("Invalid number of threads. " + "This likely indicates a bug in Numba.",)) + + # Pass num_threads through to the appropriate backend function + +See the code in ``numba/npyufunc/parfor.py``. Here ``builder.module`` is the thread pool backend library, e.g., ``tbbpool``. + +The guard against ``num_threads`` being <= 0 is not strictly necessary, but it +can protect against accidentally incorrect behavior in case the thread masking +logic contains a bug. + +The ``num_threads`` variable should be passed through to the appropriate +backend function, such as ``do_scheduling`` or ``parallel_for``. If it's used +in some way other than passing it through to the backend function, the above +considerations should be taken into account to ensure the use of the +``num_threads`` variable is safe. It would probably be better to keep such +logic in the threading backends, rather than trying to do it in code +generation. From 8011b14b2ac422d7bba62650a79af588d79a2f7e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:34:27 -0700 Subject: [PATCH 164/595] Clarify some bits about OpenMP in the threading implementation docs --- .../developer/threading_implementation.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index e34587ab574..660ed2767d0 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -41,16 +41,16 @@ consistent behavior across the various threading layers. Programming model ~~~~~~~~~~~~~~~~~ -The programming model chosen is similar to that found in OpenMP. The reasons for -this choice were that it is familiar to a lot of users, restricted in scope and -also simple. The number of threads in use is specified by calling +The programming model chosen is similar to that found in OpenMP. The reasons +for this choice were that it is familiar to a lot of users, restricted in +scope and also simple. The number of threads in use is specified by calling ``set_num_threads`` and the number of threads in use can be queried by calling ``get_num_threads``.These two functions are synonymous with their OpenMP -counterparts. The execution semantic is also similar to OpenmP in that once a -parallel region is launched altering the thread mask has no impact on the -currently executing region but will have an impact on parallel regions executed -subsequently. - +counterparts (with the above restriction that the mask must be <= the number +of launched threads). The execution semantics are also similar to OpenmP in +that once a parallel region is launched altering the thread mask, it has no +impact on the currently executing region but will have an impact on parallel +regions executed subsequently. The Implementation ~~~~~~~~~~~~~~~~~~ From b394b3204bbe5d4506799e0fc3f37419b2127b9e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:38:11 -0700 Subject: [PATCH 165/595] Fix docs build errors --- docs/source/developer/threading_implementation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index 660ed2767d0..a0b19e4ac31 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -128,7 +128,7 @@ OS ``fork()`` calls The use of TLS was also in part driven by the Linux (the most popular platform for Numba use by far) having a ``fork(2, 3P)`` call that will do TLS -propagation into child processes, see ``clone(2)``'s ``CLONE_SETTLS``. +propagation into child processes, see ``clone(2)``\ 's ``CLONE_SETTLS``. Thread ID ********* @@ -139,7 +139,7 @@ which returns a unique ID for each thread. This can be accessed from Python by njitted function). The thread ID function is useful for testing that the thread masking behavior is correct, but it should not be used outside of the tests. For example, one can call ``set_num_threads(4)`` and then collect all -unique ``_get_thread_id()``s in a parallel region to verify that only 4 +unique ``_get_thread_id()``\ 's in a parallel region to verify that only 4 threads are run. Caveats From 8b8c1986c2fab904cbb328812a51b97b6b515e33 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 15 Jan 2020 15:38:56 -0700 Subject: [PATCH 166/595] Small fix in the threading implementation docs --- docs/source/developer/threading_implementation.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index a0b19e4ac31..aff452ed38c 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -172,7 +172,7 @@ The general pattern for using ``get_num_threads`` in code generation is num_threads = builder.call(get_num_threads, []) - with cgutils.if_unlikely(builder, builder.icmp_signed('==', num_threads, + with cgutils.if_unlikely(builder, builder.icmp_signed('<=', num_threads, num_threads.type(0))): cgutils.printf(builder, "num_threads: %d\n", num_threads) context.call_conv.return_user_exc(builder, RuntimeError, @@ -181,7 +181,8 @@ The general pattern for using ``get_num_threads`` in code generation is # Pass num_threads through to the appropriate backend function -See the code in ``numba/npyufunc/parfor.py``. Here ``builder.module`` is the thread pool backend library, e.g., ``tbbpool``. +See the code in ``numba/npyufunc/parfor.py``. Here ``builder.module`` is the +thread pool backend library, e.g., ``tbbpool``. The guard against ``num_threads`` being <= 0 is not strictly necessary, but it can protect against accidentally incorrect behavior in case the thread masking From 56a826c41d47dd518c62d701df3d9f123f3e6e2d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 17 Jan 2020 13:11:09 +0000 Subject: [PATCH 167/595] Add TBB version checks at compile time. As title. --- buildscripts/condarecipe.local/meta.yaml | 6 +++--- numba/npyufunc/tbbpool.cpp | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/buildscripts/condarecipe.local/meta.yaml b/buildscripts/condarecipe.local/meta.yaml index 90dcffdb898..de22640b696 100644 --- a/buildscripts/condarecipe.local/meta.yaml +++ b/buildscripts/condarecipe.local/meta.yaml @@ -36,7 +36,7 @@ requirements: - funcsigs # [py27] - singledispatch # [py27] # TBB devel version is to match TBB libs - - tbb-devel >=2018.0.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] + - tbb-devel >=2019.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] run: - python >=3.6 - numpy >=1.15 @@ -48,7 +48,7 @@ requirements: run_constrained: # If TBB is present it must be at least this version from Anaconda due to # build flag issues triggering UB - - tbb >=2018.0.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] + - tbb >=2019.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] # avoid confusion from openblas bugs - libopenblas !=0.3.6 # [x86_64] # CUDA 8.0 or later is required for CUDA support @@ -65,7 +65,7 @@ test: - ipython # [not (armv6l or armv7l or aarch64)] - setuptools - faulthandler # [py27 and (not (armv6l or armv7l or aarch64))] - - tbb >=2018.0.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] + - tbb >=2019.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] - intel-openmp # [osx] # Need these for AOT. Do not init msvc as it may not be present - {{ compiler('c') }} # [not (win or armv6l or armv7l or aarch64)] diff --git a/numba/npyufunc/tbbpool.cpp b/numba/npyufunc/tbbpool.cpp index b7fc8a9f0b1..a089ec24244 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/npyufunc/tbbpool.cpp @@ -19,17 +19,19 @@ Implement parallel vectorize workqueue on top of Intel TBB. #include "gufunc_scheduler.h" -#if TBB_INTERFACE_VERSION >= 9106 +/* TBB 2019 U5 is the minimum required version as this is needed: + * https://github.com/intel/tbb/blob/18070344d755ece04d169e6cc40775cae9288cee/CHANGES#L133-L134 + * and therefore + * https://github.com/intel/tbb/blob/18070344d755ece04d169e6cc40775cae9288cee/CHANGES#L128-L129 + * from here: + * https://github.com/intel/tbb/blob/2019_U5/include/tbb/tbb_stddef.h#L29 + */ +#if TBB_INTERFACE_VERSION < 11006 +#error "TBB version is too old, 2019 update 5, i.e. TBB_INTERFACE_VERSION >= 11005 required" +#endif + #define TSI_INIT(count) tbb::task_scheduler_init(count) #define TSI_TERMINATE(tsi) tsi->blocking_terminate(std::nothrow) -#else -#if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE -#define TSI_INIT(count) tbb::task_scheduler_init(count, 0, /*blocking termination*/true) -#define TSI_TERMINATE(tsi) tsi->terminate() -#else -#error This version of TBB does not support blocking terminate -#endif -#endif #define _DEBUG 0 #define _TRACE_SPLIT 0 From dc99a57f5fca596a14a295cb8379afd4fd218ff3 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 17 Jan 2020 13:20:44 +0000 Subject: [PATCH 168/595] Add runtime check on TBB version. As title. --- numba/npyufunc/parallel.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index cb5bc488c29..7bdb95dc0ac 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -12,12 +12,11 @@ from __future__ import print_function, absolute_import import os -import platform import sys import warnings from threading import RLock as threadRLock import multiprocessing -from ctypes import CFUNCTYPE, c_int +from ctypes import CFUNCTYPE, c_int, CDLL import numpy as np @@ -333,6 +332,10 @@ def _launch_threads(): if _is_initialized: return + _IS_OSX = sys.platform.startswith('darwin') + _IS_LINUX = sys.platform.startswith('linux') + _IS_WINDOWS = sys.platform.startswith('win32') + def select_known_backend(backend): """ Loads a specific threading layer backend based on string @@ -340,8 +343,29 @@ def select_known_backend(backend): lib = None if backend.startswith("tbb"): try: + # first check that the TBB version is new enough + if _IS_WINDOWS: + libtbb_name = 'tbb.lib' + elif _IS_OSX: + libtbb_name = 'libtbb.dylib' + elif _IS_LINUX: + libtbb_name = 'libtbb.so.2' + else: + raise ValueError("Unknown operating system") + libtbb = CDLL(libtbb_name) + version_func = libtbb.TBB_runtime_interface_version + version_func.argtypes = [] + version_func.restype = c_int + tbb_interface_version = version_func() + if tbb_interface_version < 11005: + msg = ("The TBB threading layer requires a version " + "of TBB greater than 2019 update 5, i.e. " + "TBB_INTERFACE_VERSION >= 11005, found " + "TBB_INTERFACE_VERSION = %s") + raise RuntimeError(msg % tbb_interface_version) + # now try and load the backend from . import tbbpool as lib - except ImportError: + except (ImportError, OSError): pass elif backend.startswith("omp"): # TODO: Check that if MKL is present that it is a version @@ -374,8 +398,6 @@ def select_from_backends(backends): namedbackends = ['tbb', 'omp', 'workqueue'] lib = None - _IS_OSX = platform.system() == "Darwin" - _IS_LINUX = platform.system() == "Linux" err_helpers = dict() err_helpers['TBB'] = ("Intel TBB is required, try:\n" "$ conda/pip install tbb") From 7b1db0bb2a719f4927a35efa16c2784270641d7a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 17 Jan 2020 15:41:02 +0000 Subject: [PATCH 169/595] Make wrong TBB a warning and disable As title --- numba/npyufunc/parallel.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 7bdb95dc0ac..131e0456b28 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -356,13 +356,16 @@ def select_known_backend(backend): version_func = libtbb.TBB_runtime_interface_version version_func.argtypes = [] version_func.restype = c_int - tbb_interface_version = version_func() - if tbb_interface_version < 11005: - msg = ("The TBB threading layer requires a version " - "of TBB greater than 2019 update 5, i.e. " - "TBB_INTERFACE_VERSION >= 11005, found " - "TBB_INTERFACE_VERSION = %s") - raise RuntimeError(msg % tbb_interface_version) + tbb_iface_ver = version_func() + if tbb_iface_ver < 11005: # magic number from TBB + msg = ("The TBB threading layer requires TBB " + "version 2019 update 5 or later i.e. " + "TBB_INTERFACE_VERSION >= 11005. Found " + "TBB_INTERFACE_VERSION = %s. The TBB " + "threading layer is disabled.") + problem = errors.NumbaWarning(msg % tbb_iface_ver) + warnings.warn(problem) + raise ImportError # to trigger except + skip # now try and load the backend from . import tbbpool as lib except (ImportError, OSError): From 29bc72f6f8dc48c464d5f3fd98d91207cc4ec802 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Fri, 17 Jan 2020 08:14:21 -0800 Subject: [PATCH 170/595] Fix #5073: Slices of dynamic shared memory all alias The root of the issue was that computations of indices and slice bounds were incorrect because the shape of dynamic shared memory is generally (0,). To fix this, we compute the shape (1-D only) of dynamic shared arrays using the dynamic shared memory size and the itemsize of the type of the array when it is created. This is implemented by reading the special register %dynamic_smem_size - unfortunately NVVM doesn't provide an intrinsic for this, so we access it using inline assembly. As part of these changes, the `_generic_array` function is refactored and `_make_array` folded into it (`_generic_array` was the only caller and its parameters were the same as its local variables). The refactored version checks for errors earlier on and moves groups the creation of various variables more closely with their usages. --- numba/cuda/cudaimpl.py | 63 +++++--- numba/cuda/tests/cudapy/test_sm.py | 251 +++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 23 deletions(-) diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index 31ede321e35..3a1c0b86355 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -4,7 +4,7 @@ import operator import math -from llvmlite.llvmpy.core import Type +from llvmlite.llvmpy.core import Type, InlineAsm import llvmlite.llvmpy.core as lc import llvmlite.binding as ll @@ -627,18 +627,29 @@ def _get_target_data(context): def _generic_array(context, builder, shape, dtype, symbol_name, addrspace, can_dynsized=False): elemcount = reduce(operator.mul, shape) + + # Check for valid shape for this type of allocation + dynamic_smem = elemcount <= 0 and can_dynsized + if elemcount <= 0 and not dynamic_smem: + raise ValueError("array length <= 0") + + # Check that we support the requested dtype + other_supported_type = isinstance(dtype, (types.Record, types.Boolean)) + if dtype not in types.number_domain and not other_supported_type: + raise TypeError("unsupported type: %s" % dtype) + lldtype = context.get_data_type(dtype) laryty = Type.array(lldtype, elemcount) if addrspace == nvvm.ADDRSPACE_LOCAL: - # Special case local addrespace allocation to use alloca + # Special case local address space allocation to use alloca # NVVM is smart enough to only use local memory if no register is # available dataptr = cgutils.alloca_once(builder, laryty, name=symbol_name) else: lmod = builder.module - # Create global variable in the requested address-space + # Create global variable in the requested address space gvmem = lmod.add_global_variable(laryty, symbol_name, addrspace) # Specify alignment to avoid misalignment bug align = context.get_abi_sizeof(lldtype) @@ -646,11 +657,8 @@ def _generic_array(context, builder, shape, dtype, symbol_name, addrspace, # not a power of 2 (e.g. for a Record array) then round up accordingly. gvmem.align = 1 << (align - 1 ).bit_length() - if elemcount <= 0: - if can_dynsized: # dynamic shared memory - gvmem.linkage = lc.LINKAGE_EXTERNAL - else: - raise ValueError("array length <= 0") + if dynamic_smem: + gvmem.linkage = lc.LINKAGE_EXTERNAL else: ## Comment out the following line to workaround a NVVM bug ## which generates a invalid symbol name when the linkage @@ -660,36 +668,45 @@ def _generic_array(context, builder, shape, dtype, symbol_name, addrspace, gvmem.initializer = lc.Constant.undef(laryty) - other_supported_type = isinstance(dtype, (types.Record, types.Boolean)) - if dtype not in types.number_domain and not other_supported_type: - raise TypeError("unsupported type: %s" % dtype) - # Convert to generic address-space conv = nvvmutils.insert_addrspace_conv(lmod, Type.int(8), addrspace) addrspaceptr = gvmem.bitcast(Type.pointer(Type.int(8), addrspace)) dataptr = builder.call(conv, [addrspaceptr]) - return _make_array(context, builder, dataptr, dtype, shape) - - -def _make_array(context, builder, dataptr, dtype, shape, layout='C'): - ndim = len(shape) - # Create array object - aryty = types.Array(dtype=dtype, ndim=ndim, layout='C') - ary = context.make_array(aryty)(context, builder) - targetdata = _get_target_data(context) lldtype = context.get_data_type(dtype) itemsize = lldtype.get_abi_size(targetdata) + # Compute strides rstrides = [itemsize] for i, lastsize in enumerate(reversed(shape[1:])): rstrides.append(lastsize * rstrides[-1]) strides = [s for s in reversed(rstrides)] - - kshape = [context.get_constant(types.intp, s) for s in shape] kstrides = [context.get_constant(types.intp, s) for s in strides] + # Compute shape + if dynamic_smem: + # Compute the shape based on the dynamic shared memory configuration. + # Unfortunately NVVM does not provide an intrinsic for the + # %dynamic_smem_size register, so we must read it using inline + # assembly. + get_dynshared_size = InlineAsm.get(Type.function(Type.int(), []), + "mov.u32 $0, %dynamic_smem_size;", + '=r', side_effect=True) + dynsmem_size = builder.zext(builder.call(get_dynshared_size, []), + Type.int(width=64)) + # Only 1-D dynamic shared memory is supported so the following is a + # sufficient construction of the shape + kitemsize = context.get_constant(types.intp, itemsize) + kshape = [builder.udiv(dynsmem_size, kitemsize)] + else: + kshape = [context.get_constant(types.intp, s) for s in shape] + + # Create array object + ndim = len(shape) + aryty = types.Array(dtype=dtype, ndim=ndim, layout='C') + ary = context.make_array(aryty)(context, builder) + context.populate_array(ary, data=builder.bitcast(dataptr, ary.data.type), shape=cgutils.pack_array(builder, kshape), diff --git a/numba/cuda/tests/cudapy/test_sm.py b/numba/cuda/tests/cudapy/test_sm.py index 4e6e1ea8fa1..b2eebbc3f2d 100644 --- a/numba/cuda/tests/cudapy/test_sm.py +++ b/numba/cuda/tests/cudapy/test_sm.py @@ -124,6 +124,257 @@ def test_shared_bool(self): arr = np.random.randint(2, size=(1024,), dtype=np.bool_) self._test_shared(arr) + def _test_dynshared_slice(self, func, arr, expected): + # Check that slices of shared memory are correct + # (See Bug #5073 - prior to the addition of these tests and + # corresponding fix, slices of dynamic shared arrays all aliased each + # other) + nshared = arr.size * arr.dtype.itemsize + func[1, 1, 0, nshared](arr) + np.testing.assert_array_equal(expected, arr) + + def test_dynshared_slice_write(self): + # Test writing values into disjoint slices of dynamic shared memory + @cuda.jit + def slice_write(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[0:1] + sm2 = dynsmem[1:2] + + sm1[0] = 1 + sm2[0] = 2 + x[0] = dynsmem[0] + x[1] = dynsmem[1] + + arr = np.zeros(2, dtype=np.int32) + expected = np.array([1, 2], dtype=np.int32) + self._test_dynshared_slice(slice_write, arr, expected) + + def test_dynshared_slice_read(self): + # Test reading values from disjoint slices of dynamic shared memory + @cuda.jit + def slice_read(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[0:1] + sm2 = dynsmem[1:2] + + dynsmem[0] = 1 + dynsmem[1] = 2 + x[0] = sm1[0] + x[1] = sm2[0] + + arr = np.zeros(2, dtype=np.int32) + expected = np.array([1, 2], dtype=np.int32) + self._test_dynshared_slice(slice_read, arr, expected) + + def test_dynshared_slice_diff_sizes(self): + # Test reading values from disjoint slices of dynamic shared memory + # with different sizes + @cuda.jit + def slice_diff_sizes(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[0:1] + sm2 = dynsmem[1:3] + + dynsmem[0] = 1 + dynsmem[1] = 2 + dynsmem[2] = 3 + x[0] = sm1[0] + x[1] = sm2[0] + x[2] = sm2[1] + + arr = np.zeros(3, dtype=np.int32) + expected = np.array([1, 2, 3], dtype=np.int32) + self._test_dynshared_slice(slice_diff_sizes, arr, expected) + + def test_dynshared_slice_overlap(self): + # Test reading values from overlapping slices of dynamic shared memory + @cuda.jit + def slice_overlap(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[0:2] + sm2 = dynsmem[1:4] + + dynsmem[0] = 1 + dynsmem[1] = 2 + dynsmem[2] = 3 + dynsmem[3] = 4 + x[0] = sm1[0] + x[1] = sm1[1] + x[2] = sm2[0] + x[3] = sm2[1] + x[4] = sm2[2] + + arr = np.zeros(5, dtype=np.int32) + expected = np.array([1, 2, 2, 3, 4], dtype=np.int32) + self._test_dynshared_slice(slice_overlap, arr, expected) + + def test_dynshared_slice_gaps(self): + # Test writing values to slices of dynamic shared memory doesn't write + # outside the slice + @cuda.jit + def slice_gaps(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[1:3] + sm2 = dynsmem[4:6] + + # Initial values for dynamic shared memory, some to be overwritten + dynsmem[0] = 99 + dynsmem[1] = 99 + dynsmem[2] = 99 + dynsmem[3] = 99 + dynsmem[4] = 99 + dynsmem[5] = 99 + dynsmem[6] = 99 + + sm1[0] = 1 + sm1[1] = 2 + sm2[0] = 3 + sm2[1] = 4 + + x[0] = dynsmem[0] + x[1] = dynsmem[1] + x[2] = dynsmem[2] + x[3] = dynsmem[3] + x[4] = dynsmem[4] + x[5] = dynsmem[5] + x[6] = dynsmem[6] + + arr = np.zeros(7, dtype=np.int32) + expected = np.array([99, 1, 2, 99, 3, 4, 99], dtype=np.int32) + self._test_dynshared_slice(slice_gaps, arr, expected) + + def test_dynshared_slice_write_backwards(self): + # Test writing values into disjoint slices of dynamic shared memory + # with negative steps + @cuda.jit + def slice_write_backwards(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[1::-1] + sm2 = dynsmem[3:1:-1] + + sm1[0] = 1 + sm1[1] = 2 + sm2[0] = 3 + sm2[1] = 4 + x[0] = dynsmem[0] + x[1] = dynsmem[1] + x[2] = dynsmem[2] + x[3] = dynsmem[3] + + arr = np.zeros(4, dtype=np.int32) + expected = np.array([2, 1, 4, 3], dtype=np.int32) + self._test_dynshared_slice(slice_write_backwards, arr, expected) + + def test_dynshared_slice_nonunit_stride(self): + # Test writing values into slice of dynamic shared memory with + # non-unit stride + @cuda.jit + def slice_nonunit_stride(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[::2] + + # Initial values for dynamic shared memory, some to be overwritten + dynsmem[0] = 99 + dynsmem[1] = 99 + dynsmem[2] = 99 + dynsmem[3] = 99 + dynsmem[4] = 99 + dynsmem[5] = 99 + + sm1[0] = 1 + sm1[1] = 2 + sm1[2] = 3 + + x[0] = dynsmem[0] + x[1] = dynsmem[1] + x[2] = dynsmem[2] + x[3] = dynsmem[3] + x[4] = dynsmem[4] + x[5] = dynsmem[5] + + arr = np.zeros(6, dtype=np.int32) + expected = np.array([1, 99, 2, 99, 3, 99], dtype=np.int32) + self._test_dynshared_slice(slice_nonunit_stride, arr, expected) + + def test_dynshared_slice_nonunit_reverse_stride(self): + # Test writing values into slice of dynamic shared memory with + # reverse non-unit stride + @cuda.jit + def slice_nonunit_reverse_stride(x): + dynsmem = cuda.shared.array(0, dtype=int32) + sm1 = dynsmem[-1::-2] + + # Initial values for dynamic shared memory, some to be overwritten + dynsmem[0] = 99 + dynsmem[1] = 99 + dynsmem[2] = 99 + dynsmem[3] = 99 + dynsmem[4] = 99 + dynsmem[5] = 99 + + sm1[0] = 1 + sm1[1] = 2 + sm1[2] = 3 + + x[0] = dynsmem[0] + x[1] = dynsmem[1] + x[2] = dynsmem[2] + x[3] = dynsmem[3] + x[4] = dynsmem[4] + x[5] = dynsmem[5] + + arr = np.zeros(6, dtype=np.int32) + expected = np.array([99, 3, 99, 2, 99, 1], dtype=np.int32) + self._test_dynshared_slice(slice_nonunit_reverse_stride, arr, expected) + + def test_issue_5073(self): + # An example with which Bug #5073 (slices of dynamic shared memory all + # alias) was discovered. The kernel uses all threads in the block to + # load values into slices of dynamic shared memory. One thread per + # block then writes the loaded values back to a global array after + # syncthreads(). + + arr = np.arange(1024) + nelem = len(arr) + nthreads = 16 + nblocks = int(nelem / nthreads) + dt = nps.from_dtype(arr.dtype) + nshared = nthreads * arr.dtype.itemsize + chunksize = int(nthreads / 2) + + @cuda.jit + def sm_slice_copy(x, y, chunksize): + dynsmem = cuda.shared.array(0, dtype=dt) + sm1 = dynsmem[0:chunksize] + sm2 = dynsmem[chunksize:chunksize*2] + + tx = cuda.threadIdx.x + bx = cuda.blockIdx.x + bd = cuda.blockDim.x + + # load this block's chunk into shared + i = bx * bd + tx + if i < len(x): + if tx < chunksize: + sm1[tx] = x[i] + else: + sm2[tx - chunksize] = x[i] + + cuda.syncthreads() + + # one thread per block writes this block's chunk + if tx == 0: + for j in range(chunksize): + y[bd * bx + j] = sm1[j] + y[bd * bx + j + chunksize] = sm2[j] + + + d_result = cuda.device_array_like(arr) + sm_slice_copy[nblocks, nthreads, 0, nshared](arr, d_result, chunksize) + host_result = d_result.copy_to_host() + np.testing.assert_array_equal(arr, host_result) + if __name__ == '__main__': unittest.main() From f03632a4676db9433d2ac48e0f633c99fc3ec3fe Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Fri, 17 Jan 2020 17:03:47 +0000 Subject: [PATCH 171/595] Documentation fixes based on PR #5059 review --- docs/source/developer/debugging.rst | 22 +++++++++++++++------- docs/source/user/troubleshoot.rst | 2 ++ numba/cuda/decorators.py | 8 ++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/source/developer/debugging.rst b/docs/source/developer/debugging.rst index da9dd057434..544e9a6eb33 100644 --- a/docs/source/developer/debugging.rst +++ b/docs/source/developer/debugging.rst @@ -7,6 +7,10 @@ Notes on Debugging This section describes techniques that can be useful in debugging the compilation and execution of generated code. +.. seealso:: + :ref:`debugging-jit-compiled-code` + + Memcheck -------- @@ -20,7 +24,7 @@ discuss only the specifics of using it with Numba. .. _Memcheck: https://valgrind.org/docs/manual/mc-manual.html .. _Valgrind: https://valgrind.org/ -The Python interpreter, and some of the libraries used by Numba can generate +The Python interpreter and some of the libraries used by Numba can generate false positives with Memcheck - see `this section of the manual `_ for more information on why false positives occur. The false positives can make it @@ -34,6 +38,11 @@ The CPython source distribution includes a suppressions file, in the file generated by Python's memory allocation implementation. Additionally, the Numba repository includes a suppressions file in ``contrib/valgrind-numba.supp``. +.. note:: It is important to use the suppressions files from the versions of the + Python interpreter and Numba that you are using - these files evolve over + time, so non-current versions can fail to suppress some errors, or + erroneously suppress actual errors. + To run the Python interpreter under Memcheck with both suppressions files, it is invoked with the following command:: @@ -70,17 +79,16 @@ error. An example of an error is:: The traceback provided only outlines the C call stack, which can make it difficult to determine what the Python interpreter was doing at the time of the error. One can learn more about the state of the stack by looking at the -backtrace in GDB. Launch ``valgrind`` with an additional argument, -``--vgdb-error=0`` and attach to the process using GDB as instructed by the -output. Once an error is encountered, GDB will stop at the error and the stack -can be inspected. +backtrace in the `GNU Debugger (GDB) `_. +Launch ``valgrind`` with an additional argument, ``--vgdb-error=0`` and attach +to the process using GDB as instructed by the output. Once an error is +encountered, GDB will stop at the error and the stack can be inspected. GDB does provide support for backtracing through the Python stack, but this requires symbols which may not be easily available in your Python distribution. In this case, it is still possible to determine some information about what was happening in Python, but this depends on examining the backtrace closely. For -example, in a backtrace corresponding to the above error, we see items in the -backtrace such as: +example, in a backtrace corresponding to the above error, we see items such as: .. code-block:: diff --git a/docs/source/user/troubleshoot.rst b/docs/source/user/troubleshoot.rst index e16dbedd86a..c14b53a9eb1 100644 --- a/docs/source/user/troubleshoot.rst +++ b/docs/source/user/troubleshoot.rst @@ -378,6 +378,8 @@ still result in compilation of a ufunc, as there is no straightforward pure Python implementation of these functions. +.. _debugging-jit-compiled-code: + Debugging JIT compiled code with GDB ==================================== diff --git a/numba/cuda/decorators.py b/numba/cuda/decorators.py index 9aaf2f519e1..f888c53b2f5 100644 --- a/numba/cuda/decorators.py +++ b/numba/cuda/decorators.py @@ -23,11 +23,11 @@ def jit(func_or_sig=None, argtypes=None, device=False, inline=False, bind=True, function to compile. :param func_or_sig: A function to JIT compile, or a signature of a function - to compile. If a function is supplied, then an + to compile. If a function is supplied, then a :class:`numba.cuda.compiler.AutoJitCUDAKernel` is returned. If a - signature is supplied, then a function which takes a function to compile - and returns an :class:`numba.cuda.compiler.AutoJitCUDAKernel` is - returned. + signature is supplied, then a function is returned. The returned + function accepts another function, which it will compile and then return + a :class:`numba.cuda.compiler.AutoJitCUDAKernel`. .. note:: A kernel cannot have any return value. :param device: Indicates whether this is a device function. From bce47d4dbe4abc1843f6b55b109eb87f3f7c5e1b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 17 Jan 2020 18:11:07 +0000 Subject: [PATCH 172/595] Change library spelling on windows As title --- numba/npyufunc/parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 131e0456b28..fe2090ff055 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -345,7 +345,7 @@ def select_known_backend(backend): try: # first check that the TBB version is new enough if _IS_WINDOWS: - libtbb_name = 'tbb.lib' + libtbb_name = 'tbb' elif _IS_OSX: libtbb_name = 'libtbb.dylib' elif _IS_LINUX: From c91da5a29af272639da8ed2571aae826f6a1c956 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 17 Jan 2020 11:24:04 -0800 Subject: [PATCH 173/595] Only move contiguous data to device Looks like there was an error when trying to move non-contiguous data to device. So move the data to device first before making it (and the original data) non-contiguous. --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index 2714bc70b3a..f2db87246d7 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -159,15 +159,16 @@ def test_devicearray_view_ok(self): )) def test_devicearray_view_ok_not_c_contig(self): - original = np.array(np.arange(32), dtype="i2").reshape(4, 8)[:, ::2] - array = cuda.to_device(original) + original = np.array(np.arange(32), dtype="i2").reshape(4, 8) + array = cuda.to_device(original)[:, ::2] + original = original[:, ::2] self.assertTrue(np.all( array.view("u2").copy_to_host() == original.view("u2") )) def test_devicearray_view_bad_not_c_contig(self): - original = np.array(np.arange(32), dtype="i2").reshape(4, 8)[:, ::2] - array = cuda.to_device(original) + original = np.array(np.arange(32), dtype="i2").reshape(4, 8) + array = cuda.to_device(original)[:, ::2] with self.assertRaises(ValueError) as e: array.view("i4") self.assertEqual( From 0a9d4b964f0e470203f16839fcf1367fcc20dbf6 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 17 Jan 2020 13:50:12 -0600 Subject: [PATCH 174/595] Make State sortable for easier debugging --- numba/byteflow.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/numba/byteflow.py b/numba/byteflow.py index 688b072683b..870738c1b29 100644 --- a/numba/byteflow.py +++ b/numba/byteflow.py @@ -1031,6 +1031,7 @@ def op_CALL_METHOD(self, state, inst): self.op_CALL_FUNCTION(state, inst) +@total_ordering class State(object): """State of the trace """ @@ -1077,6 +1078,9 @@ def get_identity(self): def __hash__(self): return hash(self.get_identity()) + def __lt__(self, other): + return self.get_identity() < other.get_identity() + def __eq__(self, other): return self.get_identity() == other.get_identity() From 690f7192b9042275f3ffa86e13f1d703238bc1af Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 17 Jan 2020 13:51:42 -0600 Subject: [PATCH 175/595] Avoid duplicating work in every iteration --- numba/byteflow.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/numba/byteflow.py b/numba/byteflow.py index 870738c1b29..1afde4dab00 100644 --- a/numba/byteflow.py +++ b/numba/byteflow.py @@ -202,11 +202,11 @@ def propagate_phi_map(phismap): for rhs, state in sorted(list(defsites)): if rhs in phi_set: defsites |= phismap[rhs] - blacklist[id(defsites)].add((rhs, state)) - to_remove = blacklist[id(defsites)] - if to_remove & defsites: - defsites -= to_remove - changing = True + blacklist[phi].add((rhs, state)) + to_remove = blacklist[phi] + if to_remove & defsites: + defsites -= to_remove + changing = True _logger.debug("changing phismap: %s", _lazy_pformat(phismap)) if not changing: From a314bdad15d8111a46fe61d33b5ef964394a215d Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 17 Jan 2020 14:06:20 -0600 Subject: [PATCH 176/595] Add reproducer for #5087 --- numba/tests/test_byteflow.py | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 numba/tests/test_byteflow.py diff --git a/numba/tests/test_byteflow.py b/numba/tests/test_byteflow.py new file mode 100644 index 00000000000..f09edc7df52 --- /dev/null +++ b/numba/tests/test_byteflow.py @@ -0,0 +1,67 @@ +""" +Test byteflow.py specific issues +""" +from numba.tests.support import TestCase +from numba.compiler import run_frontend + + +class TestByteFlowIssues(TestCase): + def test_issue_5087(self): + # This is an odd issue. The number of exact number of print below is + # necessary to trigger it. Too many or few will alter the behavior. + # Also note that the function below will not be executed. The problem + # occurs at compilation. The definition below is invalid for execution. + # The problem occurs in the bytecode analysis. + def udt(): + print + print + print + + for i in range: + print + print + print + print + print + print + print + print + print + print + print + print + print + print + print + print + print + print + + for j in range: + print + print + print + print + print + print + print + for k in range: + for l in range: + print + + print + print + print + print + print + print + print + print + print + if print: + for n in range: + print + else: + print + + run_frontend(udt) From 14e0eee5f20cf55a150e2df9992fc408a0a2535a Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 17 Jan 2020 14:56:46 -0600 Subject: [PATCH 177/595] Fix --- numba/tests/test_byteflow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_byteflow.py b/numba/tests/test_byteflow.py index f09edc7df52..961b3199e77 100644 --- a/numba/tests/test_byteflow.py +++ b/numba/tests/test_byteflow.py @@ -7,8 +7,8 @@ class TestByteFlowIssues(TestCase): def test_issue_5087(self): - # This is an odd issue. The number of exact number of print below is - # necessary to trigger it. Too many or few will alter the behavior. + # This is an odd issue. The exact number of print below is + # necessary to trigger it. Too many or too few will alter the behavior. # Also note that the function below will not be executed. The problem # occurs at compilation. The definition below is invalid for execution. # The problem occurs in the bytecode analysis. From 042bcd94576dacae21355d3bc28266ddfaf0d553 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Fri, 17 Jan 2020 16:10:07 -0500 Subject: [PATCH 178/595] document participating libs --- docs/source/cuda/cuda_array_interface.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/source/cuda/cuda_array_interface.rst b/docs/source/cuda/cuda_array_interface.rst index 37c52cbd51e..ebfc696c266 100644 --- a/docs/source/cuda/cuda_array_interface.rst +++ b/docs/source/cuda/cuda_array_interface.rst @@ -104,3 +104,22 @@ Differences with CUDA Array Interface (Version 1) Versions 0 and 1 of the CUDA Array Interface neither clarified the **strides** attribute for C-contiguous arrays nor specified the treatment for zero-size arrays. + + +Interoperability +---------------- + +The following Python libraries have adopted the CUDA Array Interface: + +- **Numba** +- **CuPy** (`link `_) +- **PyTorch**: (`link `_) +- **PyArrow**: (`link `_) +- **mpi4py**: (`link `_) +- **ArrayViews**: (`link `_) +- The **RAPIDS** stack: + - **cuDF**: (`link `_) + - **cuML**: (`link `_) + - **RMM**: (`link `_) + +If your project is not on this list, please feel free to report to `Numba's issue tracker `_. From 423a1cab692096f5a13d519d60656db6da844a78 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Fri, 17 Jan 2020 16:16:37 -0500 Subject: [PATCH 179/595] add cuSignal --- docs/source/cuda/cuda_array_interface.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/cuda/cuda_array_interface.rst b/docs/source/cuda/cuda_array_interface.rst index ebfc696c266..e36a15fecf0 100644 --- a/docs/source/cuda/cuda_array_interface.rst +++ b/docs/source/cuda/cuda_array_interface.rst @@ -120,6 +120,7 @@ The following Python libraries have adopted the CUDA Array Interface: - The **RAPIDS** stack: - **cuDF**: (`link `_) - **cuML**: (`link `_) + - **cuSignal**: (`link `_) - **RMM**: (`link `_) If your project is not on this list, please feel free to report to `Numba's issue tracker `_. From 1ba824caa8ed8f5825bf61b0a34d4a8f64a03583 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Fri, 17 Jan 2020 15:09:40 -0800 Subject: [PATCH 180/595] Use subTest and assert_array_equal in test_devicearray_view_ok - Using subTest enables printing of each case that failed rather than stopping at the first test. - Using np.testing.assert_array_equal prints out the actual and expected values to make failures easier to debug. --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index f2db87246d7..28508841dfc 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -145,18 +145,12 @@ def test_devicearray_transpose_wrongaxis(self): def test_devicearray_view_ok(self): original = np.array(np.arange(12), dtype="i2").reshape(3, 4) array = cuda.to_device(original) - self.assertTrue(np.all( - array.view("i4").copy_to_host() == original.view("i4") - )) - self.assertTrue(np.all( - array.view("u4").copy_to_host() == original.view("i4") - )) - self.assertTrue(np.all( - array.view("i8").copy_to_host() == original.view("i8") - )) - self.assertTrue(np.all( - array.view("f8").copy_to_host() == original.view("f8") - )) + for dtype in ("i4", "u4", "i8", "f8"): + with self.subTest(dtype=dtype): + np.testing.assert_array_equal( + array.view(dtype).copy_to_host(), + original.view(dtype) + ) def test_devicearray_view_ok_not_c_contig(self): original = np.array(np.arange(32), dtype="i2").reshape(4, 8) From 026fc63010465589b02d6cb67a476610bd5cbf9e Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Fri, 17 Jan 2020 15:15:23 -0800 Subject: [PATCH 181/595] Swap numerator and denominator in view() dtype size check This removes some failures when running with a real device: - test_datetime_view_as_int64: now passing - test_timedelta_view_as_int64: now passing - test_devicearray_view_ok_not_c_contig: now passing - test_devicearray_view_ok: still fails for "i4" and "u4" The simulator still has fails in: - test_devicearray_view_bad_itemsize - test_devicearray_view_bad_not_c_contig This is because the NumPy view method produces different error messages to the ones that a device array produces. --- numba/cuda/cudadrv/devicearray.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 551917f26ab..1ee4b4e50b2 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -362,8 +362,8 @@ def view(self, dtype): shape = list(self.shape) shape[-1], rem = divmod( - dtype.itemsize, - shape[-1] * self.dtype.itemsize + shape[-1] * self.dtype.itemsize, + dtype.itemsize ) shape = tuple(shape) From 669bd5d548dfcd8343435d66da0a727df4f64108 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 17 Jan 2020 15:54:41 -0800 Subject: [PATCH 182/595] Update `strides` based on the changed `itemsize` --- numba/cuda/cudadrv/devicearray.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 1ee4b4e50b2..fd6704d1424 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -372,9 +372,13 @@ def view(self, dtype): "new dtype's itemsize must evenly divide the last dimension" ) + strides = list(self.strides) + strides[-1] = dtype.itemsize + strides = tuple(strides) + return DeviceNDArray( shape=shape, - strides=self.strides, + strides=strides, dtype=dtype, stream=self.stream, gpu_data=self.gpu_data, From 78859035c4dbe94bae914443cb66d59ca7feeadc Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 17 Jan 2020 15:55:41 -0800 Subject: [PATCH 183/595] Minor style fix --- numba/cuda/cudadrv/devicearray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index fd6704d1424..ac223398dcb 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -382,7 +382,7 @@ def view(self, dtype): dtype=dtype, stream=self.stream, gpu_data=self.gpu_data, - ) + ) @property def nbytes(self): From 76237fa0ae2c49dad7b314ea8fd265b06ce249b0 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 17 Jan 2020 15:59:08 -0800 Subject: [PATCH 184/595] Reuse NumPy's error messages for `view` --- numba/cuda/cudadrv/devicearray.py | 7 +++++-- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index ac223398dcb..efd6a78b8e3 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -357,7 +357,8 @@ def view(self, dtype): if self.dtype.itemsize != dtype.itemsize and not self.is_c_contiguous(): raise ValueError( - "array must be C-contiguous when changing itemsize" + "To change to a dtype of a different size," + " the array must be C-contiguous" ) shape = list(self.shape) @@ -369,7 +370,9 @@ def view(self, dtype): if rem != 0: raise ValueError( - "new dtype's itemsize must evenly divide the last dimension" + "When changing to a larger dtype," + " its size must be a divisor of the total size in bytes" + " of the last axis of the array." ) strides = list(self.strides) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index 28508841dfc..2f45d497465 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -166,7 +166,8 @@ def test_devicearray_view_bad_not_c_contig(self): with self.assertRaises(ValueError) as e: array.view("i4") self.assertEqual( - "array must be C-contiguous when changing itemsize", + "To change to a dtype of a different size," + " the array must be C-contiguous", str(e.exception)) def test_devicearray_view_bad_itemsize(self): @@ -175,7 +176,9 @@ def test_devicearray_view_bad_itemsize(self): with self.assertRaises(ValueError) as e: array.view("i4") self.assertEqual( - "new dtype's itemsize must evenly divide the last dimension", + "When changing to a larger dtype," + " its size must be a divisor of the total size in bytes" + " of the last axis of the array.", str(e.exception)) def test_devicearray_transpose_ok(self): From e368c0ecc91aefca9b34300440daf57895602a15 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Sun, 19 Jan 2020 14:03:14 +0200 Subject: [PATCH 185/595] Add SciPy 2019 talks to docs --- docs/source/user/talks.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/source/user/talks.rst b/docs/source/user/talks.rst index 33e91f01221..0b1505ef316 100644 --- a/docs/source/user/talks.rst +++ b/docs/source/user/talks.rst @@ -10,7 +10,7 @@ Talks on Numba -------------- * AnacondaCON 2018 - Accelerating Scientific Workloads with Numba - Siu Kwan Lam (`Video `__) -* `DIANA-HEP Meeting, 23 April 2018 `__ - Overview of Numba - Stan Seibert +* `DIANA-HEP Meeting, 23 April 2018 `__ - Overview of Numba - Stan Seibert Talks on Applications of Numba ------------------------------ @@ -23,9 +23,12 @@ Talks on Applications of Numba * PyData Berlin 2018 - Extending Pandas using Apache Arrow and Numba - Uwe L. Korn (`Video `__, `Blog `__) * FOSDEM 2019 - Extending Numba - Joris Geessels (`Video, Slides & Examples `__) * PyCon India 2019 - Real World Numba: Taking the Path of Least Resistance - Ankit Mahato (`Video `__) +* SciPy 2019 - Real World Numba: Creating a Skeleton Analysis Library - Juan Nunez-Iglesias (`Video `__) +* SciPy 2019 - Fast Gradient Boosting Decision Trees with PyGBM and Numba - Nicholas Hug (`Video `__) Tutorials --------- * SciPy 2017 - Numba: Tell those C++ Bullies to Get Lost - Gil Forsyth & Lorena Barba (`Video `__, `Notebooks `__) * GPU Technology Conference 2018 - GPU Computing in Python with Numba - Stan Seibert (`Notebooks `__) +* SciPy 2019 - How to Accelerate an Existing Codebase with Numba - Siu Kwan Lam & Stanley Seibert (`Video `__) From 71d8b6da8d211652139ec7d709e98bea87de5e6d Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Mon, 20 Jan 2020 12:40:55 +0200 Subject: [PATCH 186/595] Move video to talks and add new tutorial --- docs/source/user/talks.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/user/talks.rst b/docs/source/user/talks.rst index 0b1505ef316..92c44e99b1c 100644 --- a/docs/source/user/talks.rst +++ b/docs/source/user/talks.rst @@ -23,6 +23,7 @@ Talks on Applications of Numba * PyData Berlin 2018 - Extending Pandas using Apache Arrow and Numba - Uwe L. Korn (`Video `__, `Blog `__) * FOSDEM 2019 - Extending Numba - Joris Geessels (`Video, Slides & Examples `__) * PyCon India 2019 - Real World Numba: Taking the Path of Least Resistance - Ankit Mahato (`Video `__) +* SciPy 2019 - How to Accelerate an Existing Codebase with Numba - Siu Kwan Lam & Stanley Seibert (`Video `__) * SciPy 2019 - Real World Numba: Creating a Skeleton Analysis Library - Juan Nunez-Iglesias (`Video `__) * SciPy 2019 - Fast Gradient Boosting Decision Trees with PyGBM and Numba - Nicholas Hug (`Video `__) @@ -31,4 +32,4 @@ Tutorials * SciPy 2017 - Numba: Tell those C++ Bullies to Get Lost - Gil Forsyth & Lorena Barba (`Video `__, `Notebooks `__) * GPU Technology Conference 2018 - GPU Computing in Python with Numba - Stan Seibert (`Notebooks `__) -* SciPy 2019 - How to Accelerate an Existing Codebase with Numba - Siu Kwan Lam & Stanley Seibert (`Video `__) +* PyData Amsterdam 2019 - Create CUDA kernels from Python using Numba and CuPy - Valentin Haenel (`Video `__) From 66305c476b11c3043c18171a6931501a5c77ea1a Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Mon, 20 Jan 2020 02:55:50 -0800 Subject: [PATCH 187/595] Use assert_array_equal in test_devicearray_view_ok_not_c_contig --- numba/cuda/tests/cudadrv/test_cuda_ndarray.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py index 2f45d497465..c4bb5901173 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +++ b/numba/cuda/tests/cudadrv/test_cuda_ndarray.py @@ -156,9 +156,10 @@ def test_devicearray_view_ok_not_c_contig(self): original = np.array(np.arange(32), dtype="i2").reshape(4, 8) array = cuda.to_device(original)[:, ::2] original = original[:, ::2] - self.assertTrue(np.all( - array.view("u2").copy_to_host() == original.view("u2") - )) + np.testing.assert_array_equal( + array.view("u2").copy_to_host(), + original.view("u2") + ) def test_devicearray_view_bad_not_c_contig(self): original = np.array(np.arange(32), dtype="i2").reshape(4, 8) From b02b215e04d9b0e184844b9589612318258262c0 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Mon, 20 Jan 2020 03:10:20 -0800 Subject: [PATCH 188/595] Fix test_devicearray_view_ok_not_c_contig Modifications of shape and strides are only necessary when the new and old dtypes have different itemsizes. --- numba/cuda/cudadrv/devicearray.py | 39 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index efd6a78b8e3..eb34b587130 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -354,30 +354,29 @@ def view(self, dtype): copy of the data. """ dtype = np.dtype(dtype) - - if self.dtype.itemsize != dtype.itemsize and not self.is_c_contiguous(): - raise ValueError( - "To change to a dtype of a different size," - " the array must be C-contiguous" - ) - shape = list(self.shape) - shape[-1], rem = divmod( - shape[-1] * self.dtype.itemsize, - dtype.itemsize - ) - shape = tuple(shape) + strides = list(self.strides) + + if self.dtype.itemsize != dtype.itemsize: + if not self.is_c_contiguous(): + raise ValueError( + "To change to a dtype of a different size," + " the array must be C-contiguous" + ) - if rem != 0: - raise ValueError( - "When changing to a larger dtype," - " its size must be a divisor of the total size in bytes" - " of the last axis of the array." + shape[-1], rem = divmod( + shape[-1] * self.dtype.itemsize, + dtype.itemsize ) - strides = list(self.strides) - strides[-1] = dtype.itemsize - strides = tuple(strides) + if rem != 0: + raise ValueError( + "When changing to a larger dtype," + " its size must be a divisor of the total size in bytes" + " of the last axis of the array." + ) + + strides[-1] = dtype.itemsize return DeviceNDArray( shape=shape, From 33f7ef18830b27305f2c57ddd21d7d77a1876f75 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 20 Jan 2020 11:14:09 +0000 Subject: [PATCH 189/595] Add version check to tests using TBB. As title. --- numba/npyufunc/parallel.py | 62 ++++++++++++++++------------ numba/tests/test_parallel_backend.py | 4 ++ 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index fe2090ff055..a3f3258d0be 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -29,6 +29,10 @@ from numba.npyufunc.wrappers import _wrapper_info from numba.extending import overload +_IS_OSX = sys.platform.startswith('darwin') +_IS_LINUX = sys.platform.startswith('linux') +_IS_WINDOWS = sys.platform.startswith('win32') + def get_thread_count(): """ @@ -325,6 +329,35 @@ def threading_layer(): return _threading_layer +def _check_tbb_version_compatible(): + """ + Checks that if TBB is present it is of a compatible version. + """ + # first check that the TBB version is new enough + if _IS_WINDOWS: + libtbb_name = 'tbb' + elif _IS_OSX: + libtbb_name = 'libtbb.dylib' + elif _IS_LINUX: + libtbb_name = 'libtbb.so.2' + else: + raise ValueError("Unknown operating system") + libtbb = CDLL(libtbb_name) + version_func = libtbb.TBB_runtime_interface_version + version_func.argtypes = [] + version_func.restype = c_int + tbb_iface_ver = version_func() + if tbb_iface_ver < 11005: # magic number from TBB + msg = ("The TBB threading layer requires TBB " + "version 2019 update 5 or later i.e. " + "TBB_INTERFACE_VERSION >= 11005. Found " + "TBB_INTERFACE_VERSION = %s. The TBB " + "threading layer is disabled.") + problem = errors.NumbaWarning(msg % tbb_iface_ver) + warnings.warn(problem) + raise ImportError("Incompatible TBB version") # to trigger except + skip + + def _launch_threads(): with _backend_init_process_lock: with _backend_init_thread_lock: @@ -332,10 +365,6 @@ def _launch_threads(): if _is_initialized: return - _IS_OSX = sys.platform.startswith('darwin') - _IS_LINUX = sys.platform.startswith('linux') - _IS_WINDOWS = sys.platform.startswith('win32') - def select_known_backend(backend): """ Loads a specific threading layer backend based on string @@ -343,29 +372,8 @@ def select_known_backend(backend): lib = None if backend.startswith("tbb"): try: - # first check that the TBB version is new enough - if _IS_WINDOWS: - libtbb_name = 'tbb' - elif _IS_OSX: - libtbb_name = 'libtbb.dylib' - elif _IS_LINUX: - libtbb_name = 'libtbb.so.2' - else: - raise ValueError("Unknown operating system") - libtbb = CDLL(libtbb_name) - version_func = libtbb.TBB_runtime_interface_version - version_func.argtypes = [] - version_func.restype = c_int - tbb_iface_ver = version_func() - if tbb_iface_ver < 11005: # magic number from TBB - msg = ("The TBB threading layer requires TBB " - "version 2019 update 5 or later i.e. " - "TBB_INTERFACE_VERSION >= 11005. Found " - "TBB_INTERFACE_VERSION = %s. The TBB " - "threading layer is disabled.") - problem = errors.NumbaWarning(msg % tbb_iface_ver) - warnings.warn(problem) - raise ImportError # to trigger except + skip + # check if TBB is present and compatible + _check_tbb_version_compatible() # now try and load the backend from . import tbbpool as lib except (ImportError, OSError): diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index a26c1fef999..4eb59231d48 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -34,6 +34,10 @@ # Check which backends are available # TODO: Put this in a subprocess so the address space is kept clean try: + # Check it's a compatible TBB before loading it + from numba.npyufunc.parallel import _check_tbb_version_compatible + _check_tbb_version_compatible() + from numba.npyufunc import tbbpool # noqa: F401 _HAVE_TBB_POOL = True except ImportError: From aa95d99d668ee14ea534b5752a45579d34335f92 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 20 Jan 2020 11:30:27 +0000 Subject: [PATCH 190/595] Update to translate to ImportError As title --- numba/npyufunc/parallel.py | 52 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index a3f3258d0be..34a5bf7d93e 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -333,29 +333,33 @@ def _check_tbb_version_compatible(): """ Checks that if TBB is present it is of a compatible version. """ - # first check that the TBB version is new enough - if _IS_WINDOWS: - libtbb_name = 'tbb' - elif _IS_OSX: - libtbb_name = 'libtbb.dylib' - elif _IS_LINUX: - libtbb_name = 'libtbb.so.2' - else: - raise ValueError("Unknown operating system") - libtbb = CDLL(libtbb_name) - version_func = libtbb.TBB_runtime_interface_version - version_func.argtypes = [] - version_func.restype = c_int - tbb_iface_ver = version_func() - if tbb_iface_ver < 11005: # magic number from TBB - msg = ("The TBB threading layer requires TBB " - "version 2019 update 5 or later i.e. " - "TBB_INTERFACE_VERSION >= 11005. Found " - "TBB_INTERFACE_VERSION = %s. The TBB " - "threading layer is disabled.") - problem = errors.NumbaWarning(msg % tbb_iface_ver) - warnings.warn(problem) - raise ImportError("Incompatible TBB version") # to trigger except + skip + try: + # first check that the TBB version is new enough + if _IS_WINDOWS: + libtbb_name = 'tbb' + elif _IS_OSX: + libtbb_name = 'libtbb.dylib' + elif _IS_LINUX: + libtbb_name = 'libtbb.so.2' + else: + raise ValueError("Unknown operating system") + libtbb = CDLL(libtbb_name) + version_func = libtbb.TBB_runtime_interface_version + version_func.argtypes = [] + version_func.restype = c_int + tbb_iface_ver = version_func() + if tbb_iface_ver < 11005: # magic number from TBB + msg = ("The TBB threading layer requires TBB " + "version 2019 update 5 or later i.e. " + "TBB_INTERFACE_VERSION >= 11005. Found " + "TBB_INTERFACE_VERSION = %s. The TBB " + "threading layer is disabled.") + problem = errors.NumbaWarning(msg % tbb_iface_ver) + warnings.warn(problem) + except (ValueError, OSError) as e: + # Translate as an ImportError for consistent error class use, this error + # will never materialise + raise ImportError("Problem with TBB. Reason: %s" % e) def _launch_threads(): @@ -376,7 +380,7 @@ def select_known_backend(backend): _check_tbb_version_compatible() # now try and load the backend from . import tbbpool as lib - except (ImportError, OSError): + except ImportError: pass elif backend.startswith("omp"): # TODO: Check that if MKL is present that it is a version From 46a96f342f1ecd7689313681ea99b9b0f771020a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 20 Jan 2020 11:35:18 +0000 Subject: [PATCH 191/595] flake8 as title --- numba/npyufunc/parallel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 34a5bf7d93e..d5ad4bcf89a 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -350,10 +350,10 @@ def _check_tbb_version_compatible(): tbb_iface_ver = version_func() if tbb_iface_ver < 11005: # magic number from TBB msg = ("The TBB threading layer requires TBB " - "version 2019 update 5 or later i.e. " - "TBB_INTERFACE_VERSION >= 11005. Found " - "TBB_INTERFACE_VERSION = %s. The TBB " - "threading layer is disabled.") + "version 2019 update 5 or later i.e. " + "TBB_INTERFACE_VERSION >= 11005. Found " + "TBB_INTERFACE_VERSION = %s. The TBB " + "threading layer is disabled.") problem = errors.NumbaWarning(msg % tbb_iface_ver) warnings.warn(problem) except (ValueError, OSError) as e: From b46b5a6028d8a03e0789dd6c04a3d253d3cefafd Mon Sep 17 00:00:00 2001 From: Graham Markall <535640+gmarkall@users.noreply.github.com> Date: Mon, 20 Jan 2020 12:51:18 +0000 Subject: [PATCH 192/595] Apply suggestions from code review Co-Authored-By: stuartarchibald --- docs/source/reference/jit-compilation.rst | 2 +- docs/source/user/vectorize.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/reference/jit-compilation.rst b/docs/source/reference/jit-compilation.rst index ddcba3d6b1a..5ed133fde92 100644 --- a/docs/source/reference/jit-compilation.rst +++ b/docs/source/reference/jit-compilation.rst @@ -318,7 +318,7 @@ Vectorized functions (ufuncs and DUFuncs) If your function doesn't take an output array, you should omit the "arrow" in the layout string (e.g. ``"(n),(n)"``). When doing this, it is important to be aware that changes to the input arrays cannot always be relied on to be - visible outside the execution of the ufunc, as Numpy may pass in temporary + visible outside the execution of the ufunc, as NumPy may pass in temporary arrays as inputs (for example, if a cast is required). .. seealso:: diff --git a/docs/source/user/vectorize.rst b/docs/source/user/vectorize.rst index 4a887cca6ea..9fa33b61313 100644 --- a/docs/source/user/vectorize.rst +++ b/docs/source/user/vectorize.rst @@ -233,7 +233,7 @@ visible changes to the input:: This works because Numpy passes a pointer to the input data directly into the `init_values` function. However, it may also create and pass in a temporary array, in which case changes to the input are lost. For example, this can occur -when casting is required. To demonstrate this, we can use an array of `float32` +when casting is required. To demonstrate, we can use an array of `float32` with the `init_values` function:: >>> invals = np.zeros(shape=(3, 3), dtype=np.float32) From e7905e5421b635f308eb70fc316b4a2dd154d461 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Mon, 20 Jan 2020 12:55:36 +0000 Subject: [PATCH 193/595] gufunc input data section: Talk about passing data rather than pointers --- docs/source/user/vectorize.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/source/user/vectorize.rst b/docs/source/user/vectorize.rst index 9fa33b61313..312cfdb412a 100644 --- a/docs/source/user/vectorize.rst +++ b/docs/source/user/vectorize.rst @@ -230,11 +230,11 @@ visible changes to the input:: [4.2, 4.2, 4.2], [4.2, 4.2, 4.2]]) -This works because Numpy passes a pointer to the input data directly into the -`init_values` function. However, it may also create and pass in a temporary -array, in which case changes to the input are lost. For example, this can occur -when casting is required. To demonstrate, we can use an array of `float32` -with the `init_values` function:: +This works because Numpy can pass the input data directly into the `init_values` +function as the data `dtype` matches that of the declared argument. However, it +may also create and pass in a temporary array, in which case changes to the +input are lost. For example, this can occur when casting is required. To +demonstrate, we can use an array of `float32` with the `init_values` function:: >>> invals = np.zeros(shape=(3, 3), dtype=np.float32) >>> outvals = init_values(invals) From fa18438901a4cc7fbf73e4349e2189166ef91b95 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 20 Jan 2020 09:39:14 -0500 Subject: [PATCH 194/595] apply reviews --- docs/source/cuda/cuda_array_interface.rst | 78 +++++++++++------------ 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/docs/source/cuda/cuda_array_interface.rst b/docs/source/cuda/cuda_array_interface.rst index e36a15fecf0..aee84dda180 100644 --- a/docs/source/cuda/cuda_array_interface.rst +++ b/docs/source/cuda/cuda_array_interface.rst @@ -25,59 +25,56 @@ that must contain the following entries: - **shape**: ``(integer, ...)`` - A tuple of `int` (or `long`) representing the size of each dimension. + A tuple of `int` (or `long`) representing the size of each dimension. - **typestr**: `str` - The type string. This has the same definition as *typestr* in the - `numpy array interface`_. + The type string. This has the same definition as *typestr* in the + `numpy array interface`_. - **data**: `(integer, boolean)` - The **data** is a 2-tuple. The first element is the data pointer - as a Python `int` (or `long`). The data must be device-accessible. - For zero-size arrays, use `0` here. - The second element is the read-only flag as a Python `bool`. + The **data** is a 2-tuple. The first element is the data pointer + as a Python `int` (or `long`). The data must be device-accessible. + For zero-size arrays, use `0` here. + The second element is the read-only flag as a Python `bool`. - Because the user of the interface may or may not be in the same context, - the most common case is to use ``cuPointerGetAttribute`` with - ``CU_POINTER_ATTRIBUTE_DEVICE_POINTER`` in the CUDA driver API (or the - equivalent CUDA Runtime API) to retrieve a device pointer that - is usable in the currently active context. + Because the user of the interface may or may not be in the same context, + the most common case is to use ``cuPointerGetAttribute`` with + ``CU_POINTER_ATTRIBUTE_DEVICE_POINTER`` in the CUDA driver API (or the + equivalent CUDA Runtime API) to retrieve a device pointer that + is usable in the currently active context. - **version**: `integer` - An integer for the version of the interface being exported. - The current version is *2*. + An integer for the version of the interface being exported. + The current version is *2*. The following are optional entries: - **strides**: ``None`` or ``(integer, ...)`` - If **strides** is not given, or it is ``None``, the array is in - C-contiguous layout. Otherwise, a tuple of `int` (or `long`) is explicitly - given for representing the number of bytes to skip to access the next - element at each dimension. + If **strides** is not given, or it is ``None``, the array is in + C-contiguous layout. Otherwise, a tuple of `int` (or `long`) is explicitly + given for representing the number of bytes to skip to access the next + element at each dimension. - **descr** - This is for describing more complicated types. This follows the same - specification as in the `numpy array interface`_. + This is for describing more complicated types. This follows the same + specification as in the `numpy array interface`_. - **mask**: ``None`` or object exposing the ``__cuda_array_interface__`` - If ``None`` then all values in **data** are valid. All elements of the mask - array should be interpreted only as true or not true indicating which - elements of this array are valid. This has the same definition as *mask* - in the `numpy array interface`_. - - .. note:: Numba does not currently support working with masked CUDA arrays - and will raise a `NotImplementedError` exception if one is passed - to a GPU function. - - + If ``None`` then all values in **data** are valid. All elements of the mask + array should be interpreted only as true or not true indicating which + elements of this array are valid. This has the same definition as *mask* + in the `numpy array interface`_. + .. note:: Numba does not currently support working with masked CUDA arrays + and will raise a `NotImplementedError` exception if one is passed + to a GPU function. Additional information about the data pointer can be retrieved using ``cuPointerGetAttribute`` or ``cudaPointerGetAttributes``. Such information @@ -87,7 +84,6 @@ include: - is the pointer host-accessible? - is the pointer a managed memory? - .. _numpy array interface: https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.interface.html#__array_interface__ @@ -111,16 +107,16 @@ Interoperability The following Python libraries have adopted the CUDA Array Interface: -- **Numba** -- **CuPy** (`link `_) -- **PyTorch**: (`link `_) -- **PyArrow**: (`link `_) -- **mpi4py**: (`link `_) -- **ArrayViews**: (`link `_) +- Numba +- `CuPy `_ +- `PyTorch `_ +- `PyArrow `_ +- `mpi4py `_ +- `ArrayViews `_ - The **RAPIDS** stack: - - **cuDF**: (`link `_) - - **cuML**: (`link `_) - - **cuSignal**: (`link `_) - - **RMM**: (`link `_) + - `cuDF `_ + - `cuML `_ + - `cuSignal `_ + - `RMM `_ If your project is not on this list, please feel free to report to `Numba's issue tracker `_. From f2e851edd748e341184bace6cee7f22baaa64247 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 20 Jan 2020 14:17:52 -0700 Subject: [PATCH 195/595] Apply suggestions to the threading implementation docs from code review Co-Authored-By: stuartarchibald --- docs/source/developer/threading_implementation.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index aff452ed38c..620b6827138 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -26,7 +26,7 @@ the programmatic setting of the number of threads can only be done by setting the number of threads to a number less than the total number that have already been launched. This is done by "masking" out unused threads, causing them to do no work. For example, on a 16 core machine, if the user were to call -``set_num_threads(4)``, numba would always have 16 threads present, but 12 of +``set_num_threads(4)``, Numba would always have 16 threads present, but 12 of them would sit idle for parallel computations. A further call to ``set_num_threads(16)`` would cause those same threads to do work in later computations. @@ -46,7 +46,7 @@ for this choice were that it is familiar to a lot of users, restricted in scope and also simple. The number of threads in use is specified by calling ``set_num_threads`` and the number of threads in use can be queried by calling ``get_num_threads``.These two functions are synonymous with their OpenMP -counterparts (with the above restriction that the mask must be <= the number +counterparts (with the above restriction that the mask must be less than or equal to the number of launched threads). The execution semantics are also similar to OpenmP in that once a parallel region is launched altering the thread mask, it has no impact on the currently executing region but will have an impact on parallel @@ -117,10 +117,10 @@ but no further threads can run the launch sequence. This means that other threads will need their initial thread mask set some other way. This is achieved when ``get_num_threads`` is called and no thread mask is present, in this case the thread mask will be set to the default. In the implementation, -"no thread mask is present" is represented by the value -1 and the "default -thread mask" (unset) is represented by the value 0. The implementation also +"no thread mask is present" is represented by the value ``-1`` and the "default +thread mask" (unset) is represented by the value ``0``. The implementation also immediately calls ``set_num_threads(NUMBA_NUM_THREADS)`` after doing this, so -if either -1 or 0 is encountered as a result from ``get_num_threads()`` it +if either ``-1`` or ``0`` is encountered as a result from ``get_num_threads()`` it indicates a bug in the above processes. OS ``fork()`` calls @@ -155,7 +155,7 @@ Some caveats to be aware of when testing this: parallelism with it may result in deadlocks or other undefined behavior. - Certain backends may reuse the main thread for computation, but this - behavior shouldn't be relied on (for instance, for exceptions propagating). + behavior shouldn't be relied upon (for instance, if propagating exceptions). Use in Code Generation ~~~~~~~~~~~~~~~~~~~~~~ From 5ac38ca7653402c111ab2b257aa6572767fba89a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 20 Jan 2020 15:35:41 -0700 Subject: [PATCH 196/595] Some modifications to the threading implementation docs from review --- .../developer/threading_implementation.rst | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index 620b6827138..f269f3fec03 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -19,15 +19,17 @@ execute the parallel tasks. Thread masking -------------- -In order to simplify the design, it was decided that Numba should never launch -new threads beyond the threads that are launched initially with -``_launch_threads`` when the first parallel execution is run. Consequently, -the programmatic setting of the number of threads can only be done by setting -the number of threads to a number less than the total number that have already -been launched. This is done by "masking" out unused threads, causing them to -do no work. For example, on a 16 core machine, if the user were to call -``set_num_threads(4)``, Numba would always have 16 threads present, but 12 of -them would sit idle for parallel computations. A further call to +As part of its design, Numba never launches new threads beyond the threads +that are launched initially with ``numba.npyufunc.parallel._launch_threads()`` +when the first parallel execution is run. This is due to the way threads were +already implemented in Numba prior to thread masking being implemented. This +restriction was kept to keep the design simple, although it could be removed +in the future. Consequently, it's possible to programmatically set the number +of threads, but only to less than or equal to the total number that have +already been launched. This is done by "masking" out unused threads, causing +them to do no work. For example, on a 16 core machine, if the user were to +call ``set_num_threads(4)``, Numba would always have 16 threads present, but +12 of them would sit idle for parallel computations. A further call to ``set_num_threads(16)`` would cause those same threads to do work in later computations. @@ -46,11 +48,11 @@ for this choice were that it is familiar to a lot of users, restricted in scope and also simple. The number of threads in use is specified by calling ``set_num_threads`` and the number of threads in use can be queried by calling ``get_num_threads``.These two functions are synonymous with their OpenMP -counterparts (with the above restriction that the mask must be less than or equal to the number -of launched threads). The execution semantics are also similar to OpenmP in -that once a parallel region is launched altering the thread mask, it has no -impact on the currently executing region but will have an impact on parallel -regions executed subsequently. +counterparts (with the above restriction that the mask must be less than or +equal to the number of launched threads). The execution semantics are also +similar to OpenmP in that once a parallel region is launched, altering the +thread mask has no impact on the currently executing region, but will have an +impact on parallel regions executed subsequently. The Implementation ~~~~~~~~~~~~~~~~~~ @@ -135,8 +137,8 @@ Thread ID A private ``get_thread_id()`` function was added to each threading backend, which returns a unique ID for each thread. This can be accessed from Python by -``numba.npyufunc.parallel._get_thread_id()`` (it can also be used inside of an -njitted function). The thread ID function is useful for testing that the +``numba.npyufunc.parallel._get_thread_id()`` (it can also be used inside of +JIT compiled function). The thread ID function is useful for testing that the thread masking behavior is correct, but it should not be used outside of the tests. For example, one can call ``set_num_threads(4)`` and then collect all unique ``_get_thread_id()``\ 's in a parallel region to verify that only 4 @@ -145,14 +147,16 @@ threads are run. Caveats ~~~~~~~ -Some caveats to be aware of when testing this: +Some caveats to be aware of when testing thread masking: - The TBB backend may choose to schedule fewer than the given mask number of threads. Thus a test such as the one described above may return fewer than 4 unique threads. -- The workqueue backend is not threadsafe, so attempts to do nested - parallelism with it may result in deadlocks or other undefined behavior. +- The workqueue backend is not threadsafe, so attempts to do multithreading + nested parallelism with it may result in deadlocks or other undefined + behavior. The workqueue backend will raise a SIGABRT signal if it detects + nested parallelism. - Certain backends may reuse the main thread for computation, but this behavior shouldn't be relied upon (for instance, if propagating exceptions). @@ -179,10 +183,9 @@ The general pattern for using ``get_num_threads`` in code generation is ("Invalid number of threads. " "This likely indicates a bug in Numba.",)) - # Pass num_threads through to the appropriate backend function + # Pass num_threads through to the appropriate backend function here -See the code in ``numba/npyufunc/parfor.py``. Here ``builder.module`` is the -thread pool backend library, e.g., ``tbbpool``. +See the code in ``numba/npyufunc/parfor.py``. The guard against ``num_threads`` being <= 0 is not strictly necessary, but it can protect against accidentally incorrect behavior in case the thread masking From 115ba4c3808e9d117c456448bea6d87fd9dfd8c2 Mon Sep 17 00:00:00 2001 From: Graham Markall <535640+gmarkall@users.noreply.github.com> Date: Tue, 21 Jan 2020 08:50:58 +0000 Subject: [PATCH 197/595] Update docs/source/user/vectorize.rst Co-Authored-By: stuartarchibald --- docs/source/user/vectorize.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/user/vectorize.rst b/docs/source/user/vectorize.rst index 312cfdb412a..ff31089e0a4 100644 --- a/docs/source/user/vectorize.rst +++ b/docs/source/user/vectorize.rst @@ -230,7 +230,7 @@ visible changes to the input:: [4.2, 4.2, 4.2], [4.2, 4.2, 4.2]]) -This works because Numpy can pass the input data directly into the `init_values` +This works because NumPy can pass the input data directly into the `init_values` function as the data `dtype` matches that of the declared argument. However, it may also create and pass in a temporary array, in which case changes to the input are lost. For example, this can occur when casting is required. To From ce31b18bca684f8b1059ecfbfdcba47483a44fe0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 21 Jan 2020 11:57:45 +0000 Subject: [PATCH 198/595] Implement ord()/chr() As title. Closes #5116 --- docs/source/reference/pysupported.rst | 2 + numba/tests/test_unicode.py | 64 +++++++++++++++++++++++++++ numba/unicode.py | 47 ++++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/docs/source/reference/pysupported.rst b/docs/source/reference/pysupported.rst index 53da3b7e06f..434e20b7157 100644 --- a/docs/source/reference/pysupported.rst +++ b/docs/source/reference/pysupported.rst @@ -743,6 +743,7 @@ The following built-in functions are supported: * :func:`abs` * :class:`bool` +* :func:`chr` * :class:`complex` * :func:`divmod` * :func:`enumerate` @@ -756,6 +757,7 @@ The following built-in functions are supported: * :func:`map` * :func:`max` * :func:`next`: only the one-argument form +* :func:`ord` * :func:`print`: only numbers and strings; no ``file`` or ``sep`` argument * :class:`range`: The only permitted use of range is as a callable function (cannot pass range as an argument to a jitted function or return a range from diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 3df0cb8a6f0..e5f65eb1c0f 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -13,6 +13,7 @@ import numba.unittest_support as unittest from .support import (TestCase, no_pyobj_flags, MemoryLeakMixin) from numba.errors import TypingError +from numba.unicode import _MAX_UNICODE _py34_or_later = sys.version_info[:2] >= (3, 4) _py37_or_later = sys.version_info[:2] >= (3, 7) @@ -344,6 +345,14 @@ def lower_usecase(x): return x.lower() +def ord_usecase(x): + return ord(x) + + +def chr_usecase(x): + return chr(x) + + class BaseTest(MemoryLeakMixin, TestCase): def setUp(self): super(BaseTest, self).setUp() @@ -2401,5 +2410,60 @@ def test_unicode_literal_stopiteration_iter(self): f() +@unittest.skipUnless(_py34_or_later, + 'unicode support requires Python 3.4 or later') +class TestUnicodeAuxillary(BaseTest): + + def test_ord(self): + pyfunc = ord_usecase + cfunc = njit(pyfunc) + for ex in UNICODE_EXAMPLES: + for a in ex: + self.assertPreciseEqual(pyfunc(a), cfunc(a)) + + def test_ord_invalid(self): + self.disable_leak_check() + + pyfunc = ord_usecase + cfunc = njit(pyfunc) + + # wrong number of chars + for func in (pyfunc, cfunc): + for ch in ('', 'abc'): + with self.assertRaises(TypeError) as raises: + func(ch) + self.assertIn('ord() expected a character', + str(raises.exception)) + + # wrong type + with self.assertRaises(TypingError) as raises: + cfunc(1.23) + self.assertIn('Invalid use of Function', str(raises.exception)) + + def test_chr(self): + pyfunc = chr_usecase + cfunc = njit(pyfunc) + for ex in UNICODE_EXAMPLES: + for x in ex: + a = ord(x) + self.assertPreciseEqual(pyfunc(a), cfunc(a)) + + def test_chr_invalid(self): + pyfunc = chr_usecase + cfunc = njit(pyfunc) + + # value negative/>_MAX_UNICODE + for func in (pyfunc, cfunc): + for v in (-2, _MAX_UNICODE + 1): + with self.assertRaises(ValueError) as raises: + func(v) + self.assertIn("chr() arg not in range", str(raises.exception)) + + # wrong type + with self.assertRaises(TypingError) as raises: + cfunc('abc') + self.assertIn('Invalid use of Function', str(raises.exception)) + + if __name__ == '__main__': unittest.main() diff --git a/numba/unicode.py b/numba/unicode.py index f5b113d795e..d25e2b47a0b 100644 --- a/numba/unicode.py +++ b/numba/unicode.py @@ -52,6 +52,9 @@ _py38_or_later = sys.version_info[:2] >= (3, 8) +# https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/unicodeobject.c#L84-L85 # noqa: E501 +_MAX_UNICODE = 0x10ffff + # DATA MODEL @@ -2263,6 +2266,50 @@ def _unicode_swapcase(data, length, res, maxchars): def unicode_swapcase(data): return case_operation(_ascii_swapcase, _unicode_swapcase) + +# https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Python/bltinmodule.c#L1781-L1824 # noqa: E501 +@overload(ord) +def ol_ord(c): + if isinstance(c, types.UnicodeType): + def impl(c): + lc = len(c) + if lc != 1: + # CPython does TypeError + raise TypeError("ord() expected a character") + return _get_code_point(c, 0) + return impl + + +# https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/unicodeobject.c#L2005-L2028 # noqa: E501 +@register_jitable +def _unicode_char(ch): + assert ch <= _MAX_UNICODE + kind = _codepoint_to_kind(ch) + ret = _empty_string(kind, 1, kind == PY_UNICODE_1BYTE_KIND) + _set_code_point(ret, 0, ch) + return ret + + +_out_of_range_msg = "chr() arg not in range(0x%hx)" % _MAX_UNICODE + + +# https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/unicodeobject.c#L3045-L3055 # noqa: E501 +@register_jitable +def _PyUnicode_FromOrdinal(ordinal): + if (ordinal < 0 or ordinal > _MAX_UNICODE): + raise ValueError(_out_of_range_msg) + + return _unicode_char(_Py_UCS4(ordinal)) + + +# https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Python/bltinmodule.c#L715-L720 # noqa: E501 +@overload(chr) +def ol_chr(i): + if isinstance(i, types.Integer): + def impl(i): + return _PyUnicode_FromOrdinal(i) + return impl + # ------------------------------------------------------------------------------ # iteration # ------------------------------------------------------------------------------ From 151cf97fd900d1f7f07ca8bc15a6c6cf2a38113f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 21 Jan 2020 13:19:12 +0000 Subject: [PATCH 199/595] Remove redundant tests As title --- numba/tests/test_builtins.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index fbac99fdcd5..844f933c6c6 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -323,18 +323,6 @@ def test_bool_nonnumber_npm(self): with self.assertTypingError(): self.test_bool_nonnumber(flags=no_pyobj_flags) - def test_chr(self, flags=enable_pyobj_flags): - pyfunc = chr_usecase - - cr = compile_isolated(pyfunc, (types.int32,), flags=flags) - cfunc = cr.entry_point - for x in range(256): - self.assertPreciseEqual(cfunc(x), pyfunc(x)) - - def test_chr_npm(self): - with self.assertTypingError(): - self.test_chr(flags=no_pyobj_flags) - @unittest.skipIf(utils.IS_PY3, "cmp not available as global is Py3") def test_cmp(self, flags=enable_pyobj_flags): pyfunc = cmp_usecase @@ -805,18 +793,6 @@ def test_oct_npm(self): with self.assertTypingError(): self.test_oct(flags=no_pyobj_flags) - def test_ord(self, flags=enable_pyobj_flags): - pyfunc = ord_usecase - - cr = compile_isolated(pyfunc, (types.string,), flags=flags) - cfunc = cr.entry_point - for x in ['a', u'\u2020']: - self.assertPreciseEqual(cfunc(x), pyfunc(x)) - - def test_ord_npm(self): - with self.assertTypingError(): - self.test_ord(flags=no_pyobj_flags) - def test_reduce(self, flags=enable_pyobj_flags): pyfunc = reduce_usecase cr = compile_isolated(pyfunc, (types.Dummy('function_ptr'), From f9c33feb5fa54537ae77e6d157051676fb1bdac4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 21 Jan 2020 14:13:11 +0000 Subject: [PATCH 200/595] Remove redundant guard As title --- numba/tests/test_unicode.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index e5f65eb1c0f..f9b9c7f67c2 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -15,7 +15,6 @@ from numba.errors import TypingError from numba.unicode import _MAX_UNICODE -_py34_or_later = sys.version_info[:2] >= (3, 4) _py37_or_later = sys.version_info[:2] >= (3, 7) @@ -421,8 +420,6 @@ def setUp(self): ] -@unittest.skipUnless(_py34_or_later, - 'unicode support requires Python 3.4 or later') class TestUnicode(BaseTest): def test_literal(self, flags=no_pyobj_flags): @@ -2293,8 +2290,6 @@ def pyfunc(s, x, y, count): self.assertIn(msg, str(raises.exception)) -@unittest.skipUnless(_py34_or_later, - 'unicode support requires Python 3.4 or later') class TestUnicodeInTuple(BaseTest): def test_const_unicode_in_tuple(self): @@ -2372,8 +2367,6 @@ def f(): self.assertEqual(f(), (1, 0, 0, 1, 0)) -@unittest.skipUnless(_py34_or_later, - 'unicode support requires Python 3.4 or later') class TestUnicodeIteration(BaseTest): def test_unicode_iter(self): @@ -2410,8 +2403,6 @@ def test_unicode_literal_stopiteration_iter(self): f() -@unittest.skipUnless(_py34_or_later, - 'unicode support requires Python 3.4 or later') class TestUnicodeAuxillary(BaseTest): def test_ord(self): From 242ceb96e63b175653aec01c290e63106fb7ce91 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Tue, 21 Jan 2020 22:39:35 +0800 Subject: [PATCH 201/595] Apply suggestions from code review --- docs/source/cuda/cuda_array_interface.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/cuda/cuda_array_interface.rst b/docs/source/cuda/cuda_array_interface.rst index aee84dda180..f505b232e6a 100644 --- a/docs/source/cuda/cuda_array_interface.rst +++ b/docs/source/cuda/cuda_array_interface.rst @@ -113,10 +113,10 @@ The following Python libraries have adopted the CUDA Array Interface: - `PyArrow `_ - `mpi4py `_ - `ArrayViews `_ -- The **RAPIDS** stack: +- The RAPIDS stack: - `cuDF `_ - `cuML `_ - `cuSignal `_ - `RMM `_ -If your project is not on this list, please feel free to report to `Numba's issue tracker `_. +If your project is not on this list, please feel free to report it on the `Numba issue tracker `_. From 2edd12833721d23626a54b5070e54a1a8f2d362e Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 22 Jan 2020 08:58:35 -0600 Subject: [PATCH 202/595] Empty commit for 0.49.0 dev cycle From a68369906beff2f1a6a5b737d76566b61a1a3b59 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 22 Jan 2020 17:28:00 -0600 Subject: [PATCH 203/595] Start to work on (un)boxing to jitcode callconv converter --- numba/pythonapi.py | 37 +++++++++++++++++++++++++++++++++++++ numba/targets/base.py | 18 ++++++++++++------ numba/typed/typeddict.py | 28 ++++++++++++++-------------- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/numba/pythonapi.py b/numba/pythonapi.py index 5716540614e..43674349f34 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -12,6 +12,7 @@ import numba.ctypes_support as ctypes from numba import config from numba import types, utils, cgutils, lowering, _helperlib +from numba.targets import imputils if PYVERSION >= (3,3): @@ -1581,3 +1582,39 @@ def string_from_constant_string(self, string): cstr = self.context.insert_const_string(self.module, string) sz = self.context.get_constant(types.intp, len(string)) return self.string_from_string_and_size(cstr, sz) + + def call_jit_code(self, func, sig, args): + """Calls into Numba jitted code and propagate error using the Python + calling convention. + """ + builder = self.builder + cres = self.context.compile_subroutine(builder, func, sig) + got_retty = cres.signature.return_type + retty = sig.return_type + if got_retty != retty: + # This error indicates an error in *func* or the caller of this + # method. + raise errors.LoweringError( + f'mismatching signature {got_retty} != {retty}.\n' + ) + status, res = self.context.call_internal_no_propagate( + builder, cres.fndesc, sig, args, + ) + is_error_ptr = cgutils.alloca_once(builder, cgutils.bool_t, zfill=True) + res_type = self.context.get_value_type(sig.return_type) + res_ptr = cgutils.alloca_once(builder, res_type, zfill=True) + + with builder.if_else(status.is_error) as (has_err, no_err): + with has_err: + builder.store(status.is_error, is_error_ptr) + self.context.call_conv.raise_error(builder, self, status) + with no_err: + res = imputils.fix_returning_optional( + self.context, builder, sig, status, res, + ) + builder.store(res, res_ptr) + + is_error = builder.load(is_error_ptr) + res = builder.load(res_ptr) + return is_error, res + diff --git a/numba/targets/base.py b/numba/targets/base.py index e44b60224e1..58af8d2717c 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -877,18 +877,24 @@ def call_internal(self, builder, fndesc, sig, args): Given the function descriptor of an internally compiled function, emit a call to that function with the given arguments. """ - # Add call to the generated function - llvm_mod = builder.module - fn = self.declare_function(llvm_mod, fndesc) - status, res = self.call_conv.call_function(builder, fn, sig.return_type, - sig.args, args) - + status, res = self.call_internal_no_propagate(builder, fndesc, sig, args) with cgutils.if_unlikely(builder, status.is_error): self.call_conv.return_status_propagate(builder, status) res = imputils.fix_returning_optional(self, builder, sig, status, res) return res + def call_internal_no_propagate(self, builder, fndesc, sig, args): + """Similar to `.call_internal()` but does not handle or propagate + the return status automatically. + """ + # Add call to the generated function + llvm_mod = builder.module + fn = self.declare_function(llvm_mod, fndesc) + status, res = self.call_conv.call_function(builder, fn, sig.return_type, + sig.args, args) + return status, res + def call_unresolved(self, builder, name, sig, args): """ Insert a function call to an unresolved symbol with the given *name*. diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index 04610e87b04..cb0b0723168 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -14,6 +14,7 @@ NativeValue, type_callable, ) +from numba.typing import signature @njit @@ -250,29 +251,28 @@ def box_dicttype(typ, val, c): @unbox(types.DictType) def unbox_dicttype(typ, val, c): context = c.context - builder = c.builder miptr = c.pyapi.object_getattr_string(val, '_opaque') - native = c.unbox(types.MemInfoPointer(types.voidptr), miptr) + mip_type = types.MemInfoPointer(types.voidptr) + native = c.unbox(mip_type, miptr) mi = native.value - ctor = cgutils.create_struct_proxy(typ) - dstruct = ctor(context, builder) - data_pointer = context.nrt.meminfo_data(builder, mi) - data_pointer = builder.bitcast( - data_pointer, - dictobject.ll_dict_type.as_pointer(), - ) + argtypes = mip_type, typeof(typ) - dstruct.data = builder.load(data_pointer) - dstruct.meminfo = mi + def convert(mi, typ): + return dictobject._from_meminfo(mi, typ) - dctobj = dstruct._getvalue() - c.pyapi.decref(miptr) + sig = signature(typ, *argtypes) + nil_typeref = context.get_constant_null(argtypes[1]) + args = (mi, nil_typeref) + is_error, dctobj = c.pyapi.call_jit_code(convert , sig, args) + # decref here because we are stealing a reference. + c.context.nrt.decref(c.builder, typ, dctobj) - return NativeValue(dctobj) + c.pyapi.decref(miptr) + return NativeValue(dctobj, is_error=is_error) # From c2a1169e4ad3b31808e279289bc34308db4ce53a Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 22 Jan 2020 17:28:26 -0600 Subject: [PATCH 204/595] Small fix --- numba/unsafe/refcount.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/unsafe/refcount.py b/numba/unsafe/refcount.py index 38c7ed5f971..d41e8cab622 100644 --- a/numba/unsafe/refcount.py +++ b/numba/unsafe/refcount.py @@ -39,7 +39,7 @@ def codegen(context, builder, signature, args): # that's good enough for a debugging util. refct_32bit = builder.trunc(refct, ir.IntType(32)) printed = cgutils.snprintf_stackbuffer( - builder, 30, "%d".format(ty), refct_32bit, + builder, 30, "%d [%p]", refct_32bit, miptr ) pyapi.sys_write_stdout(printed) From 5fd506acc52dae9f40c097ca80cd711898a294e8 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 10:52:18 +0000 Subject: [PATCH 205/595] wip remove six --- numba/annotations/type_annotations.py | 2 +- numba/caching.py | 2 +- numba/cuda/cudadrv/devicearray.py | 7 +++---- numba/cuda/cudaimpl.py | 3 +-- numba/cuda/simulator/cudadrv/devicearray.py | 10 +++++----- numba/cuda/simulator/kernel.py | 3 ++- numba/cuda/simulator/reduction.py | 2 +- numba/dispatcher.py | 3 ++- numba/interpreter.py | 4 ++-- numba/ir.py | 3 +-- numba/ir_utils.py | 3 +-- numba/jitclass/base.py | 4 ++-- numba/jitclass/boxing.py | 5 ++--- numba/npyufunc/array_exprs.py | 4 ++-- numba/npyufunc/deviceufunc.py | 5 ++--- numba/npyufunc/parfor.py | 3 +-- numba/pycc/decorators.py | 3 +-- numba/roc/hsadrv/driver.py | 2 +- numba/six.py | 1 - numba/special.py | 2 +- numba/stencil.py | 5 ++--- numba/stencilparfor.py | 3 +-- numba/targets/slicing.py | 3 +-- numba/tests/serialize_usecases.py | 3 +-- numba/tests/support.py | 9 --------- numba/tests/test_builtins.py | 5 +---- numba/tests/test_closure.py | 3 +-- numba/tests/test_dyn_func.py | 3 +-- numba/tests/test_help.py | 2 +- numba/tests/test_listimpl.py | 1 - numba/tests/test_parallel_backend.py | 2 +- numba/tests/test_sort.py | 6 ------ numba/tests/test_svml.py | 3 +-- numba/tests/test_tracing.py | 1 - numba/tests/test_ufuncs.py | 15 +++++++-------- numba/tests/test_unicode_names.py | 3 +-- numba/typed/typeddict.py | 3 ++- numba/typed/typedlist.py | 3 ++- numba/types/containers.py | 2 +- numba/typing/context.py | 2 +- 40 files changed, 57 insertions(+), 91 deletions(-) diff --git a/numba/annotations/type_annotations.py b/numba/annotations/type_annotations.py index 36789e8e881..05f55a21696 100644 --- a/numba/annotations/type_annotations.py +++ b/numba/annotations/type_annotations.py @@ -1,6 +1,7 @@ from __future__ import print_function, absolute_import from collections import defaultdict, OrderedDict +from collections.abc import Mapping from contextlib import closing import copy import inspect @@ -12,7 +13,6 @@ from numba.io_support import StringIO from numba import ir import numba.dispatcher -from numba.six import Mapping class SourceLines(Mapping): diff --git a/numba/caching.py b/numba/caching.py index c8f4d1b01e4..680ae854af7 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -11,7 +11,7 @@ import inspect import itertools import os -from .six.moves import cPickle as pickle +import pickle import sys import tempfile import warnings diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index cb8f38b9564..1ebc55b6179 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -10,7 +10,6 @@ import functools import operator import copy -from numba import six from ctypes import c_void_p import numpy as np @@ -47,7 +46,7 @@ def requires_attr(attr, typ): requires_attr('shape', tuple) requires_attr('strides', tuple) requires_attr('dtype', np.dtype) - requires_attr('size', six.integer_types) + requires_attr('size', int) def require_cuda_ndarray(obj): @@ -81,9 +80,9 @@ def __init__(self, shape, strides, dtype, stream=0, writeback=None, gpu_data user provided device memory for the ndarray data buffer """ - if isinstance(shape, six.integer_types): + if isinstance(shape, int): shape = (shape,) - if isinstance(strides, six.integer_types): + if isinstance(strides, int): strides = (strides,) self.ndim = len(shape) if len(strides) != self.ndim: diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index 31ede321e35..923b42f7b30 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -10,7 +10,6 @@ from numba.targets.imputils import Registry from numba import cgutils -from numba import six from numba import types from numba.utils import IS_PY3 from .cudadrv import nvvm @@ -107,7 +106,7 @@ def ptx_cmem_arylike(context, builder, sig, args): constvals = [ context.get_constant(types.byte, i) - for i in six.iterbytes(arr.tobytes(order='A')) + for i in iter(arr.tobytes(order='A')) ] constary = lc.Constant.array(Type.int(8), constvals) diff --git a/numba/cuda/simulator/cudadrv/devicearray.py b/numba/cuda/simulator/cudadrv/devicearray.py index b0006be40cd..c36890b30c2 100644 --- a/numba/cuda/simulator/cudadrv/devicearray.py +++ b/numba/cuda/simulator/cudadrv/devicearray.py @@ -7,7 +7,7 @@ import numpy as np -from numba import six, types, numpy_support +from numba import types, numpy_support DeviceRecord = None from_record_like = None @@ -30,7 +30,7 @@ class FakeShape(tuple): negative indexing) ''' def __getitem__(self, k): - if isinstance(k, six.integer_types) and k < 0: + if isinstance(k, int) and k < 0: raise IndexError('tuple index out of range') return super(FakeShape, self).__getitem__(k) @@ -62,8 +62,8 @@ def __getattr__(self, attrname): attr = getattr(self._ary, attrname) return attr except AttributeError as e: - six.raise_from(AttributeError("Wrapped array has no attribute '%s'" - % attrname), e) + msg = "Wrapped array has no attribute '%s'" % attrname + raise AttributeError(msg) from e def bind(self, stream=0): return FakeCUDAArray(self._ary, stream) @@ -278,7 +278,7 @@ def requires_attr(attr, typ): requires_attr('shape', tuple) requires_attr('strides', tuple) requires_attr('dtype', np.dtype) - requires_attr('size', six.integer_types) + requires_attr('size', int) def require_cuda_ndarray(obj): diff --git a/numba/cuda/simulator/kernel.py b/numba/cuda/simulator/kernel.py index aa44f675a07..95c1f2cfde9 100644 --- a/numba/cuda/simulator/kernel.py +++ b/numba/cuda/simulator/kernel.py @@ -1,6 +1,7 @@ from __future__ import print_function from contextlib import contextmanager +from functools import reduce import sys import threading @@ -71,7 +72,7 @@ def __call__(self, *args): def fake_arg(arg): # map the arguments using any extension you've registered - _, arg = six.moves.reduce( + _, arg = reduce( lambda ty_val, extension: extension.prepare_args( *ty_val, stream=0, diff --git a/numba/cuda/simulator/reduction.py b/numba/cuda/simulator/reduction.py index d6189661ace..d00f325d856 100644 --- a/numba/cuda/simulator/reduction.py +++ b/numba/cuda/simulator/reduction.py @@ -1,4 +1,4 @@ -from numba.six.moves import reduce as pyreduce +from functools import reduce as pyreduce def Reduce(func): def reduce_wrapper(seq, res=None, init=0): diff --git a/numba/dispatcher.py b/numba/dispatcher.py index 7cedecb727c..3521e6e540c 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -7,6 +7,7 @@ import os import struct import sys +import types import uuid import weakref from copy import deepcopy @@ -683,7 +684,7 @@ def __get__(self, obj, objtype=None): if obj is None: # Unbound method return self else: # Bound method - return create_bound_method(self, obj) + return types.MethodType(self, obj) def __reduce__(self): """ diff --git a/numba/interpreter.py b/numba/interpreter.py index b8baee4ee2d..c2de7bcd9ba 100644 --- a/numba/interpreter.py +++ b/numba/interpreter.py @@ -5,7 +5,7 @@ import operator import logging -from . import config, ir, controlflow, dataflow, utils, errors, six +from . import config, ir, controlflow, dataflow, utils, errors from .utils import builtins, PYVERSION from .errors import NotDefinedError from .utils import ( @@ -377,7 +377,7 @@ def _dispatch(self, inst, kws): err = errors.NotDefinedError(e.name, loc=loc) if not config.FULL_TRACEBACKS: - six.raise_from(err, None) + raise value from None else: raise err diff --git a/numba/ir.py b/numba/ir.py index 3d6cf353d22..d591b87dc42 100644 --- a/numba/ir.py +++ b/numba/ir.py @@ -16,7 +16,7 @@ from .utils import BINOPS_TO_OPERATORS, INPLACE_BINOPS_TO_OPERATORS, UNARY_BUITINS_TO_OPERATORS, OPERATORS_TO_BUILTINS from .errors import (NotDefinedError, RedefinedError, VerificationError, ConstantInferenceError) -from .six import StringIO +from io import StringIO # terminal color markup _termcolor = errors.termcolor() @@ -1447,7 +1447,6 @@ def get_assignee(self, rhs_value, in_blocks=None): def dump(self, file=None): - from numba.six import StringIO nofile = file is None # Avoid early bind of sys.stdout as default value file = file or StringIO() diff --git a/numba/ir_utils.py b/numba/ir_utils.py index bb5c31e25a7..162adfa7424 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -14,7 +14,6 @@ from llvmlite import ir as lir import numba -from numba.six import exec_ from numba import ir, types, typing, config, analysis, utils, cgutils, rewrites from numba.typing.templates import signature, infer_global, AbstractTemplate from numba.targets.imputils import impl_ret_untracked @@ -1621,7 +1620,7 @@ def _create_function_from_code_obj(fcode, func_env, func_arg, func_clo, glbls): func_text = "def g():\n%s\n def f(%s):\n return (%s)\n return f" % ( func_env, func_arg, func_clo) loc = {} - exec_(func_text, glbls, loc) + exec(func_text, glbls, loc) # hack parameter name .0 for Python 3 versions < 3.6 if utils.PYVERSION >= (3,) and utils.PYVERSION < (3, 6): diff --git a/numba/jitclass/base.py b/numba/jitclass/base.py index 185b64db914..3c2f825f02e 100644 --- a/numba/jitclass/base.py +++ b/numba/jitclass/base.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, print_function from collections import OrderedDict +from collections.abc import Sequence import types as pytypes import inspect import operator @@ -14,7 +15,6 @@ from numba.datamodel import default_manager, models from numba.targets import imputils from numba import cgutils, utils, errors -from numba.six import exec_, Sequence from . import _box @@ -109,7 +109,7 @@ def _set_init(cls): cls._ctor_sig = init_sig ctor_source = _ctor_template.format(args=', '.join(args)) glbls = {"__numba_cls_": cls} - exec_(ctor_source, glbls) + exec(ctor_source, glbls) ctor = glbls['ctor'] cls._ctor = njit(ctor) diff --git a/numba/jitclass/boxing.py b/numba/jitclass/boxing.py index 06994426ebf..2c6d634524e 100644 --- a/numba/jitclass/boxing.py +++ b/numba/jitclass/boxing.py @@ -11,7 +11,6 @@ from numba import types, cgutils from numba.pythonapi import box, unbox, NativeValue from numba import njit -from numba.six import exec_ from . import _box @@ -37,7 +36,7 @@ def _generate_property(field, template, fname): """ source = template.format(field) glbls = {} - exec_(source, glbls) + exec(source, glbls) return njit(glbls[fname]) @@ -54,7 +53,7 @@ def _generate_method(name, func): """ source = _method_code_template.format(method=name) glbls = {} - exec_(source, glbls) + exec(source, glbls) method = njit(glbls['method']) @wraps(func) diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index ae5ebf77d4c..3fe545cf7bc 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -8,7 +8,7 @@ import numpy as np import operator -from .. import compiler, ir, types, rewrites, six, utils +from .. import compiler, ir, types, rewrites, utils from ..typing import npydecl from .dufunc import DUFunc @@ -368,7 +368,7 @@ def _lower_array_expr(lowerer, expr): # 2. Compile the AST module and extract the Python function. code_obj = compile(ast_module, expr_filename, 'exec') - six.exec_(code_obj, namespace) + exec(code_obj, namespace) impl = namespace[expr_name] # 3. Now compile a ufunc using the Python function as kernel. diff --git a/numba/npyufunc/deviceufunc.py b/numba/npyufunc/deviceufunc.py index eb63f83ef39..e5ccc58dce6 100644 --- a/numba/npyufunc/deviceufunc.py +++ b/numba/npyufunc/deviceufunc.py @@ -10,7 +10,6 @@ import numpy as np -from numba.six import exec_ from numba.utils import longint from numba.utils import IS_PY3 from numba.npyufunc.ufuncbuilder import _BaseUFuncBuilder, parse_identity @@ -403,7 +402,7 @@ def add(self, sig=None, argtypes=None, restype=None): corefn, return_type = self._compile_core(devfnsig) glbl = self._get_globals(corefn) sig = signature(types.void, *([a[:] for a in args] + [return_type[:]])) - exec_(kernelsource, glbl) + exec(kernelsource, glbl) stager = glbl['__vectorized_%s' % funcname] kernel = self._compile_kernel(stager, sig) @@ -480,7 +479,7 @@ def add(self, sig=None, argtypes=None, restype=None): glbls = self._get_globals(sig) - exec_(src, glbls) + exec(src, glbls) fnobj = glbls['__gufunc_{name}'.format(name=funcname)] outertys = list(_determine_gufunc_outer_types(args, indims + outdims)) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index e13b5c07028..b53466f18c8 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -25,7 +25,6 @@ from ..typing import signature from numba import config from numba.targets.cpu import ParallelOptions -from numba.six import exec_ from numba.parfor import print_wrapped, ensure_parallel_support import types as pytypes import operator @@ -1005,7 +1004,7 @@ def _create_gufunc_for_parfor_body( # Force gufunc outline into existence. globls = {"np": np} locls = {} - exec_(gufunc_txt, globls, locls) + exec(gufunc_txt, globls, locls) gufunc_func = locls[gufunc_name] if config.DEBUG_ARRAY_OPT: diff --git a/numba/pycc/decorators.py b/numba/pycc/decorators.py index b2e81f8a42f..a5621d00041 100644 --- a/numba/pycc/decorators.py +++ b/numba/pycc/decorators.py @@ -5,7 +5,6 @@ from numba import sigutils, typing from .compiler import ExportEntry -from numba.six import exec_ # Registry is okay to be a global because we are using pycc as a standalone # commandline tool. @@ -44,7 +43,7 @@ def process_input_files(inputs): """ for ifile in inputs: with open(ifile) as fin: - exec_(compile(fin.read(), ifile, 'exec')) + exec(compile(fin.read(), ifile, 'exec')) def clear_export_registry(): diff --git a/numba/roc/hsadrv/driver.py b/numba/roc/hsadrv/driver.py index 788b3e9c918..3d6970cc9e2 100644 --- a/numba/roc/hsadrv/driver.py +++ b/numba/roc/hsadrv/driver.py @@ -3,6 +3,7 @@ """ from __future__ import absolute_import, print_function, division +from collections.abc import Sequence import sys import atexit @@ -22,7 +23,6 @@ from .error import HsaSupportError, HsaDriverError, HsaApiError from . import enums, enums_ext, drvapi from numba.utils import longint as long -from numba.six import Sequence import numpy as np diff --git a/numba/six.py b/numba/six.py index 6604866712e..f6f619d1f5a 100644 --- a/numba/six.py +++ b/numba/six.py @@ -229,7 +229,6 @@ class _MovedItems(_LazyModule): _moved_attributes = [ - MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"), MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), diff --git a/numba/special.py b/numba/special.py index 698be36a103..b3d344819c6 100644 --- a/numba/special.py +++ b/numba/special.py @@ -31,7 +31,7 @@ def _gdb_python_call_gen(func_name, *args): defn = """def _gdb_func_injection():\n\t%s(%s)\n """ % (func_name, argstr) l = {} - numba.six.exec_(defn, {func_name: fn}, l) + exec(defn, {func_name: fn}, l) return numba.njit(l['_gdb_func_injection']) diff --git a/numba/stencil.py b/numba/stencil.py index f2f4a52a9d8..ca075b455fa 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -16,7 +16,6 @@ from numba.targets import registry from numba.targets.imputils import lower_builtin from numba.extending import register_jitable -from numba.six import exec_ import numba import operator @@ -397,7 +396,7 @@ def _type_me(self, argtys, kwtys): sig = signature(real_ret, *argtys_extra) dummy_text = ("def __numba_dummy_stencil({}{}):\n pass\n".format( ",".join(self.kernel_ir.arg_names), sig_extra)) - exec_(dummy_text) in globals(), locals() + exec(dummy_text) in globals(), locals() dummy_func = eval("__numba_dummy_stencil") sig.pysig = utils.pysignature(dummy_func) self._targetctx.insert_func_defn([(self._lower_me, self, argtys_extra)]) @@ -633,7 +632,7 @@ def _stencil_wrapper(self, result, sigret, return_type, typemap, calltypes, *arg print(func_text) # Force the new stencil function into existence. - exec_(func_text) in globals(), locals() + exec(func_text) in globals(), locals() stencil_func = eval(stencil_func_name) if sigret is not None: pysig = utils.pysignature(stencil_func) diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 1285cd1eba8..8e9944d29c7 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -19,7 +19,6 @@ from numba.ir_utils import (get_call_table, mk_unique_var, compile_to_numba_ir, replace_arg_nodes, guard, find_callname, require, find_const, GuardException) -from numba.six import exec_ from numba.utils import OPERATORS_TO_BUILTINS @@ -625,7 +624,7 @@ def _add_offset_to_slice(self, slice_var, offset_var, out_nodes, scope, return slice({} + offset, {} + offset) """.format(slice_var.start, slice_var.stop) loc = {} - exec_(f_text, {}, loc) + exec(f_text, {}, loc) f = loc['f'] args = [offset_var] arg_typs = (types.intp,) diff --git a/numba/targets/slicing.py b/numba/targets/slicing.py index 3c7cbc3e002..ca3ef6632b3 100644 --- a/numba/targets/slicing.py +++ b/numba/targets/slicing.py @@ -2,11 +2,10 @@ Implement slices and various slice computations. """ -import itertools +from itertools import zip_longest from llvmlite import ir -from numba.six.moves import zip_longest from numba import cgutils, types, typing, utils from .imputils import (lower_builtin, lower_getattr, iternext_impl, impl_ret_borrowed, diff --git a/numba/tests/serialize_usecases.py b/numba/tests/serialize_usecases.py index bfc99e4a0d4..ade941daac1 100644 --- a/numba/tests/serialize_usecases.py +++ b/numba/tests/serialize_usecases.py @@ -6,7 +6,6 @@ import math from numba import jit, generated_jit, types -from numba.six import exec_ @jit((types.int32, types.int32)) @@ -107,7 +106,7 @@ def dyn_func(x): return res """ ns = {} - exec_(code.strip(), ns) + exec(code.strip(), ns) return jit(**jit_args)(ns['dyn_func']) dyn_func = _get_dyn_func(nopython=True) diff --git a/numba/tests/support.py b/numba/tests/support.py index 98ec9332a1b..08f39b13563 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -32,7 +32,6 @@ from numba.targets import cpu import numba.unittest_support as unittest from numba.runtime import rtsys -from numba.six import PY2 enable_pyobj_flags = Flags() @@ -446,14 +445,6 @@ def run_nullary_func(self, pyfunc, flags): self.assertPreciseEqual(got, expected) return got, expected - if PY2: - @contextmanager - def subTest(self, *args, **kwargs): - """A stub TestCase.subTest backport. - This implementation is a no-op. - """ - yield - class SerialMixin(object): """Mixin to mark test for serial execution. diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index fbac99fdcd5..266a35eeee1 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -10,7 +10,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import jit, typeof, errors, types, utils, config, njit -from numba.six import PY2 from .support import TestCase, tag @@ -1045,9 +1044,7 @@ def func(a, b): # all these things should evaluate to being equal or not, all should # survive typing. - things = (1, 0, True, False, 1.0, 2.0, 1.1, 1j, None,) - if not PY2: - things = things + ("", "1") + things = (1, 0, True, False, 1.0, 2.0, 1.1, 1j, None, "", "1") for x, y in itertools.product(things, things): self.assertPreciseEqual(func.py_func(x, y), func(x, y)) diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 6df73656215..44b79104877 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -8,7 +8,6 @@ from numba import njit, jit, testing, utils from numba.errors import TypingError, UnsupportedError from .support import TestCase, tag -from numba.six import exec_ class TestClosure(TestCase): @@ -174,7 +173,7 @@ def inner(x): return inner(x) + inner(x) + z """ ns = {} - exec_(code.strip(), ns) + exec(code.strip(), ns) cfunc = njit(ns['outer']) self.assertEqual(cfunc(10), ns['outer'](10)) diff --git a/numba/tests/test_dyn_func.py b/numba/tests/test_dyn_func.py index 54f22ee6a8b..5c499bf4722 100644 --- a/numba/tests/test_dyn_func.py +++ b/numba/tests/test_dyn_func.py @@ -4,7 +4,6 @@ import numba from .support import TestCase -from numba.six import exec_ class Issue455(object): @@ -23,7 +22,7 @@ def f(x): x[i] = 1. """ d = {} - exec_(code.strip(), d) + exec(code.strip(), d) self.f.append(numba.jit("void(f8[:])", nopython=True)(d['f'])) def call_f(self): diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index 11697d62dc8..77d49ccd30d 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -7,7 +7,7 @@ import numpy as np -from numba.six.moves import builtins +import builtins from numba import types, utils from .support import TestCase, temp_directory from numba.help.inspector import inspect_function, inspect_module diff --git a/numba/tests/test_listimpl.py b/numba/tests/test_listimpl.py index ad9336259ed..8b6c0eb135c 100644 --- a/numba/tests/test_listimpl.py +++ b/numba/tests/test_listimpl.py @@ -8,7 +8,6 @@ from .support import TestCase from numba import _helperlib -from numba.six import b LIST_OK = 0 diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 2b0f4a3e5e2..27ac00be22e 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -23,7 +23,7 @@ from .test_parfors import skip_unsupported as parfors_skip_unsupported from .test_parfors import linux_only -from numba.six.moves import queue as t_queue +import queue as t_queue from numba.testing.main import _TIMEOUT as _RUNNER_TIMEOUT _TEST_TIMEOUT = _RUNNER_TIMEOUT - 60. diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index 4d982bc0bf6..78b558ead63 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -12,7 +12,6 @@ from numba import jit, types, utils, njit, errors import numba.unittest_support as unittest from numba import testing -from numba.six import PY2 from .support import TestCase, MemoryLeakMixin, tag from numba.targets.quicksort import make_py_quicksort, make_jit_quicksort @@ -20,9 +19,6 @@ from .timsort import make_py_timsort, make_jit_timsort, MergeRun -skip_py_27 = unittest.skipIf(PY2, "Not supported on Python 2") - - def make_temp_list(keys, n): return [keys[0]] * n @@ -986,7 +982,6 @@ def closure_escapee_key(z): self.assertPreciseEqual(gen(njit)(a[:]), gen(nop_compiler)(a[:])) - @skip_py_27 def test_04(self): a = ['a','b','B','b','C','A'] @@ -1005,7 +1000,6 @@ def foo(x, key=None): self.assertPreciseEqual(foo(a[:], external_key), foo.py_func(a[:], external_key)) - @skip_py_27 def test_05(self): a = ['a','b','B','b','C','A'] diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 11d9684d86c..7ea73f50357 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -13,7 +13,6 @@ from numba import prange, njit, unittest_support as unittest from numba.targets import cpu from numba.compiler import compile_isolated, Flags -from numba.six import exec_ from .support import TestCase, tag, override_env_config needs_svml = unittest.skipUnless(numba.config.USING_SVML, @@ -166,7 +165,7 @@ def combo_svml_usecase(dtype, mode, vlen, flags): body += " "*8 + "return ret" # now compile and return it along with its body in __doc__ and patterns ldict = {} - exec_(body, globals(), ldict) + exec(body, globals(), ldict) ldict[name].__doc__ = body return ldict[name], contains, avoids diff --git a/numba/tests/test_tracing.py b/numba/tests/test_tracing.py index 528efeb5976..3a23b5594ed 100644 --- a/numba/tests/test_tracing.py +++ b/numba/tests/test_tracing.py @@ -1,7 +1,6 @@ import numba.unittest_support as unittest from numba import tracing from numba.utils import StringIO -from numba.six import with_metaclass import logging logger = logging.getLogger('trace') diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index 45623a0022f..feb3ab62f35 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -18,7 +18,6 @@ from numba.config import PYVERSION from numba.errors import LoweringError, TypingError from .support import TestCase, CompilationCache, MemoryLeakMixin, tag -from numba.six import exec_, string_types from numba.typing.npydecl import supported_ufuncs, all_ufuncs is32bits = tuple.__itemsize__ == 4 @@ -55,7 +54,7 @@ def _make_ufunc_usecase(ufunc): ldict = {} arg_str = ','.join(['a{0}'.format(i) for i in range(ufunc.nargs)]) func_str = 'def fn({0}):\n np.{1}({0})'.format(arg_str, ufunc.__name__) - exec_(func_str, globals(), ldict) + exec(func_str, globals(), ldict) fn = ldict['fn'] fn.__name__ = '{0}_usecase'.format(ufunc.__name__) return fn @@ -64,7 +63,7 @@ def _make_ufunc_usecase(ufunc): def _make_unary_ufunc_usecase(ufunc): ufunc_name = ufunc.__name__ ldict = {} - exec_("def fn(x,out):\n np.{0}(x,out)".format(ufunc_name), globals(), ldict) + exec("def fn(x,out):\n np.{0}(x,out)".format(ufunc_name), globals(), ldict) fn = ldict["fn"] fn.__name__ = "{0}_usecase".format(ufunc_name) return fn @@ -72,7 +71,7 @@ def _make_unary_ufunc_usecase(ufunc): def _make_unary_ufunc_op_usecase(ufunc_op): ldict = {} - exec_("def fn(x):\n return {0}(x)".format(ufunc_op), globals(), ldict) + exec("def fn(x):\n return {0}(x)".format(ufunc_op), globals(), ldict) fn = ldict["fn"] fn.__name__ = "usecase_{0}".format(hash(ufunc_op)) return fn @@ -81,7 +80,7 @@ def _make_unary_ufunc_op_usecase(ufunc_op): def _make_binary_ufunc_usecase(ufunc): ufunc_name = ufunc.__name__ ldict = {} - exec_("def fn(x,y,out):\n np.{0}(x,y,out)".format(ufunc_name), globals(), ldict); + exec("def fn(x,y,out):\n np.{0}(x,y,out)".format(ufunc_name), globals(), ldict); fn = ldict['fn'] fn.__name__ = "{0}_usecase".format(ufunc_name) return fn @@ -89,7 +88,7 @@ def _make_binary_ufunc_usecase(ufunc): def _make_binary_ufunc_op_usecase(ufunc_op): ldict = {} - exec_("def fn(x,y):\n return x{0}y".format(ufunc_op), globals(), ldict) + exec("def fn(x,y):\n return x{0}y".format(ufunc_op), globals(), ldict) fn = ldict["fn"] fn.__name__ = "usecase_{0}".format(hash(ufunc_op)) return fn @@ -100,9 +99,9 @@ def _make_inplace_ufunc_op_usecase(ufunc_op): ufunc_op can be a string like '+=' or a function like operator.iadd """ - if isinstance(ufunc_op, string_types): + if isinstance(ufunc_op, str): ldict = {} - exec_("def fn(x,y):\n x{0}y".format(ufunc_op), globals(), ldict) + exec("def fn(x,y):\n x{0}y".format(ufunc_op), globals(), ldict) fn = ldict["fn"] fn.__name__ = "usecase_{0}".format(hash(ufunc_op)) else: diff --git a/numba/tests/test_unicode_names.py b/numba/tests/test_unicode_names.py index 62a9cc68ecf..c12be6811b8 100644 --- a/numba/tests/test_unicode_names.py +++ b/numba/tests/test_unicode_names.py @@ -3,7 +3,6 @@ from numba import njit, cfunc, cgutils -from numba.six import exec_ from numba.utils import PY2 from .support import TestCase, unittest @@ -23,7 +22,7 @@ def Ծ_Ծ(ಠ_ರೃ, ಠਊಠ): class TestUnicodeNames(TestCase): def make_testcase(self, src, fname): glb = {} - exec_(src, glb) + exec(src, glb) fn = glb[fname] return fn diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index 04610e87b04..c976c2c61d6 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -1,8 +1,9 @@ """ Python wrapper that connects CPython interpreter to the numba dictobject. """ +from collections.abc import MutableMapping + from numba import config -from numba.six import MutableMapping from numba.types import DictType, TypeRef from numba.targets.imputils import numba_typeref_ctor from numba import njit, dictobject, types, cgutils, errors, typeof diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index 9cff511a2ae..fc792ea7585 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -9,7 +9,8 @@ it should really quack like the CPython `list`. """ -from numba.six import MutableSequence +from collections.abc import MutableSequence + from numba.types import ListType, TypeRef from numba.targets.imputils import numba_typeref_ctor from numba import listobject diff --git a/numba/types/containers.py b/numba/types/containers.py index 544d70c5597..19a13cb2821 100644 --- a/numba/types/containers.py +++ b/numba/types/containers.py @@ -1,6 +1,6 @@ from __future__ import print_function, division, absolute_import -from ..six import Iterable +from collections.abc import Iterable from .abstract import (ConstSized, Container, Hashable, MutableSequence, Sequence, Type, TypeRef) from .common import Buffer, IterableType, SimpleIterableType, SimpleIteratorType diff --git a/numba/typing/context.py b/numba/typing/context.py index f29d3946586..ca7dcad93a3 100644 --- a/numba/typing/context.py +++ b/numba/typing/context.py @@ -1,6 +1,7 @@ from __future__ import print_function, absolute_import from collections import defaultdict +from collections.abc import Sequence import types as pytypes import weakref import threading @@ -14,7 +15,6 @@ from .typeof import typeof, Purpose from numba import utils -from numba.six import Sequence class Rating(object): From 8d6f174dd1e153b4cf9837ca2f9ecc615d87867b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 10:59:16 +0000 Subject: [PATCH 206/595] canonicalise six.add_metaclass --- numba/caching.py | 2 +- numba/compiler_machinery.py | 5 +++-- numba/cuda/simulator/kernel.py | 1 - numba/debuginfo.py | 2 +- numba/dispatcher.py | 2 +- numba/errors.py | 6 +++--- numba/roc/hlc/common.py | 4 ++-- numba/types/abstract.py | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/numba/caching.py b/numba/caching.py index 680ae854af7..0fce53844df 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -17,7 +17,7 @@ import warnings from .appdirs import AppDirs -from .six import add_metaclass +from numba.six import add_metaclass import numba from . import compiler, config, utils diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index db122a4d91e..c6d6dc6ccfc 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -7,7 +7,8 @@ import traceback from numba.compiler_lock import global_compiler_lock from numba import errors -from . import config, utils, transforms, six +from . import config, utils, transforms +from numba.six import add_metaclass from .tracing import event from .postproc import PostProcessor @@ -28,7 +29,7 @@ def __exit__(self, *exc): self.elapsed = timeit.default_timer() - self.ts -@six.add_metaclass(ABCMeta) +@add_metaclass(ABCMeta) class CompilerPass(object): """ The base class for all compiler passes. """ diff --git a/numba/cuda/simulator/kernel.py b/numba/cuda/simulator/kernel.py index 95c1f2cfde9..91bdd6abb22 100644 --- a/numba/cuda/simulator/kernel.py +++ b/numba/cuda/simulator/kernel.py @@ -7,7 +7,6 @@ import numpy as np -from numba import six from numba.six import reraise from .cudadrv.devicearray import to_device, auto_device from .kernelapi import Dim3, FakeCUDAModule, swapped_cuda_module diff --git a/numba/debuginfo.py b/numba/debuginfo.py index e7832f43255..acffc0ab847 100644 --- a/numba/debuginfo.py +++ b/numba/debuginfo.py @@ -9,7 +9,7 @@ from llvmlite import ir -from .six import add_metaclass +from numba.six import add_metaclass @add_metaclass(abc.ABCMeta) diff --git a/numba/dispatcher.py b/numba/dispatcher.py index 3521e6e540c..fb9e63bb604 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -19,7 +19,7 @@ from numba.typing.templates import fold_arguments from numba.typing.typeof import Purpose, typeof from numba.bytecode import get_code_object -from numba.six import create_bound_method, reraise +from numba.six import reraise from .caching import NullCache, FunctionCache diff --git a/numba/errors.py b/numba/errors.py index b232e922b41..d18577c6c06 100644 --- a/numba/errors.py +++ b/numba/errors.py @@ -12,7 +12,7 @@ import numba import numpy as np from collections import defaultdict -from numba import six +from numba.six import add_metaclass, reraise from functools import wraps from abc import abstractmethod @@ -74,7 +74,7 @@ class NumbaTypeSafetyWarning(NumbaWarning): # These are needed in the color formatting of errors setup -@six.add_metaclass(abc.ABCMeta) +@add_metaclass(abc.ABCMeta) class _ColorScheme(object): @abstractmethod @@ -722,7 +722,7 @@ def new_error_context(fmt_, *args, **kwargs): newerr = errcls(e).add_context(_format_msg(fmt_, args, kwargs)) from numba import config tb = sys.exc_info()[2] if config.FULL_TRACEBACKS else None - six.reraise(type(newerr), newerr, tb) + reraise(type(newerr), newerr, tb) __all__ += [name for (name, value) in globals().items() diff --git a/numba/roc/hlc/common.py b/numba/roc/hlc/common.py index 363143bd984..a44e99597b7 100644 --- a/numba/roc/hlc/common.py +++ b/numba/roc/hlc/common.py @@ -5,7 +5,7 @@ from __future__ import print_function, division, absolute_import from abc import abstractmethod, ABCMeta -from numba import six +from numba.six import add_metaclass import re # These are for parsing labels and metadata @@ -106,7 +106,7 @@ def alloca_addrspace_correction(llvmir): return '\n'.join(new_ir) -@six.add_metaclass(ABCMeta) +@add_metaclass(ABCMeta) class _AMDGCNModule(object): """ The AMDCGN LLVM module contract diff --git a/numba/types/abstract.py b/numba/types/abstract.py index 0fb6588eec3..960471f584a 100644 --- a/numba/types/abstract.py +++ b/numba/types/abstract.py @@ -6,7 +6,7 @@ import numpy as np -from ..six import add_metaclass +from numba.six import add_metaclass from ..utils import cached_property From f80790fcf3b2e89b6552a31be11b8f363a09289c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 11:08:33 +0000 Subject: [PATCH 207/595] move out six --- numba/caching.py | 2 +- numba/compiler_machinery.py | 2 +- numba/cuda/args.py | 2 +- numba/cuda/simulator/kernel.py | 2 +- numba/debuginfo.py | 2 +- numba/dispatcher.py | 2 +- numba/errors.py | 2 +- numba/npyufunc/parfor.py | 2 +- numba/{six.py => python_utils.py} | 0 numba/roc/hlc/common.py | 2 +- numba/types/abstract.py | 2 +- numba/utils.py | 2 +- 12 files changed, 11 insertions(+), 11 deletions(-) rename numba/{six.py => python_utils.py} (100%) diff --git a/numba/caching.py b/numba/caching.py index 0fce53844df..9a96ef272a9 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -17,7 +17,7 @@ import warnings from .appdirs import AppDirs -from numba.six import add_metaclass +from numba.python_utils import add_metaclass import numba from . import compiler, config, utils diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index c6d6dc6ccfc..a9c1c701ecf 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -8,7 +8,7 @@ from numba.compiler_lock import global_compiler_lock from numba import errors from . import config, utils, transforms -from numba.six import add_metaclass +from numba.python_utils import add_metaclass from .tracing import event from .postproc import PostProcessor diff --git a/numba/cuda/args.py b/numba/cuda/args.py index 2a2c4764146..7600ba1d43f 100644 --- a/numba/cuda/args.py +++ b/numba/cuda/args.py @@ -4,7 +4,7 @@ """ import abc -from numba.six import add_metaclass +from numba.python_utils import add_metaclass from numba.typing.typeof import typeof, Purpose diff --git a/numba/cuda/simulator/kernel.py b/numba/cuda/simulator/kernel.py index 91bdd6abb22..83abef99436 100644 --- a/numba/cuda/simulator/kernel.py +++ b/numba/cuda/simulator/kernel.py @@ -7,7 +7,7 @@ import numpy as np -from numba.six import reraise +from numba.python_utils import reraise from .cudadrv.devicearray import to_device, auto_device from .kernelapi import Dim3, FakeCUDAModule, swapped_cuda_module from ..errors import normalize_kernel_dimensions diff --git a/numba/debuginfo.py b/numba/debuginfo.py index acffc0ab847..0b0c368360e 100644 --- a/numba/debuginfo.py +++ b/numba/debuginfo.py @@ -9,7 +9,7 @@ from llvmlite import ir -from numba.six import add_metaclass +from numba.python_utils import add_metaclass @add_metaclass(abc.ABCMeta) diff --git a/numba/dispatcher.py b/numba/dispatcher.py index fb9e63bb604..9ca9543a885 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -19,7 +19,7 @@ from numba.typing.templates import fold_arguments from numba.typing.typeof import Purpose, typeof from numba.bytecode import get_code_object -from numba.six import reraise +from numba.python_utils import reraise from .caching import NullCache, FunctionCache diff --git a/numba/errors.py b/numba/errors.py index d18577c6c06..3f76a14a12e 100644 --- a/numba/errors.py +++ b/numba/errors.py @@ -12,7 +12,7 @@ import numba import numpy as np from collections import defaultdict -from numba.six import add_metaclass, reraise +from numba.python_utils import add_metaclass, reraise from functools import wraps from abc import abstractmethod diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index b53466f18c8..1f74e84795a 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -12,7 +12,7 @@ import llvmlite.ir.values as liv import numba -from .. import compiler, ir, types, six, cgutils, sigutils, lowering, parfor +from .. import compiler, ir, types, cgutils, sigutils, lowering, parfor from numba.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, diff --git a/numba/six.py b/numba/python_utils.py similarity index 100% rename from numba/six.py rename to numba/python_utils.py diff --git a/numba/roc/hlc/common.py b/numba/roc/hlc/common.py index a44e99597b7..b690ce9f03f 100644 --- a/numba/roc/hlc/common.py +++ b/numba/roc/hlc/common.py @@ -5,7 +5,7 @@ from __future__ import print_function, division, absolute_import from abc import abstractmethod, ABCMeta -from numba.six import add_metaclass +from numba.python_utils import add_metaclass import re # These are for parsing labels and metadata diff --git a/numba/types/abstract.py b/numba/types/abstract.py index 960471f584a..4a13f9b4cf1 100644 --- a/numba/types/abstract.py +++ b/numba/types/abstract.py @@ -6,7 +6,7 @@ import numpy as np -from numba.six import add_metaclass +from numba.python_utils import add_metaclass from ..utils import cached_property diff --git a/numba/utils.py b/numba/utils.py index 5e5cfceccd9..5da6a4ddb3d 100644 --- a/numba/utils.py +++ b/numba/utils.py @@ -15,7 +15,7 @@ from types import ModuleType import numpy as np -from .six import * +from .python_utils import * from .errors import UnsupportedError try: # preferred over pure-python StringIO due to threadsafety From 775a58a70d5ab248d9e79bf4358ae5aa605dd29d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 11:12:35 +0000 Subject: [PATCH 208/595] Fix up failing tests --- numba/dispatcher.py | 4 ++-- numba/tests/test_listimpl.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/numba/dispatcher.py b/numba/dispatcher.py index 9ca9543a885..c0864bce562 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -7,7 +7,7 @@ import os import struct import sys -import types +import types as pytypes import uuid import weakref from copy import deepcopy @@ -684,7 +684,7 @@ def __get__(self, obj, objtype=None): if obj is None: # Unbound method return self else: # Bound method - return types.MethodType(self, obj) + return pytypes.MethodType(self, obj) def __reduce__(self): """ diff --git a/numba/tests/test_listimpl.py b/numba/tests/test_listimpl.py index 8b6c0eb135c..68c2d0d013f 100644 --- a/numba/tests/test_listimpl.py +++ b/numba/tests/test_listimpl.py @@ -407,7 +407,8 @@ def check_sizing(self, item_size, nmax): l = List(self, item_size, 0) def make_item(v): - return b("{:0{}}".format(nmax - v - 1, item_size)[:item_size]) + tmp = "{:0{}}".format(nmax - v - 1, item_size).encode("latin-1") + return tmp[:item_size] for i in range(nmax): l.append(make_item(i)) From b2a5e69effab72703b4ed86145e093126bbffbaf Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 11:25:49 +0000 Subject: [PATCH 209/595] Fix up utils --- .flake8 | 2 +- docs/source/developer/repomap.rst | 2 - numba/python_utils.py | 46 +++---- numba/utils.py | 202 +++++------------------------- 4 files changed, 58 insertions(+), 194 deletions(-) diff --git a/.flake8 b/.flake8 index 2aa8f2d36a8..003d5fc85e5 100644 --- a/.flake8 +++ b/.flake8 @@ -35,6 +35,7 @@ exclude = numba/inline_closurecall.py numba/ir_utils.py numba/pylowering.py + numba/python_utils.py numba/io_support.py numba/parfor.py numba/numba_entry.py @@ -48,7 +49,6 @@ exclude = numba/cffi_support.py numba/interpreter.py numba/caching.py - numba/utils.py numba/debuginfo.py numba/pretty_annotate.py numba/six.py diff --git a/docs/source/developer/repomap.rst b/docs/source/developer/repomap.rst index 39822cab7cd..31fffaa77ec 100644 --- a/docs/source/developer/repomap.rst +++ b/docs/source/developer/repomap.rst @@ -240,8 +240,6 @@ Misc Support data structures - :ghfile:`numba/cgutils.py` - Utility functions for generating common code patterns in LLVM IR -- :ghfile:`numba/six.py` - Vendored subset of ``six`` package for Python 2 + - 3 compatibility - :ghfile:`numba/io_support.py` - Workaround for various names of StringIO in different Python versions (should this be in six?) - :ghfile:`numba/utils.py` - Python 2 backports of Python 3 functionality diff --git a/numba/python_utils.py b/numba/python_utils.py index f6f619d1f5a..77a93d66a26 100644 --- a/numba/python_utils.py +++ b/numba/python_utils.py @@ -32,11 +32,35 @@ __author__ = "Benjamin Peterson " __version__ = "1.9.0" - # Useful for very coarse version differentiation. PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 + +def reraise(tp, value, tb=None): + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + + +def add_metaclass(metaclass): + """Class decorator for creating a class with a metaclass.""" + def wrapper(cls): + orig_vars = cls.__dict__.copy() + slots = orig_vars.get('__slots__') + if slots is not None: + if isinstance(slots, str): + slots = [slots] + for slots_var in slots: + orig_vars.pop(slots_var) + orig_vars.pop('__dict__', None) + orig_vars.pop('__weakref__', None) + return metaclass(cls.__name__, cls.__bases__, orig_vars) + return wrapper + + if PY3: string_types = str, integer_types = int, @@ -660,12 +684,6 @@ def assertRegex(self, *args, **kwargs): exec_ = getattr(moves.builtins, "exec") - def reraise(tp, value, tb=None): - if value is None: - value = tp() - if value.__traceback__ is not tb: - raise value.with_traceback(tb) - raise value else: def exec_(_code_, _globs_=None, _locs_=None): @@ -797,20 +815,6 @@ def __new__(cls, name, this_bases, d): return type.__new__(metaclass, 'temporary_class', (), {}) -def add_metaclass(metaclass): - """Class decorator for creating a class with a metaclass.""" - def wrapper(cls): - orig_vars = cls.__dict__.copy() - slots = orig_vars.get('__slots__') - if slots is not None: - if isinstance(slots, str): - slots = [slots] - for slots_var in slots: - orig_vars.pop(slots_var) - orig_vars.pop('__dict__', None) - orig_vars.pop('__weakref__', None) - return metaclass(cls.__name__, cls.__bases__, orig_vars) - return wrapper def python_2_unicode_compatible(klass): diff --git a/numba/utils.py b/numba/utils.py index 5da6a4ddb3d..cbc8808064d 100644 --- a/numba/utils.py +++ b/numba/utils.py @@ -1,11 +1,10 @@ from __future__ import print_function, division, absolute_import import atexit -import collections +import builtins import functools -import io -import itertools import os +import operator import threading import timeit import math @@ -13,156 +12,32 @@ import traceback import weakref from types import ModuleType +from collections.abc import Mapping import numpy as np +from inspect import signature as pysignature # noqa: F401 +from inspect import Signature as pySignature # noqa: F401 +from inspect import Parameter as pyParameter # noqa: F401 + from .python_utils import * -from .errors import UnsupportedError -try: - # preferred over pure-python StringIO due to threadsafety - # note: parallel write to StringIO could cause data to go missing - from cStringIO import StringIO -except ImportError: - from io import StringIO -from numba.config import PYVERSION, MACHINE_BITS, DEVELOPER_MODE - - -IS_PY3 = PYVERSION >= (3, 0) - -if IS_PY3: - import builtins - INT_TYPES = (int,) - longint = int - get_ident = threading.get_ident - intern = sys.intern - file_replace = os.replace - asbyteint = int - - def erase_traceback(exc_value): - """ - Erase the traceback and hanging locals from the given exception instance. - """ - if exc_value.__traceback__ is not None: - traceback.clear_frames(exc_value.__traceback__) - return exc_value.with_traceback(None) - -else: - import thread - import __builtin__ as builtins - INT_TYPES = (int, long) - longint = long - get_ident = thread.get_ident - intern = intern - def asbyteint(x): - # convert 1-char str into int - return ord(x) - - if sys.platform == 'win32': - def file_replace(src, dest): - # Best-effort emulation of os.replace() - try: - os.rename(src, dest) - except OSError: - os.unlink(dest) - os.rename(src, dest) - else: - file_replace = os.rename - - def erase_traceback(exc_value): - """ - Erase the traceback and hanging locals from the given exception instance. - """ - return exc_value - -try: - from inspect import signature as pysignature - from inspect import Signature as pySignature - from inspect import Parameter as pyParameter -except ImportError: - try: - from funcsigs import signature as _pysignature - from funcsigs import Signature as pySignature - from funcsigs import Parameter as pyParameter - from funcsigs import BoundArguments - - def pysignature(*args, **kwargs): - try: - return _pysignature(*args, **kwargs) - except ValueError as e: - msg = ("Cannot obtain a signature for: %s. The error message " - "from funcsigs was: '%s'." % (args, e.message)) - raise UnsupportedError(msg) - - # monkey patch `apply_defaults` onto `BoundArguments` cf inspect in py3 - # This patch is from https://github.com/aliles/funcsigs/pull/30/files - # with minor modifications, and thanks! - # See LICENSES.third-party. - def apply_defaults(self): - arguments = self.arguments - - # Creating a new one and not modifying in-place for thread safety. - new_arguments = [] - - for name, param in self._signature.parameters.items(): - try: - new_arguments.append((name, arguments[name])) - except KeyError: - if param.default is not param.empty: - val = param.default - elif param.kind is _VAR_POSITIONAL: - val = () - elif param.kind is _VAR_KEYWORD: - val = {} - else: - # BoundArguments was likely created by bind_partial - continue - new_arguments.append((name, val)) - - self.arguments = collections.OrderedDict(new_arguments) - BoundArguments.apply_defaults = apply_defaults - except ImportError: - raise ImportError("please install the 'funcsigs' package " - "('pip install funcsigs')") - -try: - from functools import singledispatch -except ImportError: - try: - import singledispatch - except ImportError: - raise ImportError("please install the 'singledispatch' package " - "('pip install singledispatch')") - else: - # Hotfix for https://bitbucket.org/ambv/singledispatch/issues/8/inconsistent-hierarchy-with-enum - def _c3_merge(sequences): - """Merges MROs in *sequences* to a single MRO using the C3 algorithm. - - Adapted from http://www.python.org/download/releases/2.3/mro/. - - """ - result = [] - while True: - sequences = [s for s in sequences if s] # purge empty sequences - if not sequences: - return result - for s1 in sequences: # find merge candidates among seq heads - candidate = s1[0] - for s2 in sequences: - if candidate in s2[1:]: - candidate = None - break # reject the current head, it appears later - else: - break - if candidate is None: - raise RuntimeError("Inconsistent hierarchy") - result.append(candidate) - # remove the chosen candidate - for seq in sequences: - if seq[0] == candidate: - del seq[0] - - singledispatch._c3_merge = _c3_merge - - singledispatch = singledispatch.singledispatch +from numba.config import PYVERSION, MACHINE_BITS, DEVELOPER_MODE # noqa: F401 + + +INT_TYPES = (int,) +longint = int +get_ident = threading.get_ident +intern = sys.intern +file_replace = os.replace +asbyteint = int + + +def erase_traceback(exc_value): + """ + Erase the traceback and hanging locals from the given exception instance. + """ + if exc_value.__traceback__ is not None: + traceback.clear_frames(exc_value.__traceback__) + return exc_value.with_traceback(None) # Mapping between operator module functions and the corresponding built-in @@ -259,20 +134,13 @@ def _c3_merge(sequences): operator.truth: 'is_true', } -HAS_MATMUL_OPERATOR = sys.version_info >= (3, 5) - -if not IS_PY3: - BINOPS_TO_OPERATORS['/?'] = operator.div - INPLACE_BINOPS_TO_OPERATORS['/?='] = operator.idiv - OPERATORS_TO_BUILTINS[operator.div] = '/?' - OPERATORS_TO_BUILTINS[operator.idiv] = '/?' -if HAS_MATMUL_OPERATOR: - BINOPS_TO_OPERATORS['@'] = operator.matmul - INPLACE_BINOPS_TO_OPERATORS['@='] = operator.imatmul +BINOPS_TO_OPERATORS['@'] = operator.matmul +INPLACE_BINOPS_TO_OPERATORS['@='] = operator.imatmul _shutting_down = False + def _at_shutdown(): global _shutting_down _shutting_down = True @@ -340,7 +208,8 @@ def copy(self): return copy def __eq__(self, other): - return isinstance(other, ConfigOptions) and other._values == self._values + return (isinstance(other, ConfigOptions) and + other._values == self._values) def __ne__(self, other): return not self == other @@ -379,7 +248,7 @@ def __setitem__(self, key, value): # Django's cached_property -# see https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.functional.cached_property +# see https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.functional.cached_property # noqa: E501 class cached_property(object): """ @@ -489,13 +358,6 @@ def benchmark(func, maxsec=1): RANGE_ITER_OBJECTS = (builtins.range,) -if PYVERSION < (3, 0): - RANGE_ITER_OBJECTS += (builtins.xrange,) - try: - from future.types.newrange import newrange - RANGE_ITER_OBJECTS += (newrange,) - except ImportError: - pass def logger_hasHandlers(logger): @@ -516,7 +378,7 @@ def logger_hasHandlers(logger): # A dummy module for dynamically-generated functions _dynamic_modname = '' _dynamic_module = ModuleType(_dynamic_modname) -_dynamic_module.__builtins__ = moves.builtins +_dynamic_module.__builtins__ = builtins def chain_exception(new_exc, old_exc): From 23f7937e559fd244f29a60643265186dc129e3e6 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 12:00:31 +0000 Subject: [PATCH 210/595] remove PY3 guards --- numba/__init__.py | 6 +- numba/compiler_machinery.py | 9 --- numba/cuda/cudaimpl.py | 4 - numba/cuda/tests/cudadrv/test_cuda_memory.py | 4 +- numba/cuda/tests/cudapy/test_intrinsics.py | 3 - numba/lowering.py | 2 +- numba/npyufunc/array_exprs.py | 3 - numba/npyufunc/deviceufunc.py | 1 - numba/parfor.py | 12 +-- numba/pycc/compiler.py | 70 +---------------- numba/pylowering.py | 14 ++-- numba/roc/hlc/hlc.py | 6 +- numba/targets/boxing.py | 19 +---- numba/targets/builtins.py | 12 +-- numba/targets/npdatetime.py | 22 ------ numba/targets/numbers.py | 15 ---- numba/targets/slicing.py | 12 ++- numba/tests/test_array_constants.py | 2 - numba/tests/test_builtins.py | 60 +------------- numba/tests/test_dictobject.py | 14 +--- numba/tests/test_errorhandling.py | 6 +- numba/tests/test_extending.py | 70 +++++++---------- numba/tests/test_flow_control.py | 15 +--- numba/tests/test_func_lifetime.py | 2 - numba/tests/test_hashing.py | 83 +++----------------- numba/tests/test_help.py | 23 +++--- numba/tests/test_listobject.py | 6 -- numba/tests/test_lists.py | 15 +--- numba/tests/test_parfors.py | 16 +--- numba/tests/test_range.py | 1 - numba/tests/test_record_dtype.py | 6 +- numba/tests/test_slices.py | 4 - numba/tests/test_typedlist.py | 15 ---- numba/tests/test_types.py | 14 ++-- numba/tests/test_unicode_array.py | 2 - numba/typing/builtins.py | 39 +++------ numba/typing/npdatetime.py | 13 --- numba/typing/npydecl.py | 6 -- numba/typing/templates.py | 13 +-- numba/typing/typeof.py | 3 +- 40 files changed, 115 insertions(+), 527 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index a04524c28a2..3d6d1d682cc 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -42,10 +42,8 @@ import numba.withcontexts from numba.withcontexts import objmode_context as objmode -# Enable bytes/unicode array support (Python 3.x only) -from .utils import IS_PY3 -if IS_PY3: - import numba.charseq +# Enable bytes/unicode array support +import numba.charseq # Keep this for backward compatibility. test = runtests.main diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index a9c1c701ecf..f81b19d6b25 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -256,15 +256,6 @@ def _patch_error(self, desc, exc): Patches the error to show the stage that it arose in. """ newmsg = "{desc}\n{exc}".format(desc=desc, exc=exc) - - # For python2, attach the traceback of the previous exception. - if not utils.IS_PY3 and config.FULL_TRACEBACKS: - # strip the new message to just print the error string and not - # the marked up source etc (this is handled already). - stripped = _termcolor.errmsg(newmsg.split('\n')[1]) - fmt = "Caused By:\n{tb}\n{newmsg}" - newmsg = fmt.format(tb=traceback.format_exc(), newmsg=stripped) - exc.args = (newmsg,) return exc diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index 923b42f7b30..e66f221fab0 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -11,7 +11,6 @@ from numba.targets.imputils import Registry from numba import cgutils from numba import types -from numba.utils import IS_PY3 from .cudadrv import nvvm from . import nvvmutils, stubs @@ -475,9 +474,6 @@ def ptx_min_f8(context, builder, sig, args): @lower(round, types.f4) @lower(round, types.f8) def ptx_round(context, builder, sig, args): - if not IS_PY3: - raise NotImplementedError( - "round returns a float on Python 2.x") fn = builder.module.get_or_insert_function( lc.Type.function( lc.Type.int(64), diff --git a/numba/cuda/tests/cudadrv/test_cuda_memory.py b/numba/cuda/tests/cudadrv/test_cuda_memory.py index 659be752873..b4da66ac751 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_memory.py +++ b/numba/cuda/tests/cudadrv/test_cuda_memory.py @@ -4,7 +4,6 @@ from numba.cuda.cudadrv import driver, drvapi, devices from numba.cuda.testing import unittest, CUDATestCase -from numba.utils import IS_PY3 from numba.cuda.testing import skip_on_cudasim @@ -37,8 +36,7 @@ def test_host_alloc(self): def test_pinned_memory(self): ary = np.arange(10) - arybuf = ary if IS_PY3 else buffer(ary) - devmem = self.context.mempin(arybuf, ary.ctypes.data, + devmem = self.context.mempin(ary, ary.ctypes.data, ary.size * ary.dtype.itemsize, mapped=True) self._template(devmem) diff --git a/numba/cuda/tests/cudapy/test_intrinsics.py b/numba/cuda/tests/cudapy/test_intrinsics.py index 3dab9f3d034..cd0e717e21b 100644 --- a/numba/cuda/tests/cudapy/test_intrinsics.py +++ b/numba/cuda/tests/cudapy/test_intrinsics.py @@ -4,7 +4,6 @@ import re from numba import cuda, int32, float32 from numba.cuda.testing import unittest, SerialMixin, skip_on_cudasim -from numba.utils import IS_PY3 def simple_threadidx(ary): @@ -381,7 +380,6 @@ def test_simple_warpsize(self): compiled(ary) self.assertEquals(ary[0], 32, "CUDA semantics") - @unittest.skipUnless(IS_PY3, "round() returns float on Py2") def test_round_f4(self): compiled = cuda.jit("void(int64[:], float32)")(simple_round) ary = np.zeros(1, dtype=np.int32) @@ -390,7 +388,6 @@ def test_round_f4(self): compiled(ary, i) self.assertEquals(ary[0], round(i)) - @unittest.skipUnless(IS_PY3, "round() returns float on Py2") def test_round_f8(self): compiled = cuda.jit("void(int64[:], float64)")(simple_round) ary = np.zeros(1, dtype=np.int32) diff --git a/numba/lowering.py b/numba/lowering.py index aea0f31c2fc..a6f3e832e18 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -46,7 +46,7 @@ def __reduce__(self): ) def __del__(self): - if utils is None or utils.IS_PY3: + if utils is None: return if _keepalive is None: return diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index 3fe545cf7bc..c489280bec2 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -250,9 +250,6 @@ def apply(self): operator.floordiv: ast.FloorDiv, } -if not utils.IS_PY3: - _binops[operator.div] = ast.Div - _cmpops = { operator.eq: ast.Eq, diff --git a/numba/npyufunc/deviceufunc.py b/numba/npyufunc/deviceufunc.py index e5ccc58dce6..ad2e24bf65e 100644 --- a/numba/npyufunc/deviceufunc.py +++ b/numba/npyufunc/deviceufunc.py @@ -11,7 +11,6 @@ import numpy as np from numba.utils import longint -from numba.utils import IS_PY3 from numba.npyufunc.ufuncbuilder import _BaseUFuncBuilder, parse_identity from numba import sigutils, types from numba.typing import signature diff --git a/numba/parfor.py b/numba/parfor.py index bcedb4039fe..cc8d3e355f3 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -4176,13 +4176,7 @@ def generic(self, args, kws): def ensure_parallel_support(): """Check if the platform supports parallel=True and raise if it does not. """ - is_win32 = config.IS_WIN32 - is_py2 = not utils.IS_PY3 - is_32bit = config.IS_32BITS - uns1 = is_win32 and is_py2 - uns2 = is_32bit - if uns1 or uns2: - msg = ("The 'parallel' target is not currently supported on " - "Windows operating systems when using Python 2.7, or " - "on 32 bit hardware.") + if config.IS_32BITS: + msg = ("The 'parallel' target is not currently supported on 32 bit " + "hardware.") raise errors.UnsupportedParforsError(msg) diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index 12af538f395..475c3eb5cde 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -10,7 +10,6 @@ import llvmlite.llvmpy.core as lc from numba import cgutils -from numba.utils import IS_PY3 from . import llvm_types as lt from numba.compiler import compile_extra, Flags from numba.compiler_lock import global_compiler_lock @@ -304,72 +303,7 @@ def _emit_module_init_code(self, llvm_module, builder, modobj, return None -class ModuleCompilerPy2(_ModuleCompiler): - - @property - def module_create_definition(self): - """Return the signature and name of the function to initialize the module. - """ - signature = lc.Type.function(lt._pyobject_head_p, - (lt._int8_star, - self.method_def_ptr, - lt._int8_star, - lt._pyobject_head_p, - lt._int32)) - - name = "Py_InitModule4" - - if lt._trace_refs_: - name += "TraceRefs" - if lt._plat_bits == 64: - name += "_64" - - return signature, name - - @property - def module_init_definition(self): - """Return the signature and name of the function to initialize the extension. - """ - return lc.Type.function(lc.Type.void(), ()), "init" + self.module_name - - def _emit_python_wrapper(self, llvm_module): - - # Define the module initialization function. - mod_init_fn = llvm_module.add_function(*self.module_init_definition) - entry = mod_init_fn.append_basic_block('Entry') - builder = lc.Builder(entry) - pyapi = self.context.get_python_api(builder) - - # Python C API module creation function. - create_module_fn = llvm_module.add_function(*self.module_create_definition) - create_module_fn.linkage = lc.LINKAGE_EXTERNAL - - # Define a constant string for the module name. - mod_name_const = self.context.insert_const_string(llvm_module, - self.module_name) - - method_array = self._emit_method_array(llvm_module) - - mod = builder.call(create_module_fn, - (mod_name_const, - method_array, - NULL, - lc.Constant.null(lt._pyobject_head_p), - lc.Constant.int(lt._int32, sys.api_version))) - - env_array = self._emit_environment_array(llvm_module, builder, pyapi) - envgv_array = self._emit_envgvs_array(llvm_module, builder, pyapi) - - self._emit_module_init_code(llvm_module, builder, mod, - method_array, env_array, envgv_array) - # XXX No way to notify failure to caller... - - builder.ret_void() - - self.dll_exports.append(mod_init_fn.name) - - -class ModuleCompilerPy3(_ModuleCompiler): +class ModuleCompiler(_ModuleCompiler): _ptr_fun = lambda ret, *args: lc.Type.pointer(lc.Type.function(ret, args)) @@ -526,5 +460,3 @@ def _emit_python_wrapper(self, llvm_module): self.dll_exports.append(mod_init_fn.name) - -ModuleCompiler = ModuleCompilerPy3 if IS_PY3 else ModuleCompilerPy2 diff --git a/numba/pylowering.py b/numba/pylowering.py index 3ba533b7ddb..e3bafa35ec9 100644 --- a/numba/pylowering.py +++ b/numba/pylowering.py @@ -4,14 +4,15 @@ from __future__ import print_function, division, absolute_import +import builtins +import operator + from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -import operator from . import cgutils, generators, ir, types, utils from .errors import ForbiddenConstruct from .lowering import BaseLower -from .utils import builtins, HAS_MATMUL_OPERATOR, IS_PY3 # Issue #475: locals() is unsupported as calling it naively would give @@ -47,13 +48,8 @@ operator.ixor: ("number_xor", True), } -if not IS_PY3: - PYTHON_BINOPMAP[operator.div] = ("number_divide", False) - PYTHON_BINOPMAP[operator.idiv] = ("number_divide", True) - -if HAS_MATMUL_OPERATOR: - PYTHON_BINOPMAP[operator.matmul] = ("number_matrix_multiply", False) - PYTHON_BINOPMAP[operator.imatmul] = ("number_matrix_multiply", True) +PYTHON_BINOPMAP[operator.matmul] = ("number_matrix_multiply", False) +PYTHON_BINOPMAP[operator.imatmul] = ("number_matrix_multiply", True) PYTHON_COMPAREOPMAP = { operator.eq: '==', diff --git a/numba/roc/hlc/hlc.py b/numba/roc/hlc/hlc.py index 23840f30909..f02ac1dde00 100644 --- a/numba/roc/hlc/hlc.py +++ b/numba/roc/hlc/hlc.py @@ -27,11 +27,7 @@ def error_pipe(): if NOISY_CMDLINE: yield subprocess.STDOUT else: - if utils.IS_PY3: - yield subprocess.DEVNULL - else: - with open(os.devnull, 'wb') as devnull: - yield devnull + yield subprocess.DEVNULL def check_call(*args, **kwargs): diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 78591934a42..12e11f62ed1 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -8,8 +8,6 @@ from ..pythonapi import box, unbox, reflect, NativeValue from . import listobj, setobj -from ..utils import IS_PY3 - # # Scalar types @@ -203,8 +201,6 @@ def cleanup(): c.pyapi.release_buffer(buf) return NativeValue(val, cleanup=cleanup, is_error=is_error) -if IS_PY3: - @box(types.UnicodeCharSeq) def box_unicodecharseq(typ, val, c): # XXX could kind be determined from strptr? @@ -650,17 +646,10 @@ def check_element_type(nth, itemobj, expected_typobj): with c.builder.if_then(type_mismatch, likely=False): c.builder.store(cgutils.true_bit, errorptr) - if IS_PY3: - c.pyapi.err_format( - "PyExc_TypeError", - "can't unbox heterogeneous list: %S != %S", - expected_typobj, typobj, - ) - else: - # Python2 doesn't have "%S" format string. - c.pyapi.err_set_string( - "PyExc_TypeError", - "can't unbox heterogeneous list", + c.pyapi.err_format( + "PyExc_TypeError", + "can't unbox heterogeneous list: %S != %S", + expected_typobj, typobj, ) c.pyapi.decref(typobj) loop.do_break() diff --git a/numba/targets/builtins.py b/numba/targets/builtins.py index 7465793f954..05cde802066 100644 --- a/numba/targets/builtins.py +++ b/numba/targets/builtins.py @@ -195,11 +195,8 @@ def min_vararg(context, builder, sig, args): def _round_intrinsic(tp): - # round() rounds half to even on Python 3, away from zero on Python 2. - if utils.IS_PY3: - return "llvm.rint.f%d" % (tp.bitwidth,) - else: - return "llvm.round.f%d" % (tp.bitwidth,) + # round() rounds half to even + return "llvm.rint.f%d" % (tp.bitwidth,) @lower_builtin(round, types.Float) def round_impl_unary(context, builder, sig, args): @@ -209,9 +206,8 @@ def round_impl_unary(context, builder, sig, args): fnty = Type.function(llty, [llty]) fn = module.get_or_insert_function(fnty, name=_round_intrinsic(fltty)) res = builder.call(fn, args) - if utils.IS_PY3: - # unary round() returns an int on Python 3 - res = builder.fptosi(res, context.get_value_type(sig.return_type)) + # unary round() returns an int + res = builder.fptosi(res, context.get_value_type(sig.return_type)) return impl_ret_untracked(context, builder, sig.return_type, res) @lower_builtin(round, types.Float, types.Integer) diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index 9684c2f834e..5df652e97a9 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -10,8 +10,6 @@ from numba import npdatetime, types, cgutils, numpy_support from .imputils import lower_builtin, lower_constant, impl_ret_untracked -from ..utils import IS_PY3 - # datetime64 and timedelta64 use the same internal representation DATETIME64 = TIMEDELTA64 = Type.int(64) @@ -275,17 +273,6 @@ def timedelta_over_number(context, builder, sig, args): return impl_ret_untracked(context, builder, sig.return_type, res) -if not IS_PY3: - lower_builtin(operator.div, types.NPTimedelta, - types.Integer)(timedelta_over_number) - lower_builtin(operator.idiv, types.NPTimedelta, - types.Integer)(timedelta_over_number) - lower_builtin(operator.div, types.NPTimedelta, - types.Float)(timedelta_over_number) - lower_builtin(operator.idiv, types.NPTimedelta, - types.Float)(timedelta_over_number) - - @lower_builtin(operator.truediv, *TIMEDELTA_BINOP_SIG) @lower_builtin(operator.itruediv, *TIMEDELTA_BINOP_SIG) def timedelta_over_timedelta(context, builder, sig, args): @@ -304,11 +291,6 @@ def timedelta_over_timedelta(context, builder, sig, args): return impl_ret_untracked(context, builder, sig.return_type, res) -if not IS_PY3: - lower_builtin(operator.div, *TIMEDELTA_BINOP_SIG)(timedelta_over_timedelta) - lower_builtin(operator.idiv, * - TIMEDELTA_BINOP_SIG)(timedelta_over_timedelta) - if numpy_support.version >= (1, 16): # np 1.16 added support for: # * np.floor_divide on mm->q @@ -349,10 +331,6 @@ def timedelta_floor_div_timedelta(context, builder, sig, args): res = builder.load(ret) return impl_ret_untracked(context, builder, sig.return_type, res) - if not IS_PY3: - lower_builtin(operator.idiv, * - TIMEDELTA_BINOP_SIG)(timedelta_floor_div_timedelta) - def timedelta_mod_timedelta(context, builder, sig, args): # inspired by https://github.com/numpy/numpy/blob/fe8072a12d65e43bd2e0b0f9ad67ab0108cc54b3/numpy/core/src/umath/loops.c.src#L1424 # alg is basically as `a % b`: diff --git a/numba/targets/numbers.py b/numba/targets/numbers.py index 7df8be9b8e6..6633576cbd2 100644 --- a/numba/targets/numbers.py +++ b/numba/targets/numbers.py @@ -177,11 +177,6 @@ def int_floordiv_impl(context, builder, sig, args): return builder.load(quot) -if not utils.IS_PY3: - lower_builtin(operator.div, types.Integer, types.Integer)(int_floordiv_impl) - lower_builtin(operator.idiv, types.Integer, types.Integer)(int_floordiv_impl) - - @lower_builtin(operator.truediv, types.Integer, types.Integer) @lower_builtin(operator.itruediv, types.Integer, types.Integer) def int_truediv_impl(context, builder, sig, args): @@ -908,11 +903,6 @@ def real_sign_impl(context, builder, sig, args): lower_builtin(operator.ifloordiv, ty, ty)(real_floordiv_impl) lower_builtin(operator.truediv, ty, ty)(real_div_impl) lower_builtin(operator.itruediv, ty, ty)(real_div_impl) - -if not utils.IS_PY3: - lower_builtin(operator.div, ty, ty)(real_div_impl) - lower_builtin(operator.idiv, ty, ty)(real_div_impl) - lower_builtin(operator.mod, ty, ty)(real_mod_impl) lower_builtin(operator.imod, ty, ty)(real_mod_impl) lower_builtin(operator.pow, ty, ty)(real_power_impl) @@ -1165,11 +1155,6 @@ def complex_abs(z): lower_builtin(operator.imul, ty, ty)(complex_mul_impl) lower_builtin(operator.truediv, ty, ty)(complex_div_impl) lower_builtin(operator.itruediv, ty, ty)(complex_div_impl) - -if not utils.IS_PY3: - lower_builtin(operator.div, ty, ty)(complex_div_impl) - lower_builtin(operator.idiv, ty, ty)(complex_div_impl) - lower_builtin(operator.neg, ty)(complex_negate_impl) lower_builtin(operator.pos, ty)(complex_positive_impl) # Complex modulo is deprecated in python3 diff --git a/numba/targets/slicing.py b/numba/targets/slicing.py index ca3ef6632b3..26f2edb8e7f 100644 --- a/numba/targets/slicing.py +++ b/numba/targets/slicing.py @@ -215,13 +215,11 @@ def slice_indices(context, builder, sig, args): length = args[1] sli = context.make_helper(builder, sig.args[0], args[0]) - if utils.IS_PY3: - # Negative values allowed in python2.7, see changelog for python 3.4 - with builder.if_then(cgutils.is_neg_int(builder, length), likely=False): - context.call_conv.return_user_exc( - builder, ValueError, - ("length should not be negative",) - ) + with builder.if_then(cgutils.is_neg_int(builder, length), likely=False): + context.call_conv.return_user_exc( + builder, ValueError, + ("length should not be negative",) + ) with builder.if_then(cgutils.is_scalar_zero(builder, sli.step), likely=False): context.call_conv.return_user_exc( builder, ValueError, diff --git a/numba/tests/test_array_constants.py b/numba/tests/test_array_constants.py index 7b8c4e1f7fd..78a5e39f7fc 100644 --- a/numba/tests/test_array_constants.py +++ b/numba/tests/test_array_constants.py @@ -6,7 +6,6 @@ from numba.compiler import compile_isolated from numba.errors import TypingError from numba import jit, types, typeof -from numba.utils import IS_PY3 a0 = np.array(42) @@ -182,7 +181,6 @@ def pyfunc(): test(f_array) -@unittest.skipUnless(IS_PY3, "Python 3 only") class TestConstantBytes(unittest.TestCase): def test_constant_bytes(self): pyfunc = bytes_as_const_array diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index 266a35eeee1..15a58e5af79 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -334,23 +334,6 @@ def test_chr_npm(self): with self.assertTypingError(): self.test_chr(flags=no_pyobj_flags) - @unittest.skipIf(utils.IS_PY3, "cmp not available as global is Py3") - def test_cmp(self, flags=enable_pyobj_flags): - pyfunc = cmp_usecase - - cr = compile_isolated(pyfunc, (types.int32, types.int32), flags=flags) - cfunc = cr.entry_point - - x_operands = [-1, 0, 1] - y_operands = [-1, 0, 1] - for x, y in itertools.product(x_operands, y_operands): - self.assertPreciseEqual(cfunc(x, y), pyfunc(x, y)) - - @unittest.skipIf(utils.IS_PY3, "cmp not available as global is Py3") - def test_cmp_npm(self): - with self.assertTypingError(): - self.test_cmp(flags=no_pyobj_flags) - def test_complex(self, flags=enable_pyobj_flags): pyfunc = complex_usecase @@ -597,23 +580,6 @@ def test_locals_npm(self): with self.assertTypingError(): self.test_locals(flags=no_pyobj_flags) - @unittest.skipIf(utils.IS_PY3, "long is not available as global is Py3") - def test_long(self, flags=enable_pyobj_flags): - pyfunc = long_usecase - - cr = compile_isolated(pyfunc, (types.string, types.int64), flags=flags) - cfunc = cr.entry_point - - x_operands = ['-1', '0', '1', '10'] - y_operands = [2, 8, 10, 16] - for x, y in itertools.product(x_operands, y_operands): - self.assertPreciseEqual(cfunc(x, y), pyfunc(x, y)) - - @unittest.skipIf(utils.IS_PY3, "cmp not available as global is Py3") - def test_long_npm(self): - with self.assertTypingError(): - self.test_long(flags=no_pyobj_flags) - def test_map(self, flags=enable_pyobj_flags): pyfunc = map_usecase cr = compile_isolated(pyfunc, (types.Dummy('list'), @@ -731,11 +697,7 @@ def check_min_max_invalid_types(self, pyfunc, flags=enable_pyobj_flags): cfunc(1, [1]) def test_max_1_invalid_types(self): - # Heterogeneous ordering is valid in Python 2 - if utils.IS_PY3: - with self.assertRaises(TypeError): - self.check_min_max_invalid_types(max_usecase1) - else: + with self.assertRaises(TypeError): self.check_min_max_invalid_types(max_usecase1) def test_max_1_invalid_types_npm(self): @@ -743,11 +705,7 @@ def test_max_1_invalid_types_npm(self): self.check_min_max_invalid_types(max_usecase1, flags=no_pyobj_flags) def test_min_1_invalid_types(self): - # Heterogeneous ordering is valid in Python 2 - if utils.IS_PY3: - with self.assertRaises(TypeError): - self.check_min_max_invalid_types(min_usecase1) - else: + with self.assertRaises(TypeError): self.check_min_max_invalid_types(min_usecase1) def test_min_1_invalid_types_npm(self): @@ -919,20 +877,6 @@ def check(*args): check(True, 2) check(2.5j, False) - @unittest.skipIf(utils.IS_PY3, "unichr not available as global is Py3") - def test_unichr(self, flags=enable_pyobj_flags): - pyfunc = unichr_usecase - - cr = compile_isolated(pyfunc, (types.int32,), flags=flags) - cfunc = cr.entry_point - for x in range(0, 1000, 10): - self.assertPreciseEqual(cfunc(x), pyfunc(x)) - - @unittest.skipIf(utils.IS_PY3, "unichr not available as global is Py3") - def test_unichr_npm(self): - with self.assertTypingError(): - self.test_unichr(flags=no_pyobj_flags) - def test_zip(self, flags=forceobj_flags): self.run_nullary_func(zip_usecase, flags) diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 79b44e11280..e95bacc49e1 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -17,13 +17,10 @@ from numba import dictobject, typeof from numba.typed import Dict from numba.typedobjectutils import _sentry_safe_cast -from numba.utils import IS_PY3 from numba.errors import TypingError from .support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) -skip_py2 = unittest.skipUnless(IS_PY3, reason='not supported in py2') - class TestDictObject(MemoryLeakMixin, TestCase): def test_dict_bool(self): @@ -668,8 +665,7 @@ def foo(): str(raises.exception), ) - @unittest.skipUnless(utils.IS_PY3 and sys.maxsize > 2 ** 32, - "Python 3, 64 bit test only") + @unittest.skipUnless(sys.maxsize > 2 ** 32, "64 bit test only") def test_007_collision_checks(self): # this checks collisions in real life for 64bit systems @njit @@ -847,7 +843,6 @@ def foo(): print(foo()) - @skip_py2 def test_020_string_key(self): @njit def foo(): @@ -865,7 +860,6 @@ def foo(): self.assertEqual(items, [('a', 1.), ('b', 2.), ('c', 3.), ('d', 4)]) self.assertEqual(da, 1.) - @skip_py2 def test_021_long_str_key(self): @njit def foo(): @@ -1046,7 +1040,7 @@ def test_str(self): class TestDictRefctTypes(MemoryLeakMixin, TestCase): - @skip_py2 + def test_str_key(self): @njit def foo(): @@ -1077,7 +1071,6 @@ def foo(): self.assertEqual(d[str(i)], i) self.assertEqual(dict(d), expect) - @skip_py2 def test_str_val(self): @njit def foo(): @@ -1107,7 +1100,6 @@ def foo(): self.assertEqual(d[i], str(i)) self.assertEqual(dict(d), expect) - @skip_py2 def test_str_key_array_value(self): np.random.seed(123) d = Dict.empty( @@ -1219,7 +1211,6 @@ def foo(count): self.assertEqual(ct, 100) - @skip_py2 def test_delitem(self): d = Dict.empty(types.int64, types.unicode_type) d[1] = 'apple' @@ -1250,7 +1241,6 @@ def foo(d): # Value is correctly updated self.assertPreciseEqual(d[1], np.arange(10, dtype=np.int64) + 100) - @skip_py2 def test_storage_model_mismatch(self): # https://github.com/numba/numba/issues/4520 # check for storage model mismatch in refcount ops generation diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index 7cf5f62a14b..dbb7a44ff6e 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -162,11 +162,7 @@ def test_handling_unsupported_generator_expression(self): def foo(): y = (x for x in range(10)) - if utils.IS_PY3: - expected = "The use of yield in a closure is unsupported." - else: - # funcsigs falls over on py27 - expected = "Cannot obtain a signature for" + expected = "The use of yield in a closure is unsupported." for dec in jit(forceobj=True), njit: with self.assertRaises(errors.UnsupportedError) as raises: diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 0e822fb9a86..2daed832a7d 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -34,8 +34,6 @@ from numba.typing.templates import ( ConcreteTemplate, signature, infer, infer_global, AbstractTemplate) -_IS_PY3 = sys.version_info >= (3,) - # Pandas-like API implementation from .pdlike_usecase import Index, Series @@ -761,9 +759,8 @@ def impl1(a, b, c, kw=12): msg = str(e.exception) self.assertIn(sentinel, msg) self.assertIn("keyword argument default values", msg) - if _IS_PY3: - self.assertIn('', msg) - self.assertIn('', msg) + self.assertIn('', msg) + self.assertIn('', msg) # kwarg name is different def impl2(a, b, c, kwarg=None): @@ -777,9 +774,8 @@ def impl2(a, b, c, kwarg=None): msg = str(e.exception) self.assertIn(sentinel, msg) self.assertIn("keyword argument names", msg) - if _IS_PY3: - self.assertIn('', msg) - self.assertIn('', msg) + self.assertIn('', msg) + self.assertIn('', msg) # arg name is different def impl3(z, b, c, kw=None): @@ -794,29 +790,26 @@ def impl3(z, b, c, kw=None): self.assertIn(sentinel, msg) self.assertIn("argument names", msg) self.assertFalse("keyword" in msg) - if _IS_PY3: - self.assertIn('', msg) - self.assertIn('', msg) - - # impl4/5 has invalid syntax for python < 3 - if _IS_PY3: - from .overload_usecases import impl4, impl5 - with self.assertRaises(errors.TypingError) as e: - gen_ol(impl4)(1, 2, 3, 4) - msg = str(e.exception) - self.assertIn(sentinel, msg) - self.assertIn("argument names", msg) - self.assertFalse("keyword" in msg) - self.assertIn("First difference: 'z'", msg) - - with self.assertRaises(errors.TypingError) as e: - gen_ol(impl5)(1, 2, 3, 4) - msg = str(e.exception) - self.assertIn(sentinel, msg) - self.assertIn("argument names", msg) - self.assertFalse("keyword" in msg) - self.assertIn('', msg) - self.assertIn('', msg) + self.assertIn('', msg) + self.assertIn('', msg) + + from .overload_usecases import impl4, impl5 + with self.assertRaises(errors.TypingError) as e: + gen_ol(impl4)(1, 2, 3, 4) + msg = str(e.exception) + self.assertIn(sentinel, msg) + self.assertIn("argument names", msg) + self.assertFalse("keyword" in msg) + self.assertIn("First difference: 'z'", msg) + + with self.assertRaises(errors.TypingError) as e: + gen_ol(impl5)(1, 2, 3, 4) + msg = str(e.exception) + self.assertIn(sentinel, msg) + self.assertIn("argument names", msg) + self.assertFalse("keyword" in msg) + self.assertIn('', msg) + self.assertIn('', msg) # too many args def impl6(a, b, c, d, e, kw=None): @@ -831,9 +824,8 @@ def impl6(a, b, c, d, e, kw=None): self.assertIn(sentinel, msg) self.assertIn("argument names", msg) self.assertFalse("keyword" in msg) - if _IS_PY3: - self.assertIn('', msg) - self.assertIn('', msg) + self.assertIn('', msg) + self.assertIn('', msg) # too few args def impl7(a, b, kw=None): @@ -848,8 +840,7 @@ def impl7(a, b, kw=None): self.assertIn(sentinel, msg) self.assertIn("argument names", msg) self.assertFalse("keyword" in msg) - if _IS_PY3: - self.assertIn('', msg) + self.assertIn('', msg) # too many kwargs def impl8(a, b, c, kw=None, extra_kwarg=None): @@ -863,8 +854,7 @@ def impl8(a, b, c, kw=None, extra_kwarg=None): msg = str(e.exception) self.assertIn(sentinel, msg) self.assertIn("keyword argument names", msg) - if _IS_PY3: - self.assertIn('', msg) + self.assertIn('', msg) # too few kwargs def impl9(a, b, c): @@ -878,10 +868,8 @@ def impl9(a, b, c): msg = str(e.exception) self.assertIn(sentinel, msg) self.assertIn("keyword argument names", msg) - if _IS_PY3: - self.assertIn('', msg) + self.assertIn('', msg) - @unittest.skipUnless(_IS_PY3, "Python 3+ only syntax") def test_typing_vs_impl_signature_mismatch_handling_var_positional(self): """ Tests that an overload which has a differing typing and implementing diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index ddeb8ca0b42..0fd26f1b2ea 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -7,7 +7,6 @@ from numba.compiler import compile_isolated, Flags from numba import types from numba.bytecode import FunctionIdentity, ByteCode -from numba.utils import IS_PY3 from .support import TestCase, tag enable_pyobj_flags = Flags() @@ -1218,25 +1217,19 @@ def foo(): SET_BLOCK_D # noqa: F821 SET_BLOCK_E # noqa: F821 - # Whether infinite loop (i.g. while True) are optimized out. - infinite_loop_opt_out = bool(IS_PY3) - cfa, blkpts = self.get_cfa_and_namedblocks(foo) idoms = cfa.graph.immediate_dominators() - if infinite_loop_opt_out: - self.assertNotIn(blkpts['E'], idoms) + self.assertNotIn(blkpts['E'], idoms) self.assertEqual(blkpts['B'], idoms[blkpts['C']]) self.assertEqual(blkpts['B'], idoms[blkpts['D']]) domfront = cfa.graph.dominance_frontier() - if infinite_loop_opt_out: - self.assertNotIn(blkpts['E'], domfront) + self.assertNotIn(blkpts['E'], domfront) self.assertFalse(domfront[blkpts['A']]) self.assertFalse(domfront[blkpts['C']]) - if infinite_loop_opt_out: - self.assertEqual({blkpts['B']}, domfront[blkpts['B']]) - self.assertEqual({blkpts['B']}, domfront[blkpts['D']]) + self.assertEqual({blkpts['B']}, domfront[blkpts['B']]) + self.assertEqual({blkpts['B']}, domfront[blkpts['D']]) if __name__ == '__main__': diff --git a/numba/tests/test_func_lifetime.py b/numba/tests/test_func_lifetime.py index 02aca26ff63..9d4c131017f 100644 --- a/numba/tests/test_func_lifetime.py +++ b/numba/tests/test_func_lifetime.py @@ -5,7 +5,6 @@ import weakref from numba import unittest_support as unittest -from numba.utils import IS_PY3 from numba import jit, types from .support import TestCase @@ -124,7 +123,6 @@ def do_math(x): gc.collect() self.assertEqual([w() for w in wrs], [None] * len(wrs)) - @unittest.skipUnless(IS_PY3, "py3 only; known leak in py2") def test_inner_function_lifetime(self): self.check_inner_function_lifetime(forceobj=True) diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index 6c95860f873..fc165d6534f 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -13,11 +13,10 @@ from numba import jit, types, utils import numba.unittest_support as unittest -from .support import TestCase, tag, CompilationCache, skip_py38_or_later +from .support import TestCase, tag, CompilationCache from numba.targets import hashing -if utils.IS_PY3: - from numba.unicode import compile_time_get_string_data +from numba.unicode import compile_time_get_string_data def hash_usecase(x): @@ -34,28 +33,14 @@ def check_hash_values(self, values): for val in list(values): nb_hash = cfunc(val) self.assertIsInstance(nb_hash, utils.INT_TYPES) - # Always check the value on python 3 - # On python 2, if the input was an integral value, with - # magnitude < _PyHASH_MODULUS then perform the check - proceed = utils.IS_PY3 - if not proceed: - if not isinstance(val, (str, tuple)): - intinput = (not np.iscomplexobj(val) and - (isinstance(val, utils.INT_TYPES) or - float(val).is_integer())) - nonzero = val != 0 - intmin = val < 0 and abs(val) == val - notlong = abs(val) < 2 ** 31 - 1 - proceed = intinput and nonzero and not intmin and notlong - if proceed: - try: - self.assertEqual(nb_hash, hash(val)) - except AssertionError as e: - print("val, nb_hash, hash(val)") - print(val, nb_hash, hash(val)) - print("abs(val), hashing._PyHASH_MODULUS - 1") - print(abs(val), hashing._PyHASH_MODULUS - 1) - raise e + try: + self.assertEqual(nb_hash, hash(val)) + except AssertionError as e: + print("val, nb_hash, hash(val)") + print(val, nb_hash, hash(val)) + print("abs(val), hashing._PyHASH_MODULUS - 1") + print(abs(val), hashing._PyHASH_MODULUS - 1) + raise e def int_samples(self, typ=np.int64): for start in (0, -50, 60000, 1 << 32): @@ -172,38 +157,6 @@ def test_ints(self): self.check_hash_values([np.uint64(0x1ffffffffffffffe)]) self.check_hash_values([np.uint64(0x1fffffffffffffff)]) - @unittest.skipIf(utils.IS_PY3, "Python 2 only test") - def test_py27(self): - # for common types, check that those with the same contents hash to the - # same value and those with different contents hash to something - # different, this code doesn't concern itself with validity of hashes - - def check(val1, val2, val3): - a1_hash = self.cfunc(val1) - a2_hash = self.cfunc(val2) - a3_hash = self.cfunc(val3) - self.assertEqual(a1_hash, a2_hash) - self.assertFalse(a1_hash == a3_hash) - - a1 = 1 - a2 = 1 - a3 = 3 - for ty in [np.int8, np.uint8, np.int16, np.uint16, - np.int32, np.uint32, np.int64, np.uint64]: - check(ty(a1), ty(a2), ty(a3)) - - a1 = 1.23456 - a2 = 1.23456 - a3 = 3.23456 - for ty in [np.float32, np.float64]: - check(ty(a1), ty(a2), ty(a3)) - - a1 = 1.23456 + 2.23456j - a2 = 1.23456 + 2.23456j - a3 = 3.23456 + 4.23456j - for ty in [np.complex64, np.complex128]: - check(ty(a1), ty(a2), ty(a3)) - class TestTupleHashing(BaseTest): """ @@ -257,21 +210,7 @@ def split(i): self.check_tuples(self.int_samples(), split) - @unittest.skipIf(utils.IS_PY3, "Python 2 only test") - def test_py27(self): - # check that tuples with the same contents hash to the same value - # and those with different contents hash to something different - a1 = (1, 2, 3) - a2 = (1, 2, 3) - a3 = (1, 2, 4) - a1_hash = self.cfunc(a1) - a2_hash = self.cfunc(a2) - a3_hash = self.cfunc(a3) - self.assertEqual(a1_hash, a2_hash) - self.assertFalse(a1_hash == a3_hash) - - -@unittest.skipUnless(utils.IS_PY3, "unicode hash tests are Python 3 only") + class TestUnicodeHashing(BaseTest): def test_basic_unicode(self): diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index 77d49ccd30d..d9ccaea3450 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -66,15 +66,14 @@ def test_inspect_cli(self): filename = os.path.join(dirpath, 'out') # Try default format "html" - if utils.IS_PY3: - expected_file = filename + '.html' - cmds = cmdbase + ['--file', filename, 'math'] - # File shouldn't exist yet - self.assertFalse(os.path.isfile(expected_file)) - # Run CLI - subprocess.check_output(cmds) - # File should exist now - self.assertTrue(os.path.isfile(expected_file)) + expected_file = filename + '.html' + cmds = cmdbase + ['--file', filename, 'math'] + # File shouldn't exist yet + self.assertFalse(os.path.isfile(expected_file)) + # Run CLI + subprocess.check_output(cmds) + # File should exist now + self.assertTrue(os.path.isfile(expected_file)) # Try changing the format to "rst" cmds = cmdbase + ['--file', filename, '--format', 'rst', 'math'] @@ -91,7 +90,5 @@ def test_inspect_cli(self): # Run CLI with self.assertRaises(subprocess.CalledProcessError) as raises: subprocess.check_output(cmds, stderr=subprocess.STDOUT) - if utils.IS_PY3: - # No .stdout in CalledProcessError in python<3 - self.assertIn("\'foo\' is not supported", - raises.exception.stdout.decode('ascii')) + self.assertIn("\'foo\' is not supported", + raises.exception.stdout.decode('ascii')) diff --git a/numba/tests/test_listobject.py b/numba/tests/test_listobject.py index 252d553cd54..ccc935293d7 100644 --- a/numba/tests/test_listobject.py +++ b/numba/tests/test_listobject.py @@ -16,12 +16,9 @@ from numba import int32, types from numba.errors import TypingError from numba import listobject -from numba.utils import IS_PY3 from .support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) -skip_py2 = unittest.skipUnless(IS_PY3, reason='not supported in py2') - class TestCreateAppendLength(MemoryLeakMixin, TestCase): """Test list creation, append and len. """ @@ -1428,7 +1425,6 @@ def foo(): class TestStringItem(MemoryLeakMixin, TestCase): """Test list can take strings as items. """ - @skip_py2 def test_string_item(self): @njit def foo(): @@ -1479,7 +1475,6 @@ def test_cast_bool_to(self): self.check_good(types.boolean, types.float64) self.check_good(types.boolean, types.complex128) - @skip_py2 def test_cast_fail_unicode_int(self): @njit @@ -1494,7 +1489,6 @@ def foo(): str(raises.exception), ) - @skip_py2 def test_cast_fail_int_unicode(self): @njit diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 45a95a0aafe..199148f1031 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -830,15 +830,10 @@ def test_errors(self): lst = [(1,), (2, 3)] with self.assertRaises(TypeError) as raises: cfunc(lst) - if utils.IS_PY3: - msg = ("can't unbox heterogeneous list: " - "UniTuple({0} x 1) != UniTuple({0} x 2)") - self.assertEqual(str(raises.exception), msg.format(types.intp)) - else: - self.assertEqual( - str(raises.exception), - "can't unbox heterogeneous list", - ) + msg = ("can't unbox heterogeneous list: " + "UniTuple({0} x 1) != UniTuple({0} x 2)") + self.assertEqual(str(raises.exception), msg.format(types.intp)) + class TestListReflection(MemoryLeakMixin, TestCase): @@ -1277,7 +1272,6 @@ def bar(x): str(raises.exception), ) - @unittest.skipUnless(utils.IS_PY3, "Py3 only due to ordering of error") @expect_reflection_failure def test_c05(self): def bar(x): @@ -1288,7 +1282,6 @@ def bar(x): r = [[np.arange(3).astype(np.intp)]] self.compile_and_test(bar, r) - @unittest.skipUnless(utils.IS_PY3, "Py3 only due to ordering of error") def test_c06(self): def bar(x): f = x diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 3928db61e22..71ceb901db2 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -620,9 +620,8 @@ def ddot(a, v): v = np.linspace(2, 1, 10) ddot(A, v) - msg = ("The 'parallel' target is not currently supported on " - "Windows operating systems when using Python 2.7, " - "or on 32 bit hardware") + msg = ("The 'parallel' target is not currently supported on 32 bit " + "hardware") self.assertIn(msg, str(raised.exception)) @skip_unsupported @@ -1588,15 +1587,6 @@ def test_impl(arr): self.check(test_impl, arr) - -def iterate_bytecode(code): - if PYVERSION >= (3, 4): # available since Py3.4 - return dis.Bytecode(code) - else: - offsets, insts = zip(*ByteCodeIter(code)) - return insts - - class TestPrangeBase(TestParforsBase): def __init__(self, *args): @@ -1624,7 +1614,7 @@ def generate_prange_func(self, pyfunc, patch_instance): range_idx = pyfunc_code.co_names.index('range') range_locations = [] # look for LOAD_GLOBALs that point to 'range' - for instr in iterate_bytecode(pyfunc_code): + for instr in dis.Bytecode(pyfunc_code): if instr.opname == 'LOAD_GLOBAL': if instr.arg == range_idx: range_locations.append(instr.offset + 1) diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index 50828e18a4d..352cce0850a 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -169,7 +169,6 @@ def test_range_iter_list(self): self.assertEqual(cfunc(arglist), len(arglist)) @tag('important') - @unittest.skipUnless(utils.IS_PY3, "range() attrs are Py3 only") def test_range_attrs(self): pyfunc = range_attrs arglist = [(0, 0, 1), diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index a6a44e70f78..c8e4d1877d2 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -8,7 +8,6 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated from numba.itanium_mangler import mangle_type -from numba.utils import IS_PY3 from numba.config import IS_WIN32 from numba.numpy_support import version as numpy_version from .support import tag @@ -421,10 +420,7 @@ def test_from_dtype(self): self.assertEqual(rec.typeof('a'), types.float64) self.assertEqual(rec.typeof('b'), types.int16) self.assertEqual(rec.typeof('c'), types.complex64) - if IS_PY3: - self.assertEqual(rec.typeof('d'), types.UnicodeCharSeq(5)) - else: - self.assertEqual(rec.typeof('d'), types.CharSeq(5)) + self.assertEqual(rec.typeof('d'), types.UnicodeCharSeq(5)) self.assertEqual(rec.offset('a'), recordtype.fields['a'][1]) self.assertEqual(rec.offset('b'), recordtype.fields['b'][1]) self.assertEqual(rec.offset('c'), recordtype.fields['c'][1]) diff --git a/numba/tests/test_slices.py b/numba/tests/test_slices.py index 7cccc70cf16..148def6562b 100644 --- a/numba/tests/test_slices.py +++ b/numba/tests/test_slices.py @@ -155,10 +155,6 @@ def test_slice_indices(self): cfunc = jit(nopython=True)(slice_indices) for s, l in product(slices, lengths): - if l < 0 and not utils.IS_PY3: - # Passing a negative length to slice.indices in python2 is - # undefined. See https://bugs.python.org/issue14794#msg174678 - continue try: expected = slice_indices(s, l) except Exception as py_e: diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 8c48d199f08..989c83e9f14 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -8,7 +8,6 @@ from numba import int32, float32, types, prange from numba import jitclass, typeof from numba.typed import List, Dict -from numba.utils import IS_PY3 from numba.errors import TypingError from .support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) @@ -17,8 +16,6 @@ from .test_parfors import skip_unsupported as parfors_skip_unsupported -skip_py2 = unittest.skipUnless(IS_PY3, reason='not supported in py2') - # global typed-list for testing purposes global_typed_list = List.empty_list(int32) for i in (1, 2, 3): @@ -729,7 +726,6 @@ def foo(): class TestListRefctTypes(MemoryLeakMixin, TestCase): - @skip_py2 def test_str_item(self): @njit def foo(): @@ -752,7 +748,6 @@ def foo(): l.append(str(i)) self.assertEqual(l[i], str(i)) - @skip_py2 def test_str_item_refcount_replace(self): @njit def foo(): @@ -774,7 +769,6 @@ def foo(): self.assertEqual(ra, 1) self.assertEqual(rz, 2) - @skip_py2 def test_dict_as_item_in_list(self): @njit def foo(): @@ -788,7 +782,6 @@ def foo(): c = foo() self.assertEqual(2, c) - @skip_py2 def test_dict_as_item_in_list_multi_refcount(self): @njit def foo(): @@ -803,7 +796,6 @@ def foo(): c = foo() self.assertEqual(3, c) - @skip_py2 def test_list_as_value_in_dict(self): @njit def foo(): @@ -817,7 +809,6 @@ def foo(): c = foo() self.assertEqual(2, c) - @skip_py2 def test_list_as_item_in_list(self): nested_type = types.ListType(types.int32) @njit @@ -832,7 +823,6 @@ def foo(): got = foo() self.assertEqual(expected, got) - @skip_py2 def test_array_as_item_in_list(self): nested_type = types.Array(types.float64, 1, 'C') @njit @@ -847,7 +837,6 @@ def foo(): # Need to compare the nested arrays self.assertTrue(np.all(expected[0] == got[0])) - @skip_py2 def test_jitclass_as_item_in_list(self): spec = [ @@ -888,7 +877,6 @@ def bag_equal(one, two): [bag_equal(a, b) for a, b in zip(expected, got)] - @skip_py2 def test_storage_model_mismatch(self): # https://github.com/numba/numba/issues/4520 # check for storage model mismatch in refcount ops generation @@ -905,7 +893,6 @@ def test_storage_model_mismatch(self): for i, x in enumerate(ref): self.assertEqual(lst[i], ref[i]) - @skip_py2 def test_equals_on_list_with_dict_for_equal_lists(self): # https://github.com/numba/numba/issues/4879 a, b = List(), Dict() @@ -918,7 +905,6 @@ def test_equals_on_list_with_dict_for_equal_lists(self): self.assertEqual(a, c) - @skip_py2 def test_equals_on_list_with_dict_for_unequal_dicts(self): # https://github.com/numba/numba/issues/4879 a, b = List(), Dict() @@ -931,7 +917,6 @@ def test_equals_on_list_with_dict_for_unequal_dicts(self): self.assertNotEqual(a, c) - @skip_py2 def test_equals_on_list_with_dict_for_unequal_lists(self): # https://github.com/numba/numba/issues/4879 a, b = List(), Dict() diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 11fd3797d42..ffafddb7cd6 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -22,7 +22,6 @@ import numpy as np from numba import unittest_support as unittest -from numba.utils import IS_PY3 from numba import sigutils, types, typing, errors from numba.types.abstract import _typecache from numba.typing.templates import make_overload_template @@ -297,13 +296,12 @@ def check_order(values): check_order([types.float32, types.float64]) check_order([types.complex64, types.complex128]) - if IS_PY3: - with self.assertRaises(TypeError): - types.int8 <= types.uint32 - with self.assertRaises(TypeError): - types.int8 <= types.float32 - with self.assertRaises(TypeError): - types.float64 <= types.complex128 + with self.assertRaises(TypeError): + types.int8 <= types.uint32 + with self.assertRaises(TypeError): + types.int8 <= types.float32 + with self.assertRaises(TypeError): + types.float64 <= types.complex128 class TestNdIter(TestCase): diff --git a/numba/tests/test_unicode_array.py b/numba/tests/test_unicode_array.py index 3afae567d16..d19641b3d9f 100644 --- a/numba/tests/test_unicode_array.py +++ b/numba/tests/test_unicode_array.py @@ -8,7 +8,6 @@ from numba.typed import Dict from numba.tests.support import TestCase -skip_py2 = unittest.skipIf(not utils.IS_PY3, "not supported in Python 2") require_py37 = unittest.skipIf(utils.PYVERSION < (3, 7), "requires Python 3.7+") @@ -219,7 +218,6 @@ def return_not(x, i): return not x[i] -@skip_py2 @unittest.skipIf(platform.machine() == 'ppc64le', "LLVM bug") class TestUnicodeArray(TestCase): diff --git a/numba/typing/builtins.py b/numba/typing/builtins.py index 473e3144428..1de8fb5177f 100644 --- a/numba/typing/builtins.py +++ b/numba/typing/builtins.py @@ -8,7 +8,7 @@ from numba import types, prange, errors from numba.parfor import internal_prange -from numba.utils import PYVERSION, RANGE_ITER_OBJECTS, IS_PY3 +from numba.utils import RANGE_ITER_OBJECTS from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, infer_global, infer, infer_getattr, signature, bound_function, @@ -208,16 +208,6 @@ class BinOpMul(BinOp): class BinOpMul(BinOp): pass -if not IS_PY3: - @infer_global(operator.div) - class BinOpDiv(BinOp): - pass - - - @infer_global(operator.idiv) - class BinOpDiv(BinOp): - pass - @infer_global(operator.mod) class BinOpMod(ConcreteTemplate): @@ -647,15 +637,14 @@ def generic(self, args, kws): class MemoryViewAttribute(AttributeTemplate): key = types.MemoryView - if PYVERSION >= (3,): - def resolve_contiguous(self, buf): - return types.boolean + def resolve_contiguous(self, buf): + return types.boolean - def resolve_c_contiguous(self, buf): - return types.boolean + def resolve_c_contiguous(self, buf): + return types.boolean - def resolve_f_contiguous(self, buf): - return types.boolean + def resolve_f_contiguous(self, buf): + return types.boolean def resolve_itemsize(self, buf): return types.intp @@ -850,17 +839,9 @@ class Min(MinMaxBase): @infer_global(round) class Round(ConcreteTemplate): - if PYVERSION < (3, 0): - cases = [ - signature(types.float32, types.float32), - signature(types.float64, types.float64), - ] - else: - cases = [ - signature(types.intp, types.float32), - signature(types.int64, types.float64), - ] - cases += [ + cases = [ + signature(types.intp, types.float32), + signature(types.int64, types.float64), signature(types.float32, types.float32, types.intp), signature(types.float64, types.float64, types.intp), ] diff --git a/numba/typing/npdatetime.py b/numba/typing/npdatetime.py index 47c3b3980a9..4f3373be605 100644 --- a/numba/typing/npdatetime.py +++ b/numba/typing/npdatetime.py @@ -8,7 +8,6 @@ import operator from numba import npdatetime, types -from numba.utils import IS_PY3 from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, infer_global, infer, infer_getattr, signature) @@ -145,18 +144,6 @@ class TimedeltaTrueDiv(TimedeltaDivOp): class TimedeltaFloorDiv(TimedeltaDivOp): key = operator.floordiv - -if not IS_PY3: - @infer_global(operator.div) - class TimedeltaLegacyDiv(TimedeltaDivOp): - key = operator.div - - - @infer_global(operator.idiv) - class TimedeltaLegacyDiv(TimedeltaDivOp): - key = operator.idiv - - @infer_global(operator.eq) class TimedeltaCmpEq(TimedeltaCmpOp): key = operator.eq diff --git a/numba/typing/npydecl.py b/numba/typing/npydecl.py index 93e72dcd062..94e5dbb1c09 100644 --- a/numba/typing/npydecl.py +++ b/numba/typing/npydecl.py @@ -184,9 +184,6 @@ class NumpyRulesArrayOperator(Numpy_rules_ufunc): operator.ne: "not_equal", } - if not utils.IS_PY3: - _op_map[operator.div] = "divide" - @property def ufunc(self): return getattr(np, self._op_map[self.key]) @@ -240,9 +237,6 @@ class NumpyRulesInplaceArrayOperator(NumpyRulesArrayOperator): operator.ixor: "bitwise_xor", } - if not utils.IS_PY3: - _op_map[operator.idiv] = "divide" - def generic(self, args, kws): # Type the inplace operator as if an explicit output was passed, # to handle type resolution correctly. diff --git a/numba/typing/templates.py b/numba/typing/templates.py index fb0c8d1cf2d..df5b05300c1 100644 --- a/numba/typing/templates.py +++ b/numba/typing/templates.py @@ -15,8 +15,6 @@ from ..errors import TypingError, InternalError from ..targets.cpu_options import InlineOptions -_IS_PY3 = sys.version_info >= (3,) - # info store for inliner callback functions e.g. cost model _inline_info = namedtuple('inline_info', 'func_ir typemap calltypes signature') @@ -417,14 +415,9 @@ def get_args_kwargs(sig): msg = err_prefix + specialized % (sig_str, b[-1]) raise InternalError(msg) - if _IS_PY3: - def gen_diff(typing, implementing): - diff = set(typing) ^ set(implementing) - return "Difference: %s" % diff - else: - # funcsigs.Parameter cannot be hashed - def gen_diff(typing, implementing): - pass + def gen_diff(typing, implementing): + diff = set(typing) ^ set(implementing) + return "Difference: %s" % diff if a != b: specialized = "argument names.\n%s\n%s" % (sig_str, gen_diff(a, b)) diff --git a/numba/typing/typeof.py b/numba/typing/typeof.py index 7ff04d0ba90..4971ce50591 100644 --- a/numba/typing/typeof.py +++ b/numba/typing/typeof.py @@ -1,6 +1,7 @@ from __future__ import print_function, absolute_import from collections import namedtuple +from functools import singledispatch import ctypes import enum @@ -35,7 +36,7 @@ def typeof(val, purpose=Purpose.argument): return ty -@utils.singledispatch +@singledispatch def typeof_impl(val, c): """ Generic typeof() implementation. From 2120cfa496d3d848daba3db2f501427dd3d5bdd7 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 12:06:20 +0000 Subject: [PATCH 211/595] remove other py3 spellings --- numba/appdirs.py | 10 ++-------- numba/cgutils.py | 21 +++++++-------------- numba/npyufunc/parallel.py | 19 ++++++++----------- numba/targets/cpu.py | 3 +-- numba/tests/test_unicode_names.py | 6 +----- numba/types/__init__.py | 2 +- 6 files changed, 20 insertions(+), 41 deletions(-) diff --git a/numba/appdirs.py b/numba/appdirs.py index 286fcfc3911..bd97de595a0 100644 --- a/numba/appdirs.py +++ b/numba/appdirs.py @@ -20,10 +20,7 @@ import sys import os -PY3 = sys.version_info[0] == 3 - -if PY3: - unicode = str +unicode = str if sys.platform.startswith('java'): import platform @@ -410,10 +407,7 @@ def _get_win_folder_from_registry(csidl_name): registry for this guarantees us the correct answer for all CSIDL_* names. """ - if PY3: - import winreg as _winreg - else: - import _winreg + import winreg as _winreg shell_folder_name = { "CSIDL_APPDATA": "AppData", diff --git a/numba/cgutils.py b/numba/cgutils.py index 1fd714cf4f2..a21b0100499 100644 --- a/numba/cgutils.py +++ b/numba/cgutils.py @@ -1098,20 +1098,13 @@ def snprintf_stackbuffer(builder, bufsz, format, *args): return buffer -if utils.PY3: - def normalize_ir_text(text): - """ - Normalize the given string to latin1 compatible encoding that is - suitable for use in LLVM IR. - """ - # Just re-encoding to latin1 is enough - return text.encode('utf8').decode('latin1') -else: - def normalize_ir_text(text): - """ - No-op for python2. Assume there won't be unicode names. - """ - return text +def normalize_ir_text(text): + """ + Normalize the given string to latin1 compatible encoding that is + suitable for use in LLVM IR. + """ + # Just re-encoding to latin1 is enough + return text.encode('utf8').decode('latin1') def hexdump(builder, ptr, nbytes): diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 1b29b3bdf15..2d1a6af42e3 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -276,18 +276,15 @@ def __exit__(self, *args): try: - if utils.PY3: - # Force the use of an RLock in the case a fork was used to start the - # process and thereby the init sequence, some of the threading backend - # init sequences are not fork safe. Also, windows global mp locks seem - # to be fine. - if "fork" in multiprocessing.get_start_method() or _windows: - _backend_init_process_lock = multiprocessing.get_context().RLock() - else: - _backend_init_process_lock = _nop() + # Force the use of an RLock in the case a fork was used to start the + # process and thereby the init sequence, some of the threading backend + # init sequences are not fork safe. Also, windows global mp locks seem + # to be fine. + if "fork" in multiprocessing.get_start_method() or _windows: + _backend_init_process_lock = multiprocessing.get_context().RLock() else: - # windows uses spawn so is fine, linux uses fork has the lock - _backend_init_process_lock = multiprocessing.RLock() + _backend_init_process_lock = _nop() + except OSError as e: # probably lack of /dev/shm for semaphore writes, warn the user diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index b3cfafc9d03..8c1dea1238c 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -61,8 +61,7 @@ def init(self): rtsys.initialize(self) # Initialize additional implementations - if utils.PY3: - import numba.unicode + import numba.unicode def load_additional_registries(self): # Add target specific implementations diff --git a/numba/tests/test_unicode_names.py b/numba/tests/test_unicode_names.py index c12be6811b8..0d94897e360 100644 --- a/numba/tests/test_unicode_names.py +++ b/numba/tests/test_unicode_names.py @@ -3,8 +3,6 @@ from numba import njit, cfunc, cgutils -from numba.utils import PY2 - from .support import TestCase, unittest unicode_name1 = u""" @@ -18,7 +16,6 @@ def Ծ_Ծ(ಠ_ರೃ, ಠਊಠ): """ -@unittest.skipIf(PY2, "unicode identifier not supported in python2") class TestUnicodeNames(TestCase): def make_testcase(self, src, fname): glb = {} @@ -51,8 +48,7 @@ def test_normalize_ir_text(self): # try encoding to latin out.encode('latin1') - @unittest.skipIf(PY2, "unicode identifier not supported in python2") - def test_normalize_ir_text_py3(self): + def test_normalize_ir_text(self): # unicode input out = cgutils.normalize_ir_text(unicode_name2) # str returned diff --git a/numba/types/__init__.py b/numba/types/__init__.py index 46aec8a8b2f..0b19a93aebe 100644 --- a/numba/types/__init__.py +++ b/numba/types/__init__.py @@ -25,7 +25,7 @@ undefined = Undefined('undefined') py2_string_type = Opaque('str') unicode_type = UnicodeType('unicode_type') -string = unicode_type if utils.PY3 else py2_string_type +string = unicode_type unknown = Dummy('unknown') code_type = Opaque('code') From ca2f73efdbe1917560a35884649eb5d37fac7544 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 12:08:05 +0000 Subject: [PATCH 212/595] Fix up HAS_MATMUL_OPERATOR --- numba/targets/linalg.py | 5 ++--- numba/typing/npydecl.py | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/numba/targets/linalg.py b/numba/targets/linalg.py index ce41977c5f2..53c53bf8458 100644 --- a/numba/targets/linalg.py +++ b/numba/targets/linalg.py @@ -22,7 +22,6 @@ from numba import numpy_support as np_support from .arrayobj import make_array, _empty_nd_impl, array_copy from ..errors import TypingError -from ..utils import HAS_MATMUL_OPERATOR ll_char = ir.IntType(8) ll_char_p = ll_char.as_pointer() @@ -540,8 +539,8 @@ def dot_2(context, builder, sig, args): else: assert 0 -if HAS_MATMUL_OPERATOR: - lower_builtin(operator.matmul, types.Array, types.Array)(dot_2) + +lower_builtin(operator.matmul, types.Array, types.Array)(dot_2) @lower_builtin(np.vdot, types.Array, types.Array) diff --git a/numba/typing/npydecl.py b/numba/typing/npydecl.py index 94e5dbb1c09..2e2a8545ab2 100644 --- a/numba/typing/npydecl.py +++ b/numba/typing/npydecl.py @@ -1000,17 +1000,17 @@ def typer(a, b): return typer -if utils.HAS_MATMUL_OPERATOR: - @infer_global(operator.matmul) - class MatMul(MatMulTyperMixin, AbstractTemplate): - key = operator.matmul - func_name = "'@'" - - def generic(self, args, kws): - assert not kws - restype = self.matmul_typer(*args) - if restype is not None: - return signature(restype, *args) + +@infer_global(operator.matmul) +class MatMul(MatMulTyperMixin, AbstractTemplate): + key = operator.matmul + func_name = "'@'" + + def generic(self, args, kws): + assert not kws + restype = self.matmul_typer(*args) + if restype is not None: + return signature(restype, *args) def _check_linalg_matrix(a, func_name): From 34f97c2b3e1ac31045c3cdaa3d2f8c2e941416d7 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 12:34:59 +0000 Subject: [PATCH 213/595] Remove PYVERSION uses --- numba/byteflow.py | 2 +- numba/ctypes_support.py | 14 -- numba/cuda/compiler.py | 2 +- numba/cuda/tests/cudapy/test_complex.py | 1 - numba/dataflow.py | 152 ++++++---------------- numba/ir_utils.py | 22 ---- numba/npyufunc/ufuncbuilder.py | 6 +- numba/numpy_support.py | 1 - numba/object_mode_passes.py | 5 +- numba/pythonapi.py | 166 +++++++----------------- numba/roc/compiler.py | 2 +- numba/serialize.py | 9 +- numba/targets/cmathimpl.py | 17 ++- numba/targets/externals.py | 45 +------ numba/targets/mathimpl.py | 36 +++-- numba/targets/npyimpl.py | 1 - numba/testing/main.py | 50 +------ numba/tests/test_builtins.py | 7 +- numba/tests/test_closure.py | 1 - numba/tests/test_complex.py | 2 - numba/tests/test_comprehension.py | 12 +- numba/tests/test_ctypes.py | 2 +- numba/tests/test_dataflow.py | 1 - numba/tests/test_intwidth.py | 2 - numba/tests/test_mathlib.py | 8 +- numba/tests/test_numpyadapt.py | 3 +- numba/tests/test_objects.py | 1 - numba/tests/test_operators.py | 25 ---- numba/tests/test_parallel_backend.py | 63 +++------ numba/tests/test_parfors.py | 1 - numba/tests/test_print.py | 1 - numba/tests/test_return_values.py | 1 - numba/tests/test_support.py | 2 - numba/tests/test_tuples.py | 6 - numba/tests/test_ufuncs.py | 7 +- numba/tracing.py | 5 +- numba/typed_passes.py | 5 +- numba/typing/cmathdecl.py | 7 +- numba/typing/mathdecl.py | 49 +++---- numba/unittest_support.py | 3 - numba/untyped_passes.py | 5 +- 41 files changed, 181 insertions(+), 569 deletions(-) delete mode 100644 numba/ctypes_support.py diff --git a/numba/byteflow.py b/numba/byteflow.py index 01799f7bc25..11727330898 100644 --- a/numba/byteflow.py +++ b/numba/byteflow.py @@ -966,7 +966,7 @@ def op_MAKE_FUNCTION(self, state, inst, MAKE_CLOSURE=False): name = state.pop() code = state.pop() closure = annotations = kwdefaults = defaults = None - if PYVERSION >= (3, 0) and PYVERSION < (3, 6): + if PYVERSION < (3, 6): num_posdefaults = inst.arg & 0xFF num_kwdefaults = (inst.arg >> 8) & 0xFF num_annotations = (inst.arg >> 16) & 0x7FFF diff --git a/numba/ctypes_support.py b/numba/ctypes_support.py deleted file mode 100644 index 34fe9f52479..00000000000 --- a/numba/ctypes_support.py +++ /dev/null @@ -1,14 +0,0 @@ -""" -This file fixes portability issues for ctypes. -""" - -from __future__ import absolute_import -from numba.config import PYVERSION -from ctypes import * - -if PYVERSION <= (2, 7): - c_ssize_t = { - 4: c_int32, - 8: c_int64, - }[sizeof(c_size_t)] - diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index af8e9ad1c71..a9f858480d5 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, print_function +import ctypes import os from functools import reduce, wraps import operator @@ -10,7 +11,6 @@ import numpy as np -from numba import ctypes_support as ctypes from numba import config, compiler, types, sigutils from numba.typing.templates import AbstractTemplate, ConcreteTemplate from numba import funcdesc, typing, utils, serialize diff --git a/numba/cuda/tests/cudapy/test_complex.py b/numba/cuda/tests/cudapy/test_complex.py index 6e5e90d4696..235edfb8037 100644 --- a/numba/cuda/tests/cudapy/test_complex.py +++ b/numba/cuda/tests/cudapy/test_complex.py @@ -180,7 +180,6 @@ def test_isnan(self): def test_isinf(self): self.check_predicate_func(isinf_usecase) - @unittest.skipIf(utils.PYVERSION < (3, 2), "needs Python 3.2+") def test_isfinite(self): self.check_predicate_func(isfinite_usecase) diff --git a/numba/dataflow.py b/numba/dataflow.py index ec0afa48e12..1f80cf6e4e9 100644 --- a/numba/dataflow.py +++ b/numba/dataflow.py @@ -188,12 +188,8 @@ def op_BUILD_LIST(self, info, inst): def op_LIST_APPEND(self, info, inst): value = info.pop() - # Python 2.7+ added an argument to LIST_APPEND. - if sys.version_info[:2] == (2, 6): - target = info.pop() - else: - index = inst.arg - target = info.peek(index) + index = inst.arg + target = info.peek(index) appendvar = info.make_temp() res = info.make_temp() info.append(inst, target=target, value=value, appendvar=appendvar, res=res) @@ -202,11 +198,10 @@ def op_BUILD_MAP(self, info, inst): dct = info.make_temp() count = inst.arg items = [] - if sys.version_info >= (3, 5): - # In 3.5+, BUILD_MAP takes pairs from the stack - for i in range(count): - v, k = info.pop(), info.pop() - items.append((k, v)) + # BUILD_MAP takes pairs from the stack + for i in range(count): + v, k = info.pop(), info.pop() + items.append((k, v)) info.append(inst, items=items[::-1], size=count, res=dct) info.push(dct) @@ -308,62 +303,34 @@ def pop_info(info): info.pop() self.edge_process[(info.block.offset, inst.get_jump_target())] = pop_info - if utils.PYVERSION < (3, 6): - - def _op_call_function(self, info, inst, has_vararg): - narg = inst.arg & 0xff - nkws = (inst.arg >> 8) & 0xff - - def pop_kws(): - val = info.pop() - key = info.pop() - return key, val - - vararg = info.pop() if has_vararg else None - kws = list(reversed([pop_kws() for _ in range(nkws)])) - args = list(reversed([info.pop() for _ in range(narg)])) - func = info.pop() - - res = info.make_temp() - info.append(inst, func=func, args=args, kws=kws, res=res, - vararg=vararg) - info.push(res) - - def op_CALL_FUNCTION(self, info, inst): - self._op_call_function(info, inst, has_vararg=False) - - def op_CALL_FUNCTION_VAR(self, info, inst): - self._op_call_function(info, inst, has_vararg=True) - - else: - def op_CALL_FUNCTION(self, info, inst): - narg = inst.arg - args = list(reversed([info.pop() for _ in range(narg)])) - func = info.pop() - - res = info.make_temp() - info.append(inst, func=func, args=args, res=res) - info.push(res) - - def op_CALL_FUNCTION_KW(self, info, inst): - narg = inst.arg - names = info.pop() # tuple of names - args = list(reversed([info.pop() for _ in range(narg)])) - func = info.pop() - - res = info.make_temp() - info.append(inst, func=func, args=args, names=names, res=res) - info.push(res) - - def op_CALL_FUNCTION_EX(self, info, inst): - if inst.arg & 1: - errmsg = 'CALL_FUNCTION_EX with **kwargs not supported' - raise NotImplementedError(errmsg) - vararg = info.pop() - func = info.pop() - res = info.make_temp() - info.append(inst, func=func, vararg=vararg, res=res) - info.push(res) + def op_CALL_FUNCTION(self, info, inst): + narg = inst.arg + args = list(reversed([info.pop() for _ in range(narg)])) + func = info.pop() + + res = info.make_temp() + info.append(inst, func=func, args=args, res=res) + info.push(res) + + def op_CALL_FUNCTION_KW(self, info, inst): + narg = inst.arg + names = info.pop() # tuple of names + args = list(reversed([info.pop() for _ in range(narg)])) + func = info.pop() + + res = info.make_temp() + info.append(inst, func=func, args=args, names=names, res=res) + info.push(res) + + def op_CALL_FUNCTION_EX(self, info, inst): + if inst.arg & 1: + errmsg = 'CALL_FUNCTION_EX with **kwargs not supported' + raise NotImplementedError(errmsg) + vararg = info.pop() + func = info.pop() + res = info.make_temp() + info.append(inst, func=func, vararg=vararg, res=res) + info.push(res) def _build_tuple_unpack(self, info, inst): # Builds tuple from other tuples on the stack @@ -722,50 +689,17 @@ def op_RAISE_VARARGS(self, info, inst): info.append(inst, exc=exc) def op_MAKE_FUNCTION(self, info, inst, MAKE_CLOSURE=False): - if utils.PYVERSION == (2, 7): - name = None - else: - name = info.pop() + name = info.pop() code = info.pop() closure = annotations = kwdefaults = defaults = None - if utils.PYVERSION < (3, 0): - if MAKE_CLOSURE: - closure = info.pop() - num_posdefaults = inst.arg - if num_posdefaults > 0: - defaults = [] - for i in range(num_posdefaults): - defaults.append(info.pop()) - defaults = tuple(reversed(defaults)) - elif utils.PYVERSION >= (3, 0) and utils.PYVERSION < (3, 6): - num_posdefaults = inst.arg & 0xff - num_kwdefaults = (inst.arg >> 8) & 0xff - num_annotations = (inst.arg >> 16) & 0x7fff - if MAKE_CLOSURE: - closure = info.pop() - if num_annotations > 0: - annotations = info.pop() - if num_kwdefaults > 0: - kwdefaults = [] - for i in range(num_kwdefaults): - v = info.pop() - k = info.pop() - kwdefaults.append((k,v)) - kwdefaults = tuple(kwdefaults) - if num_posdefaults: - defaults = [] - for i in range(num_posdefaults): - defaults.append(info.pop()) - defaults = tuple(reversed(defaults)) - else: - if inst.arg & 0x8: - closure = info.pop() - if inst.arg & 0x4: - annotations = info.pop() - if inst.arg & 0x2: - kwdefaults = info.pop() - if inst.arg & 0x1: - defaults = info.pop() + if inst.arg & 0x8: + closure = info.pop() + if inst.arg & 0x4: + annotations = info.pop() + if inst.arg & 0x2: + kwdefaults = info.pop() + if inst.arg & 0x1: + defaults = info.pop() res = info.make_temp() info.append(inst, name=name, code=code, closure=closure, annotations=annotations, kwdefaults=kwdefaults, defaults=defaults, res=res) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 162adfa7424..c5ebbc56bf0 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -1622,28 +1622,6 @@ def _create_function_from_code_obj(fcode, func_env, func_arg, func_clo, glbls): loc = {} exec(func_text, glbls, loc) - # hack parameter name .0 for Python 3 versions < 3.6 - if utils.PYVERSION >= (3,) and utils.PYVERSION < (3, 6): - co_varnames = list(fcode.co_varnames) - if len(co_varnames) > 0 and co_varnames[0] == ".0": - co_varnames[0] = "implicit0" - fcode = pytypes.CodeType( - fcode.co_argcount, - fcode.co_kwonlyargcount, - fcode.co_nlocals, - fcode.co_stacksize, - fcode.co_flags, - fcode.co_code, - fcode.co_consts, - fcode.co_names, - tuple(co_varnames), - fcode.co_filename, - fcode.co_name, - fcode.co_firstlineno, - fcode.co_lnotab, - fcode.co_freevars, - fcode.co_cellvars) - f = loc['g']() # replace the code body f.__code__ = fcode diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 2ad35d460d0..b535b1c37b5 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -17,7 +17,6 @@ from .wrappers import build_ufunc_wrapper, build_gufunc_wrapper from numba.caching import FunctionCache, NullCache from numba.compiler_lock import global_compiler_lock -from numba.config import PYVERSION class UFuncTargetOptions(TargetOptions): @@ -262,10 +261,7 @@ def build_ufunc(self): datlist = [None] * len(ptrlist) if cres is None: - if PYVERSION >= (3, 0): - argspec = inspect.getfullargspec(self.py_func) - else: - argspec = inspect.getargspec(self.py_func) + argspec = inspect.getfullargspec(self.py_func) inct = len(argspec.args) else: inct = len(cres.signature.args) diff --git a/numba/numpy_support.py b/numba/numpy_support.py index fdf26a5454f..51166a10e49 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -12,7 +12,6 @@ version = tuple(map(int, np.__version__.split('.')[:2])) -int_divbyzero_returns_zero = config.PYVERSION <= (3, 0) # Starting from Numpy 1.10, ufuncs accept argument conversion according # to the "same_kind" rule (used to be "unsafe"). diff --git a/numba/object_mode_passes.py b/numba/object_mode_passes.py index 76dde62539f..d2cca457859 100644 --- a/numba/object_mode_passes.py +++ b/numba/object_mode_passes.py @@ -18,9 +18,8 @@ def giveup_context(state, msg): if not state.status.can_giveup: raise else: - if utils.PYVERSION >= (3,): - # Clear all references attached to the traceback - e = e.with_traceback(None) + # Clear all references attached to the traceback + e = e.with_traceback(None) warnings.warn_explicit('%s: %s' % (msg, e), errors.NumbaWarning, state.func_id.filename, diff --git a/numba/pythonapi.py b/numba/pythonapi.py index 5716540614e..980c62ee3d0 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -8,17 +8,15 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba.config import PYVERSION -import numba.ctypes_support as ctypes +import ctypes from numba import config from numba import types, utils, cgutils, lowering, _helperlib -if PYVERSION >= (3,3): - PY_UNICODE_1BYTE_KIND = _helperlib.py_unicode_1byte_kind - PY_UNICODE_2BYTE_KIND = _helperlib.py_unicode_2byte_kind - PY_UNICODE_4BYTE_KIND = _helperlib.py_unicode_4byte_kind - PY_UNICODE_WCHAR_KIND = _helperlib.py_unicode_wchar_kind +PY_UNICODE_1BYTE_KIND = _helperlib.py_unicode_1byte_kind +PY_UNICODE_2BYTE_KIND = _helperlib.py_unicode_2byte_kind +PY_UNICODE_4BYTE_KIND = _helperlib.py_unicode_4byte_kind +PY_UNICODE_WCHAR_KIND = _helperlib.py_unicode_wchar_kind class _Registry(object): @@ -176,15 +174,11 @@ def __init__(self, context, builder): self.cstring = Type.pointer(Type.int(8)) self.gil_state = Type.int(_helperlib.py_gil_state_size * 8) self.py_buffer_t = ir.ArrayType(ir.IntType(8), _helperlib.py_buffer_size) - if PYVERSION >= (3, 0): - self.py_hash_t = self.py_ssize_t - else: - self.py_hash_t = self.long - if PYVERSION >= (3,3): - self.py_unicode_1byte_kind = _helperlib.py_unicode_1byte_kind - self.py_unicode_2byte_kind = _helperlib.py_unicode_2byte_kind - self.py_unicode_4byte_kind = _helperlib.py_unicode_4byte_kind - self.py_unicode_wchar_kind = _helperlib.py_unicode_wchar_kind + self.py_hash_t = self.py_ssize_t + self.py_unicode_1byte_kind = _helperlib.py_unicode_1byte_kind + self.py_unicode_2byte_kind = _helperlib.py_unicode_2byte_kind + self.py_unicode_4byte_kind = _helperlib.py_unicode_4byte_kind + self.py_unicode_wchar_kind = _helperlib.py_unicode_wchar_kind def get_env_manager(self, env, env_body, env_ptr): return EnvironmentManager(self, env, env_body, env_ptr) @@ -489,41 +483,13 @@ def _long_from_native_int(self, ival, func_name, native_int_type, fnty = Type.function(self.pyobj, [native_int_type]) fn = self._get_function(fnty, name=func_name) resptr = cgutils.alloca_once(self.builder, self.pyobj) - - if PYVERSION < (3, 0): - # Under Python 2, we try to return a PyInt object whenever - # the given number fits in a C long. - pyint_fnty = Type.function(self.pyobj, [self.long]) - pyint_fn = self._get_function(pyint_fnty, name="PyInt_FromLong") - long_max = Constant.int(native_int_type, _helperlib.long_max) - if signed: - long_min = Constant.int(native_int_type, _helperlib.long_min) - use_pyint = self.builder.and_( - self.builder.icmp(lc.ICMP_SGE, ival, long_min), - self.builder.icmp(lc.ICMP_SLE, ival, long_max), - ) - else: - use_pyint = self.builder.icmp(lc.ICMP_ULE, ival, long_max) - - with self.builder.if_else(use_pyint) as (then, otherwise): - with then: - downcast_ival = self.builder.trunc(ival, self.long) - res = self.builder.call(pyint_fn, [downcast_ival]) - self.builder.store(res, resptr) - with otherwise: - res = self.builder.call(fn, [ival]) - self.builder.store(res, resptr) - else: - fn = self._get_function(fnty, name=func_name) - self.builder.store(self.builder.call(fn, [ival]), resptr) + fn = self._get_function(fnty, name=func_name) + self.builder.store(self.builder.call(fn, [ival]), resptr) return self.builder.load(resptr) def long_from_long(self, ival): - if PYVERSION < (3, 0): - func_name = "PyInt_FromLong" - else: - func_name = "PyLong_FromLong" + func_name = "PyLong_FromLong" fnty = Type.function(self.pyobj, [self.long]) fn = self._get_function(fnty, name=func_name) return self.builder.call(fn, [ival]) @@ -588,10 +554,6 @@ def number_subtract(self, lhs, rhs, inplace=False): def number_multiply(self, lhs, rhs, inplace=False): return self._call_number_operator("Multiply", lhs, rhs, inplace=inplace) - def number_divide(self, lhs, rhs, inplace=False): - assert PYVERSION < (3, 0) - return self._call_number_operator("Divide", lhs, rhs, inplace=inplace) - def number_truedivide(self, lhs, rhs, inplace=False): return self._call_number_operator("TrueDivide", lhs, rhs, inplace=inplace) @@ -602,7 +564,6 @@ def number_remainder(self, lhs, rhs, inplace=False): return self._call_number_operator("Remainder", lhs, rhs, inplace=inplace) def number_matrix_multiply(self, lhs, rhs, inplace=False): - assert PYVERSION >= (3, 5) return self._call_number_operator("MatrixMultiply", lhs, rhs, inplace=inplace) def number_lshift(self, lhs, rhs, inplace=False): @@ -1086,10 +1047,7 @@ def object_delitem(self, obj, key): def string_as_string(self, strobj): fnty = Type.function(self.cstring, [self.pyobj]) - if PYVERSION >= (3, 0): - fname = "PyUnicode_AsUTF8" - else: - fname = "PyString_AsString" + fname = "PyUnicode_AsUTF8" fn = self._get_function(fnty, name=fname) return self.builder.call(fn, [strobj]) @@ -1102,31 +1060,15 @@ def string_as_string_and_size(self, strobj): """ p_length = cgutils.alloca_once(self.builder, self.py_ssize_t) - if PYVERSION >= (3, 0): - fnty = Type.function(self.cstring, [self.pyobj, - self.py_ssize_t.as_pointer()]) - fname = "PyUnicode_AsUTF8AndSize" - fn = self._get_function(fnty, name=fname) - - buffer = self.builder.call(fn, [strobj, p_length]) - ok = self.builder.icmp_unsigned('!=', - ir.Constant(buffer.type, None), - buffer) - else: - fnty = Type.function(lc.Type.int(), [self.pyobj, - self.cstring.as_pointer(), - self.py_ssize_t.as_pointer()]) - fname = "PyString_AsStringAndSize" - fn = self._get_function(fnty, name=fname) - # Allocate space for the output parameters - p_buffer = cgutils.alloca_once(self.builder, self.cstring) - - status = self.builder.call(fn, [strobj, p_buffer, p_length]) - - negone = ir.Constant(status.type, -1) - ok = self.builder.icmp_signed("!=", status, negone) - buffer = self.builder.load(p_buffer) + fnty = Type.function(self.cstring, [self.pyobj, + self.py_ssize_t.as_pointer()]) + fname = "PyUnicode_AsUTF8AndSize" + fn = self._get_function(fnty, name=fname) + buffer = self.builder.call(fn, [strobj, p_length]) + ok = self.builder.icmp_unsigned('!=', + ir.Constant(buffer.type, None), + buffer) return (ok, buffer, self.builder.load(p_length)) def string_as_string_size_and_kind(self, strobj): @@ -1138,61 +1080,48 @@ def string_as_string_size_and_kind(self, strobj): The ``kind`` is a i32 (int32) of the Unicode kind constant The ``hash`` is a long/uint64_t (py_hash_t) of the Unicode constant hash """ - if PYVERSION >= (3, 3): - p_length = cgutils.alloca_once(self.builder, self.py_ssize_t) - p_kind = cgutils.alloca_once(self.builder, Type.int()) - p_ascii = cgutils.alloca_once(self.builder, Type.int()) - p_hash = cgutils.alloca_once(self.builder, self.py_hash_t) - fnty = Type.function(self.cstring, [self.pyobj, - self.py_ssize_t.as_pointer(), - Type.int().as_pointer(), - Type.int().as_pointer(), - self.py_hash_t.as_pointer()]) - fname = "numba_extract_unicode" - fn = self._get_function(fnty, name=fname) - - buffer = self.builder.call( - fn, [strobj, p_length, p_kind, p_ascii, p_hash]) - ok = self.builder.icmp_unsigned('!=', - ir.Constant(buffer.type, None), - buffer) - return (ok, buffer, self.builder.load(p_length), - self.builder.load(p_kind), self.builder.load(p_ascii), - self.builder.load(p_hash)) - else: - assert False, 'not supported on Python < 3.3' + p_length = cgutils.alloca_once(self.builder, self.py_ssize_t) + p_kind = cgutils.alloca_once(self.builder, Type.int()) + p_ascii = cgutils.alloca_once(self.builder, Type.int()) + p_hash = cgutils.alloca_once(self.builder, self.py_hash_t) + fnty = Type.function(self.cstring, [self.pyobj, + self.py_ssize_t.as_pointer(), + Type.int().as_pointer(), + Type.int().as_pointer(), + self.py_hash_t.as_pointer()]) + fname = "numba_extract_unicode" + fn = self._get_function(fnty, name=fname) + + buffer = self.builder.call( + fn, [strobj, p_length, p_kind, p_ascii, p_hash]) + ok = self.builder.icmp_unsigned('!=', + ir.Constant(buffer.type, None), + buffer) + return (ok, buffer, self.builder.load(p_length), + self.builder.load(p_kind), self.builder.load(p_ascii), + self.builder.load(p_hash)) def string_from_string_and_size(self, string, size): fnty = Type.function(self.pyobj, [self.cstring, self.py_ssize_t]) - if PYVERSION >= (3, 0): - fname = "PyUnicode_FromStringAndSize" - else: - fname = "PyString_FromStringAndSize" + fname = "PyString_FromStringAndSize" fn = self._get_function(fnty, name=fname) return self.builder.call(fn, [string, size]) def string_from_string(self, string): fnty = Type.function(self.pyobj, [self.cstring]) - if PYVERSION >= (3, 0): - fname = "PyUnicode_FromString" - else: - fname = "PyString_FromString" + fname = "PyString_FromString" fn = self._get_function(fnty, name=fname) return self.builder.call(fn, [string]) def string_from_kind_and_data(self, kind, string, size): fnty = Type.function(self.pyobj, [Type.int(), self.cstring, self.py_ssize_t]) - assert PYVERSION >= (3, 3), 'unsupported in this python-version' fname = "PyUnicode_FromKindAndData" fn = self._get_function(fnty, name=fname) return self.builder.call(fn, [kind, string, size]) def bytes_from_string_and_size(self, string, size): fnty = Type.function(self.pyobj, [self.cstring, self.py_ssize_t]) - if PYVERSION >= (3, 0): - fname = "PyBytes_FromStringAndSize" - else: - fname = "PyString_FromStringAndSize" + fname = "PyBytes_FromStringAndSize" fn = self._get_function(fnty, name=fname) return self.builder.call(fn, [string, size]) @@ -1217,10 +1146,7 @@ def borrow_none(self): def sys_write_stdout(self, fmt, *args): fnty = Type.function(Type.void(), [self.cstring], var_arg=True) - if PYVERSION >= (3, 2): - fn = self._get_function(fnty, name="PySys_FormatStdout") - else: - fn = self._get_function(fnty, name="PySys_WriteStdout") + fn = self._get_function(fnty, name="PySys_FormatStdout") return self.builder.call(fn, (fmt,) + args) def object_dump(self, obj): diff --git a/numba/roc/compiler.py b/numba/roc/compiler.py index 9100723301c..5c6d2939df4 100644 --- a/numba/roc/compiler.py +++ b/numba/roc/compiler.py @@ -1,6 +1,7 @@ from __future__ import print_function, absolute_import import copy from collections import namedtuple +import ctypes import re import numpy as np @@ -14,7 +15,6 @@ from numba.roc.hsadrv.driver import hsa, dgpu_present from .hsadrv import devicearray from numba.typing.templates import AbstractTemplate -from numba import ctypes_support as ctypes from numba import config from numba.compiler_lock import global_compiler_lock diff --git a/numba/serialize.py b/numba/serialize.py index c901f4f6fcd..a267d9ab33a 100644 --- a/numba/serialize.py +++ b/numba/serialize.py @@ -4,14 +4,7 @@ from __future__ import print_function, division, absolute_import -from .utils import PYVERSION - -# `imp` deprecated since Py3.4, use `importlib` as replacement since Py3.1 -if PYVERSION < (3, 1): - from imp import get_magic as _get_magic - bc_magic = _get_magic() -else: - from importlib.util import MAGIC_NUMBER as bc_magic +from importlib.util import MAGIC_NUMBER as bc_magic import marshal import sys diff --git a/numba/targets/cmathimpl.py b/numba/targets/cmathimpl.py index b843c79af19..0518f2ae177 100644 --- a/numba/targets/cmathimpl.py +++ b/numba/targets/cmathimpl.py @@ -11,7 +11,7 @@ from llvmlite.llvmpy.core import Type from numba.targets.imputils import Registry, impl_ret_untracked -from numba import types, cgutils, utils +from numba import types, cgutils from numba.typing import signature from . import builtins, mathimpl @@ -48,14 +48,13 @@ def isinf_float_impl(context, builder, sig, args): return impl_ret_untracked(context, builder, sig.return_type, res) -if utils.PYVERSION >= (3, 2): - @lower(cmath.isfinite, types.Complex) - def isfinite_float_impl(context, builder, sig, args): - [typ] = sig.args - [value] = args - z = context.make_complex(builder, typ, value=value) - res = is_finite(builder, z) - return impl_ret_untracked(context, builder, sig.return_type, res) +@lower(cmath.isfinite, types.Complex) +def isfinite_float_impl(context, builder, sig, args): + [typ] = sig.args + [value] = args + z = context.make_complex(builder, typ, value=value) + res = is_finite(builder, z) + return impl_ret_untracked(context, builder, sig.return_type, res) @lower(cmath.rect, types.Float, types.Float) diff --git a/numba/targets/externals.py b/numba/targets/externals.py index 1d76c88db36..0674c02fbae 100644 --- a/numba/targets/externals.py +++ b/numba/targets/externals.py @@ -12,11 +12,6 @@ from numba import _helperlib from . import intrinsics -# Require workaround for https://support.microsoft.com/en-us/kb/982107 ? -need_kb982107 = (config.PYVERSION == (2, 7) and - config.IS_WIN32 and - not config.IS_32BITS) - def _add_missing_symbol(symbol, addr): """Add missing symbol into LLVM internal symtab @@ -156,48 +151,10 @@ def _do_install(self, context): # (under Windows, different versions of the C runtime can # be loaded at the same time, for example msvcrt100 by # CPython and msvcrt120 by LLVM) - if need_kb982107 and fname.startswith('fmod'): + if fname.startswith('fmod'): ll.add_symbol(fname, c_helpers['fixed_' + fname]) else: ll.add_symbol(fname, c_helpers[fname]) - if need_kb982107: - # Make the library immortal - self._kb982107_lib = set_fnclex(context, c_helpers) - - -def set_fnclex(context, c_helpers): - """ - Install fnclex before fmod calls. - Workaround for https://support.microsoft.com/en-us/kb/982107 - """ - ptr_set_fnclex = c_helpers['set_fnclex'] - fn = ctypes.CFUNCTYPE(None, ctypes.c_void_p)(ptr_set_fnclex) - - library = compile_fnclex(context) - fnclex_ptr = library.get_pointer_to_function('fnclex') - fn(fnclex_ptr) - - return library - - -def compile_fnclex(context): - """ - Compile a function that calls fnclex to workaround - https://support.microsoft.com/en-us/kb/982107 - """ - codegen = context.codegen() - library = codegen.create_library("kb982107") - ir_mod = """ -define void @fnclex() { - call void asm sideeffect "fnclex", ""() - ret void -} - """ - ll.initialize_native_asmparser() - library.add_llvm_module(ll.parse_assembly(ir_mod)) - library.finalize() - return library - c_math_functions = _ExternalMathFunctions() diff --git a/numba/targets/mathimpl.py b/numba/targets/mathimpl.py index e2f7f76590c..a4b3d19c4d4 100644 --- a/numba/targets/mathimpl.py +++ b/numba/targets/mathimpl.py @@ -200,14 +200,10 @@ def float_impl(context, builder, sig, args): cosh_impl = unary_math_extern(math.cosh, "coshf", "cosh") tanh_impl = unary_math_extern(math.tanh, "tanhf", "tanh") -# math.floor and math.ceil return float on 2.x, int on 3.x -if utils.PYVERSION > (3, 0): - log2_impl = unary_math_extern(math.log2, "log2f", "log2") - ceil_impl = unary_math_extern(math.ceil, "ceilf", "ceil", True) - floor_impl = unary_math_extern(math.floor, "floorf", "floor", True) -else: - ceil_impl = unary_math_extern(math.ceil, "ceilf", "ceil") - floor_impl = unary_math_extern(math.floor, "floorf", "floor") +log2_impl = unary_math_extern(math.log2, "log2f", "log2") +ceil_impl = unary_math_extern(math.ceil, "ceilf", "ceil", True) +floor_impl = unary_math_extern(math.floor, "floorf", "floor", True) + gamma_impl = unary_math_extern(math.gamma, "numba_gammaf", "numba_gamma") # work-around sqrt_impl = unary_math_extern(math.sqrt, "sqrtf", "sqrt") trunc_impl = unary_math_extern(math.trunc, "truncf", "trunc", True) @@ -238,17 +234,17 @@ def isinf_int_impl(context, builder, sig, args): return impl_ret_untracked(context, builder, sig.return_type, res) -if utils.PYVERSION >= (3, 2): - @lower(math.isfinite, types.Float) - def isfinite_float_impl(context, builder, sig, args): - [val] = args - res = is_finite(builder, val) - return impl_ret_untracked(context, builder, sig.return_type, res) +@lower(math.isfinite, types.Float) +def isfinite_float_impl(context, builder, sig, args): + [val] = args + res = is_finite(builder, val) + return impl_ret_untracked(context, builder, sig.return_type, res) - @lower(math.isfinite, types.Integer) - def isfinite_int_impl(context, builder, sig, args): - res = cgutils.true_bit - return impl_ret_untracked(context, builder, sig.return_type, res) + +@lower(math.isfinite, types.Integer) +def isfinite_int_impl(context, builder, sig, args): + res = cgutils.true_bit + return impl_ret_untracked(context, builder, sig.return_type, res) @lower(math.copysign, types.Float, types.Float) @@ -458,5 +454,5 @@ def gcd(a, b): res = context.compile_internal(builder, gcd, sig, args) return impl_ret_untracked(context, builder, sig.return_type, res) -if utils.PYVERSION >= (3, 5): - lower(math.gcd, types.Integer, types.Integer)(gcd_impl) + +lower(math.gcd, types.Integer, types.Integer)(gcd_impl) diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index 279ffa66fd8..6720bfa0f36 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -17,7 +17,6 @@ from . import builtins, callconv, ufunc_db, arrayobj from .imputils import Registry, impl_ret_new_ref, force_error_model from .. import typing, types, cgutils, numpy_support, utils -from ..config import PYVERSION from ..numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype from ..typing import npydecl from ..extending import overload, intrinsic diff --git a/numba/testing/main.py b/numba/testing/main.py index 87d14effb86..30507c53a2e 100644 --- a/numba/testing/main.py +++ b/numba/testing/main.py @@ -17,7 +17,7 @@ from unittest import result, runner, signals, suite, loader, case from .loader import TestLoader -from numba.utils import PYVERSION, StringIO +from numba.utils import StringIO from numba import config try: @@ -240,51 +240,6 @@ def parseArgs(self, argv): if '-l' in argv: argv.remove('-l') self.list = True - if PYVERSION < (3, 4): - if '-m' in argv: - # We want '-m' to work on all versions, emulate this option. - dashm_posn = argv.index('-m') - # the default number of processes to use - nprocs = multiprocessing.cpu_count() - # see what else is in argv - # ensure next position is safe for access - try: - m_option = argv[dashm_posn + 1] - # see if next arg is "end options" - if m_option != '--': - #try and parse the next arg as an int - try: - nprocs = int(m_option) - except Exception: - msg = ('Expected an integer argument to ' - 'option `-m`, found "%s"') - raise ValueError(msg % m_option) - # remove the value of the option - argv.remove(m_option) - # else end options, use defaults - except IndexError: - # at end of arg list, use defaults - pass - - self.multiprocess = nprocs - argv.remove('-m') - - if '-j' in argv: - # We want '-s' to work on all versions, emulate this option. - dashs_posn = argv.index('-j') - j_option = argv[dashs_posn + 1] - self.useslice = j_option - argv.remove(j_option) - argv.remove('-j') - - self.gitdiff = False - if '-g' in argv: - self.gitdiff = True - argv.remove('-g') - - # handle tags - self._handle_tags(argv, '--tags') - self._handle_tags(argv, '--exclude-tags') super(NumbaTestProgram, self).parseArgs(argv) @@ -393,8 +348,7 @@ def _choose_gitdiff_tests(tests): # normalise the paths as they are unix style from repo.git.diff gdiff_paths = [os.path.normpath(x) for x in gdiff_paths] selected = [] - if PYVERSION > (2, 7): # inspect output changes in py3 - gdiff_paths = [os.path.join(repo.working_dir, x) for x in gdiff_paths] + gdiff_paths = [os.path.join(repo.working_dir, x) for x in gdiff_paths] for test in _flatten_suite(tests): assert isinstance(test, unittest.TestCase) fname = inspect.getsourcefile(test.__class__) diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index 15a58e5af79..b8888e0c37c 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -420,11 +420,8 @@ def test_enumerate_start_invalid_start_type(self): cr = compile_isolated(pyfunc, (), flags=enable_pyobj_flags) with self.assertRaises(TypeError) as raises: cr.entry_point() - if config.PYVERSION == (2, 7): - thing = 'index' - else: - thing = 'integer' - msg = "'float' object cannot be interpreted as an %s" % thing + + msg = "'float' object cannot be interpreted as an integer" self.assertIn(msg, str(raises.exception)) def test_enumerate_start_invalid_start_type_npm(self): diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 44b79104877..63bd2e1c720 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -157,7 +157,6 @@ def inner(x): cfunc = njit(outer) self.assertEqual(cfunc(10), outer(10)) - @unittest.skipIf(utils.PYVERSION < (3, 0), "needs Python 3") def test_inner_function_with_closure_3(self): code = """ diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index 89280d73341..8e94ad2f76a 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -188,11 +188,9 @@ def test_isinf(self, flags=enable_pyobj_flags): def test_isinf_npm(self): self.check_predicate_func(isinf_usecase, no_pyobj_flags) - @unittest.skipIf(utils.PYVERSION < (3, 2), "needs Python 3.2+") def test_isfinite(self, flags=enable_pyobj_flags): self.check_predicate_func(isfinite_usecase, enable_pyobj_flags) - @unittest.skipIf(utils.PYVERSION < (3, 2), "needs Python 3.2+") def test_isfinite_npm(self): self.check_predicate_func(isfinite_usecase, no_pyobj_flags) diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index 09014aeefc4..a5b878aff73 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -194,10 +194,7 @@ def list24(x): list6, list7, list8, list9, list10, list11, list12, list13, list14, list15, list16, list17, list18, list19, list20, - list21, list23, list24] - - if utils.PYVERSION >= (3, 0): - f.append(list22) + list21, list22, list23, list24] var = [1, 2, 3, 4, 5] for ref in f: @@ -222,13 +219,6 @@ def list24(x): else: bits = 32 - if utils.PYVERSION < (3, 0): - with self.assertRaises(TypingError) as raises: - cfunc = jit(nopython=True)(list22) - cfunc(var) - msg = "Cannot unify reflected list(int%d) and int%d" % (bits, bits) - self.assertIn(msg, str(raises.exception)) - def test_objmode_inlining(self): def objmode_func(y): z = object() diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index 3d0055a628d..ba13f5b09ea 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -1,11 +1,11 @@ from __future__ import print_function, absolute_import, division +from ctypes import * import sys import threading import numpy as np -from numba.ctypes_support import * from numba import unittest_support as unittest from numba.compiler import compile_isolated diff --git a/numba/tests/test_dataflow.py b/numba/tests/test_dataflow.py index 261e6c8dbb8..8875b3d159a 100644 --- a/numba/tests/test_dataflow.py +++ b/numba/tests/test_dataflow.py @@ -4,7 +4,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba.utils import PYVERSION from numba import types, errors from .support import TestCase, CompilationCache, skip_tryexcept_supported diff --git a/numba/tests/test_intwidth.py b/numba/tests/test_intwidth.py index d8187e8d32a..d400a98d6bd 100644 --- a/numba/tests/test_intwidth.py +++ b/numba/tests/test_intwidth.py @@ -75,8 +75,6 @@ def test_bit_length(self): self.assertEqual(f(0xffffffff), 32) self.assertEqual(f(0xffffffffffffffff), 64) self.assertEqual(f(0x10000000000000000), 65) - if utils.PYVERSION < (3, 0): - self.assertEqual(f(long(0xffffffffffffffff)), 64) @tag('important') def test_constant_int64(self, nopython=False): diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index 72ac4b57055..aab252c9ca4 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -10,7 +10,7 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags, utils from numba import types, numpy_support -from numba.config import PYVERSION, IS_WIN32, IS_32BITS +from numba.config import IS_WIN32, IS_32BITS from .support import TestCase, CompilationCache, tag enable_pyobj_flags = Flags() @@ -509,11 +509,9 @@ def test_isinf(self): def test_isinf_npm(self): self.check_predicate_func(isinf, flags=no_pyobj_flags) - @unittest.skipIf(utils.PYVERSION < (3, 2), "needs Python 3.2+") def test_isfinite(self): self.check_predicate_func(isfinite, flags=enable_pyobj_flags) - @unittest.skipIf(utils.PYVERSION < (3, 2), "needs Python 3.2+") def test_isfinite_npm(self): self.check_predicate_func(isfinite, flags=no_pyobj_flags) @@ -592,8 +590,6 @@ def test_erfc(self, flags=enable_pyobj_flags): def test_erfc_npm(self): self.test_erfc(flags=no_pyobj_flags) - @unittest.skipIf(PYVERSION == (2, 7) and IS_WIN32 and not IS_32BITS, - 'unknown error with tgamma') def test_gamma(self, flags=enable_pyobj_flags): pyfunc = gamma x_values = [1., -0.9, -0.5, 0.5] @@ -625,7 +621,6 @@ def test_pow(self, flags=enable_pyobj_flags): y_values = [x * 2 for x in x_values] self.run_binary(pyfunc, x_types, x_values, y_values, flags) - @unittest.skipIf(utils.PYVERSION < (3, 5), "gcd added in Python 3.5") def test_gcd(self, flags=enable_pyobj_flags): from itertools import product, repeat, chain pyfunc = gcd @@ -638,7 +633,6 @@ def test_gcd(self, flags=enable_pyobj_flags): x_types, x_values, y_values = zip(*chain(signed_args, unsigned_args)) self.run_binary(pyfunc, x_types, x_values, y_values, flags) - @unittest.skipIf(utils.PYVERSION < (3, 5), "gcd added in Python 3.5") def test_gcd_npm(self): self.test_gcd(flags=no_pyobj_flags) diff --git a/numba/tests/test_numpyadapt.py b/numba/tests/test_numpyadapt.py index cc001c2951d..c06613996e8 100644 --- a/numba/tests/test_numpyadapt.py +++ b/numba/tests/test_numpyadapt.py @@ -1,9 +1,10 @@ from __future__ import print_function +from ctypes import * + import numpy as np import numba.unittest_support as unittest -from numba.ctypes_support import * from numba import _helperlib diff --git a/numba/tests/test_objects.py b/numba/tests/test_objects.py index f587b4a715c..e3ff53d4320 100644 --- a/numba/tests/test_objects.py +++ b/numba/tests/test_objects.py @@ -6,7 +6,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba.utils import PYVERSION from numba import types from .support import TestCase diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index ed4bf4ebdbf..3b0f813534b 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -11,7 +11,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import jit, types, typeinfer, utils, errors -from numba.config import PYVERSION from .support import TestCase, tag from .true_div_usecase import truediv_usecase, itruediv_usecase from .matmul_usecase import (matmul_usecase, imatmul_usecase, DumbMatrix, @@ -224,18 +223,6 @@ def mul_usecase(x, y): def imul_usecase(x, y): return operator.imul(x, y) - if PYVERSION >= (3, 0): - div_usecase = NotImplemented - idiv_usecase = NotImplemented - else: - @staticmethod - def div_usecase(x, y): - return operator.div(x, y) - - @staticmethod - def idiv_usecase(x, y): - return operator.idiv(x, y) - @staticmethod def floordiv_usecase(x, y): return operator.floordiv(x, y) @@ -394,8 +381,6 @@ class TestOperators(TestCase): def run_test_ints(self, pyfunc, x_operands, y_operands, types_list, flags=force_pyobj_flags): - if pyfunc is NotImplemented: - self.skipTest("test irrelevant on this version of Python") for arg_types in types_list: cr = compile_isolated(pyfunc, arg_types, flags=flags) cfunc = cr.entry_point @@ -417,8 +402,6 @@ def run_test_ints(self, pyfunc, x_operands, y_operands, types_list, def run_test_floats(self, pyfunc, x_operands, y_operands, types_list, flags=force_pyobj_flags): - if pyfunc is NotImplemented: - self.skipTest("test irrelevant on this version of Python") for arg_types in types_list: cr = compile_isolated(pyfunc, arg_types, flags=flags) cfunc = cr.entry_point @@ -629,8 +612,6 @@ def test_meth(self): def check_div_errors(self, usecase_name, msg, flags=force_pyobj_flags, allow_complex=False): pyfunc = getattr(self.op, usecase_name) - if pyfunc is NotImplemented: - self.skipTest("%r not implemented" % (usecase_name,)) # Signed and unsigned division can take different code paths, # test them both. arg_types = [types.int32, types.uint32, types.float64] @@ -1290,9 +1271,6 @@ def control_unsigned(a, b): def run_binary(self, pyfunc, control_func, operands, types, expected_type=utils.INT_TYPES, **assertPreciseEqualArgs): - if pyfunc is NotImplemented: - self.skipTest("test irrelevant on this version of Python") - for xt, yt in types: cr = compile_isolated(pyfunc, (xt, yt), flags=Noflags) cfunc = cr.entry_point @@ -1310,9 +1288,6 @@ def run_binary(self, pyfunc, control_func, operands, types, def run_unary(self, pyfunc, control_func, operands, types, expected_type=utils.INT_TYPES): - if pyfunc is NotImplemented: - self.skipTest("test irrelevant on this version of Python") - for xt in types: cr = compile_isolated(pyfunc, (xt,), flags=Noflags) cfunc = cr.entry_point diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 27ac00be22e..5839fc77272 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -4,12 +4,13 @@ """ Tests the parallel backend """ -import threading +import faulthandler import multiprocessing -import random import os -import sys +import random import subprocess +import sys +import threading import numpy as np @@ -28,8 +29,6 @@ _TEST_TIMEOUT = _RUNNER_TIMEOUT - 60. -if utils.PYVERSION >= (3, 0): - import faulthandler # Check which backends are available # TODO: Put this in a subprocess so the address space is kept clean @@ -58,9 +57,6 @@ _gnuomp = _HAVE_OMP_POOL and omppool.openmp_vendor == "GNU" skip_unless_gnu_omp = unittest.skipUnless(_gnuomp, "GNU OpenMP only tests") -skip_unless_py3 = unittest.skipUnless(utils.PYVERSION >= (3, 0), - "Test runs on Python 3 only") - _windows = sys.platform.startswith('win') _osx = sys.platform.startswith('darwin') _windows_py27 = (sys.platform.startswith('win32') and @@ -146,8 +142,7 @@ def __call__(self): def chooser(fnlist, **kwargs): q = kwargs.get('queue') try: - if utils.PYVERSION >= (3, 0): - faulthandler.enable() + faulthandler.enable() for _ in range(int(len(fnlist) * 1.5)): fn = random.choice(fnlist) fn() @@ -184,23 +179,16 @@ def __init__(self, method): self._method = method def __call__(self, *args, **kwargs): - if utils.PYVERSION < (3, 0): - return multiprocessing.Process(*args, **kwargs) - else: - ctx = multiprocessing.get_context(self._method) - return ctx.Process(*args, **kwargs) + ctx = multiprocessing.get_context(self._method) + return ctx.Process(*args, **kwargs) def _get_mp_classes(method): - if utils.PYVERSION < (3, 0): - proc = _proc_class_impl(method) - queue = multiprocessing.Queue - else: - if method == 'default': - method = None - ctx = multiprocessing.get_context(method) - proc = _proc_class_impl(method) - queue = ctx.Queue + if method == 'default': + method = None + ctx = multiprocessing.get_context(method) + proc = _proc_class_impl(method) + queue = ctx.Queue return proc, queue @@ -244,13 +232,10 @@ class TestParallelBackendBase(TestCase): all_impls.extend(parfor_impls) parallelism = ['threading', 'random'] - if utils.PYVERSION > (3, 0): - parallelism.append('multiprocessing_spawn') - if _HAVE_OS_FORK: - parallelism.append('multiprocessing_fork') - parallelism.append('multiprocessing_forkserver') - else: - parallelism.append('multiprocessing_default') + parallelism.append('multiprocessing_spawn') + if _HAVE_OS_FORK: + parallelism.append('multiprocessing_fork') + parallelism.append('multiprocessing_forkserver') runners = { 'concurrent_jit': [ @@ -281,13 +266,10 @@ def run_compile(self, fnlist, parallelism='threading'): elif parallelism == 'multiprocessing_default': default_proc_impl(fnlist) elif parallelism == 'random': - if utils.PYVERSION < (3, 0): - ps = [thread_impl, default_proc_impl] - else: - ps = [thread_impl, spawn_proc_impl] - if _HAVE_OS_FORK: - ps.append(fork_proc_impl) - ps.append(forkserver_proc_impl) + ps = [thread_impl, spawn_proc_impl] + if _HAVE_OS_FORK: + ps.append(fork_proc_impl) + ps.append(forkserver_proc_impl) random.shuffle(ps) for impl in ps: @@ -516,7 +498,6 @@ def generate(cls): @parfors_skip_unsupported -@skip_unless_py3 class TestMiscBackendIssues(ThreadLayerTestHelper): """ Checks fixes for the issues with threading backends implementation @@ -651,7 +632,6 @@ def test_par_parent_implicit_mp_fork_par_child(self): print(out, err) @linux_only - @skip_unless_py3 def test_par_parent_explicit_mp_fork_par_child(self): """ Explicit use of multiprocessing fork context. @@ -686,7 +666,6 @@ def test_par_parent_explicit_mp_fork_par_child(self): if self._DEBUG: print(out, err) - @skip_unless_py3 def test_par_parent_mp_spawn_par_child_par_parent(self): """ Explicit use of multiprocessing spawn, this is safe. @@ -773,7 +752,6 @@ def test_serial_parent_implicit_mp_fork_par_child_then_par_parent(self): print(out, err) @linux_only - @skip_unless_py3 def test_serial_parent_explicit_mp_fork_par_child_then_par_parent(self): """ Explicit use of multiprocessing 'fork'. @@ -821,7 +799,6 @@ class TestInitSafetyIssues(TestCase): _DEBUG = False @linux_only # only linux can leak semaphores - @skip_unless_py3 # need multiprocessing.get_context to obtain spawn on linux def test_orphaned_semaphore(self): # sys path injection and separate usecase module to make sure everything # is importable by children of multiprocessing diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 71ceb901db2..aedd07a0ef1 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -20,7 +20,6 @@ from collections import defaultdict import numba -from numba.utils import PYVERSION from numba import unittest_support as unittest from .support import TestCase, captured_stdout, MemoryLeakMixin, override_env_config from numba import njit, prange, stencil, inline_closurecall diff --git a/numba/tests/test_print.py b/numba/tests/test_print.py index d21587cf4c4..c94c997d605 100644 --- a/numba/tests/test_print.py +++ b/numba/tests/test_print.py @@ -189,7 +189,6 @@ def print_kwarg(): "keyword arguments.") self.assertIn(raises.exception.msg, expected) - @unittest.skipIf(utils.PYVERSION < (3, 2), "needs Python 3.2+") def test_print_no_truncation(self): ''' See: https://github.com/numba/numba/issues/3811 ''' diff --git a/numba/tests/test_return_values.py b/numba/tests/test_return_values.py index 41b4b6d56da..1c38c6bd1e5 100644 --- a/numba/tests/test_return_values.py +++ b/numba/tests/test_return_values.py @@ -8,7 +8,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba.utils import PYVERSION from numba import types from numba.errors import TypingError diff --git a/numba/tests/test_support.py b/numba/tests/test_support.py index 6a20f3e676d..7d5eb75f190 100644 --- a/numba/tests/test_support.py +++ b/numba/tests/test_support.py @@ -22,8 +22,6 @@ class TestAssertPreciseEqual(TestCase): """ int_types = [int] - if utils.PYVERSION < (3,): - int_types.append(long) np_float_types = [np.float32, np.float64] float_types = [float] + np_float_types np_complex_types = [np.complex64, np.complex128] diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index 0a743545917..895b6c303e0 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -528,7 +528,6 @@ def call(i, j): r = call(123, 0) self.assertEqual(r, Rect(width=123, height=-321)) - @unittest.skipIf(utils.PYVERSION < (3, 0), "needs Python 3") def test_string_literal_in_ctor(self): # Test for issue #3813 @@ -611,7 +610,6 @@ def test_index(self): class TestTupleBuild(TestCase): - @unittest.skipIf(utils.PYVERSION < (3, 0), "needs Python 3") def test_build_unpack(self): def check(p): # using eval here since Python 2 doesn't even support the syntax @@ -624,8 +622,6 @@ def check(p): # Heterogeneous check((4, 5.5)) - - @unittest.skipIf(utils.PYVERSION < (3, 0), "needs Python 3") def test_build_unpack_more(self): def check(p): # using eval here since Python 2 doesn't even support the syntax @@ -638,8 +634,6 @@ def check(p): # Heterogeneous check((4, 5.5)) - - @unittest.skipIf(utils.PYVERSION < (3, 0), "needs Python 3") def test_build_unpack_call(self): def check(p): # using eval here since Python 2 doesn't even support the syntax diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index feb3ab62f35..c6c475a0c32 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -15,7 +15,6 @@ from numba.compiler import compile_isolated, Flags, DEFAULT_FLAGS from numba.numpy_support import from_dtype, version as numpy_version from numba import jit, vectorize -from numba.config import PYVERSION from numba.errors import LoweringError, TypingError from .support import TestCase, CompilationCache, MemoryLeakMixin, tag from numba.typing.npydecl import supported_ufuncs, all_ufuncs @@ -341,8 +340,7 @@ def test_divide_ufunc(self, flags=no_pyobj_flags): # Bear in mind that in python3 divide IS true_divide # so the out type for int types will be a double int_out_type = None - if PYVERSION >= (3, 0): - int_out_type = types.float64 + int_out_type = types.float64 self.binary_ufunc_test(np.divide, flags=flags, int_output_type=int_out_type) @@ -1212,8 +1210,7 @@ def test_multiply_array_op(self): @tag('important') def test_divide_array_op(self): int_out_type = None - if PYVERSION >= (3, 0): - int_out_type = types.float64 + int_out_type = types.float64 self.binary_op_test('/', int_output_type=int_out_type) @tag('important') diff --git a/numba/tracing.py b/numba/tracing.py index 1b6dafcec99..d4439b872a7 100644 --- a/numba/tracing.py +++ b/numba/tracing.py @@ -153,10 +153,7 @@ def wrapper(*args, **kwds): elif type(func) == property: raise NotImplementedError - if config.PYVERSION >= (3, 0): - spec = inspect.getfullargspec(func) - else: - spec = inspect.getargspec(func) + spec = inspect.getfullargspec(func) return rewrap(wraps(func)(wrapper)) arg0 = len(args) and args[0] or None diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 1511dde5d88..5ddc83b48c9 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -27,9 +27,8 @@ def fallback_context(state, msg): if not state.status.can_fallback: raise else: - if utils.PYVERSION >= (3,): - # Clear all references attached to the traceback - e = e.with_traceback(None) + # Clear all references attached to the traceback + e = e.with_traceback(None) # this emits a warning containing the error message body in the # case of fallback from npm to objmode loop_lift = '' if state.flags.enable_looplift else 'OUT' diff --git a/numba/typing/cmathdecl.py b/numba/typing/cmathdecl.py index 920faf03c23..575245e4d50 100644 --- a/numba/typing/cmathdecl.py +++ b/numba/typing/cmathdecl.py @@ -36,10 +36,9 @@ class CMath_predicate(ConcreteTemplate): sorted(types.complex_domain)] -if utils.PYVERSION >= (3, 2): - @infer_global(cmath.isfinite) - class CMath_isfinite(CMath_predicate): - pass +@infer_global(cmath.isfinite) +class CMath_isfinite(CMath_predicate): + pass @infer_global(cmath.log) diff --git a/numba/typing/mathdecl.py b/numba/typing/mathdecl.py index 14f960bd8f5..052e23dee2a 100644 --- a/numba/typing/mathdecl.py +++ b/numba/typing/mathdecl.py @@ -61,17 +61,11 @@ class Math_converter(ConcreteTemplate): signature(types.int64, types.float64), ] -# math.floor and math.ceil return float on 2.x, int on 3.x -if utils.PYVERSION > (3, 0): - @infer_global(math.floor) - @infer_global(math.ceil) - class Math_floor_ceil(Math_converter): - pass -else: - @infer_global(math.floor) - @infer_global(math.ceil) - class Math_floor_ceil(Math_unary): - pass + +@infer_global(math.floor) +@infer_global(math.ceil) +class Math_floor_ceil(Math_converter): + pass @infer_global(math.copysign) @@ -102,10 +96,10 @@ class Math_predicate(ConcreteTemplate): signature(types.boolean, types.float64), ] -if utils.PYVERSION >= (3, 2): - @infer_global(math.isfinite) - class Math_isfinite(Math_predicate): - pass + +@infer_global(math.isfinite) +class Math_isfinite(Math_predicate): + pass @infer_global(math.pow) @@ -118,19 +112,18 @@ class Math_pow(ConcreteTemplate): ] -if utils.PYVERSION >= (3, 5): - @infer_global(math.gcd) - class Math_gcd(ConcreteTemplate): - cases = [ - signature(types.int64, types.int64, types.int64), - signature(types.int32, types.int32, types.int32), - signature(types.int16, types.int16, types.int16), - signature(types.int8, types.int8, types.int8), - signature(types.uint64, types.uint64, types.uint64), - signature(types.uint32, types.uint32, types.uint32), - signature(types.uint16, types.uint16, types.uint16), - signature(types.uint8, types.uint8, types.uint8), - ] +@infer_global(math.gcd) +class Math_gcd(ConcreteTemplate): + cases = [ + signature(types.int64, types.int64, types.int64), + signature(types.int32, types.int32, types.int32), + signature(types.int16, types.int16, types.int16), + signature(types.int8, types.int8, types.int8), + signature(types.uint64, types.uint64, types.uint64), + signature(types.uint32, types.uint32, types.uint32), + signature(types.uint16, types.uint16, types.uint16), + signature(types.uint8, types.uint8, types.uint8), + ] @infer_global(math.frexp) diff --git a/numba/unittest_support.py b/numba/unittest_support.py index 841d285ec49..82eeb3fd0f1 100644 --- a/numba/unittest_support.py +++ b/numba/unittest_support.py @@ -4,7 +4,4 @@ import sys import warnings from . import config - -from numba.config import PYVERSION - from unittest import * diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index a19437b14ef..8001c6bf66b 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -36,9 +36,8 @@ def fallback_context(state, msg): if not state.status.can_fallback: raise else: - if utils.PYVERSION >= (3,): - # Clear all references attached to the traceback - e = e.with_traceback(None) + # Clear all references attached to the traceback + e = e.with_traceback(None) # this emits a warning containing the error message body in the # case of fallback from npm to objmode loop_lift = '' if state.flags.enable_looplift else 'OUT' From 788cdb821e1c7012fecbe9010e05a2a752c38a1d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 13:12:48 +0000 Subject: [PATCH 214/595] Remove future imports --- numba/__init__.py | 1 - numba/_runtests.py | 2 -- numba/_version.py | 1 - numba/annotations/type_annotations.py | 2 -- numba/array_analysis.py | 1 - numba/bytecode.py | 1 - numba/caching.py | 1 - numba/callwrapper.py | 2 -- numba/ccallback.py | 1 - numba/cffi_support.py | 1 - numba/cgutils.py | 1 - numba/compiler.py | 2 -- numba/compiler_machinery.py | 2 -- numba/config.py | 2 -- numba/consts.py | 2 -- numba/controlflow.py | 2 -- numba/cuda/__init__.py | 2 -- numba/cuda/api.py | 1 - numba/cuda/compiler.py | 3 --- numba/cuda/cudadecl.py | 1 - numba/cuda/cudadrv/autotune.py | 1 - numba/cuda/cudadrv/devicearray.py | 1 - numba/cuda/cudadrv/devices.py | 1 - numba/cuda/cudadrv/driver.py | 1 - numba/cuda/cudadrv/drvapi.py | 1 - numba/cuda/cudadrv/enums.py | 1 - numba/cuda/cudadrv/error.py | 3 --- numba/cuda/cudadrv/libs.py | 1 - numba/cuda/cudadrv/ndarray.py | 2 -- numba/cuda/cudadrv/nvvm.py | 1 - numba/cuda/cudaimpl.py | 2 -- numba/cuda/cudamath.py | 1 - numba/cuda/decorators.py | 1 - numba/cuda/descriptor.py | 1 - numba/cuda/device_init.py | 2 -- numba/cuda/dispatcher.py | 2 -- numba/cuda/errors.py | 2 -- numba/cuda/initialize.py | 3 --- numba/cuda/intrinsic_wrapper.py | 1 - numba/cuda/kernels/reduction.py | 1 - numba/cuda/libdevice.py | 1 - numba/cuda/nvvmutils.py | 1 - numba/cuda/printimpl.py | 2 -- numba/cuda/random.py | 1 - numba/cuda/simulator/__init__.py | 2 -- numba/cuda/simulator/api.py | 1 - numba/cuda/simulator/kernel.py | 2 -- numba/cuda/simulator_init.py | 1 - numba/cuda/stubs.py | 1 - numba/cuda/target.py | 1 - numba/cuda/testing.py | 2 -- numba/cuda/tests/cudadrv/test_context_stack.py | 2 -- numba/cuda/tests/cudadrv/test_cuda_array_slicing.py | 2 -- numba/cuda/tests/cudadrv/test_cuda_auto_context.py | 1 - numba/cuda/tests/cudadrv/test_cuda_driver.py | 2 -- numba/cuda/tests/cudadrv/test_cuda_libraries.py | 2 -- numba/cuda/tests/cudadrv/test_deallocations.py | 2 -- numba/cuda/tests/cudadrv/test_detect.py | 1 - numba/cuda/tests/cudadrv/test_events.py | 1 - numba/cuda/tests/cudadrv/test_host_alloc.py | 1 - numba/cuda/tests/cudadrv/test_inline_ptx.py | 2 -- numba/cuda/tests/cudadrv/test_ir_patch.py | 2 -- numba/cuda/tests/cudadrv/test_linker.py | 1 - numba/cuda/tests/cudadrv/test_nvvm_driver.py | 2 -- numba/cuda/tests/cudadrv/test_pinned.py | 2 -- numba/cuda/tests/cudadrv/test_profiler.py | 1 - numba/cuda/tests/cudadrv/test_reset_device.py | 1 - numba/cuda/tests/cudadrv/test_select_device.py | 1 - numba/cuda/tests/cudapy/test_array.py | 2 -- numba/cuda/tests/cudapy/test_array_args.py | 2 -- numba/cuda/tests/cudapy/test_array_methods.py | 2 -- numba/cuda/tests/cudapy/test_atomics.py | 2 -- numba/cuda/tests/cudapy/test_autojit.py | 1 - numba/cuda/tests/cudapy/test_blackscholes.py | 2 -- numba/cuda/tests/cudapy/test_boolean.py | 1 - numba/cuda/tests/cudapy/test_complex.py | 2 -- numba/cuda/tests/cudapy/test_complex_kernel.py | 1 - numba/cuda/tests/cudapy/test_const_string.py | 2 -- numba/cuda/tests/cudapy/test_constmem.py | 2 -- numba/cuda/tests/cudapy/test_cuda_autojit.py | 1 - numba/cuda/tests/cudapy/test_datetime.py | 2 -- numba/cuda/tests/cudapy/test_debug.py | 2 -- numba/cuda/tests/cudapy/test_debuginfo.py | 2 -- numba/cuda/tests/cudapy/test_deprecation.py | 2 -- numba/cuda/tests/cudapy/test_device_func.py | 3 --- numba/cuda/tests/cudapy/test_errors.py | 2 -- numba/cuda/tests/cudapy/test_exception.py | 2 -- numba/cuda/tests/cudapy/test_fastmath.py | 2 -- numba/cuda/tests/cudapy/test_forall.py | 2 -- numba/cuda/tests/cudapy/test_freevar.py | 2 -- numba/cuda/tests/cudapy/test_globals.py | 1 - numba/cuda/tests/cudapy/test_gufunc.py | 2 -- numba/cuda/tests/cudapy/test_gufunc_scalar.py | 1 - numba/cuda/tests/cudapy/test_gufunc_scheduling.py | 1 - numba/cuda/tests/cudapy/test_idiv.py | 1 - numba/cuda/tests/cudapy/test_inspect.py | 1 - numba/cuda/tests/cudapy/test_intrinsics.py | 2 -- numba/cuda/tests/cudapy/test_ipc.py | 2 -- numba/cuda/tests/cudapy/test_lang.py | 1 - numba/cuda/tests/cudapy/test_laplace.py | 1 - numba/cuda/tests/cudapy/test_localmem.py | 2 -- numba/cuda/tests/cudapy/test_macro.py | 1 - numba/cuda/tests/cudapy/test_mandel.py | 1 - numba/cuda/tests/cudapy/test_math.py | 1 - numba/cuda/tests/cudapy/test_matmul.py | 2 -- numba/cuda/tests/cudapy/test_minmax.py | 2 -- numba/cuda/tests/cudapy/test_montecarlo.py | 1 - numba/cuda/tests/cudapy/test_nondet.py | 1 - numba/cuda/tests/cudapy/test_operator.py | 2 -- numba/cuda/tests/cudapy/test_powi.py | 1 - numba/cuda/tests/cudapy/test_print.py | 2 -- numba/cuda/tests/cudapy/test_py2_div_issue.py | 1 - numba/cuda/tests/cudapy/test_random.py | 2 -- numba/cuda/tests/cudapy/test_record_dtype.py | 2 -- numba/cuda/tests/cudapy/test_reduction.py | 1 - numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py | 2 -- numba/cuda/tests/cudapy/test_serialize.py | 1 - numba/cuda/tests/cudapy/test_slicing.py | 1 - numba/cuda/tests/cudapy/test_sync.py | 1 - numba/cuda/tests/cudapy/test_userexc.py | 2 -- numba/cuda/tests/cudapy/test_vectorize.py | 2 -- numba/cuda/tests/cudapy/test_vectorize_complex.py | 1 - numba/cuda/tests/cudapy/test_vectorize_decor.py | 2 -- numba/cuda/tests/cudapy/test_vectorize_device.py | 1 - numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py | 1 - numba/cuda/tests/cudapy/test_warp_ops.py | 1 - numba/cuda/tests/cudasim/test_cudasim_issues.py | 2 -- numba/cuda/tests/nocuda/test_library_lookup.py | 2 -- numba/cuda/tests/nocuda/test_nvvm.py | 2 -- numba/cuda/vectorizers.py | 2 -- numba/dataflow.py | 2 -- numba/datamodel/manager.py | 2 -- numba/datamodel/models.py | 2 -- numba/datamodel/packer.py | 2 -- numba/datamodel/registry.py | 2 -- numba/datamodel/testing.py | 2 -- numba/debuginfo.py | 1 - numba/decorators.py | 1 - numba/dispatcher.py | 1 - numba/dummyarray.py | 2 -- numba/errors.py | 1 - numba/extending.py | 1 - numba/findlib.py | 1 - numba/funcdesc.py | 1 - numba/generators.py | 1 - numba/help/inspector.py | 1 - numba/inline_closurecall.py | 2 -- numba/interpreter.py | 2 -- numba/ir.py | 2 -- numba/ir_utils.py | 1 - numba/itanium_mangler.py | 1 - numba/jitclass/base.py | 2 -- numba/jitclass/boxing.py | 1 - numba/jitclass/decorators.py | 2 -- numba/lowering.py | 2 -- numba/macro.py | 1 - numba/npyufunc/__init__.py | 1 - numba/npyufunc/array_exprs.py | 2 -- numba/npyufunc/decorators.py | 1 - numba/npyufunc/deviceufunc.py | 1 - numba/npyufunc/dufunc.py | 2 -- numba/npyufunc/parallel.py | 1 - numba/npyufunc/parfor.py | 2 -- numba/npyufunc/sigparse.py | 1 - numba/npyufunc/ufuncbuilder.py | 1 - numba/npyufunc/wrappers.py | 2 -- numba/numba_entry.py | 2 -- numba/numpy_support.py | 2 -- numba/object_mode_passes.py | 1 - numba/parfor.py | 1 - numba/postproc.py | 2 -- numba/pycc/__init__.py | 1 - numba/pycc/cc.py | 2 -- numba/pycc/compiler.py | 1 - numba/pycc/decorators.py | 2 -- numba/pycc/platform.py | 2 -- numba/pylowering.py | 1 - numba/python_utils.py | 1 - numba/pythonapi.py | 2 -- numba/rewrites/ir_print.py | 2 -- numba/rewrites/registry.py | 2 -- numba/roc/__init__.py | 1 - numba/roc/api.py | 2 -- numba/roc/codegen.py | 2 -- numba/roc/compiler.py | 1 - numba/roc/decorators.py | 1 - numba/roc/descriptor.py | 1 - numba/roc/dispatch.py | 2 -- numba/roc/enums.py | 2 -- numba/roc/gcn_occupancy.py | 2 -- numba/roc/hlc/__init__.py | 2 -- numba/roc/hlc/common.py | 1 - numba/roc/hlc/config.py | 2 -- numba/roc/hlc/hlc.py | 1 - numba/roc/hlc/libhlc.py | 2 -- numba/roc/hsadecl.py | 1 - numba/roc/hsadrv/devicearray.py | 1 - numba/roc/hsadrv/devices.py | 1 - numba/roc/hsadrv/driver.py | 1 - numba/roc/hsadrv/drvapi.py | 2 -- numba/roc/hsadrv/error.py | 3 --- numba/roc/hsaimpl.py | 2 -- numba/roc/mathdecl.py | 1 - numba/roc/mathimpl.py | 1 - numba/roc/stubs.py | 1 - numba/roc/target.py | 2 -- numba/roc/tests/hsadrv/test_async.py | 2 -- numba/roc/tests/hsadrv/test_driver.py | 1 - numba/roc/tests/hsapy/run_far_branch.py | 2 -- numba/roc/tests/hsapy/test_atomics.py | 1 - numba/roc/tests/hsapy/test_autojit.py | 2 -- numba/roc/tests/hsapy/test_barrier.py | 2 -- numba/roc/tests/hsapy/test_compiler.py | 2 -- numba/roc/tests/hsapy/test_decorator.py | 2 -- numba/roc/tests/hsapy/test_gufuncbuilding.py | 2 -- numba/roc/tests/hsapy/test_intrinsics.py | 2 -- numba/roc/tests/hsapy/test_large_code.py | 2 -- numba/roc/tests/hsapy/test_linkage.py | 2 -- numba/roc/tests/hsapy/test_math.py | 2 -- numba/roc/tests/hsapy/test_matmul.py | 2 -- numba/roc/tests/hsapy/test_occupancy.py | 2 -- numba/roc/tests/hsapy/test_positioning.py | 2 -- numba/roc/tests/hsapy/test_reduction.py | 2 -- numba/roc/tests/hsapy/test_scan.py | 2 -- numba/roc/tests/hsapy/test_simple.py | 2 -- numba/roc/tests/hsapy/test_ufuncbuilding.py | 2 -- numba/roc/vectorizers.py | 2 -- numba/runtime/__init__.py | 2 -- numba/runtime/context.py | 2 -- numba/runtime/nrt.py | 2 -- numba/runtime/nrtdynmod.py | 1 - numba/scripts/generate_lower_listing.py | 1 - numba/serialize.py | 1 - numba/servicelib/__init__.py | 1 - numba/servicelib/service.py | 1 - numba/servicelib/threadlocal.py | 1 - numba/sigutils.py | 2 -- numba/special.py | 2 -- numba/targets/__init__.py | 1 - numba/targets/arraymath.py | 1 - numba/targets/arrayobj.py | 1 - numba/targets/base.py | 2 -- numba/targets/builtins.py | 2 -- numba/targets/cffiimpl.py | 1 - numba/targets/cmathimpl.py | 1 - numba/targets/codegen.py | 2 -- numba/targets/cpu.py | 2 -- numba/targets/cpu_options.py | 1 - numba/targets/descriptors.py | 1 - numba/targets/fastmathpass.py | 2 -- numba/targets/gdb_hook.py | 2 -- numba/targets/hashing.py | 1 - numba/targets/heapq.py | 1 - numba/targets/imputils.py | 1 - numba/targets/intrinsics.py | 1 - numba/targets/linalg.py | 1 - numba/targets/listobj.py | 1 - numba/targets/mathimpl.py | 1 - numba/targets/npyfuncs.py | 1 - numba/targets/npyimpl.py | 1 - numba/targets/numbers.py | 2 -- numba/targets/optional.py | 2 -- numba/targets/options.py | 1 - numba/targets/polynomial.py | 1 - numba/targets/printimpl.py | 1 - numba/targets/quicksort.py | 3 --- numba/targets/randomimpl.py | 1 - numba/targets/registry.py | 2 -- numba/targets/removerefctpass.py | 1 - numba/targets/setobj.py | 1 - numba/targets/ufunc_db.py | 1 - numba/testing/__init__.py | 2 -- numba/testing/main.py | 2 -- numba/tests/cache_usecases.py | 1 - numba/tests/cffi_usecases.py | 2 -- numba/tests/cfunc_cache_usecases.py | 1 - numba/tests/complex_usecases.py | 2 -- numba/tests/ctypes_usecases.py | 2 -- numba/tests/enum_usecases.py | 2 -- numba/tests/npyufunc/test_caching.py | 2 -- numba/tests/npyufunc/test_dufunc.py | 2 -- numba/tests/npyufunc/test_errors.py | 2 -- numba/tests/npyufunc/test_gufunc.py | 2 -- numba/tests/npyufunc/test_parallel_env_variable.py | 1 - numba/tests/npyufunc/test_parallel_low_work.py | 1 - numba/tests/npyufunc/test_parallel_ufunc_issues.py | 2 -- numba/tests/npyufunc/test_ufunc.py | 2 -- numba/tests/npyufunc/test_ufuncbuilding.py | 2 -- numba/tests/npyufunc/test_vectorize_decor.py | 2 -- numba/tests/support.py | 1 - numba/tests/test_analysis.py | 1 - numba/tests/test_annotations.py | 2 -- numba/tests/test_api.py | 2 -- numba/tests/test_array_analysis.py | 2 -- numba/tests/test_array_attr.py | 2 -- numba/tests/test_array_constants.py | 2 -- numba/tests/test_array_exprs.py | 2 -- numba/tests/test_array_iterators.py | 2 -- numba/tests/test_array_manipulation.py | 2 -- numba/tests/test_array_methods.py | 2 -- numba/tests/test_array_reductions.py | 2 -- numba/tests/test_array_return.py | 2 -- numba/tests/test_auto_constants.py | 2 -- numba/tests/test_blackscholes.py | 2 -- numba/tests/test_boundscheck.py | 2 -- numba/tests/test_buffer_protocol.py | 2 -- numba/tests/test_builtins.py | 2 -- numba/tests/test_caching.py | 2 -- numba/tests/test_cffi.py | 2 -- numba/tests/test_cfunc.py | 1 - numba/tests/test_cgutils.py | 2 -- numba/tests/test_chained_assign.py | 2 -- numba/tests/test_cli.py | 1 - numba/tests/test_closure.py | 2 -- numba/tests/test_codegen.py | 1 - numba/tests/test_compile_cache.py | 2 -- numba/tests/test_complex.py | 2 -- numba/tests/test_comprehension.py | 2 -- numba/tests/test_conversion.py | 2 -- numba/tests/test_ctypes.py | 2 -- numba/tests/test_dataflow.py | 2 -- numba/tests/test_datamodel.py | 2 -- numba/tests/test_debug.py | 2 -- numba/tests/test_debuginfo.py | 2 -- numba/tests/test_del.py | 2 -- numba/tests/test_deprecations.py | 1 - numba/tests/test_dictimpl.py | 1 - numba/tests/test_dictobject.py | 1 - numba/tests/test_dicts.py | 2 -- numba/tests/test_dispatcher.py | 2 -- numba/tests/test_dummyarray.py | 1 - numba/tests/test_dyn_array.py | 2 -- numba/tests/test_dyn_func.py | 2 -- numba/tests/test_enums.py | 1 - numba/tests/test_errorhandling.py | 1 - numba/tests/test_errormodels.py | 1 - numba/tests/test_exceptions.py | 1 - numba/tests/test_extended_arg.py | 2 -- numba/tests/test_extending.py | 2 -- numba/tests/test_fancy_indexing.py | 2 -- numba/tests/test_fastmath.py | 2 -- numba/tests/test_flow_control.py | 2 -- numba/tests/test_func_interface.py | 2 -- numba/tests/test_func_lifetime.py | 3 --- numba/tests/test_gdb.py | 1 - numba/tests/test_generators.py | 2 -- numba/tests/test_gil.py | 2 -- numba/tests/test_globals.py | 1 - numba/tests/test_hashing.py | 1 - numba/tests/test_heapq.py | 2 -- numba/tests/test_help.py | 2 -- numba/tests/test_import.py | 2 -- numba/tests/test_indexing.py | 2 -- numba/tests/test_inlining.py | 2 -- numba/tests/test_interproc.py | 2 -- numba/tests/test_ir.py | 2 -- numba/tests/test_ir_inlining.py | 1 - numba/tests/test_itanium_mangler.py | 1 - numba/tests/test_iteration.py | 2 -- numba/tests/test_jit_module.py | 1 - numba/tests/test_jitclasses.py | 2 -- numba/tests/test_linalg.py | 2 -- numba/tests/test_listimpl.py | 1 - numba/tests/test_listobject.py | 1 - numba/tests/test_lists.py | 2 -- numba/tests/test_literal_dispatch.py | 2 -- numba/tests/test_llvm_version_check.py | 2 -- numba/tests/test_locals.py | 2 -- numba/tests/test_looplifting.py | 2 -- numba/tests/test_make_function_to_jit_function.py | 2 -- numba/tests/test_mandelbrot.py | 2 -- numba/tests/test_map_filter_reduce.py | 2 -- numba/tests/test_mathlib.py | 2 -- numba/tests/test_maxmin.py | 1 - numba/tests/test_mixed_tuple_unroller.py | 2 -- numba/tests/test_multi3.py | 2 -- numba/tests/test_nan.py | 1 - numba/tests/test_nested_calls.py | 1 - numba/tests/test_np_functions.py | 1 - numba/tests/test_npdatetime.py | 1 - numba/tests/test_nrt.py | 2 -- numba/tests/test_nrt_refct.py | 1 - numba/tests/test_numberctor.py | 2 -- numba/tests/test_numbers.py | 1 - numba/tests/test_numconv.py | 1 - numba/tests/test_numpy_support.py | 1 - numba/tests/test_numpyadapt.py | 2 -- numba/tests/test_obj_lifetime.py | 2 -- numba/tests/test_object_mode.py | 1 - numba/tests/test_objects.py | 1 - numba/tests/test_operators.py | 2 -- numba/tests/test_optional.py | 2 -- numba/tests/test_overlap.py | 2 -- numba/tests/test_parallel_backend.py | 1 - numba/tests/test_parfors.py | 1 - numba/tests/test_parfors_caching.py | 2 -- numba/tests/test_pipeline.py | 2 -- numba/tests/test_polynomial.py | 2 -- numba/tests/test_practical_lowering_issues.py | 1 - numba/tests/test_print.py | 2 -- numba/tests/test_pycc.py | 2 -- numba/tests/test_python_int.py | 2 -- numba/tests/test_random.py | 2 -- numba/tests/test_range.py | 2 -- numba/tests/test_recarray_usecases.py | 2 -- numba/tests/test_record_dtype.py | 2 -- numba/tests/test_recursion.py | 2 -- numba/tests/test_return_values.py | 1 - numba/tests/test_runtests.py | 2 -- numba/tests/test_serialize.py | 2 -- numba/tests/test_sets.py | 2 -- numba/tests/test_slices.py | 2 -- numba/tests/test_sort.py | 2 -- numba/tests/test_stencils.py | 1 - numba/tests/test_storeslice.py | 2 -- numba/tests/test_support.py | 2 -- numba/tests/test_svml.py | 2 -- numba/tests/test_sys_stdin_assignment.py | 2 -- numba/tests/test_target_overloadselector.py | 2 -- numba/tests/test_try_except.py | 2 -- numba/tests/test_tuples.py | 2 -- numba/tests/test_typeconv.py | 1 - numba/tests/test_typedlist.py | 2 -- numba/tests/test_typedobjectutils.py | 1 - numba/tests/test_typeinfer.py | 2 -- numba/tests/test_typenames.py | 2 -- numba/tests/test_typeof.py | 1 - numba/tests/test_types.py | 1 - numba/tests/test_typingerror.py | 2 -- numba/tests/test_ufuncs.py | 2 -- numba/tests/test_unicode.py | 1 - numba/tests/test_unicode_array.py | 2 -- numba/tests/test_unicode_literals.py | 2 -- numba/tests/test_unicode_names.py | 1 - numba/tests/test_unpack_sequence.py | 2 -- numba/tests/test_unsafe_intrinsics.py | 2 -- numba/tests/test_usecases.py | 2 -- numba/tests/test_vectorization_type_inference.py | 1 - numba/tests/test_warnings.py | 1 - numba/tests/test_withlifting.py | 2 -- numba/tests/test_wrapper.py | 2 -- numba/tests/timsort.py | 1 - numba/tests/true_div_usecase.py | 3 --- numba/tracing.py | 2 -- numba/transforms.py | 1 - numba/typeconv/castgraph.py | 2 -- numba/typeconv/rules.py | 1 - numba/typeconv/typeconv.py | 2 -- numba/typed/__init__.py | 2 -- numba/typed/typedlist.py | 1 - numba/typed_passes.py | 1 - numba/typeinfer.py | 1 - numba/types/__init__.py | 2 -- numba/types/abstract.py | 2 -- numba/types/common.py | 1 - numba/types/containers.py | 2 -- numba/types/functions.py | 2 -- numba/types/iterators.py | 3 --- numba/types/misc.py | 2 -- numba/types/npytypes.py | 2 -- numba/types/scalars.py | 2 -- numba/typing/__init__.py | 1 - numba/typing/arraydecl.py | 2 -- numba/typing/builtins.py | 2 -- numba/typing/cffi_utils.py | 1 - numba/typing/collections.py | 2 -- numba/typing/context.py | 2 -- numba/typing/ctypes_utils.py | 1 - numba/typing/dictdecl.py | 1 - numba/typing/listdecl.py | 2 -- numba/typing/npdatetime.py | 1 - numba/typing/npydecl.py | 2 -- numba/typing/randomdecl.py | 2 -- numba/typing/setdecl.py | 2 -- numba/typing/templates.py | 1 - numba/typing/typeof.py | 2 -- numba/untyped_passes.py | 1 - numba/utils.py | 2 -- 478 files changed, 769 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index 3d6d1d682cc..b886e2e1fcc 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -1,7 +1,6 @@ """ Expose top-level symbols that are safe for import * """ -from __future__ import print_function, division, absolute_import import platform import re diff --git a/numba/_runtests.py b/numba/_runtests.py index 5989fdeca2f..22ba5b0a72e 100644 --- a/numba/_runtests.py +++ b/numba/_runtests.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import json import re import logging diff --git a/numba/_version.py b/numba/_version.py index 0e158819a8c..06d32884336 100644 --- a/numba/_version.py +++ b/numba/_version.py @@ -1,4 +1,3 @@ - # This file helps to compute a version number in source trees obtained from # git-archive tarball (such as those provided by githubs download-from-tag # feature). Distribution tarballs (built by setup.py sdist) and build diff --git a/numba/annotations/type_annotations.py b/numba/annotations/type_annotations.py index 05f55a21696..34765eab4e3 100644 --- a/numba/annotations/type_annotations.py +++ b/numba/annotations/type_annotations.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from collections import defaultdict, OrderedDict from collections.abc import Mapping from contextlib import closing diff --git a/numba/array_analysis.py b/numba/array_analysis.py index 08409aa5c44..2437085d749 100644 --- a/numba/array_analysis.py +++ b/numba/array_analysis.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: BSD-2-Clause # -from __future__ import print_function, division, absolute_import import types as pytypes # avoid confusion with numba.types import numpy import operator diff --git a/numba/bytecode.py b/numba/bytecode.py index 5773469614f..42bef84c0bd 100644 --- a/numba/bytecode.py +++ b/numba/bytecode.py @@ -2,7 +2,6 @@ From NumbaPro """ -from __future__ import print_function, division, absolute_import from collections import namedtuple, OrderedDict import dis diff --git a/numba/caching.py b/numba/caching.py index 9a96ef272a9..ead099a5c20 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -2,7 +2,6 @@ Caching mechanism for compiled functions. """ -from __future__ import print_function, division, absolute_import from abc import ABCMeta, abstractmethod, abstractproperty import contextlib diff --git a/numba/callwrapper.py b/numba/callwrapper.py index b0d11c8d35f..9cb41039d86 100644 --- a/numba/callwrapper.py +++ b/numba/callwrapper.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from llvmlite.llvmpy.core import Type, Builder, Constant import llvmlite.llvmpy.core as lc diff --git a/numba/ccallback.py b/numba/ccallback.py index 5440bd22043..ec82857f6ea 100644 --- a/numba/ccallback.py +++ b/numba/ccallback.py @@ -2,7 +2,6 @@ Implementation of compiled C callbacks (@cfunc). """ -from __future__ import print_function, division, absolute_import import ctypes diff --git a/numba/cffi_support.py b/numba/cffi_support.py index 732e15bcbab..56ae9b609b3 100644 --- a/numba/cffi_support.py +++ b/numba/cffi_support.py @@ -2,5 +2,4 @@ """ Alias to numba.typing.cffi_utils for backward compatibility """ -from __future__ import print_function, division, absolute_import from numba.typing.cffi_utils import * diff --git a/numba/cgutils.py b/numba/cgutils.py index a21b0100499..5fc42209a34 100644 --- a/numba/cgutils.py +++ b/numba/cgutils.py @@ -2,7 +2,6 @@ Generic helpers for LLVM code generation. """ -from __future__ import print_function, division, absolute_import import collections from contextlib import contextmanager diff --git a/numba/compiler.py b/numba/compiler.py index f5bdaa263c4..89203f58968 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from collections import namedtuple import sys import copy diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index f81b19d6b25..1fa5f9803b1 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import timeit from abc import abstractmethod, ABCMeta from collections import namedtuple, OrderedDict diff --git a/numba/config.py b/numba/config.py index 4b3482f1217..aaeaafcba7f 100644 --- a/numba/config.py +++ b/numba/config.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import platform import sys import os diff --git a/numba/consts.py b/numba/consts.py index 22ffb9cc0fb..9910795637a 100644 --- a/numba/consts.py +++ b/numba/consts.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from types import ModuleType import weakref diff --git a/numba/controlflow.py b/numba/controlflow.py index c03cc3933cb..1931d50b27f 100644 --- a/numba/controlflow.py +++ b/numba/controlflow.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import collections import functools import sys diff --git a/numba/cuda/__init__.py b/numba/cuda/__init__.py index eea07957c65..20b48949c5c 100644 --- a/numba/cuda/__init__.py +++ b/numba/cuda/__init__.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from numba import config import numba.testing diff --git a/numba/cuda/api.py b/numba/cuda/api.py index db8e95e6833..39da6632fad 100644 --- a/numba/cuda/api.py +++ b/numba/cuda/api.py @@ -2,7 +2,6 @@ API that are reported to numba.cuda """ -from __future__ import print_function, absolute_import import contextlib diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index a9f858480d5..9bcf1c89b19 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -1,6 +1,3 @@ -from __future__ import absolute_import, print_function - - import ctypes import os from functools import reduce, wraps diff --git a/numba/cuda/cudadecl.py b/numba/cuda/cudadecl.py index 853f5043bea..1a85470f544 100644 --- a/numba/cuda/cudadecl.py +++ b/numba/cuda/cudadecl.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from numba import types from numba.typing.npydecl import register_number_classes from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, diff --git a/numba/cuda/cudadrv/autotune.py b/numba/cuda/cudadrv/autotune.py index 2dae5293f24..7a7b0298a1d 100644 --- a/numba/cuda/cudadrv/autotune.py +++ b/numba/cuda/cudadrv/autotune.py @@ -2,7 +2,6 @@ - Parse jit compile info - Compute warp occupancy histogram """ -from __future__ import division, absolute_import, print_function import math import re diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 1ebc55b6179..0c2d5ed9c2e 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -3,7 +3,6 @@ on the object. If it exists and evaluate to True, it must define shape, strides, dtype and size attributes similar to a NumPy ndarray. """ -from __future__ import print_function, absolute_import, division import warnings import math diff --git a/numba/cuda/cudadrv/devices.py b/numba/cuda/cudadrv/devices.py index 5f4a43be549..626239be57f 100644 --- a/numba/cuda/cudadrv/devices.py +++ b/numba/cuda/cudadrv/devices.py @@ -10,7 +10,6 @@ - This module must be imported by the main-thread. """ -from __future__ import print_function, absolute_import, division import functools import threading from contextlib import contextmanager diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index 4d949d1eb98..e932985f983 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -11,7 +11,6 @@ """ -from __future__ import absolute_import, print_function, division import sys import os import ctypes diff --git a/numba/cuda/cudadrv/drvapi.py b/numba/cuda/cudadrv/drvapi.py index 0efbfff7fdc..e48ff5e7ae4 100644 --- a/numba/cuda/cudadrv/drvapi.py +++ b/numba/cuda/cudadrv/drvapi.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division from ctypes import * from . import _extras diff --git a/numba/cuda/cudadrv/enums.py b/numba/cuda/cudadrv/enums.py index 665a49aa49f..6528c8a0fba 100644 --- a/numba/cuda/cudadrv/enums.py +++ b/numba/cuda/cudadrv/enums.py @@ -1,7 +1,6 @@ """ Enum values for CUDA driver """ -from __future__ import print_function, absolute_import, division CUDA_SUCCESS = 0 diff --git a/numba/cuda/cudadrv/error.py b/numba/cuda/cudadrv/error.py index 8c0a9f7f538..37381fb33dd 100644 --- a/numba/cuda/cudadrv/error.py +++ b/numba/cuda/cudadrv/error.py @@ -1,6 +1,3 @@ -from __future__ import print_function, absolute_import, division - - class CudaDriverError(Exception): pass diff --git a/numba/cuda/cudadrv/libs.py b/numba/cuda/cudadrv/libs.py index b64265cb76b..a0fcc3ffc9e 100644 --- a/numba/cuda/cudadrv/libs.py +++ b/numba/cuda/cudadrv/libs.py @@ -9,7 +9,6 @@ - or can be discovered by the system loader. """ -from __future__ import print_function import os import sys import ctypes diff --git a/numba/cuda/cudadrv/ndarray.py b/numba/cuda/cudadrv/ndarray.py index b8db583cbf9..5a9f77aaca5 100644 --- a/numba/cuda/cudadrv/ndarray.py +++ b/numba/cuda/cudadrv/ndarray.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from . import devices, driver from numba.targets.registry import cpu_target diff --git a/numba/cuda/cudadrv/nvvm.py b/numba/cuda/cudadrv/nvvm.py index ca2d626f19e..8c6b56534e2 100644 --- a/numba/cuda/cudadrv/nvvm.py +++ b/numba/cuda/cudadrv/nvvm.py @@ -1,7 +1,6 @@ """ This is a direct translation of nvvm.h """ -from __future__ import print_function, absolute_import, division import sys, logging, re from ctypes import (c_void_p, c_int, POINTER, c_char_p, c_size_t, byref, c_char) diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index e66f221fab0..4dfc202e1d7 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from functools import reduce import operator import math diff --git a/numba/cuda/cudamath.py b/numba/cuda/cudamath.py index 12e98810d18..ece0551e9ae 100644 --- a/numba/cuda/cudamath.py +++ b/numba/cuda/cudamath.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import math from numba import types, utils from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, diff --git a/numba/cuda/decorators.py b/numba/cuda/decorators.py index f888c53b2f5..aadbbda28df 100644 --- a/numba/cuda/decorators.py +++ b/numba/cuda/decorators.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division from numba import config, sigutils, types from warnings import warn from .compiler import (compile_kernel, compile_device, declare_device_function, diff --git a/numba/cuda/descriptor.py b/numba/cuda/descriptor.py index b92d79e5c5a..7fdad86d459 100644 --- a/numba/cuda/descriptor.py +++ b/numba/cuda/descriptor.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from numba.targets.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from .target import CUDATargetContext, CUDATypingContext diff --git a/numba/cuda/device_init.py b/numba/cuda/device_init.py index 8f6521ee917..9a955cf1310 100644 --- a/numba/cuda/device_init.py +++ b/numba/cuda/device_init.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - # Re export from .stubs import (threadIdx, blockIdx, blockDim, gridDim, laneid, warpsize, syncthreads, syncthreads_count, syncwarp, diff --git a/numba/cuda/dispatcher.py b/numba/cuda/dispatcher.py index 935a8949f5c..89d0100d8aa 100644 --- a/numba/cuda/dispatcher.py +++ b/numba/cuda/dispatcher.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import numpy as np from numba.targets.descriptors import TargetDescriptor diff --git a/numba/cuda/errors.py b/numba/cuda/errors.py index 79da66f91d3..1d7a074c09d 100644 --- a/numba/cuda/errors.py +++ b/numba/cuda/errors.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numbers diff --git a/numba/cuda/initialize.py b/numba/cuda/initialize.py index 4b4878367e5..cd0523d35de 100644 --- a/numba/cuda/initialize.py +++ b/numba/cuda/initialize.py @@ -1,6 +1,3 @@ -from __future__ import absolute_import, print_function - - def init_jit(): from numba.cuda.dispatcher import CUDADispatcher return CUDADispatcher diff --git a/numba/cuda/intrinsic_wrapper.py b/numba/cuda/intrinsic_wrapper.py index d81bf69a019..cd3d563fe95 100644 --- a/numba/cuda/intrinsic_wrapper.py +++ b/numba/cuda/intrinsic_wrapper.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import from .decorators import jit import numba diff --git a/numba/cuda/kernels/reduction.py b/numba/cuda/kernels/reduction.py index 6894d5a4967..6b9ef1a59da 100644 --- a/numba/cuda/kernels/reduction.py +++ b/numba/cuda/kernels/reduction.py @@ -1,7 +1,6 @@ """ A library written in CUDA Python for generating reduction kernels """ -from __future__ import division from numba.numpy_support import from_dtype diff --git a/numba/cuda/libdevice.py b/numba/cuda/libdevice.py index 4327fc1ce5d..56e247e2c88 100644 --- a/numba/cuda/libdevice.py +++ b/numba/cuda/libdevice.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import sys import math from llvmlite.llvmpy.core import Type diff --git a/numba/cuda/nvvmutils.py b/numba/cuda/nvvmutils.py index fcf55217e6f..75d0de08d4b 100644 --- a/numba/cuda/nvvmutils.py +++ b/numba/cuda/nvvmutils.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import itertools import llvmlite.llvmpy.core as lc from .cudadrv import nvvm diff --git a/numba/cuda/printimpl.py b/numba/cuda/printimpl.py index 304a95c95b1..b46cf1cb5c6 100644 --- a/numba/cuda/printimpl.py +++ b/numba/cuda/printimpl.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from llvmlite.llvmpy.core import Type, Constant from numba import types, typing, cgutils, utils diff --git a/numba/cuda/random.py b/numba/cuda/random.py index ea16b2053f2..f84cd9737cc 100644 --- a/numba/cuda/random.py +++ b/numba/cuda/random.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import math from numba import cuda, float32, float64, uint32, int64, uint64, from_dtype,\ diff --git a/numba/cuda/simulator/__init__.py b/numba/cuda/simulator/__init__.py index 6deac693084..ed6511b3d7e 100644 --- a/numba/cuda/simulator/__init__.py +++ b/numba/cuda/simulator/__init__.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - from .api import * from .reduction import Reduce from .cudadrv.devicearray import (device_array, device_array_like, pinned, diff --git a/numba/cuda/simulator/api.py b/numba/cuda/simulator/api.py index 2c2d82334b4..da9e403eb03 100644 --- a/numba/cuda/simulator/api.py +++ b/numba/cuda/simulator/api.py @@ -1,7 +1,6 @@ ''' Contains CUDA API functions ''' -from __future__ import absolute_import from contextlib import contextmanager from .cudadrv.devices import require_context, reset, gpus diff --git a/numba/cuda/simulator/kernel.py b/numba/cuda/simulator/kernel.py index 83abef99436..97284dc24ec 100644 --- a/numba/cuda/simulator/kernel.py +++ b/numba/cuda/simulator/kernel.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from contextlib import contextmanager from functools import reduce import sys diff --git a/numba/cuda/simulator_init.py b/numba/cuda/simulator_init.py index 52d327f45a9..1a314c6e2c2 100644 --- a/numba/cuda/simulator_init.py +++ b/numba/cuda/simulator_init.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import from .simulator import * diff --git a/numba/cuda/stubs.py b/numba/cuda/stubs.py index c2a89b20c43..2a4188f75a5 100644 --- a/numba/cuda/stubs.py +++ b/numba/cuda/stubs.py @@ -1,7 +1,6 @@ """ This scripts specifies all PTX special objects. """ -from __future__ import print_function, absolute_import, division import operator import numpy import llvmlite.llvmpy.core as lc diff --git a/numba/cuda/target.py b/numba/cuda/target.py index 9c70ae9e1ca..d6a90759479 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import re from llvmlite.llvmpy.core import (Type, Builder, LINKAGE_INTERNAL, Constant, ICMP_EQ) diff --git a/numba/cuda/testing.py b/numba/cuda/testing.py index 0ce62cf7ba6..765ced8235a 100644 --- a/numba/cuda/testing.py +++ b/numba/cuda/testing.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import contextlib import sys diff --git a/numba/cuda/tests/cudadrv/test_context_stack.py b/numba/cuda/tests/cudadrv/test_context_stack.py index e41ceb2d1f2..a0f1b2d8a03 100644 --- a/numba/cuda/tests/cudadrv/test_context_stack.py +++ b/numba/cuda/tests/cudadrv/test_context_stack.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numbers from ctypes import byref import weakref diff --git a/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py b/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py index 265912b08be..67562bf613e 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +++ b/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from itertools import product import numpy as np diff --git a/numba/cuda/tests/cudadrv/test_cuda_auto_context.py b/numba/cuda/tests/cudadrv/test_cuda_auto_context.py index db694633b00..075684a467d 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +++ b/numba/cuda/tests/cudadrv/test_cuda_auto_context.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba import cuda from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudadrv/test_cuda_driver.py b/numba/cuda/tests/cudadrv/test_cuda_driver.py index d74a3433685..2c9ebd8a328 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_driver.py +++ b/numba/cuda/tests/cudadrv/test_cuda_driver.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from ctypes import c_int, sizeof from numba.cuda.cudadrv.driver import host_to_device, device_to_host from numba.cuda.cudadrv import devices diff --git a/numba/cuda/tests/cudadrv/test_cuda_libraries.py b/numba/cuda/tests/cudadrv/test_cuda_libraries.py index 38e30981885..48e620e1e0e 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_libraries.py +++ b/numba/cuda/tests/cudadrv/test_cuda_libraries.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - from numba.cuda.testing import unittest from numba.cuda.testing import skip_on_cudasim, skip_unless_conda_cudatoolkit from numba.findlib import find_lib diff --git a/numba/cuda/tests/cudadrv/test_deallocations.py b/numba/cuda/tests/cudadrv/test_deallocations.py index dcc20f88383..f53f33da293 100644 --- a/numba/cuda/tests/cudadrv/test_deallocations.py +++ b/numba/cuda/tests/cudadrv/test_deallocations.py @@ -1,5 +1,3 @@ -from __future__ import division - from contextlib import contextmanager import numpy as np diff --git a/numba/cuda/tests/cudadrv/test_detect.py b/numba/cuda/tests/cudadrv/test_detect.py index a3f84b943b5..22d47732078 100644 --- a/numba/cuda/tests/cudadrv/test_detect.py +++ b/numba/cuda/tests/cudadrv/test_detect.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function import os import sys import subprocess diff --git a/numba/cuda/tests/cudadrv/test_events.py b/numba/cuda/tests/cudadrv/test_events.py index 66c34ee59f0..8bccdc15448 100644 --- a/numba/cuda/tests/cudadrv/test_events.py +++ b/numba/cuda/tests/cudadrv/test_events.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function import numpy as np from numba import cuda from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudadrv/test_host_alloc.py b/numba/cuda/tests/cudadrv/test_host_alloc.py index 8249d1f3481..eebb598aa86 100644 --- a/numba/cuda/tests/cudadrv/test_host_alloc.py +++ b/numba/cuda/tests/cudadrv/test_host_alloc.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import import numpy as np from numba.cuda.cudadrv import driver from numba import cuda diff --git a/numba/cuda/tests/cudadrv/test_inline_ptx.py b/numba/cuda/tests/cudadrv/test_inline_ptx.py index 040f7d79339..ee93f3485e5 100644 --- a/numba/cuda/tests/cudadrv/test_inline_ptx.py +++ b/numba/cuda/tests/cudadrv/test_inline_ptx.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from llvmlite.llvmpy.core import Module, Type, Builder, InlineAsm from llvmlite import binding as ll diff --git a/numba/cuda/tests/cudadrv/test_ir_patch.py b/numba/cuda/tests/cudadrv/test_ir_patch.py index 6f5d8d5da13..a9104591845 100644 --- a/numba/cuda/tests/cudadrv/test_ir_patch.py +++ b/numba/cuda/tests/cudadrv/test_ir_patch.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from numba.cuda.testing import unittest from numba.cuda.testing import skip_on_cudasim diff --git a/numba/cuda/tests/cudadrv/test_linker.py b/numba/cuda/tests/cudadrv/test_linker.py index ffee8be5a5a..c41bdacc9af 100644 --- a/numba/cuda/tests/cudadrv/test_linker.py +++ b/numba/cuda/tests/cudadrv/test_linker.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import os.path import numpy as np from numba.cuda.testing import unittest diff --git a/numba/cuda/tests/cudadrv/test_nvvm_driver.py b/numba/cuda/tests/cudadrv/test_nvvm_driver.py index 3efefe2eea2..8035af7c3c9 100644 --- a/numba/cuda/tests/cudadrv/test_nvvm_driver.py +++ b/numba/cuda/tests/cudadrv/test_nvvm_driver.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - from llvmlite.llvmpy.core import Module, Type, Builder from numba.cuda.cudadrv.nvvm import (NVVM, CompilationUnit, llvm_to_ptx, set_cuda_kernel, fix_data_layout, diff --git a/numba/cuda/tests/cudadrv/test_pinned.py b/numba/cuda/tests/cudadrv/test_pinned.py index 40aff7cafb7..456c37a4fd2 100644 --- a/numba/cuda/tests/cudadrv/test_pinned.py +++ b/numba/cuda/tests/cudadrv/test_pinned.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudadrv/test_profiler.py b/numba/cuda/tests/cudadrv/test_profiler.py index 1c2887ad47e..0c0bf037a6c 100644 --- a/numba/cuda/tests/cudadrv/test_profiler.py +++ b/numba/cuda/tests/cudadrv/test_profiler.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function import numba.unittest_support as unittest from numba.cuda.testing import CUDATestCase from numba import cuda diff --git a/numba/cuda/tests/cudadrv/test_reset_device.py b/numba/cuda/tests/cudadrv/test_reset_device.py index ba7cb62500e..13c85a7e61b 100644 --- a/numba/cuda/tests/cudadrv/test_reset_device.py +++ b/numba/cuda/tests/cudadrv/test_reset_device.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import threading from numba import cuda from numba.cuda.cudadrv.driver import driver diff --git a/numba/cuda/tests/cudadrv/test_select_device.py b/numba/cuda/tests/cudadrv/test_select_device.py index 7fae3eda9bb..8aa68755a3b 100644 --- a/numba/cuda/tests/cudadrv/test_select_device.py +++ b/numba/cuda/tests/cudadrv/test_select_device.py @@ -1,7 +1,6 @@ # # Test does not work on some cards. # -from __future__ import print_function, absolute_import, division import threading try: from Queue import Queue # Python 2 diff --git a/numba/cuda/tests/cudapy/test_array.py b/numba/cuda/tests/cudapy/test_array.py index 3d64efd9412..a0168ab779d 100644 --- a/numba/cuda/tests/cudapy/test_array.py +++ b/numba/cuda/tests/cudapy/test_array.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_array_args.py b/numba/cuda/tests/cudapy/test_array_args.py index b6ced8f6e2f..aae211e744b 100644 --- a/numba/cuda/tests/cudapy/test_array_args.py +++ b/numba/cuda/tests/cudapy/test_array_args.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_array_methods.py b/numba/cuda/tests/cudapy/test_array_methods.py index 3305f309c1a..88fbe45f16e 100644 --- a/numba/cuda/tests/cudapy/test_array_methods.py +++ b/numba/cuda/tests/cudapy/test_array_methods.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from numba import unittest_support as unittest import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_atomics.py b/numba/cuda/tests/cudapy/test_atomics.py index 3db5e9d5bb0..cf872815b6a 100644 --- a/numba/cuda/tests/cudapy/test_atomics.py +++ b/numba/cuda/tests/cudapy/test_atomics.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import random import numpy as np diff --git a/numba/cuda/tests/cudapy/test_autojit.py b/numba/cuda/tests/cudapy/test_autojit.py index ab349b52e63..51284af767b 100644 --- a/numba/cuda/tests/cudapy/test_autojit.py +++ b/numba/cuda/tests/cudapy/test_autojit.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import numpy as np from numba import cuda from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_blackscholes.py b/numba/cuda/tests/cudapy/test_blackscholes.py index 3d4329e9494..4c28de04f55 100644 --- a/numba/cuda/tests/cudapy/test_blackscholes.py +++ b/numba/cuda/tests/cudapy/test_blackscholes.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np import math import time diff --git a/numba/cuda/tests/cudapy/test_boolean.py b/numba/cuda/tests/cudapy/test_boolean.py index 3c788b02c18..b4829910b3a 100644 --- a/numba/cuda/tests/cudapy/test_boolean.py +++ b/numba/cuda/tests/cudapy/test_boolean.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba.cuda.testing import unittest, SerialMixin from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_complex.py b/numba/cuda/tests/cudapy/test_complex.py index 235edfb8037..73a300679e1 100644 --- a/numba/cuda/tests/cudapy/test_complex.py +++ b/numba/cuda/tests/cudapy/test_complex.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import cmath import math import itertools diff --git a/numba/cuda/tests/cudapy/test_complex_kernel.py b/numba/cuda/tests/cudapy/test_complex_kernel.py index daee9347114..f23b9d148e8 100644 --- a/numba/cuda/tests/cudapy/test_complex_kernel.py +++ b/numba/cuda/tests/cudapy/test_complex_kernel.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba import cuda from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_const_string.py b/numba/cuda/tests/cudapy/test_const_string.py index 89f41c98654..caf3b882161 100644 --- a/numba/cuda/tests/cudapy/test_const_string.py +++ b/numba/cuda/tests/cudapy/test_const_string.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import re from numba.cuda.testing import unittest, skip_on_cudasim from llvmlite import ir diff --git a/numba/cuda/tests/cudapy/test_constmem.py b/numba/cuda/tests/cudapy/test_constmem.py index fcde81ab176..0f916ff5489 100644 --- a/numba/cuda/tests/cudapy/test_constmem.py +++ b/numba/cuda/tests/cudapy/test_constmem.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_cuda_autojit.py b/numba/cuda/tests/cudapy/test_cuda_autojit.py index 195a5353c95..a8df6f2b2d4 100644 --- a/numba/cuda/tests/cudapy/test_cuda_autojit.py +++ b/numba/cuda/tests/cudapy/test_cuda_autojit.py @@ -1,4 +1,3 @@ -from __future__ import print_function from numba import unittest_support as unittest from numba import cuda import numpy as np diff --git a/numba/cuda/tests/cudapy/test_datetime.py b/numba/cuda/tests/cudapy/test_datetime.py index 86936892a96..da9f3628de5 100644 --- a/numba/cuda/tests/cudapy/test_datetime.py +++ b/numba/cuda/tests/cudapy/test_datetime.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np from numba import cuda, vectorize, guvectorize diff --git a/numba/cuda/tests/cudapy/test_debug.py b/numba/cuda/tests/cudapy/test_debug.py index 060d88ad365..5399fa18f2c 100644 --- a/numba/cuda/tests/cudapy/test_debug.py +++ b/numba/cuda/tests/cudapy/test_debug.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba.cuda.testing import skip_on_cudasim, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_debuginfo.py b/numba/cuda/tests/cudapy/test_debuginfo.py index bd598c9985c..f4494aa09c5 100644 --- a/numba/cuda/tests/cudapy/test_debuginfo.py +++ b/numba/cuda/tests/cudapy/test_debuginfo.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from numba.tests.support import override_config, TestCase from numba.cuda.testing import skip_on_cudasim from numba import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_deprecation.py b/numba/cuda/tests/cudapy/test_deprecation.py index f3888425020..d1504dd0a46 100644 --- a/numba/cuda/tests/cudapy/test_deprecation.py +++ b/numba/cuda/tests/cudapy/test_deprecation.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import warnings from contextlib import contextmanager diff --git a/numba/cuda/tests/cudapy/test_device_func.py b/numba/cuda/tests/cudapy/test_device_func.py index b05a2b553f2..39b95ef65e3 100644 --- a/numba/cuda/tests/cudapy/test_device_func.py +++ b/numba/cuda/tests/cudapy/test_device_func.py @@ -1,6 +1,3 @@ -from __future__ import print_function, absolute_import, division - - import re import types diff --git a/numba/cuda/tests/cudapy/test_errors.py b/numba/cuda/tests/cudapy/test_errors.py index 3028f0e8503..a75456d12c1 100644 --- a/numba/cuda/tests/cudapy/test_errors.py +++ b/numba/cuda/tests/cudapy/test_errors.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_exception.py b/numba/cuda/tests/cudapy/test_exception.py index a4f5b074350..1044a8bf7e0 100644 --- a/numba/cuda/tests/cudapy/test_exception.py +++ b/numba/cuda/tests/cudapy/test_exception.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import config, cuda, jit diff --git a/numba/cuda/tests/cudapy/test_fastmath.py b/numba/cuda/tests/cudapy/test_fastmath.py index 7de7c3a4a32..11ddd1475d9 100644 --- a/numba/cuda/tests/cudapy/test_fastmath.py +++ b/numba/cuda/tests/cudapy/test_fastmath.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_forall.py b/numba/cuda/tests/cudapy/test_forall.py index 350898330ce..5d55fd4bb7c 100644 --- a/numba/cuda/tests/cudapy/test_forall.py +++ b/numba/cuda/tests/cudapy/test_forall.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_freevar.py b/numba/cuda/tests/cudapy/test_freevar.py index 24c18b873b6..38eb32e13c5 100644 --- a/numba/cuda/tests/cudapy/test_freevar.py +++ b/numba/cuda/tests/cudapy/test_freevar.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_globals.py b/numba/cuda/tests/cudapy/test_globals.py index 07f8b7882c4..41ac1fbf656 100644 --- a/numba/cuda/tests/cudapy/test_globals.py +++ b/numba/cuda/tests/cudapy/test_globals.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function, division import numpy as np from numba import cuda, int32, float32 from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_gufunc.py b/numba/cuda/tests/cudapy/test_gufunc.py index c5531a77b25..ceac7f16bff 100644 --- a/numba/cuda/tests/cudapy/test_gufunc.py +++ b/numba/cuda/tests/cudapy/test_gufunc.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np import numpy.core.umath_tests as ut diff --git a/numba/cuda/tests/cudapy/test_gufunc_scalar.py b/numba/cuda/tests/cudapy/test_gufunc_scalar.py index 213540b5cc8..07caa2589a3 100644 --- a/numba/cuda/tests/cudapy/test_gufunc_scalar.py +++ b/numba/cuda/tests/cudapy/test_gufunc_scalar.py @@ -3,7 +3,6 @@ See Numpy documentation for detail about gufunc: http://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html """ -from __future__ import absolute_import, print_function, division import numpy as np from numba import guvectorize, cuda from numba import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py index 21214af110a..6a5559a3f3a 100644 --- a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +++ b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function, division from numba.npyufunc.deviceufunc import GUFuncEngine from numba import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_idiv.py b/numba/cuda/tests/cudapy/test_idiv.py index 635a9e4c1d0..828396d7a67 100644 --- a/numba/cuda/tests/cudapy/test_idiv.py +++ b/numba/cuda/tests/cudapy/test_idiv.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import import numpy as np from numba import cuda, float32, float64, int32 from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_inspect.py b/numba/cuda/tests/cudapy/test_inspect.py index 9ecacd06381..19226632c61 100644 --- a/numba/cuda/tests/cudapy/test_inspect.py +++ b/numba/cuda/tests/cudapy/test_inspect.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from numba import cuda, float64, intp from numba.cuda.testing import unittest, SerialMixin from numba.cuda.testing import skip_on_cudasim diff --git a/numba/cuda/tests/cudapy/test_intrinsics.py b/numba/cuda/tests/cudapy/test_intrinsics.py index cd0e717e21b..83e8338320b 100644 --- a/numba/cuda/tests/cudapy/test_intrinsics.py +++ b/numba/cuda/tests/cudapy/test_intrinsics.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np import re from numba import cuda, int32, float32 diff --git a/numba/cuda/tests/cudapy/test_ipc.py b/numba/cuda/tests/cudapy/test_ipc.py index cebf2a3af66..39d1d5ff1e2 100644 --- a/numba/cuda/tests/cudapy/test_ipc.py +++ b/numba/cuda/tests/cudapy/test_ipc.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - import sys import multiprocessing as mp import traceback diff --git a/numba/cuda/tests/cudapy/test_lang.py b/numba/cuda/tests/cudapy/test_lang.py index f0133a09226..58ecf09a38b 100644 --- a/numba/cuda/tests/cudapy/test_lang.py +++ b/numba/cuda/tests/cudapy/test_lang.py @@ -2,7 +2,6 @@ Test basic language features """ -from __future__ import print_function, absolute_import, division import numpy as np from numba import cuda, float64 diff --git a/numba/cuda/tests/cudapy/test_laplace.py b/numba/cuda/tests/cudapy/test_laplace.py index 99fc049ca57..9bd9a917d5b 100644 --- a/numba/cuda/tests/cudapy/test_laplace.py +++ b/numba/cuda/tests/cudapy/test_laplace.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import numpy as np import time from numba import cuda, config, float64, void diff --git a/numba/cuda/tests/cudapy/test_localmem.py b/numba/cuda/tests/cudapy/test_localmem.py index 605beae5676..0a1573dc790 100644 --- a/numba/cuda/tests/cudapy/test_localmem.py +++ b/numba/cuda/tests/cudapy/test_localmem.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import cuda, int32, complex128 diff --git a/numba/cuda/tests/cudapy/test_macro.py b/numba/cuda/tests/cudapy/test_macro.py index b6644c4feb8..84538c014ba 100644 --- a/numba/cuda/tests/cudapy/test_macro.py +++ b/numba/cuda/tests/cudapy/test_macro.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import import numpy as np from numba import cuda, float32 from numba.errors import MacroError diff --git a/numba/cuda/tests/cudapy/test_mandel.py b/numba/cuda/tests/cudapy/test_mandel.py index 75a3413601a..40547bf2530 100644 --- a/numba/cuda/tests/cudapy/test_mandel.py +++ b/numba/cuda/tests/cudapy/test_mandel.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division from numba import cuda from numba.cuda.testing import unittest diff --git a/numba/cuda/tests/cudapy/test_math.py b/numba/cuda/tests/cudapy/test_math.py index 933f5627d56..1b182dfd60a 100644 --- a/numba/cuda/tests/cudapy/test_math.py +++ b/numba/cuda/tests/cudapy/test_math.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import sys import numpy as np from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_matmul.py b/numba/cuda/tests/cudapy/test_matmul.py index 31ff2f9472e..36755c0a178 100644 --- a/numba/cuda/tests/cudapy/test_matmul.py +++ b/numba/cuda/tests/cudapy/test_matmul.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba import cuda, config, float32 diff --git a/numba/cuda/tests/cudapy/test_minmax.py b/numba/cuda/tests/cudapy/test_minmax.py index a87145e399b..10a45a0db94 100644 --- a/numba/cuda/tests/cudapy/test_minmax.py +++ b/numba/cuda/tests/cudapy/test_minmax.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import cuda, float64 diff --git a/numba/cuda/tests/cudapy/test_montecarlo.py b/numba/cuda/tests/cudapy/test_montecarlo.py index b646b75d510..2b7fe63f8e9 100644 --- a/numba/cuda/tests/cudapy/test_montecarlo.py +++ b/numba/cuda/tests/cudapy/test_montecarlo.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import math from numba import cuda from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_nondet.py b/numba/cuda/tests/cudapy/test_nondet.py index 1b612eaa742..657aa297803 100644 --- a/numba/cuda/tests/cudapy/test_nondet.py +++ b/numba/cuda/tests/cudapy/test_nondet.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba import cuda, float32 from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_operator.py b/numba/cuda/tests/cudapy/test_operator.py index f6b5fb191f0..e60e7d9d98d 100644 --- a/numba/cuda/tests/cudapy/test_operator.py +++ b/numba/cuda/tests/cudapy/test_operator.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba.cuda.testing import unittest, SerialMixin from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_powi.py b/numba/cuda/tests/cudapy/test_powi.py index 130504432c0..2fa2ab475d4 100644 --- a/numba/cuda/tests/cudapy/test_powi.py +++ b/numba/cuda/tests/cudapy/test_powi.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import math import numpy as np from numba import cuda, float64, int8, int32 diff --git a/numba/cuda/tests/cudapy/test_print.py b/numba/cuda/tests/cudapy/test_print.py index 59513d127a2..891b48a596b 100644 --- a/numba/cuda/tests/cudapy/test_print.py +++ b/numba/cuda/tests/cudapy/test_print.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_py2_div_issue.py b/numba/cuda/tests/cudapy/test_py2_div_issue.py index 545d0480ad9..71ca02d43b4 100644 --- a/numba/cuda/tests/cudapy/test_py2_div_issue.py +++ b/numba/cuda/tests/cudapy/test_py2_div_issue.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba import cuda, float32, int32 from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_random.py b/numba/cuda/tests/cudapy/test_random.py index 476a766917d..2ebfee76bfd 100644 --- a/numba/cuda/tests/cudapy/test_random.py +++ b/numba/cuda/tests/cudapy/test_random.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import math import numpy as np diff --git a/numba/cuda/tests/cudapy/test_record_dtype.py b/numba/cuda/tests/cudapy/test_record_dtype.py index b07770dd4af..47b2ed42b42 100644 --- a/numba/cuda/tests/cudapy/test_record_dtype.py +++ b/numba/cuda/tests/cudapy/test_record_dtype.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import sys import numpy as np diff --git a/numba/cuda/tests/cudapy/test_reduction.py b/numba/cuda/tests/cudapy/test_reduction.py index 48be4162831..9c87335b275 100644 --- a/numba/cuda/tests/cudapy/test_reduction.py +++ b/numba/cuda/tests/cudapy/test_reduction.py @@ -1,4 +1,3 @@ -from __future__ import print_function import numpy as np from numba import cuda from numba import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py b/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py index 81a98279a9b..f513e6b8072 100644 --- a/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +++ b/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import cuda diff --git a/numba/cuda/tests/cudapy/test_serialize.py b/numba/cuda/tests/cudapy/test_serialize.py index c2289e32724..9d3bdc03336 100644 --- a/numba/cuda/tests/cudapy/test_serialize.py +++ b/numba/cuda/tests/cudapy/test_serialize.py @@ -1,4 +1,3 @@ -from __future__ import print_function import pickle import numpy as np from numba import cuda, vectorize, numpy_support, types diff --git a/numba/cuda/tests/cudapy/test_slicing.py b/numba/cuda/tests/cudapy/test_slicing.py index fb110d0258e..0d6adbfdf63 100644 --- a/numba/cuda/tests/cudapy/test_slicing.py +++ b/numba/cuda/tests/cudapy/test_slicing.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba import cuda, float32, int32 from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_sync.py b/numba/cuda/tests/cudapy/test_sync.py index 81d1aac9045..70c39797c33 100644 --- a/numba/cuda/tests/cudapy/test_sync.py +++ b/numba/cuda/tests/cudapy/test_sync.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba import cuda, int32, float32 from numba.cuda.testing import unittest, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_userexc.py b/numba/cuda/tests/cudapy/test_userexc.py index 073a5dba8bd..139c0f76a4a 100644 --- a/numba/cuda/tests/cudapy/test_userexc.py +++ b/numba/cuda/tests/cudapy/test_userexc.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from numba.cuda.testing import unittest, SerialMixin, skip_on_cudasim from numba import cuda, config diff --git a/numba/cuda/tests/cudapy/test_vectorize.py b/numba/cuda/tests/cudapy/test_vectorize.py index d3ca8c13fb5..d2814207bc6 100644 --- a/numba/cuda/tests/cudapy/test_vectorize.py +++ b/numba/cuda/tests/cudapy/test_vectorize.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import vectorize diff --git a/numba/cuda/tests/cudapy/test_vectorize_complex.py b/numba/cuda/tests/cudapy/test_vectorize_complex.py index 607167b7da8..e06c20888f8 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_complex.py +++ b/numba/cuda/tests/cudapy/test_vectorize_complex.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function, division import numpy as np from numba import vectorize from numba import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_vectorize_decor.py b/numba/cuda/tests/cudapy/test_vectorize_decor.py index 7c9d235935c..9e0b0ef4fae 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_decor.py +++ b/numba/cuda/tests/cudapy/test_vectorize_decor.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_vectorize_device.py b/numba/cuda/tests/cudapy/test_vectorize_device.py index 1619bef1fb4..dbdbe62374b 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_device.py +++ b/numba/cuda/tests/cudapy/test_vectorize_device.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function, division from numba import vectorize from numba import cuda, float32 import numpy as np diff --git a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py index 78c81a5d68c..61cc2d8dfb8 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +++ b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function, division import numpy as np from numba import vectorize from numba import cuda, float64 diff --git a/numba/cuda/tests/cudapy/test_warp_ops.py b/numba/cuda/tests/cudapy/test_warp_ops.py index bf45724f0ab..99d724a5193 100644 --- a/numba/cuda/tests/cudapy/test_warp_ops.py +++ b/numba/cuda/tests/cudapy/test_warp_ops.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import numpy as np from numba import cuda, config, int32, int64, float32, float64 from numba.cuda.testing import unittest, SerialMixin, skip_on_cudasim diff --git a/numba/cuda/tests/cudasim/test_cudasim_issues.py b/numba/cuda/tests/cudasim/test_cudasim_issues.py index a20b94c2762..39b7c70a99b 100644 --- a/numba/cuda/tests/cudasim/test_cudasim_issues.py +++ b/numba/cuda/tests/cudasim/test_cudasim_issues.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - import threading import numpy as np diff --git a/numba/cuda/tests/nocuda/test_library_lookup.py b/numba/cuda/tests/nocuda/test_library_lookup.py index eb8c23bda56..f104331f723 100644 --- a/numba/cuda/tests/nocuda/test_library_lookup.py +++ b/numba/cuda/tests/nocuda/test_library_lookup.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import sys import os import multiprocessing as mp diff --git a/numba/cuda/tests/nocuda/test_nvvm.py b/numba/cuda/tests/nocuda/test_nvvm.py index 7a72645c539..7ee8e9d2da8 100644 --- a/numba/cuda/tests/nocuda/test_nvvm.py +++ b/numba/cuda/tests/nocuda/test_nvvm.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - from numba.cuda.compiler import compile_kernel from numba.cuda.cudadrv import nvvm from numba.cuda.testing import skip_on_cudasim, SerialMixin diff --git a/numba/cuda/vectorizers.py b/numba/cuda/vectorizers.py index d23b3469cfd..cbbf8183426 100644 --- a/numba/cuda/vectorizers.py +++ b/numba/cuda/vectorizers.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from numba import cuda from numba.npyufunc import deviceufunc from . import dispatcher diff --git a/numba/dataflow.py b/numba/dataflow.py index 1f80cf6e4e9..398911b8f67 100644 --- a/numba/dataflow.py +++ b/numba/dataflow.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import collections from pprint import pprint import sys diff --git a/numba/datamodel/manager.py b/numba/datamodel/manager.py index 974c0647ae9..0096d9206ef 100644 --- a/numba/datamodel/manager.py +++ b/numba/datamodel/manager.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import weakref from numba import types diff --git a/numba/datamodel/models.py b/numba/datamodel/models.py index 3859190c642..81db633db9e 100644 --- a/numba/datamodel/models.py +++ b/numba/datamodel/models.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from functools import partial from llvmlite import ir diff --git a/numba/datamodel/packer.py b/numba/datamodel/packer.py index 672b1283d67..261123d4df2 100644 --- a/numba/datamodel/packer.py +++ b/numba/datamodel/packer.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from collections import deque from numba import cgutils, types diff --git a/numba/datamodel/registry.py b/numba/datamodel/registry.py index e68849f6592..18bdc475ef0 100644 --- a/numba/datamodel/registry.py +++ b/numba/datamodel/registry.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import functools from .manager import DataModelManager diff --git a/numba/datamodel/testing.py b/numba/datamodel/testing.py index 181d791e2e1..bf19124b46a 100644 --- a/numba/datamodel/testing.py +++ b/numba/datamodel/testing.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from llvmlite import ir from llvmlite import binding as ll diff --git a/numba/debuginfo.py b/numba/debuginfo.py index 0b0c368360e..3dc6bb4fd91 100644 --- a/numba/debuginfo.py +++ b/numba/debuginfo.py @@ -2,7 +2,6 @@ Implements helpers to build LLVM debuginfo. """ -from __future__ import absolute_import import abc import os.path diff --git a/numba/decorators.py b/numba/decorators.py index 387914f0ce1..acfb2cbcd7c 100644 --- a/numba/decorators.py +++ b/numba/decorators.py @@ -2,7 +2,6 @@ Define @jit and related decorators. """ -from __future__ import print_function, division, absolute_import import sys import warnings diff --git a/numba/dispatcher.py b/numba/dispatcher.py index c0864bce562..b53571a23ee 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, division, absolute_import import collections import functools diff --git a/numba/dummyarray.py b/numba/dummyarray.py index 7b0222e3691..33b3f441b34 100644 --- a/numba/dummyarray.py +++ b/numba/dummyarray.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division - from collections import namedtuple import itertools import functools diff --git a/numba/errors.py b/numba/errors.py index 3f76a14a12e..e99ddfc03f6 100644 --- a/numba/errors.py +++ b/numba/errors.py @@ -2,7 +2,6 @@ Numba-specific errors and warnings. """ -from __future__ import print_function, division, absolute_import import abc import contextlib diff --git a/numba/extending.py b/numba/extending.py index 7acef9eb7b4..5a33ba322a1 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -1,4 +1,3 @@ - import os import inspect import uuid diff --git a/numba/findlib.py b/numba/findlib.py index 49ae8a13560..4e72a5ca67d 100644 --- a/numba/findlib.py +++ b/numba/findlib.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import sys import os import re diff --git a/numba/funcdesc.py b/numba/funcdesc.py index 740e43e9381..24a3f3e6e66 100644 --- a/numba/funcdesc.py +++ b/numba/funcdesc.py @@ -1,7 +1,6 @@ """ Function descriptors. """ -from __future__ import print_function, division, absolute_import from collections import defaultdict import sys diff --git a/numba/generators.py b/numba/generators.py index 82e37afbb61..ae19dbb6297 100644 --- a/numba/generators.py +++ b/numba/generators.py @@ -1,7 +1,6 @@ """ Support for lowering generators. """ -from __future__ import print_function, division, absolute_import from llvmlite.llvmpy.core import Constant, Type, Builder diff --git a/numba/help/inspector.py b/numba/help/inspector.py index ef051b1db68..1121d18d051 100644 --- a/numba/help/inspector.py +++ b/numba/help/inspector.py @@ -4,7 +4,6 @@ This file contains functions to inspect Numba's support for a given Python module or a Python package. """ -from __future__ import print_function import argparse import pkgutil diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 6d918bf7f95..3b35923c97e 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import types as pytypes # avoid confusion with numba.types import ctypes import numba diff --git a/numba/interpreter.py b/numba/interpreter.py index c2de7bcd9ba..0adf556afdb 100644 --- a/numba/interpreter.py +++ b/numba/interpreter.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import collections import dis import operator diff --git a/numba/ir.py b/numba/ir.py index d591b87dc42..2c3ce17853f 100644 --- a/numba/ir.py +++ b/numba/ir.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from collections import defaultdict import copy import itertools diff --git a/numba/ir_utils.py b/numba/ir_utils.py index c5ebbc56bf0..612a985975b 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -2,7 +2,6 @@ # Copyright (c) 2017 Intel Corporation # SPDX-License-Identifier: BSD-2-Clause # -from __future__ import print_function, absolute_import import numpy diff --git a/numba/itanium_mangler.py b/numba/itanium_mangler.py index 7d0915c05df..ccbf95b50eb 100644 --- a/numba/itanium_mangler.py +++ b/numba/itanium_mangler.py @@ -28,7 +28,6 @@ scheme for them to avoid leading digits. """ -from __future__ import print_function, absolute_import import re diff --git a/numba/jitclass/base.py b/numba/jitclass/base.py index 3c2f825f02e..fbc69a902b1 100644 --- a/numba/jitclass/base.py +++ b/numba/jitclass/base.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - from collections import OrderedDict from collections.abc import Sequence import types as pytypes diff --git a/numba/jitclass/boxing.py b/numba/jitclass/boxing.py index 2c6d634524e..b108bd3767f 100644 --- a/numba/jitclass/boxing.py +++ b/numba/jitclass/boxing.py @@ -2,7 +2,6 @@ Implement logic relating to wrapping (box) and unwrapping (unbox) instances of jitclasses for use inside the python interpreter. """ -from __future__ import print_function, absolute_import from functools import wraps, partial diff --git a/numba/jitclass/decorators.py b/numba/jitclass/decorators.py index 764c69844ee..a5e21391080 100644 --- a/numba/jitclass/decorators.py +++ b/numba/jitclass/decorators.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - from numba import config, types from .base import register_class_type, ClassBuilder diff --git a/numba/lowering.py b/numba/lowering.py index a6f3e832e18..a1bee302d9e 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import weakref import time from collections import namedtuple, deque diff --git a/numba/macro.py b/numba/macro.py index 25640a936e9..1c928a9798c 100644 --- a/numba/macro.py +++ b/numba/macro.py @@ -3,7 +3,6 @@ Macros are expanded on block-by-block """ -from __future__ import absolute_import, print_function, division # Expose the Macro object from the corresponding IR rewrite pass from .rewrites.macros import Macro diff --git a/numba/npyufunc/__init__.py b/numba/npyufunc/__init__.py index b1736268832..2485895a13c 100644 --- a/numba/npyufunc/__init__.py +++ b/numba/npyufunc/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, division, absolute_import from .decorators import Vectorize, GUVectorize, vectorize, guvectorize from ._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index c489280bec2..e15bff9050e 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import ast from collections import defaultdict, OrderedDict import contextlib diff --git a/numba/npyufunc/decorators.py b/numba/npyufunc/decorators.py index cc706c83314..a73fda4aef5 100644 --- a/numba/npyufunc/decorators.py +++ b/numba/npyufunc/decorators.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import import inspect from . import _internal, dufunc diff --git a/numba/npyufunc/deviceufunc.py b/numba/npyufunc/deviceufunc.py index ad2e24bf65e..7f7d10388a6 100644 --- a/numba/npyufunc/deviceufunc.py +++ b/numba/npyufunc/deviceufunc.py @@ -1,7 +1,6 @@ """ Implements custom ufunc dispatch mechanism for non-CPU devices. """ -from __future__ import print_function, absolute_import from collections import OrderedDict import operator diff --git a/numba/npyufunc/dufunc.py b/numba/npyufunc/dufunc.py index e55192e4f5e..b51e3e0baa1 100644 --- a/numba/npyufunc/dufunc.py +++ b/numba/npyufunc/dufunc.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - from numba import serialize from .. import jit, typeof, utils, types, numpy_support, sigutils diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 2d1a6af42e3..853fb35910f 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -9,7 +9,6 @@ UFuncCore also defines a work-stealing mechanism that allows idle threads to steal works from other threads. """ -from __future__ import print_function, absolute_import import os import platform diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 1f74e84795a..cc2cf61c070 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import ast import copy from collections import OrderedDict diff --git a/numba/npyufunc/sigparse.py b/numba/npyufunc/sigparse.py index 722d26b1f63..bd9ec871cb0 100644 --- a/numba/npyufunc/sigparse.py +++ b/numba/npyufunc/sigparse.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function, division import tokenize import string from numba import utils diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index b535b1c37b5..cf074e8ac2d 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, division, absolute_import import inspect from contextlib import contextmanager diff --git a/numba/npyufunc/wrappers.py b/numba/npyufunc/wrappers.py index c3f27d67506..6e8972fa8fd 100644 --- a/numba/npyufunc/wrappers.py +++ b/numba/npyufunc/wrappers.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from collections import namedtuple import numpy as np diff --git a/numba/numba_entry.py b/numba/numba_entry.py index 3747b234f45..e58fde14ca1 100644 --- a/numba/numba_entry.py +++ b/numba/numba_entry.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import sys import argparse import os diff --git a/numba/numpy_support.py b/numba/numpy_support.py index 51166a10e49..bf48d89211c 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import collections import ctypes import re diff --git a/numba/object_mode_passes.py b/numba/object_mode_passes.py index d2cca457859..19e32834a1f 100644 --- a/numba/object_mode_passes.py +++ b/numba/object_mode_passes.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from contextlib import contextmanager import warnings from . import (config, errors, types, funcdesc, utils, typing, pylowering, diff --git a/numba/parfor.py b/numba/parfor.py index cc8d3e355f3..ad3cd67a4a7 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -12,7 +12,6 @@ https://github.com/IntelLabs/ParallelAccelerator.jl 'Parallelizing Julia with a Non-invasive DSL', T. Anderson et al., ECOOP'17. """ -from __future__ import print_function, division, absolute_import import types as pytypes # avoid confusion with numba.types import sys, math import os diff --git a/numba/postproc.py b/numba/postproc.py index 40435648c34..cc5e617075f 100644 --- a/numba/postproc.py +++ b/numba/postproc.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from . import analysis, ir, transforms, utils diff --git a/numba/pycc/__init__.py b/numba/pycc/__init__.py index de5af1e3acd..8c8c24c4bde 100644 --- a/numba/pycc/__init__.py +++ b/numba/pycc/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, division, absolute_import import os import logging diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index ee635eb5fcb..064f6bdd790 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from distutils import dir_util, log from distutils.command import build_ext from distutils.extension import Extension diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index 475c3eb5cde..06662a87292 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, division, absolute_import import logging import os diff --git a/numba/pycc/decorators.py b/numba/pycc/decorators.py index a5621d00041..7a9684be240 100644 --- a/numba/pycc/decorators.py +++ b/numba/pycc/decorators.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import re import warnings diff --git a/numba/pycc/platform.py b/numba/pycc/platform.py index 6ded3d4926e..36df465260b 100644 --- a/numba/pycc/platform.py +++ b/numba/pycc/platform.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from distutils.ccompiler import CCompiler, new_compiler from distutils.command.build_ext import build_ext from distutils.sysconfig import customize_compiler diff --git a/numba/pylowering.py b/numba/pylowering.py index e3bafa35ec9..ba3ff312c48 100644 --- a/numba/pylowering.py +++ b/numba/pylowering.py @@ -2,7 +2,6 @@ Lowering implementation for object mode. """ -from __future__ import print_function, division, absolute_import import builtins import operator diff --git a/numba/python_utils.py b/numba/python_utils.py index 77a93d66a26..782cf6d0f6f 100644 --- a/numba/python_utils.py +++ b/numba/python_utils.py @@ -20,7 +20,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from __future__ import absolute_import import contextlib import functools diff --git a/numba/pythonapi.py b/numba/pythonapi.py index 980c62ee3d0..ebeb8b99664 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from collections import namedtuple import contextlib import pickle diff --git a/numba/rewrites/ir_print.py b/numba/rewrites/ir_print.py index 45caf310556..6d9fa35062a 100644 --- a/numba/rewrites/ir_print.py +++ b/numba/rewrites/ir_print.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from numba import ir, errors from . import register_rewrite, Rewrite diff --git a/numba/rewrites/registry.py b/numba/rewrites/registry.py index 2c0661571e3..97494e216c7 100644 --- a/numba/rewrites/registry.py +++ b/numba/rewrites/registry.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from collections import defaultdict from numba import config diff --git a/numba/roc/__init__.py b/numba/roc/__init__.py index 5103b77994d..aaf15bb0825 100644 --- a/numba/roc/__init__.py +++ b/numba/roc/__init__.py @@ -1,7 +1,6 @@ """ Module that deals with HSA in a high level way """ -from __future__ import print_function, absolute_import, division import os import numba.testing from .api import * diff --git a/numba/roc/api.py b/numba/roc/api.py index 83adeabce50..634c655361a 100644 --- a/numba/roc/api.py +++ b/numba/roc/api.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import numpy as np from numba import mviewbuf from numba.roc.hsadrv.devices import get_context diff --git a/numba/roc/codegen.py b/numba/roc/codegen.py index 03f37f4d007..8102378d5fc 100644 --- a/numba/roc/codegen.py +++ b/numba/roc/codegen.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from llvmlite import binding as ll from llvmlite.llvmpy import core as lc from numba import utils diff --git a/numba/roc/compiler.py b/numba/roc/compiler.py index 5c6d2939df4..f1bf0d63608 100644 --- a/numba/roc/compiler.py +++ b/numba/roc/compiler.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import copy from collections import namedtuple import ctypes diff --git a/numba/roc/decorators.py b/numba/roc/decorators.py index 452c23a2183..51920051eab 100644 --- a/numba/roc/decorators.py +++ b/numba/roc/decorators.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division from numba import sigutils, types from .compiler import (compile_kernel, compile_device, AutoJitHSAKernel, compile_device_template) diff --git a/numba/roc/descriptor.py b/numba/roc/descriptor.py index e607c99523f..5a94528596c 100644 --- a/numba/roc/descriptor.py +++ b/numba/roc/descriptor.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from numba.targets.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from .target import HSATargetContext, HSATypingContext diff --git a/numba/roc/dispatch.py b/numba/roc/dispatch.py index bb8bf1a442e..88b5108e24c 100644 --- a/numba/roc/dispatch.py +++ b/numba/roc/dispatch.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division, print_function - import numpy as np from numba.npyufunc.deviceufunc import (UFuncMechanism, GenerializedUFunc, diff --git a/numba/roc/enums.py b/numba/roc/enums.py index e60f08e6b33..e799028d895 100644 --- a/numba/roc/enums.py +++ b/numba/roc/enums.py @@ -1,4 +1,2 @@ -from __future__ import print_function, absolute_import, division - CLK_LOCAL_MEM_FENCE = 0 CLK_GLOBAL_MEM_FENCE = 1 diff --git a/numba/roc/gcn_occupancy.py b/numba/roc/gcn_occupancy.py index 241ab7c9823..9a4aea6ad27 100644 --- a/numba/roc/gcn_occupancy.py +++ b/numba/roc/gcn_occupancy.py @@ -1,5 +1,3 @@ -from __future__ import division, print_function - import math from collections import namedtuple diff --git a/numba/roc/hlc/__init__.py b/numba/roc/hlc/__init__.py index dabfe520fdb..26e32a9ba60 100644 --- a/numba/roc/hlc/__init__.py +++ b/numba/roc/hlc/__init__.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import os # 32-bit private, local, and region pointers. 64-bit global, constant and flat. diff --git a/numba/roc/hlc/common.py b/numba/roc/hlc/common.py index b690ce9f03f..9ab647016d6 100644 --- a/numba/roc/hlc/common.py +++ b/numba/roc/hlc/common.py @@ -2,7 +2,6 @@ Shared code for the low level compiler tooling """ -from __future__ import print_function, division, absolute_import from abc import abstractmethod, ABCMeta from numba.python_utils import add_metaclass diff --git a/numba/roc/hlc/config.py b/numba/roc/hlc/config.py index f98f975e9e5..fcd50c4bc16 100644 --- a/numba/roc/hlc/config.py +++ b/numba/roc/hlc/config.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import sys import os diff --git a/numba/roc/hlc/hlc.py b/numba/roc/hlc/hlc.py index f02ac1dde00..7336207702f 100644 --- a/numba/roc/hlc/hlc.py +++ b/numba/roc/hlc/hlc.py @@ -1,6 +1,5 @@ # A temporary wrapper to connect to the HLC LLVM binaries. # Currently, connect to commandline interface. -from __future__ import print_function, absolute_import import sys from subprocess import check_call, check_output import subprocess diff --git a/numba/roc/hlc/libhlc.py b/numba/roc/hlc/libhlc.py index b78733bc80d..8660412f018 100644 --- a/numba/roc/hlc/libhlc.py +++ b/numba/roc/hlc/libhlc.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import os import sys from collections import namedtuple diff --git a/numba/roc/hsadecl.py b/numba/roc/hsadecl.py index efd10595e48..9de693cd0b1 100644 --- a/numba/roc/hsadecl.py +++ b/numba/roc/hsadecl.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from numba import types from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, diff --git a/numba/roc/hsadrv/devicearray.py b/numba/roc/hsadrv/devicearray.py index 277fde22efc..3f388470a0d 100644 --- a/numba/roc/hsadrv/devicearray.py +++ b/numba/roc/hsadrv/devicearray.py @@ -3,7 +3,6 @@ attribute on the object. If it exists and evaluate to True, it must define shape, strides, dtype and size attributes similar to a NumPy ndarray. """ -from __future__ import print_function, absolute_import, division import warnings import math import copy diff --git a/numba/roc/hsadrv/devices.py b/numba/roc/hsadrv/devices.py index 904bad53ebf..cabb3cc8a1b 100644 --- a/numba/roc/hsadrv/devices.py +++ b/numba/roc/hsadrv/devices.py @@ -1,7 +1,6 @@ """ Expose each GPU device directly """ -from __future__ import print_function, absolute_import, division import functools from numba import servicelib from .driver import hsa as driver, Context as _Context diff --git a/numba/roc/hsadrv/driver.py b/numba/roc/hsadrv/driver.py index 3d6970cc9e2..d6919cbb9ef 100644 --- a/numba/roc/hsadrv/driver.py +++ b/numba/roc/hsadrv/driver.py @@ -2,7 +2,6 @@ HSA driver bridge implementation """ -from __future__ import absolute_import, print_function, division from collections.abc import Sequence import sys diff --git a/numba/roc/hsadrv/drvapi.py b/numba/roc/hsadrv/drvapi.py index 8ffcdc8d8da..1761d341743 100644 --- a/numba/roc/hsadrv/drvapi.py +++ b/numba/roc/hsadrv/drvapi.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import ctypes import warnings diff --git a/numba/roc/hsadrv/error.py b/numba/roc/hsadrv/error.py index c3c6ffae9d2..8af88c89328 100644 --- a/numba/roc/hsadrv/error.py +++ b/numba/roc/hsadrv/error.py @@ -1,6 +1,3 @@ -from __future__ import print_function, absolute_import, division - - class HsaDriverError(Exception): pass diff --git a/numba/roc/hsaimpl.py b/numba/roc/hsaimpl.py index 0e97a7b6188..a5ae907cf30 100644 --- a/numba/roc/hsaimpl.py +++ b/numba/roc/hsaimpl.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import operator from functools import reduce diff --git a/numba/roc/mathdecl.py b/numba/roc/mathdecl.py index 3824969772e..c663f705439 100644 --- a/numba/roc/mathdecl.py +++ b/numba/roc/mathdecl.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import math from numba import types, utils from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, diff --git a/numba/roc/mathimpl.py b/numba/roc/mathimpl.py index 6ad6d1138f4..47140796e42 100644 --- a/numba/roc/mathimpl.py +++ b/numba/roc/mathimpl.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division import math import warnings diff --git a/numba/roc/stubs.py b/numba/roc/stubs.py index b28d8a37a60..d32059a122e 100644 --- a/numba/roc/stubs.py +++ b/numba/roc/stubs.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import from numba import types, ir, typing, macro diff --git a/numba/roc/target.py b/numba/roc/target.py index e0a3232bdd9..201fb7b9b27 100644 --- a/numba/roc/target.py +++ b/numba/roc/target.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import re from llvmlite.llvmpy import core as lc diff --git a/numba/roc/tests/hsadrv/test_async.py b/numba/roc/tests/hsadrv/test_async.py index 78a86ec65fe..b1b33d09c95 100644 --- a/numba/roc/tests/hsadrv/test_async.py +++ b/numba/roc/tests/hsadrv/test_async.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import roc diff --git a/numba/roc/tests/hsadrv/test_driver.py b/numba/roc/tests/hsadrv/test_driver.py index 4b9d100ddd4..3deb16f20ad 100644 --- a/numba/roc/tests/hsadrv/test_driver.py +++ b/numba/roc/tests/hsadrv/test_driver.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import ctypes import os import threading diff --git a/numba/roc/tests/hsapy/run_far_branch.py b/numba/roc/tests/hsapy/run_far_branch.py index 81f0193b90d..5846b767757 100644 --- a/numba/roc/tests/hsapy/run_far_branch.py +++ b/numba/roc/tests/hsapy/run_far_branch.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import math import numpy as np diff --git a/numba/roc/tests/hsapy/test_atomics.py b/numba/roc/tests/hsapy/test_atomics.py index 71b7b8a4bb4..117232d0f7a 100644 --- a/numba/roc/tests/hsapy/test_atomics.py +++ b/numba/roc/tests/hsapy/test_atomics.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import import numpy as np import numba diff --git a/numba/roc/tests/hsapy/test_autojit.py b/numba/roc/tests/hsapy/test_autojit.py index a31bfc0c741..606dcb46189 100644 --- a/numba/roc/tests/hsapy/test_autojit.py +++ b/numba/roc/tests/hsapy/test_autojit.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np import numba.unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_barrier.py b/numba/roc/tests/hsapy/test_barrier.py index 9f339d3199f..61dff0ed3e9 100644 --- a/numba/roc/tests/hsapy/test_barrier.py +++ b/numba/roc/tests/hsapy/test_barrier.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba import unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_compiler.py b/numba/roc/tests/hsapy/test_compiler.py index 45de88603b6..b606f46cb8f 100644 --- a/numba/roc/tests/hsapy/test_compiler.py +++ b/numba/roc/tests/hsapy/test_compiler.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import tempfile import os import numpy as np diff --git a/numba/roc/tests/hsapy/test_decorator.py b/numba/roc/tests/hsapy/test_decorator.py index 80392fb229c..f1dc16169a7 100644 --- a/numba/roc/tests/hsapy/test_decorator.py +++ b/numba/roc/tests/hsapy/test_decorator.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np import numba.unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_gufuncbuilding.py b/numba/roc/tests/hsapy/test_gufuncbuilding.py index da17d4ee0df..a7c4f4d5542 100644 --- a/numba/roc/tests/hsapy/test_gufuncbuilding.py +++ b/numba/roc/tests/hsapy/test_gufuncbuilding.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_intrinsics.py b/numba/roc/tests/hsapy/test_intrinsics.py index 6a954abbb27..dfc47e06eec 100644 --- a/numba/roc/tests/hsapy/test_intrinsics.py +++ b/numba/roc/tests/hsapy/test_intrinsics.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_large_code.py b/numba/roc/tests/hsapy/test_large_code.py index d3cef00b9e8..cf3f2cdcfc9 100644 --- a/numba/roc/tests/hsapy/test_large_code.py +++ b/numba/roc/tests/hsapy/test_large_code.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import sys import os import os.path diff --git a/numba/roc/tests/hsapy/test_linkage.py b/numba/roc/tests/hsapy/test_linkage.py index eb6b6e9350c..69494dcea99 100644 --- a/numba/roc/tests/hsapy/test_linkage.py +++ b/numba/roc/tests/hsapy/test_linkage.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numba.unittest_support as unittest from numba import roc diff --git a/numba/roc/tests/hsapy/test_math.py b/numba/roc/tests/hsapy/test_math.py index 7d373aa4118..0e09fcf5dc8 100644 --- a/numba/roc/tests/hsapy/test_math.py +++ b/numba/roc/tests/hsapy/test_math.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np import math diff --git a/numba/roc/tests/hsapy/test_matmul.py b/numba/roc/tests/hsapy/test_matmul.py index 643f50bbdbe..1b42dc266f7 100644 --- a/numba/roc/tests/hsapy/test_matmul.py +++ b/numba/roc/tests/hsapy/test_matmul.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from timeit import default_timer as timer import numpy as np diff --git a/numba/roc/tests/hsapy/test_occupancy.py b/numba/roc/tests/hsapy/test_occupancy.py index 7f0fd743b0d..66e46217818 100644 --- a/numba/roc/tests/hsapy/test_occupancy.py +++ b/numba/roc/tests/hsapy/test_occupancy.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from numba import unittest_support as unittest from numba.roc.gcn_occupancy import get_limiting_factors diff --git a/numba/roc/tests/hsapy/test_positioning.py b/numba/roc/tests/hsapy/test_positioning.py index c9db57c763c..fae3a6d7d10 100644 --- a/numba/roc/tests/hsapy/test_positioning.py +++ b/numba/roc/tests/hsapy/test_positioning.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import roc import numba.unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_reduction.py b/numba/roc/tests/hsapy/test_reduction.py index 6a9b4b8abd2..0bbbe836088 100644 --- a/numba/roc/tests/hsapy/test_reduction.py +++ b/numba/roc/tests/hsapy/test_reduction.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_scan.py b/numba/roc/tests/hsapy/test_scan.py index 639fcae7eed..289bd19132d 100644 --- a/numba/roc/tests/hsapy/test_scan.py +++ b/numba/roc/tests/hsapy/test_scan.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/roc/tests/hsapy/test_simple.py b/numba/roc/tests/hsapy/test_simple.py index 13e15c95113..f2f470bca66 100644 --- a/numba/roc/tests/hsapy/test_simple.py +++ b/numba/roc/tests/hsapy/test_simple.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import roc from numba.roc.hsadrv.error import HsaKernelLaunchError diff --git a/numba/roc/tests/hsapy/test_ufuncbuilding.py b/numba/roc/tests/hsapy/test_ufuncbuilding.py index 1e8fb8d3032..64c8a65a456 100644 --- a/numba/roc/tests/hsapy/test_ufuncbuilding.py +++ b/numba/roc/tests/hsapy/test_ufuncbuilding.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import unittest_support as unittest diff --git a/numba/roc/vectorizers.py b/numba/roc/vectorizers.py index 29385968f58..19f11e4d315 100644 --- a/numba/roc/vectorizers.py +++ b/numba/roc/vectorizers.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from numba import roc from numba.npyufunc import deviceufunc diff --git a/numba/runtime/__init__.py b/numba/runtime/__init__.py index 5653f954dba..59047003169 100644 --- a/numba/runtime/__init__.py +++ b/numba/runtime/__init__.py @@ -1,3 +1 @@ -from __future__ import absolute_import - from .nrt import rtsys diff --git a/numba/runtime/context.py b/numba/runtime/context.py index e8cb5d1bf81..e62bd1b06e1 100644 --- a/numba/runtime/context.py +++ b/numba/runtime/context.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from llvmlite import ir from numba import cgutils, types diff --git a/numba/runtime/nrt.py b/numba/runtime/nrt.py index 482d7f0335c..6f51e3c8b35 100644 --- a/numba/runtime/nrt.py +++ b/numba/runtime/nrt.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from collections import namedtuple from weakref import finalize as _finalize diff --git a/numba/runtime/nrtdynmod.py b/numba/runtime/nrtdynmod.py index c736352aa6b..c859b0d2b68 100644 --- a/numba/runtime/nrtdynmod.py +++ b/numba/runtime/nrtdynmod.py @@ -2,7 +2,6 @@ Dynamically generate the NRT module """ -from __future__ import print_function, absolute_import, division from numba.config import MACHINE_BITS from numba import cgutils, types diff --git a/numba/scripts/generate_lower_listing.py b/numba/scripts/generate_lower_listing.py index 4dc1746739e..3a99c1b63eb 100644 --- a/numba/scripts/generate_lower_listing.py +++ b/numba/scripts/generate_lower_listing.py @@ -3,7 +3,6 @@ using reStructured text. """ -from __future__ import print_function from subprocess import check_output diff --git a/numba/serialize.py b/numba/serialize.py index a267d9ab33a..6994b723f1b 100644 --- a/numba/serialize.py +++ b/numba/serialize.py @@ -2,7 +2,6 @@ Serialization support for compiled functions. """ -from __future__ import print_function, division, absolute_import from importlib.util import MAGIC_NUMBER as bc_magic diff --git a/numba/servicelib/__init__.py b/numba/servicelib/__init__.py index fd378494b7f..d743baad684 100644 --- a/numba/servicelib/__init__.py +++ b/numba/servicelib/__init__.py @@ -1,3 +1,2 @@ -from __future__ import absolute_import from .service import Service from .threadlocal import TLStack diff --git a/numba/servicelib/service.py b/numba/servicelib/service.py index 8103d251ae0..c3230401968 100644 --- a/numba/servicelib/service.py +++ b/numba/servicelib/service.py @@ -2,7 +2,6 @@ Implement background services for the application. This is implemented as a cooperative concurrent task. """ -from __future__ import absolute_import, print_function, division import functools diff --git a/numba/servicelib/threadlocal.py b/numba/servicelib/threadlocal.py index ca115dd11a1..dd4e5946011 100644 --- a/numba/servicelib/threadlocal.py +++ b/numba/servicelib/threadlocal.py @@ -2,7 +2,6 @@ Implements: - Threadlocal stack """ -from __future__ import print_function, absolute_import, division import threading diff --git a/numba/sigutils.py b/numba/sigutils.py index 705d79ec088..6348a9e1fdc 100644 --- a/numba/sigutils.py +++ b/numba/sigutils.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from numba import types, typing diff --git a/numba/special.py b/numba/special.py index b3d344819c6..d05f9ca457a 100644 --- a/numba/special.py +++ b/numba/special.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import sys import numpy as np diff --git a/numba/targets/__init__.py b/numba/targets/__init__.py index c3961685ab8..e69de29bb2d 100644 --- a/numba/targets/__init__.py +++ b/numba/targets/__init__.py @@ -1 +0,0 @@ -from __future__ import absolute_import diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 1ee5cf79ab5..c0551dd7ebf 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -2,7 +2,6 @@ Implementation of math operations on Array objects. """ -from __future__ import print_function, absolute_import, division import math from collections import namedtuple diff --git a/numba/targets/arrayobj.py b/numba/targets/arrayobj.py index 3dd7d9d89b3..40c4f25629e 100644 --- a/numba/targets/arrayobj.py +++ b/numba/targets/arrayobj.py @@ -3,7 +3,6 @@ the buffer protocol. """ -from __future__ import print_function, absolute_import, division import functools import math diff --git a/numba/targets/base.py b/numba/targets/base.py index e44b60224e1..bb1a25e110c 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from collections import namedtuple, defaultdict import copy import os diff --git a/numba/targets/builtins.py b/numba/targets/builtins.py index 05cde802066..e0f501710d5 100644 --- a/numba/targets/builtins.py +++ b/numba/targets/builtins.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import math from functools import reduce diff --git a/numba/targets/cffiimpl.py b/numba/targets/cffiimpl.py index ebc8906a653..48cc8155f5d 100644 --- a/numba/targets/cffiimpl.py +++ b/numba/targets/cffiimpl.py @@ -2,7 +2,6 @@ Implementation of some CFFI functions """ -from __future__ import print_function, absolute_import, division from numba.targets.imputils import Registry from numba import types diff --git a/numba/targets/cmathimpl.py b/numba/targets/cmathimpl.py index 0518f2ae177..005081ca50e 100644 --- a/numba/targets/cmathimpl.py +++ b/numba/targets/cmathimpl.py @@ -2,7 +2,6 @@ Implement the cmath module functions. """ -from __future__ import print_function, absolute_import, division import cmath import math diff --git a/numba/targets/codegen.py b/numba/targets/codegen.py index 5f9fdc3c087..6c03052ae9e 100644 --- a/numba/targets/codegen.py +++ b/numba/targets/codegen.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import warnings import functools import locale diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 8c1dea1238c..dc247ce05a0 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import sys import platform diff --git a/numba/targets/cpu_options.py b/numba/targets/cpu_options.py index 9db4af210e6..758f95b8479 100644 --- a/numba/targets/cpu_options.py +++ b/numba/targets/cpu_options.py @@ -1,7 +1,6 @@ """ Defines CPU Options for use in the CPU target """ -from __future__ import print_function, division, absolute_import class FastMathOptions(object): diff --git a/numba/targets/descriptors.py b/numba/targets/descriptors.py index e4b2796443b..52a41e2de38 100644 --- a/numba/targets/descriptors.py +++ b/numba/targets/descriptors.py @@ -2,7 +2,6 @@ Target Descriptors """ -from __future__ import print_function, division, absolute_import class TargetDescriptor(object): diff --git a/numba/targets/fastmathpass.py b/numba/targets/fastmathpass.py index 98037227085..d6dd1b89c20 100644 --- a/numba/targets/fastmathpass.py +++ b/numba/targets/fastmathpass.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - from llvmlite import ir from llvmlite.ir.transforms import Visitor, CallVisitor diff --git a/numba/targets/gdb_hook.py b/numba/targets/gdb_hook.py index 817437266a3..b0ee6322ba3 100644 --- a/numba/targets/gdb_hook.py +++ b/numba/targets/gdb_hook.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import os import sys diff --git a/numba/targets/hashing.py b/numba/targets/hashing.py index d322c25b70b..fa65318ba6c 100644 --- a/numba/targets/hashing.py +++ b/numba/targets/hashing.py @@ -1,7 +1,6 @@ """ Hash implementations for Numba types """ -from __future__ import print_function, absolute_import, division import math import numpy as np diff --git a/numba/targets/heapq.py b/numba/targets/heapq.py index feadf434cc0..e86ab12fdff 100644 --- a/numba/targets/heapq.py +++ b/numba/targets/heapq.py @@ -1,6 +1,5 @@ # A port of https://github.com/python/cpython/blob/e42b7051/Lib/heapq.py -from __future__ import print_function, absolute_import, division import heapq as hq diff --git a/numba/targets/imputils.py b/numba/targets/imputils.py index f8ec0a0be70..4865b15e720 100644 --- a/numba/targets/imputils.py +++ b/numba/targets/imputils.py @@ -2,7 +2,6 @@ Utilities to simplify the boilerplate for native lowering. """ -from __future__ import print_function, absolute_import, division import collections import contextlib diff --git a/numba/targets/intrinsics.py b/numba/targets/intrinsics.py index 7010a535517..c87e4c9b1df 100644 --- a/numba/targets/intrinsics.py +++ b/numba/targets/intrinsics.py @@ -1,7 +1,6 @@ """ LLVM pass that converts intrinsic into other math calls """ -from __future__ import print_function, absolute_import from llvmlite import ir diff --git a/numba/targets/linalg.py b/numba/targets/linalg.py index 53c53bf8458..dd1f48e3257 100644 --- a/numba/targets/linalg.py +++ b/numba/targets/linalg.py @@ -2,7 +2,6 @@ Implementation of linear algebra operations. """ -from __future__ import print_function, absolute_import, division import contextlib diff --git a/numba/targets/listobj.py b/numba/targets/listobj.py index 9611f8d2213..98a5c2debcc 100644 --- a/numba/targets/listobj.py +++ b/numba/targets/listobj.py @@ -2,7 +2,6 @@ Support for native homogeneous lists. """ -from __future__ import print_function, absolute_import, division import math import operator diff --git a/numba/targets/mathimpl.py b/numba/targets/mathimpl.py index a4b3d19c4d4..b466c399f7d 100644 --- a/numba/targets/mathimpl.py +++ b/numba/targets/mathimpl.py @@ -2,7 +2,6 @@ Provide math calls that uses intrinsics or libc math functions. """ -from __future__ import print_function, absolute_import, division import math import operator import sys diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index fc719e700e5..e84dab199c3 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -4,7 +4,6 @@ Python builtins """ -from __future__ import print_function, absolute_import, division import math diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index 6720bfa0f36..f70312c9886 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -2,7 +2,6 @@ Implementation of functions in the Numpy package. """ -from __future__ import print_function, division, absolute_import import math import sys diff --git a/numba/targets/numbers.py b/numba/targets/numbers.py index 6633576cbd2..c3235a05d08 100644 --- a/numba/targets/numbers.py +++ b/numba/targets/numbers.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import math import numbers diff --git a/numba/targets/optional.py b/numba/targets/optional.py index c965314ed4b..ce718e72278 100644 --- a/numba/targets/optional.py +++ b/numba/targets/optional.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import operator from numba import types, cgutils, typing diff --git a/numba/targets/options.py b/numba/targets/options.py index 7f3fe9efb27..eb5e0006fc1 100644 --- a/numba/targets/options.py +++ b/numba/targets/options.py @@ -1,7 +1,6 @@ """ Target Options """ -from __future__ import print_function, division, absolute_import from .. import config diff --git a/numba/targets/polynomial.py b/numba/targets/polynomial.py index 13a03bfb893..785fe6f1f37 100644 --- a/numba/targets/polynomial.py +++ b/numba/targets/polynomial.py @@ -2,7 +2,6 @@ Implementation of operations involving polynomials. """ -from __future__ import print_function, absolute_import, division import numpy as np diff --git a/numba/targets/printimpl.py b/numba/targets/printimpl.py index ae8dea88f56..b95c04a2a42 100644 --- a/numba/targets/printimpl.py +++ b/numba/targets/printimpl.py @@ -1,7 +1,6 @@ """ This file implements print functionality for the CPU. """ -from __future__ import print_function, absolute_import, division from llvmlite.llvmpy.core import Type from numba import types, typing, cgutils from numba.targets.imputils import Registry, impl_ret_untracked diff --git a/numba/targets/quicksort.py b/numba/targets/quicksort.py index 81982e3b8b7..dc87572d2c0 100644 --- a/numba/targets/quicksort.py +++ b/numba/targets/quicksort.py @@ -1,6 +1,3 @@ - -from __future__ import print_function, absolute_import, division - import collections import numpy as np diff --git a/numba/targets/randomimpl.py b/numba/targets/randomimpl.py index 1238049e835..6ea9892555a 100644 --- a/numba/targets/randomimpl.py +++ b/numba/targets/randomimpl.py @@ -2,7 +2,6 @@ Implement the random and np.random module functions. """ -from __future__ import print_function, absolute_import, division import math import os diff --git a/numba/targets/registry.py b/numba/targets/registry.py index b423ed559a6..106a0603174 100644 --- a/numba/targets/registry.py +++ b/numba/targets/registry.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import contextlib from . import cpu diff --git a/numba/targets/removerefctpass.py b/numba/targets/removerefctpass.py index 8e963b1d8ea..2403f746fa7 100644 --- a/numba/targets/removerefctpass.py +++ b/numba/targets/removerefctpass.py @@ -2,7 +2,6 @@ Implement a rewrite pass on LLVM module to remove unnecessary refcount operation. """ -from __future__ import absolute_import, print_function from llvmlite.ir.transforms import CallVisitor diff --git a/numba/targets/setobj.py b/numba/targets/setobj.py index 7d135d34478..2a2b6729f72 100644 --- a/numba/targets/setobj.py +++ b/numba/targets/setobj.py @@ -2,7 +2,6 @@ Support for native homogeneous sets. """ -from __future__ import print_function, absolute_import, division import collections import contextlib diff --git a/numba/targets/ufunc_db.py b/numba/targets/ufunc_db.py index f6cc516a144..e537c9b952a 100644 --- a/numba/targets/ufunc_db.py +++ b/numba/targets/ufunc_db.py @@ -7,7 +7,6 @@ ufunc """ -from __future__ import print_function, division, absolute_import import numpy as np diff --git a/numba/testing/__init__.py b/numba/testing/__init__.py index a993e525be4..aa9fd6b5451 100644 --- a/numba/testing/__init__.py +++ b/numba/testing/__init__.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import os import sys import functools diff --git a/numba/testing/main.py b/numba/testing/main.py index 30507c53a2e..bf35331119e 100644 --- a/numba/testing/main.py +++ b/numba/testing/main.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numba.unittest_support as unittest import collections diff --git a/numba/tests/cache_usecases.py b/numba/tests/cache_usecases.py index d8429b56f2d..7dfef49b380 100644 --- a/numba/tests/cache_usecases.py +++ b/numba/tests/cache_usecases.py @@ -4,7 +4,6 @@ See test_dispatcher.py. """ -from __future__ import division, print_function, absolute_import import sys diff --git a/numba/tests/cffi_usecases.py b/numba/tests/cffi_usecases.py index bc3293975fb..f0e708bf71c 100644 --- a/numba/tests/cffi_usecases.py +++ b/numba/tests/cffi_usecases.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import sys import numpy as np diff --git a/numba/tests/cfunc_cache_usecases.py b/numba/tests/cfunc_cache_usecases.py index b7621fccfaf..3430abd3a4e 100644 --- a/numba/tests/cfunc_cache_usecases.py +++ b/numba/tests/cfunc_cache_usecases.py @@ -4,7 +4,6 @@ See test_cfunc.py. """ -from __future__ import division, print_function, absolute_import import sys diff --git a/numba/tests/complex_usecases.py b/numba/tests/complex_usecases.py index 7983f56eea9..113cd69217a 100644 --- a/numba/tests/complex_usecases.py +++ b/numba/tests/complex_usecases.py @@ -1,5 +1,3 @@ -from __future__ import division - import cmath diff --git a/numba/tests/ctypes_usecases.py b/numba/tests/ctypes_usecases.py index f29226601e1..5ed8d3ab8e1 100644 --- a/numba/tests/ctypes_usecases.py +++ b/numba/tests/ctypes_usecases.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from ctypes import * import sys diff --git a/numba/tests/enum_usecases.py b/numba/tests/enum_usecases.py index 1de3762db2c..027aa0ba7d7 100644 --- a/numba/tests/enum_usecases.py +++ b/numba/tests/enum_usecases.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from enum import Enum, IntEnum diff --git a/numba/tests/npyufunc/test_caching.py b/numba/tests/npyufunc/test_caching.py index aef8dd0b659..02de5e2690c 100644 --- a/numba/tests/npyufunc/test_caching.py +++ b/numba/tests/npyufunc/test_caching.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import sys import os.path import re diff --git a/numba/tests/npyufunc/test_dufunc.py b/numba/tests/npyufunc/test_dufunc.py index f0dd4f3a75f..d0ec1475b28 100644 --- a/numba/tests/npyufunc/test_dufunc.py +++ b/numba/tests/npyufunc/test_dufunc.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import pickle import numpy as np diff --git a/numba/tests/npyufunc/test_errors.py b/numba/tests/npyufunc/test_errors.py index c930d671594..d02bf3c3e80 100644 --- a/numba/tests/npyufunc/test_errors.py +++ b/numba/tests/npyufunc/test_errors.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - import contextlib import sys diff --git a/numba/tests/npyufunc/test_gufunc.py b/numba/tests/npyufunc/test_gufunc.py index f82bd49310c..e2ed9970aa8 100644 --- a/numba/tests/npyufunc/test_gufunc.py +++ b/numba/tests/npyufunc/test_gufunc.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - import numpy as np import numpy.core.umath_tests as ut diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index 87058188f37..c06e89f2eb8 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function, division from numba import unittest_support as unittest from numba.npyufunc.parallel import get_thread_count from os import environ as env diff --git a/numba/tests/npyufunc/test_parallel_low_work.py b/numba/tests/npyufunc/test_parallel_low_work.py index 19433609293..9357b42d2c8 100644 --- a/numba/tests/npyufunc/test_parallel_low_work.py +++ b/numba/tests/npyufunc/test_parallel_low_work.py @@ -1,7 +1,6 @@ """ There was a deadlock problem when work count is smaller than number of threads. """ -from __future__ import absolute_import, print_function, division from numba import unittest_support as unittest diff --git a/numba/tests/npyufunc/test_parallel_ufunc_issues.py b/numba/tests/npyufunc/test_parallel_ufunc_issues.py index 7f02a8164df..99acffe0ea2 100644 --- a/numba/tests/npyufunc/test_parallel_ufunc_issues.py +++ b/numba/tests/npyufunc/test_parallel_ufunc_issues.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import time import ctypes diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index 875a550681e..1c89b6570c4 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/tests/npyufunc/test_ufuncbuilding.py b/numba/tests/npyufunc/test_ufuncbuilding.py index e4763b470ab..932cf813d38 100644 --- a/numba/tests/npyufunc/test_ufuncbuilding.py +++ b/numba/tests/npyufunc/test_ufuncbuilding.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import sys import numpy as np diff --git a/numba/tests/npyufunc/test_vectorize_decor.py b/numba/tests/npyufunc/test_vectorize_decor.py index 888d6f7532e..32ab0223ba8 100644 --- a/numba/tests/npyufunc/test_vectorize_decor.py +++ b/numba/tests/npyufunc/test_vectorize_decor.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - import math import numpy as np diff --git a/numba/tests/support.py b/numba/tests/support.py index 08f39b13563..0c7e72f5ac5 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -1,7 +1,6 @@ """ Assorted utilities for use in tests. """ -from __future__ import print_function import cmath import contextlib diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index 965a1aa6395..acdc833709f 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -1,5 +1,4 @@ # Tests numba.analysis functions -from __future__ import print_function, absolute_import, division import collections import numpy as np diff --git a/numba/tests/test_annotations.py b/numba/tests/test_annotations.py index a2d69763058..3daf58fa57d 100644 --- a/numba/tests/test_annotations.py +++ b/numba/tests/test_annotations.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division - import re import numba diff --git a/numba/tests/test_api.py b/numba/tests/test_api.py index de667cb1930..138d0d2bef2 100644 --- a/numba/tests/test_api.py +++ b/numba/tests/test_api.py @@ -1,5 +1,3 @@ -from __future__ import division - import numba from numba import unittest_support as unittest diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index a98d15eacfd..c3d37a730c7 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -1,5 +1,3 @@ -from __future__ import division - import itertools import numpy as np diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index 15c61b37dca..7fc9c99bc0a 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np import numba.unittest_support as unittest diff --git a/numba/tests/test_array_constants.py b/numba/tests/test_array_constants.py index 78a5e39f7fc..2391b7e3fdd 100644 --- a/numba/tests/test_array_constants.py +++ b/numba/tests/test_array_constants.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np import numba.unittest_support as unittest diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index 4bb0f1ab8a6..e108f2f1170 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import gc import numpy as np diff --git a/numba/tests/test_array_iterators.py b/numba/tests/test_array_iterators.py index 117348b9e30..7c073824dc1 100644 --- a/numba/tests/test_array_iterators.py +++ b/numba/tests/test_array_iterators.py @@ -1,5 +1,3 @@ -from __future__ import division - import itertools import numpy as np diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 972516fe95b..5aa39daa7f1 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from functools import partial from itertools import permutations import numba.unittest_support as unittest diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index ce9ad8c9b1e..fdf6cba4bfc 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -1,5 +1,3 @@ -from __future__ import division - from itertools import product, cycle, permutations import sys import warnings diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index de2ab8eac6d..34b427737d6 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -1,5 +1,3 @@ -from __future__ import division - from itertools import product, combinations_with_replacement import numpy as np diff --git a/numba/tests/test_array_return.py b/numba/tests/test_array_return.py index e774f75a916..2caf24f5112 100644 --- a/numba/tests/test_array_return.py +++ b/numba/tests/test_array_return.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba.compiler import compile_isolated diff --git a/numba/tests/test_auto_constants.py b/numba/tests/test_auto_constants.py index f38fbc985a8..05a7a1cd252 100644 --- a/numba/tests/test_auto_constants.py +++ b/numba/tests/test_auto_constants.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import math import sys diff --git a/numba/tests/test_blackscholes.py b/numba/tests/test_blackscholes.py index 99717a8085a..4e024cf1444 100644 --- a/numba/tests/test_blackscholes.py +++ b/numba/tests/test_blackscholes.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import math import numpy as np diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index e2769d3e9e1..d103cea365e 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba.compiler import compile_isolated, DEFAULT_FLAGS diff --git a/numba/tests/test_buffer_protocol.py b/numba/tests/test_buffer_protocol.py index eb500c731a8..fccd0e9831c 100644 --- a/numba/tests/test_buffer_protocol.py +++ b/numba/tests/test_buffer_protocol.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import array import sys diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index b8888e0c37c..716e80ff6ac 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import itertools import functools import sys diff --git a/numba/tests/test_caching.py b/numba/tests/test_caching.py index 0c675f801ff..cd3805cfb98 100644 --- a/numba/tests/test_caching.py +++ b/numba/tests/test_caching.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import sys import multiprocessing as mp diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index 26589830a19..1205bb30686 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import array import numpy as np import sys diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index 445ba714dcd..5894d663e95 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -2,7 +2,6 @@ Tests for @cfunc and friends. """ -from __future__ import division, print_function, absolute_import import ctypes import os diff --git a/numba/tests/test_cgutils.py b/numba/tests/test_cgutils.py index 7e2ab875d9c..7fd06573e5e 100644 --- a/numba/tests/test_cgutils.py +++ b/numba/tests/test_cgutils.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import contextlib import ctypes import struct diff --git a/numba/tests/test_chained_assign.py b/numba/tests/test_chained_assign.py index d23929fea82..8aec31dc7cd 100644 --- a/numba/tests/test_chained_assign.py +++ b/numba/tests/test_chained_assign.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from numba import jit import numba.unittest_support as unittest import numpy as np diff --git a/numba/tests/test_cli.py b/numba/tests/test_cli.py index 39bf369b48c..f2321dde7ae 100644 --- a/numba/tests/test_cli.py +++ b/numba/tests/test_cli.py @@ -1,5 +1,4 @@ # Tests for the CLI -from __future__ import print_function, division, absolute_import import os import subprocess diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 63bd2e1c720..548be0eed2a 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -1,5 +1,3 @@ -from __future__ import print_function - # import numpy in two ways, both uses needed import numpy as np import numpy diff --git a/numba/tests/test_codegen.py b/numba/tests/test_codegen.py index 17d78947b32..eb1267f488e 100644 --- a/numba/tests/test_codegen.py +++ b/numba/tests/test_codegen.py @@ -2,7 +2,6 @@ Tests for numba.targets.codegen. """ -from __future__ import print_function import warnings import base64 diff --git a/numba/tests/test_compile_cache.py b/numba/tests/test_compile_cache.py index 699d326b3af..1a87265f887 100644 --- a/numba/tests/test_compile_cache.py +++ b/numba/tests/test_compile_cache.py @@ -1,5 +1,3 @@ -from __future__ import division - import numba.unittest_support as unittest from contextlib import contextmanager diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index 8e94ad2f76a..614e7a00797 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import cmath import itertools import math diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index a5b878aff73..3b6f5bbcf1b 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest from .support import TestCase diff --git a/numba/tests/test_conversion.py b/numba/tests/test_conversion.py index 365d72b224f..467601ce928 100644 --- a/numba/tests/test_conversion.py +++ b/numba/tests/test_conversion.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import array import gc import itertools diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index ba13f5b09ea..11028992446 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from ctypes import * import sys import threading diff --git a/numba/tests/test_dataflow.py b/numba/tests/test_dataflow.py index 8875b3d159a..919eeff1ef2 100644 --- a/numba/tests/test_dataflow.py +++ b/numba/tests/test_dataflow.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import warnings import numba.unittest_support as unittest diff --git a/numba/tests/test_datamodel.py b/numba/tests/test_datamodel.py index 6ac8ae8466e..2d113baf126 100644 --- a/numba/tests/test_datamodel.py +++ b/numba/tests/test_datamodel.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from llvmlite import ir, binding as ll from numba import types diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index bd4c48e114d..5832b82dbce 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import os import platform import re diff --git a/numba/tests/test_debuginfo.py b/numba/tests/test_debuginfo.py index 0fe3e2f0b30..244b6f8180b 100644 --- a/numba/tests/test_debuginfo.py +++ b/numba/tests/test_debuginfo.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import re from .support import TestCase, override_config, tag diff --git a/numba/tests/test_del.py b/numba/tests/test_del.py index 8791f40e04c..eab43d5d97b 100644 --- a/numba/tests/test_del.py +++ b/numba/tests/test_del.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import re from numba.compiler import compile_isolated diff --git a/numba/tests/test_deprecations.py b/numba/tests/test_deprecations.py index f2c92513cf4..d367dda0e25 100644 --- a/numba/tests/test_deprecations.py +++ b/numba/tests/test_deprecations.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import warnings from numba import jit from numba.errors import (NumbaDeprecationWarning, diff --git a/numba/tests/test_dictimpl.py b/numba/tests/test_dictimpl.py index 788030e1244..ba88b3f0018 100644 --- a/numba/tests/test_dictimpl.py +++ b/numba/tests/test_dictimpl.py @@ -1,7 +1,6 @@ """ Testing C implementation of the numba dictionary """ -from __future__ import print_function, absolute_import, division import ctypes import random diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index e95bacc49e1..dbb085d6068 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -5,7 +5,6 @@ correctly. Detailed testing of the underlying dictionary operations is done in test_dictimpl.py. """ -from __future__ import print_function, absolute_import, division import sys import warnings diff --git a/numba/tests/test_dicts.py b/numba/tests/test_dicts.py index 5be862d4c14..ed85cf08eb6 100644 --- a/numba/tests/test_dicts.py +++ b/numba/tests/test_dicts.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from numba import njit from numba.errors import TypingError import numba.unittest_support as unittest diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index d6d07c899cb..84322390a3d 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import errno import multiprocessing import os diff --git a/numba/tests/test_dummyarray.py b/numba/tests/test_dummyarray.py index cfe7e457a38..d504b6c1c75 100644 --- a/numba/tests/test_dummyarray.py +++ b/numba/tests/test_dummyarray.py @@ -1,4 +1,3 @@ -from __future__ import print_function import numba.unittest_support as unittest import itertools import numpy as np diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index e06e55e343c..786eb5959d4 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import contextlib import sys import numpy as np diff --git a/numba/tests/test_dyn_func.py b/numba/tests/test_dyn_func.py index 5c499bf4722..d58b7606dc3 100644 --- a/numba/tests/test_dyn_func.py +++ b/numba/tests/test_dyn_func.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np import numba diff --git a/numba/tests/test_enums.py b/numba/tests/test_enums.py index d468271ad01..cf65a1abc0d 100644 --- a/numba/tests/test_enums.py +++ b/numba/tests/test_enums.py @@ -2,7 +2,6 @@ Tests for enum support. """ -from __future__ import print_function import numpy as np import numba.unittest_support as unittest diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index dbb7a44ff6e..a989de061fb 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -1,7 +1,6 @@ """ Unspecified error handling tests """ -from __future__ import division from numba import jit, njit, typed, int64 from numba import unittest_support as unittest diff --git a/numba/tests/test_errormodels.py b/numba/tests/test_errormodels.py index aafa743d469..a6dc276c427 100644 --- a/numba/tests/test_errormodels.py +++ b/numba/tests/test_errormodels.py @@ -1,7 +1,6 @@ """ Test setting/overriding error models """ -from __future__ import division from numba import jit from numba import unittest_support as unittest diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index c726ca1396f..78c01a0538d 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -1,4 +1,3 @@ - import numpy as np import sys import traceback diff --git a/numba/tests/test_extended_arg.py b/numba/tests/test_extended_arg.py index 16e5ecc79bd..05397936488 100644 --- a/numba/tests/test_extended_arg.py +++ b/numba/tests/test_extended_arg.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest import dis diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 2daed832a7d..7baa0676fa3 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import math import operator import sys diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index efa037ba5ac..36694535bfe 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import itertools import numpy as np diff --git a/numba/tests/test_fastmath.py b/numba/tests/test_fastmath.py index dcc5f87b402..495abb0004c 100644 --- a/numba/tests/test_fastmath.py +++ b/numba/tests/test_fastmath.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import math import numpy as np diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index 0fd26f1b2ea..bd21c32650b 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import itertools import numba.unittest_support as unittest diff --git a/numba/tests/test_func_interface.py b/numba/tests/test_func_interface.py index 454a2fd93eb..816b0837566 100644 --- a/numba/tests/test_func_interface.py +++ b/numba/tests/test_func_interface.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest from numba import jit diff --git a/numba/tests/test_func_lifetime.py b/numba/tests/test_func_lifetime.py index 9d4c131017f..cbdadde007f 100644 --- a/numba/tests/test_func_lifetime.py +++ b/numba/tests/test_func_lifetime.py @@ -1,6 +1,3 @@ - -from __future__ import print_function, absolute_import - import gc import weakref diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index d6834920a75..0126b04e87c 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -1,7 +1,6 @@ """ Tests gdb bindings """ -from __future__ import print_function import os import platform import subprocess diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index ad2720fed58..86ca2f030b1 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import sys import numpy as np diff --git a/numba/tests/test_gil.py b/numba/tests/test_gil.py index 30b68ef91dd..8635b7ddefe 100644 --- a/numba/tests/test_gil.py +++ b/numba/tests/test_gil.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import ctypes import ctypes.util import os diff --git a/numba/tests/test_globals.py b/numba/tests/test_globals.py index cefaf8d8eeb..76fc18f3461 100644 --- a/numba/tests/test_globals.py +++ b/numba/tests/test_globals.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import import numpy as np from numba import jit from numba import unittest_support as unittest diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index fc165d6534f..5639e71dbda 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -2,7 +2,6 @@ """ Test hashing of various supported types. """ -from __future__ import print_function import numba.unittest_support as unittest diff --git a/numba/tests/test_heapq.py b/numba/tests/test_heapq.py index f4ee1a12b85..8c557d16d2a 100644 --- a/numba/tests/test_heapq.py +++ b/numba/tests/test_heapq.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import heapq as hq import itertools diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index d9ccaea3450..d71bf07c2fd 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import sys import subprocess import types as pytypes diff --git a/numba/tests/test_import.py b/numba/tests/test_import.py index cbabf9de2ce..44b2389807c 100644 --- a/numba/tests/test_import.py +++ b/numba/tests/test_import.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import subprocess import sys diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index 2984b6ba6da..7f2a4a7d838 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import decimal import itertools diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 1e4f27c7097..155729b2aad 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import re import numpy as np diff --git a/numba/tests/test_interproc.py b/numba/tests/test_interproc.py index f84db11a373..048cecd5303 100644 --- a/numba/tests/test_interproc.py +++ b/numba/tests/test_interproc.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import gc from numba import jit, int32 diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index 55c1a9520e7..39156a16e24 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest from numba import compiler, ir, objmode import numpy as np diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index e3ed772bbd4..fe70d4658ee 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -3,7 +3,6 @@ LLVM or low level inlining. """ -from __future__ import print_function, absolute_import import numpy as np diff --git a/numba/tests/test_itanium_mangler.py b/numba/tests/test_itanium_mangler.py index 29eb9618f33..5b727fb5c43 100644 --- a/numba/tests/test_itanium_mangler.py +++ b/numba/tests/test_itanium_mangler.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, absolute_import import re diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index 64bf3c34c84..e64278c9bbe 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np from numba import njit diff --git a/numba/tests/test_jit_module.py b/numba/tests/test_jit_module.py index 05e74d2ae9e..3a4f82aa1fb 100644 --- a/numba/tests/test_jit_module.py +++ b/numba/tests/test_jit_module.py @@ -1,4 +1,3 @@ - import os import sys import shutil diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index c67327798dc..942d251a69a 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function, division - from collections import OrderedDict import ctypes import random diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index 5f6e338d20f..3ccedfbfb99 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -1,5 +1,3 @@ -from __future__ import division, print_function - import contextlib import gc from itertools import product, cycle diff --git a/numba/tests/test_listimpl.py b/numba/tests/test_listimpl.py index 68c2d0d013f..d7249b9a6b0 100644 --- a/numba/tests/test_listimpl.py +++ b/numba/tests/test_listimpl.py @@ -1,7 +1,6 @@ """ Testing C implementation of the numba typed-list """ -from __future__ import print_function, absolute_import, division import ctypes import struct diff --git a/numba/tests/test_listobject.py b/numba/tests/test_listobject.py index ccc935293d7..3b926a48caf 100644 --- a/numba/tests/test_listobject.py +++ b/numba/tests/test_listobject.py @@ -10,7 +10,6 @@ assumes that they work. """ -from __future__ import print_function, absolute_import, division from numba import njit from numba import int32, types diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 199148f1031..119c3ff3150 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from collections import namedtuple import contextlib import itertools diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index 57fdd8820ce..9d065cf47cf 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np import numba diff --git a/numba/tests/test_llvm_version_check.py b/numba/tests/test_llvm_version_check.py index 8b1b85480fc..984f94af42a 100644 --- a/numba/tests/test_llvm_version_check.py +++ b/numba/tests/test_llvm_version_check.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import imp import sys diff --git a/numba/tests/test_locals.py b/numba/tests/test_locals.py index 162826fdb7c..d5fa1a517dd 100644 --- a/numba/tests/test_locals.py +++ b/numba/tests/test_locals.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from numba import compiler, float32 from numba import unittest_support as unittest diff --git a/numba/tests/test_looplifting.py b/numba/tests/test_looplifting.py index c3243d79c85..66bbbd7d64d 100644 --- a/numba/tests/test_looplifting.py +++ b/numba/tests/test_looplifting.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np from numba import types, utils diff --git a/numba/tests/test_make_function_to_jit_function.py b/numba/tests/test_make_function_to_jit_function.py index ef37e5463b3..362e16431c2 100644 --- a/numba/tests/test_make_function_to_jit_function.py +++ b/numba/tests/test_make_function_to_jit_function.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from numba import njit, errors from numba.extending import overload import numpy as np diff --git a/numba/tests/test_mandelbrot.py b/numba/tests/test_mandelbrot.py index c32511aebdc..aac984bdb71 100644 --- a/numba/tests/test_mandelbrot.py +++ b/numba/tests/test_mandelbrot.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import types, utils diff --git a/numba/tests/test_map_filter_reduce.py b/numba/tests/test_map_filter_reduce.py index 37849ca6655..531ee3113c8 100644 --- a/numba/tests/test_map_filter_reduce.py +++ b/numba/tests/test_map_filter_reduce.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from numba import njit from numba import unittest_support as unittest diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index aab252c9ca4..b209d40ff22 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import itertools import math import sys diff --git a/numba/tests/test_maxmin.py b/numba/tests/test_maxmin.py index 12972e04680..ab1e8821b87 100644 --- a/numba/tests/test_maxmin.py +++ b/numba/tests/test_maxmin.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import, division from numba import unittest_support as unittest from numba.compiler import compile_isolated from numba import types diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 00a8c2bbeca..1291108dc3a 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import sys import numpy as np diff --git a/numba/tests/test_multi3.py b/numba/tests/test_multi3.py index 73b2789f874..32c81ad4881 100644 --- a/numba/tests/test_multi3.py +++ b/numba/tests/test_multi3.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import random import numpy as np diff --git a/numba/tests/test_nan.py b/numba/tests/test_nan.py index 951ed6ea277..3a791914538 100644 --- a/numba/tests/test_nan.py +++ b/numba/tests/test_nan.py @@ -1,4 +1,3 @@ -from __future__ import print_function import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import types diff --git a/numba/tests/test_nested_calls.py b/numba/tests/test_nested_calls.py index 8647a5f368b..a1a96d9aecd 100644 --- a/numba/tests/test_nested_calls.py +++ b/numba/tests/test_nested_calls.py @@ -3,7 +3,6 @@ Usually due to invalid type conversion between function boundaries. """ -from __future__ import print_function, division, absolute_import from numba import int32, int64 from numba import jit, generated_jit, types diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 7a648d71fd5..d22ae5d2fba 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -1,5 +1,4 @@ # Tests numpy methods of -from __future__ import print_function, absolute_import, division import itertools import math diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 63b0cabc00c..929d220041f 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -4,7 +4,6 @@ # NOTE: datetime64 and timedelta64 ufuncs are tested in test_ufuncs. -from __future__ import print_function import contextlib import itertools diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 352bfde8e7a..2ea5120bb8c 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division, print_function - import math import os import platform diff --git a/numba/tests/test_nrt_refct.py b/numba/tests/test_nrt_refct.py index 95ab5b34401..ed182e43788 100644 --- a/numba/tests/test_nrt_refct.py +++ b/numba/tests/test_nrt_refct.py @@ -2,7 +2,6 @@ Tests issues or edge cases for producing invalid NRT refct """ -from __future__ import division, absolute_import, print_function import gc diff --git a/numba/tests/test_numberctor.py b/numba/tests/test_numberctor.py index dc8eb69f084..d78f0e2d3b4 100644 --- a/numba/tests/test_numberctor.py +++ b/numba/tests/test_numberctor.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/tests/test_numbers.py b/numba/tests/test_numbers.py index 05c3ce88d65..dcf465bd82e 100644 --- a/numba/tests/test_numbers.py +++ b/numba/tests/test_numbers.py @@ -1,5 +1,4 @@ # (Some) Tests for targets/numbers.py -from __future__ import print_function, absolute_import, division import numpy as np diff --git a/numba/tests/test_numconv.py b/numba/tests/test_numconv.py index d799bfb7155..f1a5f6d371d 100644 --- a/numba/tests/test_numconv.py +++ b/numba/tests/test_numconv.py @@ -1,4 +1,3 @@ -from __future__ import print_function import itertools import numba.unittest_support as unittest from numba.compiler import compile_isolated diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index bbf8d986e09..d7fd772d0ee 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -2,7 +2,6 @@ Test helper functions from numba.numpy_support. """ -from __future__ import print_function import sys from itertools import product diff --git a/numba/tests/test_numpyadapt.py b/numba/tests/test_numpyadapt.py index c06613996e8..82bdc2175b9 100644 --- a/numba/tests/test_numpyadapt.py +++ b/numba/tests/test_numpyadapt.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from ctypes import * import numpy as np diff --git a/numba/tests/test_obj_lifetime.py b/numba/tests/test_obj_lifetime.py index 02c679875f3..0f845569e1f 100644 --- a/numba/tests/test_obj_lifetime.py +++ b/numba/tests/test_obj_lifetime.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import collections import sys import weakref diff --git a/numba/tests/test_object_mode.py b/numba/tests/test_object_mode.py index 45513913db2..156b278155b 100644 --- a/numba/tests/test_object_mode.py +++ b/numba/tests/test_object_mode.py @@ -2,7 +2,6 @@ Testing object mode specifics. """ -from __future__ import print_function import numpy as np diff --git a/numba/tests/test_objects.py b/numba/tests/test_objects.py index e3ff53d4320..90ba1e68a36 100644 --- a/numba/tests/test_objects.py +++ b/numba/tests/test_objects.py @@ -2,7 +2,6 @@ Test generic manipulation of objects. """ -from __future__ import print_function import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 3b0f813534b..cba69c86997 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import copy import itertools import operator diff --git a/numba/tests/test_optional.py b/numba/tests/test_optional.py index 827d1413e55..d855f812e72 100644 --- a/numba/tests/test_optional.py +++ b/numba/tests/test_optional.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import itertools import numpy as np diff --git a/numba/tests/test_overlap.py b/numba/tests/test_overlap.py index 5fb1c1bc268..29c3e631013 100644 --- a/numba/tests/test_overlap.py +++ b/numba/tests/test_overlap.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import numpy as np from numba import unittest_support as unittest diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 5839fc77272..058479418ad 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, absolute_import """ Tests the parallel backend diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index aedd07a0ef1..26c86e0bfbc 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: BSD-2-Clause # -from __future__ import print_function, division, absolute_import from math import sqrt import numbers diff --git a/numba/tests/test_parfors_caching.py b/numba/tests/test_parfors_caching.py index 03667f89b7e..8360b92ec58 100644 --- a/numba/tests/test_parfors_caching.py +++ b/numba/tests/test_parfors_caching.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import os.path import numpy as np diff --git a/numba/tests/test_pipeline.py b/numba/tests/test_pipeline.py index b21f8937062..96274223429 100644 --- a/numba/tests/test_pipeline.py +++ b/numba/tests/test_pipeline.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from numba.compiler import Compiler from numba import jit, generated_jit, types, objmode from numba.ir import FunctionIR diff --git a/numba/tests/test_polynomial.py b/numba/tests/test_polynomial.py index 1eed9cedb15..9a5bbfac00a 100644 --- a/numba/tests/test_polynomial.py +++ b/numba/tests/test_polynomial.py @@ -1,5 +1,3 @@ -from __future__ import division, print_function - import gc from itertools import product diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index 044c7133044..8bf82f1f2c6 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -3,7 +3,6 @@ """ -from __future__ import print_function import numpy as np from numba import njit, types, ir diff --git a/numba/tests/test_print.py b/numba/tests/test_print.py index c94c997d605..03ec4b7e23a 100644 --- a/numba/tests/test_print.py +++ b/numba/tests/test_print.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import sys import numpy as np diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index 82635a72617..305a61d98a8 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import contextlib import imp import os diff --git a/numba/tests/test_python_int.py b/numba/tests/test_python_int.py index b32f31e17dc..d8e63681cba 100644 --- a/numba/tests/test_python_int.py +++ b/numba/tests/test_python_int.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import types diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index 80e94cfb35a..78d8019e7c2 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import collections import functools import math diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index 352cce0850a..62cc477a244 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest import sys diff --git a/numba/tests/test_recarray_usecases.py b/numba/tests/test_recarray_usecases.py index 26d153dbc25..0270c323992 100644 --- a/numba/tests/test_recarray_usecases.py +++ b/numba/tests/test_recarray_usecases.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import sys import numpy as np diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index c8e4d1877d2..e9c2c1df156 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import sys import numpy as np diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index a7deb4a0a74..c7db9781e1a 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import math import warnings diff --git a/numba/tests/test_return_values.py b/numba/tests/test_return_values.py index 1c38c6bd1e5..3d35fea83c0 100644 --- a/numba/tests/test_return_values.py +++ b/numba/tests/test_return_values.py @@ -2,7 +2,6 @@ Test return values """ -from __future__ import print_function import math diff --git a/numba/tests/test_runtests.py b/numba/tests/test_runtests.py index 58e4cd5debd..9bd6dbbf000 100755 --- a/numba/tests/test_runtests.py +++ b/numba/tests/test_runtests.py @@ -1,5 +1,3 @@ -from __future__ import division, print_function - import sys import subprocess diff --git a/numba/tests/test_serialize.py b/numba/tests/test_serialize.py index 2e456df6292..93958ec3ae6 100644 --- a/numba/tests/test_serialize.py +++ b/numba/tests/test_serialize.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import contextlib import gc import pickle diff --git a/numba/tests/test_sets.py b/numba/tests/test_sets.py index 54b3d52750a..3a33cbd495a 100644 --- a/numba/tests/test_sets.py +++ b/numba/tests/test_sets.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numba.unittest_support as unittest from collections import namedtuple diff --git a/numba/tests/test_slices.py b/numba/tests/test_slices.py index 148def6562b..d578a485ce7 100644 --- a/numba/tests/test_slices.py +++ b/numba/tests/test_slices.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from functools import partial import itertools from itertools import chain, product, starmap diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index 78b558ead63..909237ecb49 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import copy import itertools import math diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index f06d2e1f73b..8b0d2525381 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: BSD-2-Clause # -from __future__ import print_function, division, absolute_import import sys import numpy as np diff --git a/numba/tests/test_storeslice.py b/numba/tests/test_storeslice.py index e03fd6954de..e47f9873e2b 100644 --- a/numba/tests/test_storeslice.py +++ b/numba/tests/test_storeslice.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np import numba.unittest_support as unittest diff --git a/numba/tests/test_support.py b/numba/tests/test_support.py index 7d5eb75f190..b350e419323 100644 --- a/numba/tests/test_support.py +++ b/numba/tests/test_support.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import itertools import numpy as np diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 7ea73f50357..99f6fe8f1d4 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -1,5 +1,3 @@ -from __future__ import division, print_function - import math import numpy as np import subprocess diff --git a/numba/tests/test_sys_stdin_assignment.py b/numba/tests/test_sys_stdin_assignment.py index 1990b1a8fd2..f9d88e23547 100644 --- a/numba/tests/test_sys_stdin_assignment.py +++ b/numba/tests/test_sys_stdin_assignment.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - import sys import unittest diff --git a/numba/tests/test_target_overloadselector.py b/numba/tests/test_target_overloadselector.py index fafc48386e1..8cf208388df 100644 --- a/numba/tests/test_target_overloadselector.py +++ b/numba/tests/test_target_overloadselector.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from itertools import product, permutations from collections import defaultdict diff --git a/numba/tests/test_try_except.py b/numba/tests/test_try_except.py index eb0fef57a09..3d19e930c83 100644 --- a/numba/tests/test_try_except.py +++ b/numba/tests/test_try_except.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import warnings from itertools import product diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index 895b6c303e0..635b207acf4 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import collections import itertools diff --git a/numba/tests/test_typeconv.py b/numba/tests/test_typeconv.py index 1d701f0d301..cd0c22f92af 100644 --- a/numba/tests/test_typeconv.py +++ b/numba/tests/test_typeconv.py @@ -1,4 +1,3 @@ -from __future__ import print_function import itertools from numba import unittest_support as unittest diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 989c83e9f14..e8863072cf9 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import, division - from itertools import product import numpy as np diff --git a/numba/tests/test_typedobjectutils.py b/numba/tests/test_typedobjectutils.py index 43ab5cb121f..cef073845b2 100644 --- a/numba/tests/test_typedobjectutils.py +++ b/numba/tests/test_typedobjectutils.py @@ -1,7 +1,6 @@ """ Unit-tests for `typedobjectutils.py` """ -from __future__ import print_function, absolute_import, division import warnings diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index aff0e13b426..96e6381e626 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import os, sys, subprocess import itertools diff --git a/numba/tests/test_typenames.py b/numba/tests/test_typenames.py index b0756570c15..7cb5ed77a1b 100644 --- a/numba/tests/test_typenames.py +++ b/numba/tests/test_typenames.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - import numpy as np from numba import types diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index ecbea8bb7e5..8a2a77dce3c 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -2,7 +2,6 @@ Tests for the typeof() machinery. """ -from __future__ import print_function import array from collections import namedtuple diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index ffafddb7cd6..2c713444dac 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -2,7 +2,6 @@ Tests for numba.types. """ -from __future__ import print_function, absolute_import from collections import namedtuple import contextlib diff --git a/numba/tests/test_typingerror.py b/numba/tests/test_typingerror.py index 6fa19509ec1..6575c7a7286 100644 --- a/numba/tests/test_typingerror.py +++ b/numba/tests/test_typingerror.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import math import re import textwrap diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index c6c475a0c32..b8ae6163926 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import functools import itertools import re diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 3df0cb8a6f0..f484d298d48 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -3,7 +3,6 @@ # This file tests Python 3.4 style unicode strings # Tests should be skipped on Python < 3.4 -from __future__ import print_function import sys from itertools import product diff --git a/numba/tests/test_unicode_array.py b/numba/tests/test_unicode_array.py index d19641b3d9f..0727d5e67ef 100644 --- a/numba/tests/test_unicode_array.py +++ b/numba/tests/test_unicode_array.py @@ -1,5 +1,3 @@ -from __future__ import print_function, unicode_literals - import platform import numpy as np diff --git a/numba/tests/test_unicode_literals.py b/numba/tests/test_unicode_literals.py index 72feecc8605..2924f284474 100644 --- a/numba/tests/test_unicode_literals.py +++ b/numba/tests/test_unicode_literals.py @@ -1,5 +1,3 @@ -from __future__ import print_function, unicode_literals - import sys import numba.unittest_support as unittest diff --git a/numba/tests/test_unicode_names.py b/numba/tests/test_unicode_names.py index 0d94897e360..9017520f83c 100644 --- a/numba/tests/test_unicode_names.py +++ b/numba/tests/test_unicode_names.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import print_function, absolute_import from numba import njit, cfunc, cgutils diff --git a/numba/tests/test_unpack_sequence.py b/numba/tests/test_unpack_sequence.py index f14f92e714c..dbe360213b8 100644 --- a/numba/tests/test_unpack_sequence.py +++ b/numba/tests/test_unpack_sequence.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np import numba.unittest_support as unittest diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index c9b397fdade..13c77001614 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import random import numpy as np diff --git a/numba/tests/test_usecases.py b/numba/tests/test_usecases.py index c64e6afda9b..7217e543fa5 100644 --- a/numba/tests/test_usecases.py +++ b/numba/tests/test_usecases.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import itertools import numpy as np diff --git a/numba/tests/test_vectorization_type_inference.py b/numba/tests/test_vectorization_type_inference.py index b07429bffe8..7d347630847 100644 --- a/numba/tests/test_vectorization_type_inference.py +++ b/numba/tests/test_vectorization_type_inference.py @@ -1,4 +1,3 @@ -from __future__ import print_function from numba import vectorize, jit, bool_, double, int_, float_, typeof, int8 import numba.unittest_support as unittest import numpy as np diff --git a/numba/tests/test_warnings.py b/numba/tests/test_warnings.py index 9a70d297d14..1dbdf5bc097 100644 --- a/numba/tests/test_warnings.py +++ b/numba/tests/test_warnings.py @@ -1,4 +1,3 @@ -from __future__ import print_function import os import subprocess import sys diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index 8891da622cc..05317f0e799 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import copy import warnings import numpy as np diff --git a/numba/tests/test_wrapper.py b/numba/tests/test_wrapper.py index 47960325559..24519279e6f 100644 --- a/numba/tests/test_wrapper.py +++ b/numba/tests/test_wrapper.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import numpy as np import numba.unittest_support as unittest diff --git a/numba/tests/timsort.py b/numba/tests/timsort.py index a23e19bdb56..419eb528414 100644 --- a/numba/tests/timsort.py +++ b/numba/tests/timsort.py @@ -4,7 +4,6 @@ For more information, see listsort.txt in CPython's source tree. """ -from __future__ import print_function, absolute_import, division import collections diff --git a/numba/tests/true_div_usecase.py b/numba/tests/true_div_usecase.py index ba525717050..dd249822e62 100644 --- a/numba/tests/true_div_usecase.py +++ b/numba/tests/true_div_usecase.py @@ -1,6 +1,3 @@ -from __future__ import division - - # These functions have their own module in order to be compiled with the right # __future__ flag (and be tested alongside the 2.x legacy division operator). diff --git a/numba/tracing.py b/numba/tracing.py index d4439b872a7..5121a4a993b 100644 --- a/numba/tracing.py +++ b/numba/tracing.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import logging import sys import types diff --git a/numba/transforms.py b/numba/transforms.py index 7c8a6aee7b7..b1c5c3c65b5 100644 --- a/numba/transforms.py +++ b/numba/transforms.py @@ -2,7 +2,6 @@ Implement transformation on Numba IR """ -from __future__ import absolute_import, print_function from collections import namedtuple, defaultdict import logging diff --git a/numba/typeconv/castgraph.py b/numba/typeconv/castgraph.py index 1a93535c9a2..2591c0cc51e 100644 --- a/numba/typeconv/castgraph.py +++ b/numba/typeconv/castgraph.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from collections import defaultdict from functools import total_ordering import enum diff --git a/numba/typeconv/rules.py b/numba/typeconv/rules.py index 499cc592d30..00f8fcba78b 100644 --- a/numba/typeconv/rules.py +++ b/numba/typeconv/rules.py @@ -1,4 +1,3 @@ -from __future__ import print_function, absolute_import import itertools from .typeconv import TypeManager, TypeCastingRules from numba import types diff --git a/numba/typeconv/typeconv.py b/numba/typeconv/typeconv.py index 45dac7369a3..57e425cedc5 100644 --- a/numba/typeconv/typeconv.py +++ b/numba/typeconv/typeconv.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - try: # This is usually the the first C extension import performed when importing # Numba, if it fails to import, provide some feedback diff --git a/numba/typed/__init__.py b/numba/typed/__init__.py index 5ea13aff79e..9f60cfa6614 100644 --- a/numba/typed/__init__.py +++ b/numba/typed/__init__.py @@ -1,4 +1,2 @@ -from __future__ import absolute_import - from .typeddict import Dict from .typedlist import List diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index fc792ea7585..4d6346d81f4 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -1,4 +1,3 @@ - """ Python wrapper that connects CPython interpreter to the Numba typed-list. diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 5ddc83b48c9..59a6c744674 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from contextlib import contextmanager import warnings diff --git a/numba/typeinfer.py b/numba/typeinfer.py index 5ce88f77864..789c8ae6f9a 100644 --- a/numba/typeinfer.py +++ b/numba/typeinfer.py @@ -12,7 +12,6 @@ Constraints push types forward following the dataflow. """ -from __future__ import print_function, division, absolute_import import logging import operator diff --git a/numba/types/__init__.py b/numba/types/__init__.py index 0b19a93aebe..f970a89ae42 100644 --- a/numba/types/__init__.py +++ b/numba/types/__init__.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import struct import numpy as np diff --git a/numba/types/abstract.py b/numba/types/abstract.py index 4a13f9b4cf1..c7574352ef0 100644 --- a/numba/types/abstract.py +++ b/numba/types/abstract.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from abc import ABCMeta, abstractmethod, abstractproperty import itertools import weakref diff --git a/numba/types/common.py b/numba/types/common.py index 12fd759d744..f1806540c60 100644 --- a/numba/types/common.py +++ b/numba/types/common.py @@ -1,7 +1,6 @@ """ Helper classes / mixins for defining types. """ -from __future__ import print_function, division, absolute_import from .abstract import ArrayCompatible, Dummy, IterableType, IteratorType diff --git a/numba/types/containers.py b/numba/types/containers.py index 19a13cb2821..76f2800d23f 100644 --- a/numba/types/containers.py +++ b/numba/types/containers.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from collections.abc import Iterable from .abstract import (ConstSized, Container, Hashable, MutableSequence, Sequence, Type, TypeRef) diff --git a/numba/types/functions.py b/numba/types/functions.py index 66571d72841..e0c5553f163 100644 --- a/numba/types/functions.py +++ b/numba/types/functions.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import traceback from .abstract import Callable, DTypeSpec, Dummy, Literal, Type, weakref diff --git a/numba/types/iterators.py b/numba/types/iterators.py index 1619d2c734f..9023627fb2c 100644 --- a/numba/types/iterators.py +++ b/numba/types/iterators.py @@ -1,6 +1,3 @@ -from __future__ import print_function, division, absolute_import - - from .common import SimpleIterableType, SimpleIteratorType diff --git a/numba/types/misc.py b/numba/types/misc.py index 4fa64b68a94..05de8ce764b 100644 --- a/numba/types/misc.py +++ b/numba/types/misc.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from .abstract import Callable, Literal, Type from .common import Dummy, IterableType, Opaque, SimpleIteratorType from ..typeconv import Conversion diff --git a/numba/types/npytypes.py b/numba/types/npytypes.py index 1f40a06188d..637ff472ad9 100644 --- a/numba/types/npytypes.py +++ b/numba/types/npytypes.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import collections from llvmlite import ir diff --git a/numba/types/scalars.py b/numba/types/scalars.py index 46d0b1ce5e8..4aaf1074691 100644 --- a/numba/types/scalars.py +++ b/numba/types/scalars.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import enum import numpy as np diff --git a/numba/typing/__init__.py b/numba/typing/__init__.py index dc910c12e0d..7a30bbd0c05 100644 --- a/numba/typing/__init__.py +++ b/numba/typing/__init__.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import from .context import BaseContext, Context from .templates import (signature, make_concrete_template, Signature, fold_arguments) diff --git a/numba/typing/arraydecl.py b/numba/typing/arraydecl.py index c52f3adf1d4..e43548c4b4f 100644 --- a/numba/typing/arraydecl.py +++ b/numba/typing/arraydecl.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import numpy as np import operator from collections import namedtuple diff --git a/numba/typing/builtins.py b/numba/typing/builtins.py index 1de8fb5177f..1300837c002 100644 --- a/numba/typing/builtins.py +++ b/numba/typing/builtins.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import itertools import numpy as np diff --git a/numba/typing/cffi_utils.py b/numba/typing/cffi_utils.py index cc3c70966f3..b388bddf80f 100644 --- a/numba/typing/cffi_utils.py +++ b/numba/typing/cffi_utils.py @@ -3,7 +3,6 @@ Support for CFFI. Allows checking whether objects are CFFI functions and obtaining the pointer and numba signature. """ -from __future__ import print_function, division, absolute_import from types import BuiltinFunctionType import ctypes diff --git a/numba/typing/collections.py b/numba/typing/collections.py index b89eae2ff8c..bb4639a3e79 100644 --- a/numba/typing/collections.py +++ b/numba/typing/collections.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - from .. import types, utils, errors import operator from .templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, diff --git a/numba/typing/context.py b/numba/typing/context.py index ca7dcad93a3..171171d87ef 100644 --- a/numba/typing/context.py +++ b/numba/typing/context.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from collections import defaultdict from collections.abc import Sequence import types as pytypes diff --git a/numba/typing/ctypes_utils.py b/numba/typing/ctypes_utils.py index 9784ec5d271..ea093c1b375 100644 --- a/numba/typing/ctypes_utils.py +++ b/numba/typing/ctypes_utils.py @@ -2,7 +2,6 @@ Support for typing ctypes function pointers. """ -from __future__ import absolute_import import ctypes import sys diff --git a/numba/typing/dictdecl.py b/numba/typing/dictdecl.py index a3ef3eabff1..73187be5d22 100644 --- a/numba/typing/dictdecl.py +++ b/numba/typing/dictdecl.py @@ -1,7 +1,6 @@ """ This implements the typing template for `dict()`. """ -from __future__ import absolute_import, print_function from .. import types, errors from .templates import ( diff --git a/numba/typing/listdecl.py b/numba/typing/listdecl.py index 315c8271d18..ed2db02090c 100644 --- a/numba/typing/listdecl.py +++ b/numba/typing/listdecl.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import operator from .. import types from .templates import (ConcreteTemplate, AbstractTemplate, AttributeTemplate, diff --git a/numba/typing/npdatetime.py b/numba/typing/npdatetime.py index 4f3373be605..16624bae470 100644 --- a/numba/typing/npdatetime.py +++ b/numba/typing/npdatetime.py @@ -2,7 +2,6 @@ Typing declarations for np.timedelta64. """ -from __future__ import print_function, division, absolute_import from itertools import product import operator diff --git a/numba/typing/npydecl.py b/numba/typing/npydecl.py index 2e2a8545ab2..a97a394b4f5 100644 --- a/numba/typing/npydecl.py +++ b/numba/typing/npydecl.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import warnings import numpy as np diff --git a/numba/typing/randomdecl.py b/numba/typing/randomdecl.py index 4d40b72038a..2d244df79e3 100644 --- a/numba/typing/randomdecl.py +++ b/numba/typing/randomdecl.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import random import numpy as np diff --git a/numba/typing/setdecl.py b/numba/typing/setdecl.py index 1748234bc15..7889093d957 100644 --- a/numba/typing/setdecl.py +++ b/numba/typing/setdecl.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import operator from .. import types diff --git a/numba/typing/templates.py b/numba/typing/templates.py index df5b05300c1..f09dba50261 100644 --- a/numba/typing/templates.py +++ b/numba/typing/templates.py @@ -1,7 +1,6 @@ """ Define typing templates """ -from __future__ import print_function, division, absolute_import import functools import sys diff --git a/numba/typing/typeof.py b/numba/typing/typeof.py index 4971ce50591..4a30c8aabef 100644 --- a/numba/typing/typeof.py +++ b/numba/typing/typeof.py @@ -1,5 +1,3 @@ -from __future__ import print_function, absolute_import - from collections import namedtuple from functools import singledispatch import ctypes diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index 8001c6bf66b..1124a44836c 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -1,4 +1,3 @@ -from __future__ import print_function, division, absolute_import from collections import defaultdict, namedtuple from copy import deepcopy, copy diff --git a/numba/utils.py b/numba/utils.py index cbc8808064d..59eaa96433c 100644 --- a/numba/utils.py +++ b/numba/utils.py @@ -1,5 +1,3 @@ -from __future__ import print_function, division, absolute_import - import atexit import builtins import functools From fb1b8318ceaffe00823fc99255f96444a91c0625 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 13:22:02 +0000 Subject: [PATCH 215/595] fix bad refactor --- numba/targets/externals.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/numba/targets/externals.py b/numba/targets/externals.py index 0674c02fbae..699f8abcdc0 100644 --- a/numba/targets/externals.py +++ b/numba/targets/externals.py @@ -151,10 +151,7 @@ def _do_install(self, context): # (under Windows, different versions of the C runtime can # be loaded at the same time, for example msvcrt100 by # CPython and msvcrt120 by LLVM) - if fname.startswith('fmod'): - ll.add_symbol(fname, c_helpers['fixed_' + fname]) - else: - ll.add_symbol(fname, c_helpers[fname]) + ll.add_symbol(fname, c_helpers[fname]) c_math_functions = _ExternalMathFunctions() From a55b7d68046cd45b48543f4b469b3ebcba59a807 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 13:23:26 +0000 Subject: [PATCH 216/595] Remove missed singledispatch --- numba/cuda/printimpl.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/numba/cuda/printimpl.py b/numba/cuda/printimpl.py index b46cf1cb5c6..78fbf47ee32 100644 --- a/numba/cuda/printimpl.py +++ b/numba/cuda/printimpl.py @@ -1,6 +1,8 @@ +from functools import singledispatch + from llvmlite.llvmpy.core import Type, Constant -from numba import types, typing, cgutils, utils +from numba import types, typing, cgutils from numba.targets.imputils import Registry from . import nvvmutils @@ -12,7 +14,7 @@ # NOTE: we don't use @lower here since print_item() doesn't return a LLVM value -@utils.singledispatch +@singledispatch def print_item(ty, context, builder, val): """ Handle printing of a single value of the given Numba type. From 23fdc44bc2ec53bb04dcb3fe47a2b189d8002305 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 14:35:43 +0000 Subject: [PATCH 217/595] wip rm six/python_utils --- numba/caching.py | 2 +- numba/compiler_machinery.py | 2 +- numba/cuda/args.py | 2 +- numba/cuda/simulator/kernel.py | 2 +- numba/debuginfo.py | 2 +- numba/dispatcher.py | 2 +- numba/errors.py | 2 +- numba/python_utils.py | 25 +------------- numba/roc/hlc/common.py | 2 +- numba/testing/main.py | 2 +- numba/tests/support.py | 4 +-- numba/types/abstract.py | 2 +- numba/utils.py | 60 +++++++++++++++++++++++++++++++++- 13 files changed, 72 insertions(+), 37 deletions(-) diff --git a/numba/caching.py b/numba/caching.py index ead099a5c20..c674abf9b0f 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -16,7 +16,7 @@ import warnings from .appdirs import AppDirs -from numba.python_utils import add_metaclass +from numba.utils import add_metaclass import numba from . import compiler, config, utils diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index 1fa5f9803b1..d1c94e8a019 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -6,7 +6,7 @@ from numba.compiler_lock import global_compiler_lock from numba import errors from . import config, utils, transforms -from numba.python_utils import add_metaclass +from numba.utils import add_metaclass from .tracing import event from .postproc import PostProcessor diff --git a/numba/cuda/args.py b/numba/cuda/args.py index 7600ba1d43f..f07b19da07a 100644 --- a/numba/cuda/args.py +++ b/numba/cuda/args.py @@ -4,7 +4,7 @@ """ import abc -from numba.python_utils import add_metaclass +from numba.utils import add_metaclass from numba.typing.typeof import typeof, Purpose diff --git a/numba/cuda/simulator/kernel.py b/numba/cuda/simulator/kernel.py index 97284dc24ec..5fa674e2af4 100644 --- a/numba/cuda/simulator/kernel.py +++ b/numba/cuda/simulator/kernel.py @@ -5,7 +5,7 @@ import numpy as np -from numba.python_utils import reraise +from numba.utils import reraise from .cudadrv.devicearray import to_device, auto_device from .kernelapi import Dim3, FakeCUDAModule, swapped_cuda_module from ..errors import normalize_kernel_dimensions diff --git a/numba/debuginfo.py b/numba/debuginfo.py index 3dc6bb4fd91..6f12373e32c 100644 --- a/numba/debuginfo.py +++ b/numba/debuginfo.py @@ -8,7 +8,7 @@ from llvmlite import ir -from numba.python_utils import add_metaclass +from numba.utils import add_metaclass @add_metaclass(abc.ABCMeta) diff --git a/numba/dispatcher.py b/numba/dispatcher.py index b53571a23ee..82ac2aaaf54 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -18,7 +18,7 @@ from numba.typing.templates import fold_arguments from numba.typing.typeof import Purpose, typeof from numba.bytecode import get_code_object -from numba.python_utils import reraise +from numba.utils import reraise from .caching import NullCache, FunctionCache diff --git a/numba/errors.py b/numba/errors.py index e99ddfc03f6..6a80cc3c83b 100644 --- a/numba/errors.py +++ b/numba/errors.py @@ -11,7 +11,7 @@ import numba import numpy as np from collections import defaultdict -from numba.python_utils import add_metaclass, reraise +from numba.utils import add_metaclass, reraise from functools import wraps from abc import abstractmethod diff --git a/numba/python_utils.py b/numba/python_utils.py index 782cf6d0f6f..c0fd05aa850 100644 --- a/numba/python_utils.py +++ b/numba/python_utils.py @@ -36,29 +36,6 @@ PY3 = sys.version_info[0] == 3 -def reraise(tp, value, tb=None): - if value is None: - value = tp() - if value.__traceback__ is not tb: - raise value.with_traceback(tb) - raise value - - -def add_metaclass(metaclass): - """Class decorator for creating a class with a metaclass.""" - def wrapper(cls): - orig_vars = cls.__dict__.copy() - slots = orig_vars.get('__slots__') - if slots is not None: - if isinstance(slots, str): - slots = [slots] - for slots_var in slots: - orig_vars.pop(slots_var) - orig_vars.pop('__dict__', None) - orig_vars.pop('__weakref__', None) - return metaclass(cls.__name__, cls.__bases__, orig_vars) - return wrapper - if PY3: string_types = str, @@ -567,7 +544,7 @@ def next(self): get_function_closure = operator.attrgetter(_func_closure) get_function_code = operator.attrgetter(_func_code) get_function_defaults = operator.attrgetter(_func_defaults) -get_function_globals = operator.attrgetter(_func_globals) +get_function_globals = operator.attrgetter("__globals__") if PY3: diff --git a/numba/roc/hlc/common.py b/numba/roc/hlc/common.py index 9ab647016d6..7fd82c6362f 100644 --- a/numba/roc/hlc/common.py +++ b/numba/roc/hlc/common.py @@ -4,7 +4,7 @@ from abc import abstractmethod, ABCMeta -from numba.python_utils import add_metaclass +from numba.utils import add_metaclass import re # These are for parsing labels and metadata diff --git a/numba/testing/main.py b/numba/testing/main.py index bf35331119e..e8f99e1960c 100644 --- a/numba/testing/main.py +++ b/numba/testing/main.py @@ -12,10 +12,10 @@ import time import warnings +from io import StringIO from unittest import result, runner, signals, suite, loader, case from .loader import TestLoader -from numba.utils import StringIO from numba import config try: diff --git a/numba/tests/support.py b/numba/tests/support.py index 0c7e72f5ac5..05ccb781482 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -170,7 +170,7 @@ def assertNoNRTLeak(self): _bool_types = (bool, np.bool_) _exact_typesets = [_bool_types, utils.INT_TYPES, (str,), (np.integer,), - (utils.text_type), (bytes, np.bytes_)] + (bytes, np.bytes_)] _approx_typesets = [(float,), (complex,), (np.inexact)] _sequence_typesets = [(tuple, list)] _float_types = (float, np.floating) @@ -609,7 +609,7 @@ def captured_output(stream_name): """Return a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO.""" orig_stdout = getattr(sys, stream_name) - setattr(sys, stream_name, utils.StringIO()) + setattr(sys, stream_name, io.StringIO()) try: yield getattr(sys, stream_name) finally: diff --git a/numba/types/abstract.py b/numba/types/abstract.py index c7574352ef0..1353b46c69a 100644 --- a/numba/types/abstract.py +++ b/numba/types/abstract.py @@ -4,7 +4,7 @@ import numpy as np -from numba.python_utils import add_metaclass +from numba.utils import add_metaclass from ..utils import cached_property diff --git a/numba/utils.py b/numba/utils.py index 59eaa96433c..b4c3b19fe11 100644 --- a/numba/utils.py +++ b/numba/utils.py @@ -17,7 +17,7 @@ from inspect import Signature as pySignature # noqa: F401 from inspect import Parameter as pyParameter # noqa: F401 -from .python_utils import * +#from .python_utils import * from numba.config import PYVERSION, MACHINE_BITS, DEVELOPER_MODE # noqa: F401 @@ -28,6 +28,64 @@ file_replace = os.replace asbyteint = int +# ------------------------------------------------------------------------------ +# Start: Originally from `numba.six` under the following license + +"""Utilities for writing code that runs on Python 2 and 3""" + +# Copyright (c) 2010-2015 Benjamin Peterson +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +def add_metaclass(metaclass): + """Class decorator for creating a class with a metaclass.""" + def wrapper(cls): + orig_vars = cls.__dict__.copy() + slots = orig_vars.get('__slots__') + if slots is not None: + if isinstance(slots, str): + slots = [slots] + for slots_var in slots: + orig_vars.pop(slots_var) + orig_vars.pop('__dict__', None) + orig_vars.pop('__weakref__', None) + return metaclass(cls.__name__, cls.__bases__, orig_vars) + return wrapper + + +def reraise(tp, value, tb=None): + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + +def iteritems(d, **kw): + return iter(d.items(**kw)) + +def itervalues(d, **kw): + return iter(d.values(**kw)) + +get_function_globals = operator.attrgetter("__globals__") + +# End: Originally from `numba.six` under the following license +# ------------------------------------------------------------------------------ def erase_traceback(exc_value): """ From c2361e33fc2c817af060c0b9875418c9ee6cc169 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 14:42:16 +0000 Subject: [PATCH 218/595] Fix up bug --- numba/pythonapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/pythonapi.py b/numba/pythonapi.py index ebeb8b99664..69084b9e7f5 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -1107,7 +1107,7 @@ def string_from_string_and_size(self, string, size): def string_from_string(self, string): fnty = Type.function(self.pyobj, [self.cstring]) - fname = "PyString_FromString" + fname = "PyUnicode_FromString" fn = self._get_function(fnty, name=fname) return self.builder.call(fn, [string]) From e5d2cbdd3715df78f24eb0630c6b76d9a2babda7 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 22 Jan 2020 16:46:01 +0000 Subject: [PATCH 219/595] remove six move --- numba/annotations/type_annotations.py | 2 +- numba/caching.py | 6 +- numba/interpreter.py | 8 +- numba/io_support.py | 7 - numba/lowering.py | 15 +- numba/python_utils.py | 836 -------------------------- numba/testing/notebook.py | 1 - numba/tests/test_annotations.py | 5 +- numba/tests/test_array_analysis.py | 7 +- numba/tests/test_array_exprs.py | 3 +- numba/tests/test_extended_arg.py | 10 +- numba/tests/test_looplifting.py | 7 +- numba/utils.py | 1 - 13 files changed, 25 insertions(+), 883 deletions(-) delete mode 100644 numba/io_support.py delete mode 100644 numba/python_utils.py diff --git a/numba/annotations/type_annotations.py b/numba/annotations/type_annotations.py index 34765eab4e3..28cb6bf2605 100644 --- a/numba/annotations/type_annotations.py +++ b/numba/annotations/type_annotations.py @@ -7,8 +7,8 @@ import re import sys import textwrap +from io import StringIO -from numba.io_support import StringIO from numba import ir import numba.dispatcher diff --git a/numba/caching.py b/numba/caching.py index c674abf9b0f..0247cd95f98 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -16,10 +16,10 @@ import warnings from .appdirs import AppDirs -from numba.utils import add_metaclass +from numba.utils import add_metaclass, file_replace import numba -from . import compiler, config, utils +from . import compiler, config from .errors import NumbaWarning from numba.targets.base import BaseContext from numba.targets.codegen import CodeLibrary @@ -573,7 +573,7 @@ def _open_for_write(self, filepath): try: with open(tmpname, "wb") as f: yield f - utils.file_replace(tmpname, filepath) + file_replace(tmpname, filepath) except Exception: # In case of error, remove dangling tmp file try: diff --git a/numba/interpreter.py b/numba/interpreter.py index 0adf556afdb..e07d4b11f56 100644 --- a/numba/interpreter.py +++ b/numba/interpreter.py @@ -1,16 +1,18 @@ +import builtins import collections import dis import operator import logging -from . import config, ir, controlflow, dataflow, utils, errors -from .utils import builtins, PYVERSION +from . import config, ir, controlflow, dataflow, errors from .errors import NotDefinedError from .utils import ( + PYVERSION, BINOPS_TO_OPERATORS, INPLACE_BINOPS_TO_OPERATORS, UNARY_BUITINS_TO_OPERATORS, OPERATORS_TO_BUILTINS, + get_function_globals ) from numba.byteflow import Flow, AdaptDFA, AdaptCFA from numba.unsafe import eh @@ -318,7 +320,7 @@ def get_global_value(self, name): as a builtins (second). If both failed, return a ir.UNDEFINED. """ try: - return utils.get_function_globals(self.func_id.func)[name] + return get_function_globals(self.func_id.func)[name] except KeyError: return getattr(builtins, name, ir.UNDEFINED) diff --git a/numba/io_support.py b/numba/io_support.py deleted file mode 100644 index dff5bdb0682..00000000000 --- a/numba/io_support.py +++ /dev/null @@ -1,7 +0,0 @@ -try: - try: - from cStringIO import StringIO - except ImportError: - from StringIO import StringIO -except ImportError: - from io import StringIO diff --git a/numba/lowering.py b/numba/lowering.py index a1bee302d9e..c826b610d26 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -44,20 +44,7 @@ def __reduce__(self): ) def __del__(self): - if utils is None: - return - if _keepalive is None: - return - if time is None or time.time is None: - return - _keepalive.append((time.time(), self)) - if len(_keepalive) > 10: - cur = time.time() - while _keepalive and cur - _keepalive[0][0] > 1: - _keepalive.popleft() - - -_keepalive = deque() + return def _rebuild_env(modname, consts, env_name): diff --git a/numba/python_utils.py b/numba/python_utils.py deleted file mode 100644 index c0fd05aa850..00000000000 --- a/numba/python_utils.py +++ /dev/null @@ -1,836 +0,0 @@ -"""Utilities for writing code that runs on Python 2 and 3""" - -# Copyright (c) 2010-2015 Benjamin Peterson -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - - -import contextlib -import functools -import itertools -import operator -import sys -import types - -__author__ = "Benjamin Peterson " -__version__ = "1.9.0" - -# Useful for very coarse version differentiation. -PY2 = sys.version_info[0] == 2 -PY3 = sys.version_info[0] == 3 - - - -if PY3: - string_types = str, - integer_types = int, - class_types = type, - text_type = str - binary_type = bytes - - MAXSIZE = sys.maxsize -else: - string_types = basestring, - integer_types = (int, long) - class_types = (type, types.ClassType) - text_type = unicode - binary_type = str - - if sys.platform.startswith("java"): - # Jython always uses 32 bits. - MAXSIZE = int((1 << 31) - 1) - else: - # It's possible to have sizeof(long) != sizeof(Py_ssize_t). - class X(object): - def __len__(self): - return 1 << 31 - try: - len(X()) - except OverflowError: - # 32-bit - MAXSIZE = int((1 << 31) - 1) - else: - # 64-bit - MAXSIZE = int((1 << 63) - 1) - del X - - -def _add_doc(func, doc): - """Add documentation to a function.""" - func.__doc__ = doc - - -def _import_module(name): - """Import module, returning the module after the last dot.""" - __import__(name) - return sys.modules[name] - - -class _LazyDescr(object): - - def __init__(self, name): - self.name = name - - def __get__(self, obj, tp): - result = self._resolve() - setattr(obj, self.name, result) # Invokes __set__. - try: - # This is a bit ugly, but it avoids running this again by - # removing this descriptor. - delattr(obj.__class__, self.name) - except AttributeError: - pass - return result - - -class MovedModule(_LazyDescr): - - def __init__(self, name, old, new=None): - super(MovedModule, self).__init__(name) - if PY3: - if new is None: - new = name - self.mod = new - else: - self.mod = old - - def _resolve(self): - return _import_module(self.mod) - - def __getattr__(self, attr): - _module = self._resolve() - value = getattr(_module, attr) - setattr(self, attr, value) - return value - - -class _LazyModule(types.ModuleType): - - def __init__(self, name): - super(_LazyModule, self).__init__(name) - self.__doc__ = self.__class__.__doc__ - - def __dir__(self): - attrs = ["__doc__", "__name__"] - attrs += [attr.name for attr in self._moved_attributes] - return attrs - - # Subclasses should override this - _moved_attributes = [] - - -class MovedAttribute(_LazyDescr): - - def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): - super(MovedAttribute, self).__init__(name) - if PY3: - if new_mod is None: - new_mod = name - self.mod = new_mod - if new_attr is None: - if old_attr is None: - new_attr = name - else: - new_attr = old_attr - self.attr = new_attr - else: - self.mod = old_mod - if old_attr is None: - old_attr = name - self.attr = old_attr - - def _resolve(self): - module = _import_module(self.mod) - return getattr(module, self.attr) - - -class _SixMetaPathImporter(object): - """ - A meta path importer to import six.moves and its submodules. - - This class implements a PEP302 finder and loader. It should be compatible - with Python 2.5 and all existing versions of Python3 - """ - def __init__(self, six_module_name): - self.name = six_module_name - self.known_modules = {} - - def _add_module(self, mod, *fullnames): - for fullname in fullnames: - self.known_modules[self.name + "." + fullname] = mod - - def _get_module(self, fullname): - return self.known_modules[self.name + "." + fullname] - - def find_module(self, fullname, path=None): - if fullname in self.known_modules: - return self - return None - - def __get_module(self, fullname): - try: - return self.known_modules[fullname] - except KeyError: - raise ImportError("This loader does not know module " + fullname) - - def load_module(self, fullname): - try: - # in case of a reload - return sys.modules[fullname] - except KeyError: - pass - mod = self.__get_module(fullname) - if isinstance(mod, MovedModule): - mod = mod._resolve() - else: - mod.__loader__ = self - sys.modules[fullname] = mod - return mod - - def is_package(self, fullname): - """ - Return true, if the named module is a package. - - We need this method to get correct spec objects with - Python 3.4 (see PEP451) - """ - return hasattr(self.__get_module(fullname), "__path__") - - def get_code(self, fullname): - """Return None - - Required, if is_package is implemented""" - self.__get_module(fullname) # eventually raises ImportError - return None - get_source = get_code # same as get_code - -_importer = _SixMetaPathImporter(__name__) - - -class _MovedItems(_LazyModule): - """Lazy loading of moved objects""" - __path__ = [] # mark as package - - -_moved_attributes = [ - MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), - MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"), - MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), - MovedAttribute("intern", "__builtin__", "sys"), - MovedAttribute("map", "itertools", "builtins", "imap", "map"), - MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"), - MovedAttribute("reload_module", "__builtin__", "imp", "reload"), - MovedAttribute("reduce", "__builtin__", "functools"), - MovedAttribute("shlex_quote", "pipes", "shlex", "quote"), - MovedAttribute("StringIO", "StringIO", "io"), - MovedAttribute("UserDict", "UserDict", "collections"), - MovedAttribute("UserList", "UserList", "collections"), - MovedAttribute("UserString", "UserString", "collections"), - MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"), - MovedAttribute("zip", "itertools", "builtins", "izip", "zip"), - MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"), - - MovedModule("builtins", "__builtin__"), - MovedModule("configparser", "ConfigParser"), - MovedModule("copyreg", "copy_reg"), - MovedModule("dbm_gnu", "gdbm", "dbm.gnu"), - MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"), - MovedModule("http_cookiejar", "cookielib", "http.cookiejar"), - MovedModule("http_cookies", "Cookie", "http.cookies"), - MovedModule("html_entities", "htmlentitydefs", "html.entities"), - MovedModule("html_parser", "HTMLParser", "html.parser"), - MovedModule("http_client", "httplib", "http.client"), - MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"), - MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"), - MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"), - MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"), - MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"), - MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"), - MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"), - MovedModule("cPickle", "cPickle", "pickle"), - MovedModule("queue", "Queue"), - MovedModule("reprlib", "repr"), - MovedModule("socketserver", "SocketServer"), - MovedModule("_thread", "thread", "_thread"), - MovedModule("tkinter", "Tkinter"), - MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"), - MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"), - MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"), - MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"), - MovedModule("tkinter_tix", "Tix", "tkinter.tix"), - MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"), - MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"), - MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"), - MovedModule("tkinter_colorchooser", "tkColorChooser", - "tkinter.colorchooser"), - MovedModule("tkinter_commondialog", "tkCommonDialog", - "tkinter.commondialog"), - MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"), - MovedModule("tkinter_font", "tkFont", "tkinter.font"), - MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"), - MovedModule("tkinter_tksimpledialog", "tkSimpleDialog", - "tkinter.simpledialog"), - MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"), - MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"), - MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"), - MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), - MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"), - MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"), - MovedModule("winreg", "_winreg"), -] -for attr in _moved_attributes: - setattr(_MovedItems, attr.name, attr) - if isinstance(attr, MovedModule): - _importer._add_module(attr, "moves." + attr.name) -del attr - -_MovedItems._moved_attributes = _moved_attributes - -moves = _MovedItems(__name__ + ".moves") -_importer._add_module(moves, "moves") - - -class Module_six_moves_urllib_parse(_LazyModule): - """Lazy loading of moved objects in six.moves.urllib_parse""" - - -_urllib_parse_moved_attributes = [ - MovedAttribute("ParseResult", "urlparse", "urllib.parse"), - MovedAttribute("SplitResult", "urlparse", "urllib.parse"), - MovedAttribute("parse_qs", "urlparse", "urllib.parse"), - MovedAttribute("parse_qsl", "urlparse", "urllib.parse"), - MovedAttribute("urldefrag", "urlparse", "urllib.parse"), - MovedAttribute("urljoin", "urlparse", "urllib.parse"), - MovedAttribute("urlparse", "urlparse", "urllib.parse"), - MovedAttribute("urlsplit", "urlparse", "urllib.parse"), - MovedAttribute("urlunparse", "urlparse", "urllib.parse"), - MovedAttribute("urlunsplit", "urlparse", "urllib.parse"), - MovedAttribute("quote", "urllib", "urllib.parse"), - MovedAttribute("quote_plus", "urllib", "urllib.parse"), - MovedAttribute("unquote", "urllib", "urllib.parse"), - MovedAttribute("unquote_plus", "urllib", "urllib.parse"), - MovedAttribute("urlencode", "urllib", "urllib.parse"), - MovedAttribute("splitquery", "urllib", "urllib.parse"), - MovedAttribute("splittag", "urllib", "urllib.parse"), - MovedAttribute("splituser", "urllib", "urllib.parse"), - MovedAttribute("uses_fragment", "urlparse", "urllib.parse"), - MovedAttribute("uses_netloc", "urlparse", "urllib.parse"), - MovedAttribute("uses_params", "urlparse", "urllib.parse"), - MovedAttribute("uses_query", "urlparse", "urllib.parse"), - MovedAttribute("uses_relative", "urlparse", "urllib.parse"), -] -for attr in _urllib_parse_moved_attributes: - setattr(Module_six_moves_urllib_parse, attr.name, attr) -del attr - -Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes - -_importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"), - "moves.urllib_parse", "moves.urllib.parse") - - -class Module_six_moves_urllib_error(_LazyModule): - """Lazy loading of moved objects in six.moves.urllib_error""" - - -_urllib_error_moved_attributes = [ - MovedAttribute("URLError", "urllib2", "urllib.error"), - MovedAttribute("HTTPError", "urllib2", "urllib.error"), - MovedAttribute("ContentTooShortError", "urllib", "urllib.error"), -] -for attr in _urllib_error_moved_attributes: - setattr(Module_six_moves_urllib_error, attr.name, attr) -del attr - -Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes - -_importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"), - "moves.urllib_error", "moves.urllib.error") - - -class Module_six_moves_urllib_request(_LazyModule): - """Lazy loading of moved objects in six.moves.urllib_request""" - - -_urllib_request_moved_attributes = [ - MovedAttribute("urlopen", "urllib2", "urllib.request"), - MovedAttribute("install_opener", "urllib2", "urllib.request"), - MovedAttribute("build_opener", "urllib2", "urllib.request"), - MovedAttribute("pathname2url", "urllib", "urllib.request"), - MovedAttribute("url2pathname", "urllib", "urllib.request"), - MovedAttribute("getproxies", "urllib", "urllib.request"), - MovedAttribute("Request", "urllib2", "urllib.request"), - MovedAttribute("OpenerDirector", "urllib2", "urllib.request"), - MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"), - MovedAttribute("ProxyHandler", "urllib2", "urllib.request"), - MovedAttribute("BaseHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"), - MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"), - MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"), - MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"), - MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"), - MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"), - MovedAttribute("FileHandler", "urllib2", "urllib.request"), - MovedAttribute("FTPHandler", "urllib2", "urllib.request"), - MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"), - MovedAttribute("UnknownHandler", "urllib2", "urllib.request"), - MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"), - MovedAttribute("urlretrieve", "urllib", "urllib.request"), - MovedAttribute("urlcleanup", "urllib", "urllib.request"), - MovedAttribute("URLopener", "urllib", "urllib.request"), - MovedAttribute("FancyURLopener", "urllib", "urllib.request"), - MovedAttribute("proxy_bypass", "urllib", "urllib.request"), -] -for attr in _urllib_request_moved_attributes: - setattr(Module_six_moves_urllib_request, attr.name, attr) -del attr - -Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes - -_importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"), - "moves.urllib_request", "moves.urllib.request") - - -class Module_six_moves_urllib_response(_LazyModule): - """Lazy loading of moved objects in six.moves.urllib_response""" - - -_urllib_response_moved_attributes = [ - MovedAttribute("addbase", "urllib", "urllib.response"), - MovedAttribute("addclosehook", "urllib", "urllib.response"), - MovedAttribute("addinfo", "urllib", "urllib.response"), - MovedAttribute("addinfourl", "urllib", "urllib.response"), -] -for attr in _urllib_response_moved_attributes: - setattr(Module_six_moves_urllib_response, attr.name, attr) -del attr - -Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes - -_importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"), - "moves.urllib_response", "moves.urllib.response") - - -class Module_six_moves_urllib_robotparser(_LazyModule): - """Lazy loading of moved objects in six.moves.urllib_robotparser""" - - -_urllib_robotparser_moved_attributes = [ - MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"), -] -for attr in _urllib_robotparser_moved_attributes: - setattr(Module_six_moves_urllib_robotparser, attr.name, attr) -del attr - -Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes - -_importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"), - "moves.urllib_robotparser", "moves.urllib.robotparser") - - -class Module_six_moves_urllib(types.ModuleType): - """Create a six.moves.urllib namespace that resembles the Python 3 namespace""" - __path__ = [] # mark as package - parse = _importer._get_module("moves.urllib_parse") - error = _importer._get_module("moves.urllib_error") - request = _importer._get_module("moves.urllib_request") - response = _importer._get_module("moves.urllib_response") - robotparser = _importer._get_module("moves.urllib_robotparser") - - def __dir__(self): - return ['parse', 'error', 'request', 'response', 'robotparser'] - -_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"), - "moves.urllib") - - -def add_move(move): - """Add an item to six.moves.""" - setattr(_MovedItems, move.name, move) - - -def remove_move(name): - """Remove item from six.moves.""" - try: - delattr(_MovedItems, name) - except AttributeError: - try: - del moves.__dict__[name] - except KeyError: - raise AttributeError("no such move, %r" % (name,)) - - -if PY3: - _meth_func = "__func__" - _meth_self = "__self__" - - _func_closure = "__closure__" - _func_code = "__code__" - _func_defaults = "__defaults__" - _func_globals = "__globals__" -else: - _meth_func = "im_func" - _meth_self = "im_self" - - _func_closure = "func_closure" - _func_code = "func_code" - _func_defaults = "func_defaults" - _func_globals = "func_globals" - - -try: - advance_iterator = next -except NameError: - def advance_iterator(it): - return it.next() -next = advance_iterator - - -try: - callable = callable -except NameError: - def callable(obj): - return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) - - -if PY3: - def get_unbound_function(unbound): - return unbound - - create_bound_method = types.MethodType - - Iterator = object -else: - def get_unbound_function(unbound): - return unbound.im_func - - def create_bound_method(func, obj): - return types.MethodType(func, obj, obj.__class__) - - class Iterator(object): - - def next(self): - return type(self).__next__(self) - - callable = callable -_add_doc(get_unbound_function, - """Get the function out of a possibly unbound function""") - - -get_method_function = operator.attrgetter(_meth_func) -get_method_self = operator.attrgetter(_meth_self) -get_function_closure = operator.attrgetter(_func_closure) -get_function_code = operator.attrgetter(_func_code) -get_function_defaults = operator.attrgetter(_func_defaults) -get_function_globals = operator.attrgetter("__globals__") - - -if PY3: - def iterkeys(d, **kw): - return iter(d.keys(**kw)) - - def itervalues(d, **kw): - return iter(d.values(**kw)) - - def iteritems(d, **kw): - return iter(d.items(**kw)) - - def iterlists(d, **kw): - return iter(d.lists(**kw)) - - viewkeys = operator.methodcaller("keys") - - viewvalues = operator.methodcaller("values") - - viewitems = operator.methodcaller("items") -else: - def iterkeys(d, **kw): - return iter(d.iterkeys(**kw)) - - def itervalues(d, **kw): - return iter(d.itervalues(**kw)) - - def iteritems(d, **kw): - return iter(d.iteritems(**kw)) - - def iterlists(d, **kw): - return iter(d.iterlists(**kw)) - - viewkeys = operator.methodcaller("viewkeys") - - viewvalues = operator.methodcaller("viewvalues") - - viewitems = operator.methodcaller("viewitems") - -_add_doc(iterkeys, "Return an iterator over the keys of a dictionary.") -_add_doc(itervalues, "Return an iterator over the values of a dictionary.") -_add_doc(iteritems, - "Return an iterator over the (key, value) pairs of a dictionary.") -_add_doc(iterlists, - "Return an iterator over the (key, [values]) pairs of a dictionary.") - - -if PY3: - def b(s): - return s.encode("latin-1") - def u(s): - return s - unichr = chr - if sys.version_info[1] <= 1: - def int2byte(i): - return bytes((i,)) - else: - # This is about 2x faster than the implementation above on 3.2+ - int2byte = operator.methodcaller("to_bytes", 1, "big") - byte2int = operator.itemgetter(0) - indexbytes = operator.getitem - iterbytes = iter - import io - StringIO = io.StringIO - BytesIO = io.BytesIO - _assertCountEqual = "assertCountEqual" - _assertRaisesRegex = "assertRaisesRegex" - _assertRegex = "assertRegex" -else: - def b(s): - return s - # Workaround for standalone backslash - def u(s): - return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") - unichr = unichr - int2byte = chr - def byte2int(bs): - return ord(bs[0]) - def indexbytes(buf, i): - return ord(buf[i]) - iterbytes = functools.partial(itertools.imap, ord) - import StringIO as _StringIO - # make StringIO.StringIO work with `with` - class StringIO(_StringIO.StringIO): - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - self.close() - - BytesIO = StringIO - _assertCountEqual = "assertItemsEqual" - _assertRaisesRegex = "assertRaisesRegexp" - _assertRegex = "assertRegexpMatches" -_add_doc(b, """Byte literal""") -_add_doc(u, """Text literal""") - - -def assertCountEqual(self, *args, **kwargs): - return getattr(self, _assertCountEqual)(*args, **kwargs) - - -def assertRaisesRegex(self, *args, **kwargs): - return getattr(self, _assertRaisesRegex)(*args, **kwargs) - - -def assertRegex(self, *args, **kwargs): - return getattr(self, _assertRegex)(*args, **kwargs) - - -if PY3: - exec_ = getattr(moves.builtins, "exec") - - - -else: - def exec_(_code_, _globs_=None, _locs_=None): - """Execute code in a namespace.""" - if _globs_ is None: - frame = sys._getframe(1) - _globs_ = frame.f_globals - if _locs_ is None: - _locs_ = frame.f_locals - del frame - elif _locs_ is None: - _locs_ = _globs_ - exec("""exec _code_ in _globs_, _locs_""") - - - exec_("""def reraise(tp, value, tb=None): - raise tp, value, tb -""") - - -if sys.version_info[:2] == (3, 2): - exec_("""def raise_from(value, from_value): - if from_value is None: - raise value - raise value from from_value -""") -elif sys.version_info[:2] > (3, 2): - exec_("""def raise_from(value, from_value): - raise value from from_value -""") -else: - def raise_from(value, from_value): - raise value - - -print_ = getattr(moves.builtins, "print", None) -if print_ is None: - def print_(*args, **kwargs): - """The new-style print function for Python 2.4 and 2.5.""" - fp = kwargs.pop("file", sys.stdout) - if fp is None: - return - def write(data): - if not isinstance(data, basestring): - data = str(data) - # If the file has an encoding, encode unicode with it. - if (isinstance(fp, file) and - isinstance(data, unicode) and - fp.encoding is not None): - errors = getattr(fp, "errors", None) - if errors is None: - errors = "strict" - data = data.encode(fp.encoding, errors) - fp.write(data) - want_unicode = False - sep = kwargs.pop("sep", None) - if sep is not None: - if isinstance(sep, unicode): - want_unicode = True - elif not isinstance(sep, str): - raise TypeError("sep must be None or a string") - end = kwargs.pop("end", None) - if end is not None: - if isinstance(end, unicode): - want_unicode = True - elif not isinstance(end, str): - raise TypeError("end must be None or a string") - if kwargs: - raise TypeError("invalid keyword arguments to print()") - if not want_unicode: - for arg in args: - if isinstance(arg, unicode): - want_unicode = True - break - if want_unicode: - newline = unicode("\n") - space = unicode(" ") - else: - newline = "\n" - space = " " - if sep is None: - sep = space - if end is None: - end = newline - for i, arg in enumerate(args): - if i: - write(sep) - write(arg) - write(end) -if sys.version_info[:2] < (3, 3): - _print = print_ - def print_(*args, **kwargs): - fp = kwargs.get("file", sys.stdout) - flush = kwargs.pop("flush", False) - _print(*args, **kwargs) - if flush and fp is not None: - fp.flush() - -_add_doc(reraise, """Reraise an exception.""") - -if sys.version_info[0:2] < (3, 4): - def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, - updated=functools.WRAPPER_UPDATES): - def wrapper(f): - f = functools.wraps(wrapped, assigned, updated)(f) - f.__wrapped__ = wrapped - return f - return wrapper -else: - wraps = functools.wraps - - -if sys.version_info[:2] < (3, 3): - from collections import (Mapping, MutableMapping, Sequence, - MutableSequence, Iterable) -else: - from collections.abc import (Mapping, MutableMapping, Sequence, - MutableSequence, Iterable) - - -def with_metaclass(meta, *bases): - """Create a base class with a metaclass.""" - # This requires a bit of explanation: the basic idea is to make a dummy - # metaclass for one level of class instantiation that replaces itself with - # the actual metaclass. - class metaclass(meta): - def __new__(cls, name, this_bases, d): - return meta(name, bases, d) - return type.__new__(metaclass, 'temporary_class', (), {}) - - - - -def python_2_unicode_compatible(klass): - """ - A decorator that defines __unicode__ and __str__ methods under Python 2. - Under Python 3 it does nothing. - - To support Python 2 and 3 with a single code base, define a __str__ method - returning text and apply this decorator to the class. - """ - if PY2: - if '__str__' not in klass.__dict__: - raise ValueError("@python_2_unicode_compatible cannot be applied " - "to %s because it doesn't define __str__()." % - klass.__name__) - klass.__unicode__ = klass.__str__ - klass.__str__ = lambda self: self.__unicode__().encode('utf-8') - return klass - - -# Complete the moves implementation. -# This code is at the end of this module to speed up module loading. -# Turn this module into a package. -__path__ = [] # required for PEP 302 and PEP 451 -__package__ = __name__ # see PEP 366 @ReservedAssignment -if globals().get("__spec__") is not None: - __spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable -# Remove other six meta path importers, since they cause problems. This can -# happen if six is removed from sys.modules and then reloaded. (Setuptools does -# this for some reason.) -if sys.meta_path: - for i, importer in enumerate(sys.meta_path): - # Here's some real nastiness: Another "instance" of the six module might - # be floating around. Therefore, we can't use isinstance() to check for - # the six meta path importer, since the other six instance will have - # inserted an importer with different class. - if (type(importer).__name__ == "_SixMetaPathImporter" and - importer.name == __name__): - del sys.meta_path[i] - break - del i, importer -# Finally, add the importer to the meta path import hook. -sys.meta_path.append(_importer) diff --git a/numba/testing/notebook.py b/numba/testing/notebook.py index 94a301ff369..07e879dd8bc 100644 --- a/numba/testing/notebook.py +++ b/numba/testing/notebook.py @@ -33,7 +33,6 @@ class NotebookTest(TestCase): """ - IGNORE_TYPES = ["execute_request", "execute_input", "status", "pyin"] STRIP_KEYS = ["execution_count", "traceback", "prompt_number", "source"] NBFORMAT_VERSION = 4 diff --git a/numba/tests/test_annotations.py b/numba/tests/test_annotations.py index 3daf58fa57d..80700d9e06e 100644 --- a/numba/tests/test_annotations.py +++ b/numba/tests/test_annotations.py @@ -1,10 +1,9 @@ import re +from io import StringIO import numba from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, utils -from numba.io_support import StringIO try: import jinja2 @@ -159,7 +158,7 @@ def foo(appleorange, berrycherry): foo(1, 2) # Exercise the method - strbuf = utils.StringIO() + strbuf = StringIO() foo.inspect_types(strbuf) # Ensure deletion show up after their use lines = strbuf.getvalue().splitlines() diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index c3d37a730c7..06e737486fa 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -3,10 +3,11 @@ import numpy as np import sys from collections import namedtuple +from io import StringIO from numba import unittest_support as unittest -from numba import (njit, typeof, types, typing, typeof, ir, utils, bytecode, - jitclass, prange, postproc) +from numba import (njit, typeof, types, typing, typeof, ir, bytecode, jitclass, + prange, postproc) from .support import TestCase, tag from numba.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager @@ -167,7 +168,7 @@ def compare_ir(self, ir_list): outputs = [] for func_ir in ir_list: remove_dead(func_ir.blocks, func_ir.arg_names, func_ir) - output = utils.StringIO() + output = StringIO() func_ir.dump(file=output) outputs.append(output.getvalue()) self.assertTrue(len(set(outputs)) == 1) # assert all outputs are equal diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index e108f2f1170..1ab36395c1d 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -1,4 +1,5 @@ import gc +from io import StringIO import numpy as np @@ -460,7 +461,7 @@ def test_annotations(self): a = np.linspace(0, 1, 10) cfunc(a, a, a, a) - buf = utils.StringIO() + buf = StringIO() cfunc.inspect_types(buf) res = buf.getvalue() self.assertIn("# u.1 = ", res) diff --git a/numba/tests/test_extended_arg.py b/numba/tests/test_extended_arg.py index 05397936488..87654762907 100644 --- a/numba/tests/test_extended_arg.py +++ b/numba/tests/test_extended_arg.py @@ -4,7 +4,7 @@ import struct import sys -from numba import jit, utils +from numba import jit from .support import TestCase, tweak_code @@ -23,12 +23,8 @@ def f(): b = bytearray(f.__code__.co_code) consts = f.__code__.co_consts - if utils.PYVERSION >= (3, 6): - bytecode_len = 0xff - bytecode_format = " Date: Wed, 22 Jan 2020 16:53:06 +0000 Subject: [PATCH 220/595] Fix up repo map --- docs/source/developer/repomap.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/source/developer/repomap.rst b/docs/source/developer/repomap.rst index 31fffaa77ec..9937cc42c02 100644 --- a/docs/source/developer/repomap.rst +++ b/docs/source/developer/repomap.rst @@ -240,8 +240,6 @@ Misc Support data structures - :ghfile:`numba/cgutils.py` - Utility functions for generating common code patterns in LLVM IR -- :ghfile:`numba/io_support.py` - Workaround for various names of StringIO - in different Python versions (should this be in six?) - :ghfile:`numba/utils.py` - Python 2 backports of Python 3 functionality (also imports local copy of ``six``) - :ghfile:`numba/appdirs.py` - Vendored package for determining application @@ -271,8 +269,6 @@ Misc Support on the host, but not the data. - :ghfile:`numba/callwrapper.py` - Handles argument unboxing and releasing the GIL when moving from Python to nopython mode -- :ghfile:`numba/ctypes_support.py` - Import this instead of ``ctypes`` to - workaround portability issue with Python 2.7 - :ghfile:`numba/cffi_support.py` - Alias of numba.typing.cffi_utils for backward compatibility (still needed?) - :ghfile:`numba/numpy_support.py` - Helper functions for working with NumPy From 9796ef4c2055b895ab94791ea4dc4bd2ced7f05d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 10:23:49 +0000 Subject: [PATCH 221/595] Fix refactor scope error --- numba/targets/boxing.py | 121 ++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 12e11f62ed1..5ab80a71a62 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -201,66 +201,67 @@ def cleanup(): c.pyapi.release_buffer(buf) return NativeValue(val, cleanup=cleanup, is_error=is_error) - @box(types.UnicodeCharSeq) - def box_unicodecharseq(typ, val, c): - # XXX could kind be determined from strptr? - unicode_kind = { - 1: c.pyapi.py_unicode_1byte_kind, - 2: c.pyapi.py_unicode_2byte_kind, - 4: c.pyapi.py_unicode_4byte_kind}[numpy_support.sizeof_unicode_char] - kind = c.context.get_constant(types.int32, unicode_kind) - rawptr = cgutils.alloca_once_value(c.builder, value=val) - strptr = c.builder.bitcast(rawptr, c.pyapi.cstring) - - fullsize = c.context.get_constant(types.intp, typ.count) - zero = fullsize.type(0) - one = fullsize.type(1) - step = fullsize.type(numpy_support.sizeof_unicode_char) - count = cgutils.alloca_once_value(c.builder, zero) - with cgutils.loop_nest(c.builder, [fullsize], fullsize.type) as [idx]: - # Get char at idx - ch = c.builder.load(c.builder.gep(strptr, [c.builder.mul(idx, step)])) - # If the char is a non-null-byte, store the next index as count - with c.builder.if_then(cgutils.is_not_null(c.builder, ch)): - c.builder.store(c.builder.add(idx, one), count) - strlen = c.builder.load(count) - return c.pyapi.string_from_kind_and_data(kind, strptr, strlen) - - - @unbox(types.UnicodeCharSeq) - def unbox_unicodecharseq(typ, obj, c): - lty = c.context.get_value_type(typ) - - ok, buffer, size, kind, is_ascii, hashv = \ - c.pyapi.string_as_string_size_and_kind(obj) - - # If conversion is ok, copy the buffer to the output storage. - with cgutils.if_likely(c.builder, ok): - # Check if the returned string size fits in the charseq - storage_size = ir.Constant(size.type, typ.count) - size_fits = c.builder.icmp_unsigned("<=", size, storage_size) - - # Allow truncation of string - size = c.builder.select(size_fits, size, storage_size) - - # Initialize output to zero bytes - null_string = ir.Constant(lty, None) - outspace = cgutils.alloca_once_value(c.builder, null_string) - - # We don't need to set the NULL-terminator because the storage - # is already zero-filled. - cgutils.memcpy(c.builder, - c.builder.bitcast(outspace, buffer.type), - buffer, size) - - ret = c.builder.load(outspace) - return NativeValue(ret, is_error=c.builder.not_(ok)) - - - @box(types.Bytes) - def box_bytes(typ, val, c): - obj = c.context.make_helper(c.builder, typ, val) - return c.pyapi.bytes_from_string_and_size(obj.data, obj.nitems) + +@box(types.UnicodeCharSeq) +def box_unicodecharseq(typ, val, c): + # XXX could kind be determined from strptr? + unicode_kind = { + 1: c.pyapi.py_unicode_1byte_kind, + 2: c.pyapi.py_unicode_2byte_kind, + 4: c.pyapi.py_unicode_4byte_kind}[numpy_support.sizeof_unicode_char] + kind = c.context.get_constant(types.int32, unicode_kind) + rawptr = cgutils.alloca_once_value(c.builder, value=val) + strptr = c.builder.bitcast(rawptr, c.pyapi.cstring) + + fullsize = c.context.get_constant(types.intp, typ.count) + zero = fullsize.type(0) + one = fullsize.type(1) + step = fullsize.type(numpy_support.sizeof_unicode_char) + count = cgutils.alloca_once_value(c.builder, zero) + with cgutils.loop_nest(c.builder, [fullsize], fullsize.type) as [idx]: + # Get char at idx + ch = c.builder.load(c.builder.gep(strptr, [c.builder.mul(idx, step)])) + # If the char is a non-null-byte, store the next index as count + with c.builder.if_then(cgutils.is_not_null(c.builder, ch)): + c.builder.store(c.builder.add(idx, one), count) + strlen = c.builder.load(count) + return c.pyapi.string_from_kind_and_data(kind, strptr, strlen) + + +@unbox(types.UnicodeCharSeq) +def unbox_unicodecharseq(typ, obj, c): + lty = c.context.get_value_type(typ) + + ok, buffer, size, kind, is_ascii, hashv = \ + c.pyapi.string_as_string_size_and_kind(obj) + + # If conversion is ok, copy the buffer to the output storage. + with cgutils.if_likely(c.builder, ok): + # Check if the returned string size fits in the charseq + storage_size = ir.Constant(size.type, typ.count) + size_fits = c.builder.icmp_unsigned("<=", size, storage_size) + + # Allow truncation of string + size = c.builder.select(size_fits, size, storage_size) + + # Initialize output to zero bytes + null_string = ir.Constant(lty, None) + outspace = cgutils.alloca_once_value(c.builder, null_string) + + # We don't need to set the NULL-terminator because the storage + # is already zero-filled. + cgutils.memcpy(c.builder, + c.builder.bitcast(outspace, buffer.type), + buffer, size) + + ret = c.builder.load(outspace) + return NativeValue(ret, is_error=c.builder.not_(ok)) + + +@box(types.Bytes) +def box_bytes(typ, val, c): + obj = c.context.make_helper(c.builder, typ, val) + return c.pyapi.bytes_from_string_and_size(obj.data, obj.nitems) @box(types.CharSeq) From 419a2ffc8c79940ee258d619dfa20a0057ed94c2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 10:27:59 +0000 Subject: [PATCH 222/595] rm 34 --- numba/targets/hashing.py | 52 ++++++++++++------------------------- numba/tests/test_caching.py | 20 -------------- numba/tests/test_unicode.py | 7 ----- 3 files changed, 17 insertions(+), 62 deletions(-) diff --git a/numba/targets/hashing.py b/numba/targets/hashing.py index fa65318ba6c..7612bfc56cb 100644 --- a/numba/targets/hashing.py +++ b/numba/targets/hashing.py @@ -17,43 +17,25 @@ from numba import types, errors from numba.unsafe.bytes import grab_byte, grab_uint64_t -_py34_or_later = sys.version_info[:2] >= (3, 4) _py38_or_later = sys.version_info[:2] >= (3, 8) -if _py34_or_later: - # This is Py_hash_t, which is a Py_ssize_t, which has sizeof(size_t): - # https://github.com/python/cpython/blob/d1dd6be613381b996b9071443ef081de8e5f3aff/Include/pyport.h#L91-L96 # noqa: E501 - _hash_width = sys.hash_info.width - _Py_hash_t = getattr(types, 'int%s' % _hash_width) - _Py_uhash_t = getattr(types, 'uint%s' % _hash_width) - - # Constants from CPython source, obtained by various means: - # https://github.com/python/cpython/blob/d1dd6be613381b996b9071443ef081de8e5f3aff/Include/pyhash.h # noqa: E501 - _PyHASH_INF = sys.hash_info.inf - _PyHASH_NAN = sys.hash_info.nan - _PyHASH_MODULUS = _Py_uhash_t(sys.hash_info.modulus) - _PyHASH_BITS = 31 if types.intp.bitwidth == 32 else 61 # mersenne primes - _PyHASH_MULTIPLIER = 0xf4243 # 1000003UL - _PyHASH_IMAG = _PyHASH_MULTIPLIER - _PyLong_SHIFT = sys.int_info.bits_per_digit - _Py_HASH_CUTOFF = sys.hash_info.cutoff - _Py_hashfunc_name = sys.hash_info.algorithm -else: - _hash_width = types.intp.bitwidth - _Py_hash_t = getattr(types, 'int%s' % _hash_width) - _Py_uhash_t = getattr(types, 'uint%s' % _hash_width) - - # these are largely just copied in from python 3 as reasonable defaults - _PyHASH_INF = 314159 - _PyHASH_NAN = 0 - _PyHASH_BITS = 31 if types.intp.bitwidth == 32 else 61 # mersenne primes - _PyHASH_MODULUS = _Py_uhash_t((1 << _PyHASH_BITS) - 1) - _PyHASH_MULTIPLIER = 0xf4243 # 1000003UL - _PyHASH_IMAG = _PyHASH_MULTIPLIER - _PyLong_SHIFT = 30 if types.intp.bitwidth == 64 else 15 - _Py_HASH_CUTOFF = 0 - # set this as siphash24 for py27... TODO: implement py27 string first! - _Py_hashfunc_name = "siphash24" +# This is Py_hash_t, which is a Py_ssize_t, which has sizeof(size_t): +# https://github.com/python/cpython/blob/d1dd6be613381b996b9071443ef081de8e5f3aff/Include/pyport.h#L91-L96 # noqa: E501 +_hash_width = sys.hash_info.width +_Py_hash_t = getattr(types, 'int%s' % _hash_width) +_Py_uhash_t = getattr(types, 'uint%s' % _hash_width) + +# Constants from CPython source, obtained by various means: +# https://github.com/python/cpython/blob/d1dd6be613381b996b9071443ef081de8e5f3aff/Include/pyhash.h # noqa: E501 +_PyHASH_INF = sys.hash_info.inf +_PyHASH_NAN = sys.hash_info.nan +_PyHASH_MODULUS = _Py_uhash_t(sys.hash_info.modulus) +_PyHASH_BITS = 31 if types.intp.bitwidth == 32 else 61 # mersenne primes +_PyHASH_MULTIPLIER = 0xf4243 # 1000003UL +_PyHASH_IMAG = _PyHASH_MULTIPLIER +_PyLong_SHIFT = sys.int_info.bits_per_digit +_Py_HASH_CUTOFF = sys.hash_info.cutoff +_Py_hashfunc_name = sys.hash_info.algorithm # hash(obj) is implemented by calling obj.__hash__() diff --git a/numba/tests/test_caching.py b/numba/tests/test_caching.py index cd3805cfb98..2260d3bc971 100644 --- a/numba/tests/test_caching.py +++ b/numba/tests/test_caching.py @@ -1,27 +1,11 @@ -import sys -import multiprocessing as mp - from numba import njit from .support import ( - unittest, TestCase, SerialMixin, run_in_new_process_caching ) -_py34_or_later = sys.version_info[:2] >= (3, 4) -_has_mp_get_context = hasattr(mp, 'get_context') -_skip_no_unicode = unittest.skipUnless( - _py34_or_later, - "unicode requires py3.4+", -) -_skip_no_mp_spawn = unittest.skipUnless( - _has_mp_get_context, - "requires multiprocessing.get_context", -) - - def constant_unicode_cache(): c = "abcd" return hash(c), c @@ -54,12 +38,8 @@ def run_test(self, func): res = run_in_new_process_caching(func) self.assertEqual(res['exitcode'], 0) - @_skip_no_unicode - @_skip_no_mp_spawn def test_constant_unicode_cache(self): self.run_test(check_constant_unicode_cache) - @_skip_no_unicode - @_skip_no_mp_spawn def test_dict_cache(self): self.run_test(check_dict_cache) diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index f484d298d48..92e7931a1f1 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -13,7 +13,6 @@ from .support import (TestCase, no_pyobj_flags, MemoryLeakMixin) from numba.errors import TypingError -_py34_or_later = sys.version_info[:2] >= (3, 4) _py37_or_later = sys.version_info[:2] >= (3, 7) @@ -411,8 +410,6 @@ def setUp(self): ] -@unittest.skipUnless(_py34_or_later, - 'unicode support requires Python 3.4 or later') class TestUnicode(BaseTest): def test_literal(self, flags=no_pyobj_flags): @@ -2283,8 +2280,6 @@ def pyfunc(s, x, y, count): self.assertIn(msg, str(raises.exception)) -@unittest.skipUnless(_py34_or_later, - 'unicode support requires Python 3.4 or later') class TestUnicodeInTuple(BaseTest): def test_const_unicode_in_tuple(self): @@ -2362,8 +2357,6 @@ def f(): self.assertEqual(f(), (1, 0, 0, 1, 0)) -@unittest.skipUnless(_py34_or_later, - 'unicode support requires Python 3.4 or later') class TestUnicodeIteration(BaseTest): def test_unicode_iter(self): From 800a22f6efa09e0287a58dd2b472f2c7c423b59d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 10:38:19 +0000 Subject: [PATCH 223/595] rm 35 --- numba/special.py | 5 ---- numba/tests/test_mixed_tuple_unroller.py | 30 ------------------------ numba/untyped_passes.py | 5 ++-- 3 files changed, 2 insertions(+), 38 deletions(-) diff --git a/numba/special.py b/numba/special.py index d05f9ca457a..65416445e64 100644 --- a/numba/special.py +++ b/numba/special.py @@ -1,5 +1,3 @@ -import sys - import numpy as np from .typing.typeof import typeof @@ -89,9 +87,6 @@ def literally(obj): def literal_unroll(container): - from numba.errors import UnsupportedError - if sys.version_info[:2] < (3, 6): - raise UnsupportedError("literal_unroll is only support in Python > 3.5") return container diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 1291108dc3a..c6bd299b8a7 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -1,4 +1,3 @@ -import sys import numpy as np from numba.tests.support import (TestCase, MemoryLeakMixin, @@ -15,11 +14,7 @@ NoPythonBackend, PartialTypeInference) from numba.ir_utils import (compute_cfg_from_blocks, flatten_labels) -_lt_py_36 = sys.version_info[:2] < (3, 6) -skip_lt_py36 = unittest.skipIf(_lt_py_36, "Unsupported on < Python 3.6") - -@skip_lt_py36 class TestLiteralTupleInterpretation(MemoryLeakMixin, TestCase): def check(self, func, var): @@ -86,7 +81,6 @@ def run_pass(self, state): return True -@skip_lt_py36 class TestLoopCanonicalisation(MemoryLeakMixin, TestCase): def get_pipeline(use_canonicaliser, use_partial_typing=False): @@ -467,7 +461,6 @@ def compare_cfg(a, b): len(canonicalise_loops_fndesc.calltypes)) -@skip_lt_py36 class TestMixedTupleUnroll(MemoryLeakMixin, TestCase): def test_01(self): @@ -1218,7 +1211,6 @@ def gen(a): self.assertEqual(cfunc(), pyfunc()) -@skip_lt_py36 class TestConstListUnroll(MemoryLeakMixin, TestCase): def test_01(self): @@ -1513,27 +1505,6 @@ def foo(): str(raises.exception)) -@unittest.skipIf(not _lt_py_36, "Python < 3.6 only test") -class TestLiteralUnrollPy2(TestCase): - - def test_py_lt_36_not_supported(self): - - @njit - def foo(): - x = (1000, 2000, 3000, 4000) - acc = 0 - for a in literal_unroll(x): - acc += a - return acc - - with self.assertRaises(errors.TypingError) as raises: - foo() - - self.assertIn("literal_unroll is only support in Python > 3.5", - str(raises.exception)) - - -@skip_lt_py36 class TestMore(TestCase): def test_invalid_use_of_unroller(self): @njit @@ -1734,7 +1705,6 @@ def add_pass(x, y): return [pm] -@skip_lt_py36 class TestLiteralUnrollPassTriggering(TestCase): def test_literal_unroll_not_invoked(self): diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index 1124a44836c..d5735e6f8b5 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -3,7 +3,7 @@ from .compiler_machinery import FunctionPass, register_pass from . import (config, bytecode, interpreter, postproc, errors, types, rewrites, - transforms, ir, utils) + transforms, ir) from .special import literal_unroll import warnings from .analysis import ( @@ -1181,8 +1181,7 @@ def unroll_loop(self, state, loop_info): blks = state.func_ir.blocks orig_lbl = tuple(this_loop_body) - # python 2 can't star unpack - replace, delete = orig_lbl[0], orig_lbl[1:] + replace, *delete = orig_lbl unroll, header_block = unrolled_body, this_loop.header unroll_lbl = [x for x in sorted(unroll.blocks.keys())] blks[replace] = unroll.blocks[unroll_lbl[0]] From f87001bdedce417e17a20eee64d0586bc70c5b9e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 10:50:23 +0000 Subject: [PATCH 224/595] win32 py27 restriction fix --- numba/tests/support.py | 5 +---- numba/tests/test_parfors.py | 9 ++------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/numba/tests/support.py b/numba/tests/support.py index 05ccb781482..0a3dc26bb70 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -47,11 +47,8 @@ tag = testing.make_tag_decorator(['important', 'long_running']) -_windows_py27 = (sys.platform.startswith('win32') and - sys.version_info[:2] == (2, 7)) _32bit = sys.maxsize <= 2 ** 32 -_reason = 'parfors not supported' -skip_parfors_unsupported = unittest.skipIf(_32bit or _windows_py27, _reason) +skip_parfors_unsupported = unittest.skipIf(_32bit, 'parfors not supported') skip_py38_or_later = unittest.skipIf( utils.PYVERSION >= (3, 8), "unsupported on py3.8 or later" diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 26c86e0bfbc..336034b7bc5 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -41,10 +41,6 @@ import cmath - -# for decorating tests, marking that Windows with Python 2.7 is not supported -_windows_py27 = (sys.platform.startswith('win32') and - sys.version_info[:2] == (2, 7)) _32bit = sys.maxsize <= 2 ** 32 skip_unsupported = skip_parfors_unsupported test_disabled = unittest.skipIf(True, 'Test disabled') @@ -601,13 +597,12 @@ def test_kmeans(self): self.assertTrue( countNonParforArrayAccesses(test_kmeans_example, arg_typs) == 0) - @unittest.skipIf(not (_windows_py27 or _32bit), - "Only impacts Windows with Python 2.7 / 32 bit hardware") + @unittest.skipIf(not _32bit, "Only impacts 32 bit hardware") @needs_blas def test_unsupported_combination_raises(self): """ This test is in place until issues with the 'parallel' - target on Windows with Python 2.7 / 32 bit hardware are fixed. + target on 32 bit hardware are fixed. """ with self.assertRaises(errors.UnsupportedParforsError) as raised: @njit(parallel=True) From 085b8d03ec42a76633137a996569a41fd1bd1c52 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 10:57:36 +0000 Subject: [PATCH 225/595] fix up stencils --- numba/tests/test_stencils.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index 8b0d2525381..3b35275ad27 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -19,17 +19,11 @@ from numba.compiler import compile_extra, Flags from numba.targets import registry from numba.targets.cpu import ParallelOptions -from .support import tag +from .support import tag, skip_parfors_unsupported, _32bit from numba.errors import LoweringError, TypingError -# for decorating tests, marking that Windows with Python 2.7 is not supported -_py27 = sys.version_info[:2] == (2, 7) -_windows_py27 = (sys.platform.startswith('win32') and _py27) -_32bit = sys.maxsize <= 2 ** 32 -_reason = 'parfors not supported' -_unsupported = _32bit or _windows_py27 -skip_unsupported = unittest.skipIf(_unsupported, _reason) +skip_unsupported = skip_parfors_unsupported @stencil @@ -77,9 +71,8 @@ def stencil_with_standard_indexing_2d(a, b): def addone_njit(a): return a + 1 -# guard against the decorator being run on unsupported platforms -# as it will raise and stop test discovery from working -if not _unsupported: + +if not _32bit: # prevent compilation on unsupported 32bit targets @njit(parallel=True) def addone_pjit(a): return a + 1 @@ -1276,10 +1269,7 @@ def computebound(mins, maxs): returner = self.gen_return(retvar) ast.copy_location(returner, node) - if _py27: - add_kwarg = [ast.Name('neighborhood', ast.Param())] - else: - add_kwarg = [ast.arg('neighborhood', None)] + add_kwarg = [ast.arg('neighborhood', None)] defaults = [ast.Name(id='None', ctx=ast.Load())] newargs = ast.arguments( @@ -1325,11 +1315,7 @@ def visit_FunctionDef(self, node): if self._argnames is not None or self._kwargnames is not None: raise RuntimeError("multiple definition of function/args?") - if _py27: - attr = 'id' - else: - attr = 'arg' - + attr = 'arg' self._argnames = [getattr(x, attr) for x in node.args.args] if node.args.kwarg: self._kwargnames = [x.arg for x in node.args.kwarg] From 70b45955067a68af0b0a02f42521fde30902e99a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 11:00:18 +0000 Subject: [PATCH 226/595] remove staticmethod --- numba/tests/npyufunc/test_vectorize_decor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/npyufunc/test_vectorize_decor.py b/numba/tests/npyufunc/test_vectorize_decor.py index 32ab0223ba8..cb61ea1eae3 100644 --- a/numba/tests/npyufunc/test_vectorize_decor.py +++ b/numba/tests/npyufunc/test_vectorize_decor.py @@ -97,7 +97,7 @@ class TestParallelVectorizeDecor(unittest.TestCase, BaseVectorizeDecor): class TestCPUVectorizeJitted(unittest.TestCase, BaseVectorizeDecor): target = 'cpu' - wrapper = staticmethod(jit) # staticmethod required for py27 + wrapper = jit class BaseVectorizeNopythonArg(unittest.TestCase, CheckWarningsMixin): From adffc861785c1f89e9a114a5dcff58008d739e58 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 11:02:58 +0000 Subject: [PATCH 227/595] more parfors unsupported --- numba/tests/test_array_analysis.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 06e737486fa..de47501af2e 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -8,7 +8,7 @@ from numba import unittest_support as unittest from numba import (njit, typeof, types, typing, typeof, ir, bytecode, jitclass, prange, postproc) -from .support import TestCase, tag +from .support import TestCase, tag, skip_parfors_unsupported from numba.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager from numba.targets import cpu, registry @@ -24,12 +24,8 @@ from numba.compiler_machinery import FunctionPass, PassManager, register_pass -# for parallel tests, marking that Windows with Python 2.7 is not supported -_windows_py27 = (sys.platform.startswith('win32') and - sys.version_info[:2] == (2, 7)) -_32bit = sys.maxsize <= 2 ** 32 -_reason = 'parfors not supported' -skip_unsupported = unittest.skipIf(_32bit or _windows_py27, _reason) + +skip_unsupported = skip_parfors_unsupported # test class for #3700 From 379a54b008821f1bf9a00fa8a10ebfad9e32c088 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 11:33:33 +0000 Subject: [PATCH 228/595] even more parfors unsupported --- numba/tests/support.py | 3 + numba/tests/test_array_attr.py | 6 +- numba/tests/test_comprehension.py | 6 +- numba/tests/test_debug.py | 7 +- numba/tests/test_gdb.py | 10 +- numba/tests/test_inlining.py | 12 +- numba/tests/test_parallel_backend.py | 18 +- numba/tests/test_parfors.py | 343 +++++++++++++-------------- numba/tests/test_typedlist.py | 5 +- 9 files changed, 201 insertions(+), 209 deletions(-) diff --git a/numba/tests/support.py b/numba/tests/support.py index 0a3dc26bb70..573777d1d6a 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -65,6 +65,9 @@ _msg = "SciPy needed for test" skip_unless_scipy = unittest.skipIf(scipy is None, _msg) +_lnx_reason = 'linux only test' +linux_only = unittest.skipIf(not sys.platform.startswith('linux'), _lnx_reason) + class CompilationCache(object): """ diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index 7fc9c99bc0a..65820a65074 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -5,9 +5,9 @@ from numba.compiler import compile_isolated from numba.numpy_support import from_dtype from numba import types, njit, typeof, numpy_support -from .support import TestCase, CompilationCache, MemoryLeakMixin, tag +from .support import (TestCase, CompilationCache, MemoryLeakMixin, tag, + skip_parfors_unsupported) from numba.errors import TypingError -from .test_parfors import skip_unsupported def array_dtype(a): @@ -238,7 +238,7 @@ def test_array_ctypes_data(self): arr = np.arange(3) self.assertEqual(pyfunc(arr), cfunc(arr)) - @skip_unsupported + @skip_parfors_unsupported def test_array_ctypes_ref_error_in_parallel(self): # Issue #2887 from ctypes import CFUNCTYPE, c_void_p, c_int32, c_double, c_bool diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index 3b6f5bbcf1b..ce173a6a69e 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -11,12 +11,10 @@ from numba.compiler import compile_isolated from numba import types, utils, jit, types from numba.errors import TypingError, LoweringError -from .support import tag +from .support import tag, _32bit from numba.tests.support import captured_stdout -from .test_parfors import _windows_py27, _32bit - -PARALLEL_SUPPORTED = not (_windows_py27 or _32bit) +PARALLEL_SUPPORTED = not _32bit def comp_list(n): l = [i for i in range(n)] diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 5832b82dbce..1a0ca3e509b 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -7,14 +7,13 @@ import numpy as np from .support import (TestCase, override_config, override_env_config, - captured_stdout, forbid_codegen) + captured_stdout, forbid_codegen, skip_parfors_unsupported) from numba import unittest_support as unittest from numba import jit, jitclass, types from numba.compiler import compile_isolated, Flags from numba.targets.cpu import ParallelOptions from numba.errors import NumbaPerformanceWarning from numba import compiler, prange -from .test_parfors import skip_unsupported from .matmul_usecase import needs_blas def simple_nopython(somearg): @@ -237,7 +236,7 @@ def check_parfors_warning(self, warn_list): self.assertTrue(warning_found, "Warning message should be found.") @needs_blas - @skip_unsupported + @skip_parfors_unsupported def test_warns(self): """ Test that using parallel=True on a function that does not have parallel @@ -250,7 +249,7 @@ def test_warns(self): flags=force_parallel_flags) self.check_parfors_warning(w) - @skip_unsupported + @skip_parfors_unsupported def test_array_debug_opt_stats(self): """ Test that NUMBA_DEBUG_ARRAY_OPT_STATS produces valid output diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index 0126b04e87c..0c9391711a3 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -13,8 +13,8 @@ from numba import unittest_support as unittest from numba.targets.gdb_hook import _confirm_gdb -from .support import (TestCase, captured_stdout, tag) -from .test_parfors import skip_unsupported as parfors_skip_unsupported +from .support import (TestCase, captured_stdout, tag, skip_parfors_unsupported) + _platform = sys.platform @@ -118,19 +118,19 @@ def test_gdb_split_init_and_break_objmode_impl(self): with captured_stdout(): _dbg_jit(impl_gdb_call_w_bp)(10) - @parfors_skip_unsupported + @skip_parfors_unsupported @needs_gdb_harness def test_gdb_split_init_and_break_w_parallel_cpython_impl(self): with captured_stdout(): impl_gdb_split_init_and_break_w_parallel(10) - @parfors_skip_unsupported + @skip_parfors_unsupported @needs_gdb_harness def test_gdb_split_init_and_break_w_parallel_nopython_impl(self): with captured_stdout(): _dbg_njit(impl_gdb_split_init_and_break_w_parallel)(10) - @parfors_skip_unsupported + @skip_parfors_unsupported @needs_gdb_harness def test_gdb_split_init_and_break_w_parallel_objmode_impl(self): with captured_stdout(): diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 155729b2aad..6851e1683ac 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -1,14 +1,14 @@ import re import numpy as np -from .support import TestCase, override_config, captured_stdout +from .support import (TestCase, override_config, captured_stdout, + skip_parfors_unsupported) import numba from numba import unittest_support as unittest from numba import jit, njit, types, ir, compiler from numba.ir_utils import guard, find_callname, find_const, get_definition from numba.targets.registry import CPUDispatcher from numba.inline_closurecall import inline_closure_call -from .test_parfors import skip_unsupported from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, @@ -160,7 +160,7 @@ def test_multiple_inner_functions(self): self.assert_not_has_pattern('%s.more' % prefix, asm) self.assert_not_has_pattern('%s.inner' % prefix, asm) - @skip_unsupported + @skip_parfors_unsupported def test_inline_call_after_parfor(self): # replace the call to make sure inlining doesn't cause label conflict # with parfor body @@ -172,7 +172,7 @@ def test_impl(A): A = np.arange(10) self.assertEqual(test_impl(A), j_func(A)) - @skip_unsupported + @skip_parfors_unsupported def test_inline_update_target_def(self): def test_impl(a): @@ -199,7 +199,7 @@ def test_impl(a): self.assertEqual(len(func_ir._definitions['b']), 2) - @skip_unsupported + @skip_parfors_unsupported def test_inline_var_dict_ret(self): # make sure inline_closure_call returns the variable replacement dict # and it contains the original variable name used in locals @@ -228,7 +228,7 @@ def test_impl(): self.assertTrue('b' in var_map) - @skip_unsupported + @skip_parfors_unsupported def test_inline_call_branch_pruning(self): # branch pruning pass should run properly in inlining to enable # functions with type checks diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 058479418ad..9d20e6fa209 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -18,10 +18,8 @@ from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize -from .support import temp_directory, override_config, TestCase, tag - -from .test_parfors import skip_unsupported as parfors_skip_unsupported -from .test_parfors import linux_only +from .support import (temp_directory, override_config, TestCase, tag, + skip_parfors_unsupported, linux_only) import queue as t_queue from numba.testing.main import _TIMEOUT as _RUNNER_TIMEOUT @@ -58,10 +56,8 @@ _windows = sys.platform.startswith('win') _osx = sys.platform.startswith('darwin') -_windows_py27 = (sys.platform.startswith('win32') and - sys.version_info[:2] == (2, 7)) _32bit = sys.maxsize <= 2 ** 32 -_parfors_unsupported = _32bit or _windows_py27 +_parfors_unsupported = _32bit _HAVE_OS_FORK = not _windows @@ -455,7 +451,7 @@ def run_cmd(self, cmdline, env=None): return out.decode(), err.decode() -@parfors_skip_unsupported +@skip_parfors_unsupported class TestThreadingLayerSelection(ThreadLayerTestHelper): """ Checks that numba.threading_layer() reports correctly. @@ -496,7 +492,7 @@ def generate(cls): TestThreadingLayerSelection.generate() -@parfors_skip_unsupported +@skip_parfors_unsupported class TestMiscBackendIssues(ThreadLayerTestHelper): """ Checks fixes for the issues with threading backends implementation @@ -559,7 +555,7 @@ def foo(n): # 32bit or windows py27 (not that this runs on windows) -@parfors_skip_unsupported +@skip_parfors_unsupported @skip_unless_gnu_omp class TestForkSafetyIssues(ThreadLayerTestHelper): """ @@ -792,7 +788,7 @@ def test_serial_parent_explicit_mp_fork_par_child_then_par_parent(self): print(out, err) -@parfors_skip_unsupported +@skip_parfors_unsupported class TestInitSafetyIssues(TestCase): _DEBUG = False diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 336034b7bc5..c4957750649 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -20,7 +20,6 @@ import numba from numba import unittest_support as unittest -from .support import TestCase, captured_stdout, MemoryLeakMixin, override_env_config from numba import njit, prange, stencil, inline_closurecall from numba import compiler, typing, errors, typed_passes from numba.targets import cpu @@ -35,17 +34,15 @@ from numba.unsafe.ndarray import empty_inferred as unsafe_empty from numba.compiler import compile_isolated, Flags from numba.bytecode import ByteCodeIter -from .support import tag, override_env_config, skip_parfors_unsupported from .matmul_usecase import needs_blas from .test_linalg import needs_lapack +from .support import (TestCase, captured_stdout, MemoryLeakMixin, + override_env_config, linux_only, tag, + skip_parfors_unsupported, _32bit) import cmath -_32bit = sys.maxsize <= 2 ** 32 -skip_unsupported = skip_parfors_unsupported test_disabled = unittest.skipIf(True, 'Test disabled') -_lnx_reason = 'linux only test' -linux_only = unittest.skipIf(not sys.platform.startswith('linux'), _lnx_reason) x86_only = unittest.skipIf(platform.machine() not in ('i386', 'x86_64'), 'x86 only test') _GLOBAL_INT_FOR_TESTING1 = 17 @@ -494,7 +491,7 @@ def check(self, pyfunc, *args, **kwargs): cfunc, cpfunc = self.compile_all(pyfunc, *args) self.check_parfors_vs_others(pyfunc, cfunc, cpfunc, *args, **kwargs) - @skip_unsupported + @skip_parfors_unsupported @tag('important') def test_arraymap(self): def test_impl(a, x, y): @@ -506,7 +503,7 @@ def test_impl(a, x, y): self.check(test_impl, A, X, Y) - @skip_unsupported + @skip_parfors_unsupported @needs_blas @tag('important') def test_mvdot(self): @@ -518,7 +515,7 @@ def test_impl(a, v): self.check(test_impl, A, v) - @skip_unsupported + @skip_parfors_unsupported @tag('important') def test_0d_broadcast(self): def test_impl(): @@ -528,7 +525,7 @@ def test_impl(): self.check(test_impl) self.assertTrue(countParfors(test_impl, ()) == 1) - @skip_unsupported + @skip_parfors_unsupported @tag('important') def test_2d_parfor(self): def test_impl(): @@ -538,7 +535,7 @@ def test_impl(): self.check(test_impl) self.assertTrue(countParfors(test_impl, ()) == 1) - @skip_unsupported + @skip_parfors_unsupported @tag('important') def test_pi(self): def test_impl(n): @@ -550,7 +547,7 @@ def test_impl(n): self.assertTrue(countParfors(test_impl, (types.int64, )) == 1) self.assertTrue(countArrays(test_impl, (types.intp,)) == 0) - @skip_unsupported + @skip_parfors_unsupported @tag('important') def test_fuse_argmin_argmax_max_min(self): for op in [np.argmin, np.argmax, np.min, np.max]: @@ -563,14 +560,14 @@ def test_impl(n): self.assertTrue(countParfors(test_impl, (types.int64, )) == 1) self.assertTrue(countArrays(test_impl, (types.intp,)) == 0) - @skip_unsupported + @skip_parfors_unsupported @tag('important') def test_blackscholes(self): # blackscholes takes 5 1D float array args args = (numba.float64[:], ) * 5 self.assertTrue(countParfors(blackscholes_impl, args) == 1) - @skip_unsupported + @skip_parfors_unsupported @needs_blas @tag('important') def test_logistic_regression(self): @@ -579,7 +576,7 @@ def test_logistic_regression(self): self.assertTrue(countParfors(lr_impl, args) == 1) self.assertTrue(countArrayAllocs(lr_impl, args) == 1) - @skip_unsupported + @skip_parfors_unsupported @tag('important') def test_kmeans(self): np.random.seed(0) @@ -617,7 +614,7 @@ def ddot(a, v): "hardware") self.assertIn(msg, str(raised.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_simple01(self): def test_impl(): return np.ones(()) @@ -625,61 +622,61 @@ def test_impl(): self.check(test_impl) self.assertIn("\'@do_scheduling\' not found", str(raises.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_simple02(self): def test_impl(): return np.ones((1,)) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple03(self): def test_impl(): return np.ones((1, 2)) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple04(self): def test_impl(): return np.ones(1) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple07(self): def test_impl(): return np.ones((1, 2), dtype=np.complex128) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple08(self): def test_impl(): return np.ones((1, 2)) + np.ones((1, 2)) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple09(self): def test_impl(): return np.ones((1, 1)) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple10(self): def test_impl(): return np.ones((0, 0)) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple11(self): def test_impl(): return np.ones((10, 10)) + 1. self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple12(self): def test_impl(): return np.ones((10, 10)) + np.complex128(1.) self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple13(self): def test_impl(): return np.complex128(1.) @@ -687,45 +684,45 @@ def test_impl(): self.check(test_impl) self.assertIn("\'@do_scheduling\' not found", str(raises.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_simple14(self): def test_impl(): return np.ones((10, 10))[0::20] self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_simple15(self): def test_impl(v1, v2, m1, m2): return v1 + v1 self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported def test_simple16(self): def test_impl(v1, v2, m1, m2): return m1 + m1 self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported def test_simple17(self): def test_impl(v1, v2, m1, m2): return m2 + v1 self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported @needs_lapack def test_simple18(self): def test_impl(v1, v2, m1, m2): return m1.T + np.linalg.svd(m2)[1] self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported @needs_blas def test_simple19(self): def test_impl(v1, v2, m1, m2): return np.dot(m1, v2) self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported @needs_blas def test_simple20(self): def test_impl(v1, v2, m1, m2): @@ -735,20 +732,20 @@ def test_impl(v1, v2, m1, m2): self.check(test_impl, *self.simple_args) self.assertIn("\'@do_scheduling\' not found", str(raises.exception)) - @skip_unsupported + @skip_parfors_unsupported @needs_blas def test_simple21(self): def test_impl(v1, v2, m1, m2): return np.dot(v1, v1) self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported def test_simple22(self): def test_impl(v1, v2, m1, m2): return np.sum(v1 + v1) self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported def test_simple23(self): def test_impl(v1, v2, m1, m2): x = 2 * v1 @@ -756,7 +753,7 @@ def test_impl(v1, v2, m1, m2): return 4 * np.sum(x**2 + y**2 < 1) / 10 self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported def test_simple24(self): def test_impl(): n = 20 @@ -787,7 +784,7 @@ def test_impl(v1, v2, m1, m2): self.check(test_impl, *self.simple_args) - @skip_unsupported + @skip_parfors_unsupported def test_np_func_direct_import(self): from numpy import ones # import here becomes FreeVar def test_impl(n): @@ -796,14 +793,14 @@ def test_impl(n): n = 111 self.check(test_impl, n) - @skip_unsupported + @skip_parfors_unsupported def test_np_random_func_direct_import(self): def test_impl(n): A = randn(n) return A[0] self.assertTrue(countParfors(test_impl, (types.int64, )) == 1) - @skip_unsupported + @skip_parfors_unsupported def test_arange(self): # test with stop only def test_impl1(n): @@ -820,7 +817,7 @@ def test_impl3(s, n, t): self.check(test_impl2, 2, arg) self.check(test_impl3, 2, arg, 2) - @skip_unsupported + @skip_parfors_unsupported def test_linspace(self): # without num def test_impl1(start, stop): @@ -833,7 +830,7 @@ def test_impl2(start, stop, num): self.check(test_impl1, 2, arg) self.check(test_impl2, 2, arg, 30) - @skip_unsupported + @skip_parfors_unsupported def test_size_assertion(self): def test_impl(m, n): A = np.ones(m) @@ -847,7 +844,7 @@ def test_impl(m, n): msg = "Sizes of A, B do not match" self.assertIn(msg, str(raises.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_mean(self): def test_impl(A): return A.mean() @@ -859,7 +856,7 @@ def test_impl(A): self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 1, 'C'), )) == 1) self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 2, 'C'), )) == 1) - @skip_unsupported + @skip_parfors_unsupported def test_var(self): def test_impl(A): return A.var() @@ -873,7 +870,7 @@ def test_impl(A): self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 1, 'C'), )) == 2) self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 2, 'C'), )) == 2) - @skip_unsupported + @skip_parfors_unsupported def test_std(self): def test_impl(A): return A.std() @@ -887,14 +884,14 @@ def test_impl(A): self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 1, 'C'), )) == 2) self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 2, 'C'), )) == 2) - @skip_unsupported + @skip_parfors_unsupported def test_issue4963_globals(self): def test_impl(): buf = np.zeros((_GLOBAL_INT_FOR_TESTING1, _GLOBAL_INT_FOR_TESTING2)) return buf self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_issue4963_freevars(self): _FREEVAR_INT_FOR_TESTING1 = 17 _FREEVAR_INT_FOR_TESTING2 = 5 @@ -903,7 +900,7 @@ def test_impl(): return buf self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_random_parfor(self): """ Test function with only a random call to make sure a random function @@ -914,7 +911,7 @@ def test_impl(n): return A self.assertTrue(countParfors(test_impl, (types.int64, )) == 1) - @skip_unsupported + @skip_parfors_unsupported def test_randoms(self): def test_impl(n): A = np.random.standard_normal(size=(n, n)) @@ -933,7 +930,7 @@ def test_impl(n): np.testing.assert_allclose(parfor_output, py_output, rtol=0.05) self.assertTrue(countParfors(test_impl, (types.int64, )) == 1) - @skip_unsupported + @skip_parfors_unsupported def test_dead_randoms(self): def test_impl(n): A = np.random.standard_normal(size=(n, n)) @@ -951,7 +948,7 @@ def test_impl(n): self.assertEqual(parfor_output, py_output) self.assertTrue(countParfors(test_impl, (types.int64, )) == 0) - @skip_unsupported + @skip_parfors_unsupported def test_cfg(self): # from issue #2477 def test_impl(x, is_positive, N): @@ -968,7 +965,7 @@ def test_impl(x, is_positive, N): is_positive = np.zeros(N) self.check(test_impl, x, is_positive, N) - @skip_unsupported + @skip_parfors_unsupported def test_reduce(self): def test_impl(A): init_val = 10 @@ -1010,7 +1007,7 @@ def test_impl(A): # this doesn't fuse due to mixed indices self.assertTrue(countParfors(test_impl, (numba.float64[:,:],)) == 2) - @skip_unsupported + @skip_parfors_unsupported def test_min(self): def test_impl1(A): return A.min() @@ -1038,7 +1035,7 @@ def test_impl2(A): pcfunc.entry_point(np.array([], dtype=np.int64)) self.assertIn(msg, str(e.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_max(self): def test_impl1(A): return A.max() @@ -1066,7 +1063,7 @@ def test_impl2(A): pcfunc.entry_point(np.array([], dtype=np.int64)) self.assertIn(msg, str(e.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_use_of_reduction_var1(self): def test_impl(): acc = 0 @@ -1080,7 +1077,7 @@ def test_impl(): pcfunc = self.compile_parallel(test_impl, ()) self.assertIn(msg, str(e.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_argmin(self): def test_impl1(A): return A.argmin() @@ -1107,7 +1104,7 @@ def test_impl2(A): pcfunc.entry_point(np.array([], dtype=np.int64)) self.assertIn(msg, str(e.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_argmax(self): def test_impl1(A): return A.argmax() @@ -1134,7 +1131,7 @@ def test_impl2(A): pcfunc.entry_point(np.array([], dtype=np.int64)) self.assertIn(msg, str(e.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_array_access1(self): # signed index of the prange generated by sum() should be replaced # resulting in array A to be eliminated (see issue #2846) @@ -1146,7 +1143,7 @@ def test_impl(n): self.check(test_impl, n) self.assertEqual(countArrays(test_impl, (types.intp,)), 0) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_array_access2(self): # in this test, the prange index has the same name (i) in two loops # thus, i has multiple definitions and is harder to replace @@ -1167,7 +1164,7 @@ def test_impl(n): self.check(test_impl, n) self.assertEqual(countNonParforArrayAccesses(test_impl, (types.intp,)), 0) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_array_access3(self): def test_impl(n): A = np.ones(n, np.int64) @@ -1182,7 +1179,7 @@ def test_impl(n): self.check(test_impl, n) self.assertIn("Overwrite of parallel loop index", str(raises.exception)) - @skip_unsupported + @skip_parfors_unsupported @needs_blas def test_parfor_array_access4(self): # in this test, one index of a multi-dim access should be replaced @@ -1222,7 +1219,7 @@ def test_impl(A, b): self.assertTrue(build_tuple_found) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_dtype_type(self): # test array type replacement creates proper type def test_impl(a): @@ -1233,7 +1230,7 @@ def test_impl(a): a = np.ones(10) self.check(test_impl, a) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_array_access5(self): # one dim is slice in multi-dim access def test_impl(n): @@ -1247,7 +1244,7 @@ def test_impl(n): self.check(test_impl, n) self.assertEqual(countNonParforArrayAccesses(test_impl, (types.intp,)), 0) - @skip_unsupported + @skip_parfors_unsupported @test_disabled # Test itself is problematic, see #3155 def test_parfor_hoist_setitem(self): # Make sure that read of out is not hoisted. @@ -1259,7 +1256,7 @@ def test_impl(out): out = np.ones(1) self.check(test_impl, out) - @skip_unsupported + @skip_parfors_unsupported @needs_blas def test_parfor_generate_fuse(self): # issue #2857 @@ -1278,7 +1275,7 @@ def test_impl(N, D): self.assertEqual(countArrayAllocs(test_impl, (types.intp, types.intp)), 4) self.assertEqual(countParfors(test_impl, (types.intp, types.intp)), 4) - @skip_unsupported + @skip_parfors_unsupported def test_ufunc_expr(self): # issue #2885 def test_impl(A, B): @@ -1289,7 +1286,7 @@ def test_impl(A, B): B[1] = 0 self.check(test_impl, A, B) - @skip_unsupported + @skip_parfors_unsupported def test_find_callname_intrinsic(self): def test_impl(n): A = unsafe_empty((n,)) @@ -1301,7 +1298,7 @@ def test_impl(n): # as a different name self.assertEqual(countArrayAllocs(test_impl, (types.intp,)), 1) - @skip_unsupported + @skip_parfors_unsupported def test_reduction_var_reuse(self): # issue #3139 def test_impl(n): @@ -1315,7 +1312,7 @@ def test_impl(n): return acc self.check(test_impl, 16) - @skip_unsupported + @skip_parfors_unsupported def test_two_d_array_reduction_reuse(self): def test_impl(n): shp = (13, 17) @@ -1333,7 +1330,7 @@ def test_impl(n): self.check(test_impl, 100) - @skip_unsupported + @skip_parfors_unsupported def test_one_d_array_reduction(self): def test_impl(n): result = np.zeros(1, np.int_) @@ -1345,7 +1342,7 @@ def test_impl(n): self.check(test_impl, 100) - @skip_unsupported + @skip_parfors_unsupported def test_two_d_array_reduction(self): def test_impl(n): shp = (13, 17) @@ -1360,7 +1357,7 @@ def test_impl(n): self.check(test_impl, 100) - @skip_unsupported + @skip_parfors_unsupported def test_two_d_array_reduction_with_float_sizes(self): # result1 is float32 and tmp is float64. # Tests reduction with differing dtypes. @@ -1376,7 +1373,7 @@ def test_impl(n): self.check(test_impl, 100) - @skip_unsupported + @skip_parfors_unsupported def test_two_d_array_reduction_prod(self): def test_impl(n): shp = (13, 17) @@ -1390,7 +1387,7 @@ def test_impl(n): self.check(test_impl, 100) - @skip_unsupported + @skip_parfors_unsupported def test_three_d_array_reduction(self): def test_impl(n): shp = (3, 2, 7) @@ -1403,7 +1400,7 @@ def test_impl(n): self.check(test_impl, 100) - @skip_unsupported + @skip_parfors_unsupported def test_preparfor_canonicalize_kws(self): # test canonicalize_array_math typing for calls with kw args def test_impl(A): @@ -1413,7 +1410,7 @@ def test_impl(A): A = np.arange(n) self.check(test_impl, A) - @skip_unsupported + @skip_parfors_unsupported def test_preparfor_datetime64(self): # test array.dtype transformation for datetime64 def test_impl(A): @@ -1423,7 +1420,7 @@ def test_impl(A): cpfunc = self.compile_parallel(test_impl, (numba.typeof(A),)) self.assertEqual(cpfunc.entry_point(A), test_impl(A)) - @skip_unsupported + @skip_parfors_unsupported def test_no_hoisting_with_member_function_call(self): def test_impl(X): n = X.shape[0] @@ -1439,7 +1436,7 @@ def test_impl(X): self.check(test_impl, np.random.ranf(128)) - @skip_unsupported + @skip_parfors_unsupported def test_array_compare_scalar(self): """ issue3671: X != 0 becomes an arrayexpr with operator.ne. That is turned into a parfor by devectorizing. Make sure @@ -1452,7 +1449,7 @@ def test_impl(): self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_reshape_with_neg_one(self): # issue3314 def test_impl(a, b): @@ -1471,7 +1468,7 @@ def test_impl(a, b): self.check(test_impl, a, b) - @skip_unsupported + @skip_parfors_unsupported def test_reshape_with_large_neg(self): # issue3314 def test_impl(a, b): @@ -1490,7 +1487,7 @@ def test_impl(a, b): self.check(test_impl, a, b) - @skip_unsupported + @skip_parfors_unsupported def test_reshape_with_too_many_neg_one(self): # issue3314 with self.assertRaises(ValueError) as raised: @@ -1513,7 +1510,7 @@ def test_impl(a, b): msg = ("The reshape API may only include one negative argument.") self.assertIn(msg, str(raised.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_ndarray_fill(self): def test_impl(x): x.fill(7.0) @@ -1522,7 +1519,7 @@ def test_impl(x): self.check(test_impl, x) self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 1, 'C'),)) == 1) - @skip_unsupported + @skip_parfors_unsupported def test_ndarray_fill2d(self): def test_impl(x): x.fill(7.0) @@ -1531,13 +1528,13 @@ def test_impl(x): self.check(test_impl, x) self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 2, 'C'),)) == 1) - @skip_unsupported + @skip_parfors_unsupported def test_0d_array(self): def test_impl(n): return np.sum(n) + np.prod(n) + np.min(n) + np.max(n) + np.var(n) self.check(test_impl, np.array(7), check_scheduling=False) - @skip_unsupported + @skip_parfors_unsupported def test_array_analysis_optional_def(self): def test_impl(x, half): size = len(x) @@ -1556,7 +1553,7 @@ def check(self, pyfunc, *args, **kwargs): cfunc, cpfunc = self.compile_all(pyfunc, *args) self.check_parfors_vs_others(pyfunc, cfunc, cpfunc, *args, **kwargs) - @skip_unsupported + @skip_parfors_unsupported def test_reduction(self): # issue4299 @njit(parallel=True) @@ -1566,7 +1563,7 @@ def test_impl(arr): arr = np.arange(10).astype(np.float64) self.check(test_impl, arr) - @skip_unsupported + @skip_parfors_unsupported def test_multiple_reduction_vars(self): @njit(parallel=True) def test_impl(arr): @@ -1751,7 +1748,7 @@ def foo(): class TestPrange(TestPrangeBase): """ Tests Prange """ - @skip_unsupported + @skip_parfors_unsupported def test_prange01(self): def test_impl(): n = 4 @@ -1762,7 +1759,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange02(self): def test_impl(): n = 4 @@ -1773,7 +1770,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange03(self): def test_impl(): s = 10 @@ -1783,7 +1780,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange03mul(self): def test_impl(): s = 3 @@ -1793,7 +1790,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange03sub(self): def test_impl(): s = 100 @@ -1803,7 +1800,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange03div(self): def test_impl(): s = 10 @@ -1813,7 +1810,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange04(self): def test_impl(): a = 2 @@ -1828,7 +1825,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange05(self): def test_impl(): n = 4 @@ -1840,7 +1837,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange06(self): def test_impl(): n = 4 @@ -1852,7 +1849,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange07(self): def test_impl(): n = 4 @@ -1864,7 +1861,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange08(self): def test_impl(): n = 4 @@ -1877,7 +1874,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange08_1(self): def test_impl(): n = 4 @@ -1890,7 +1887,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange09(self): def test_impl(): n = 4 @@ -1904,7 +1901,7 @@ def test_impl(): scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange10(self): def test_impl(): n = 4 @@ -1920,7 +1917,7 @@ def test_impl(): scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported @unittest.skip("list append is not thread-safe yet (#2391, #2408)") def test_prange11(self): def test_impl(): @@ -1929,7 +1926,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange12(self): def test_impl(): acc = 0 @@ -1941,7 +1938,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange13(self): def test_impl(n): acc = 0 @@ -1951,7 +1948,7 @@ def test_impl(n): self.prange_tester(test_impl, np.int32(4), scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange14(self): def test_impl(A): s = 3 @@ -1965,7 +1962,7 @@ def test_impl(A): scheduler_type='unsigned', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange15(self): # from issue 2587 # test parfor type inference when there is multi-dimensional indexing @@ -1979,7 +1976,7 @@ def test_impl(N): check_fastmath=True) # Tests for negative ranges - @skip_unsupported + @skip_parfors_unsupported def test_prange16(self): def test_impl(N): acc = 0 @@ -1989,7 +1986,7 @@ def test_impl(N): self.prange_tester(test_impl, 1024, scheduler_type='signed', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange17(self): def test_impl(N): acc = 0 @@ -2000,7 +1997,7 @@ def test_impl(N): self.prange_tester(test_impl, 9, scheduler_type='signed', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange18(self): def test_impl(N): acc = 0 @@ -2013,7 +2010,7 @@ def test_impl(N): self.prange_tester(test_impl, 9, scheduler_type='signed', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange19(self): def test_impl(N): acc = 0 @@ -2026,7 +2023,7 @@ def test_impl(N): self.prange_tester(test_impl, 9, scheduler_type='signed', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange20(self): def test_impl(N): acc = 0 @@ -2037,7 +2034,7 @@ def test_impl(N): self.prange_tester(test_impl, 9, scheduler_type='signed', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange21(self): def test_impl(N): acc = 0 @@ -2047,7 +2044,7 @@ def test_impl(N): self.prange_tester(test_impl, 9, scheduler_type='signed', check_fastmath=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange22(self): def test_impl(): a = 0 @@ -2064,7 +2061,7 @@ def test_impl(): self.prange_tester(test_impl, scheduler_type='signed', check_fastmath=True, check_fastmath_result=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange23(self): # test non-contig input def test_impl(A): @@ -2075,7 +2072,7 @@ def test_impl(A): self.prange_tester(test_impl, A, scheduler_type='unsigned', check_fastmath=True, check_fastmath_result=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange24(self): # test non-contig input, signed range def test_impl(A): @@ -2086,7 +2083,7 @@ def test_impl(A): self.prange_tester(test_impl, A, scheduler_type='signed', check_fastmath=True, check_fastmath_result=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange25(self): def test_impl(A): n = len(A) @@ -2105,7 +2102,7 @@ def test_impl(A): self.assertEqual(len(hoisted_allocs), 0) # should this work? - @skip_unsupported + @skip_parfors_unsupported def test_prange26(self): def test_impl(A): B = A[::3] @@ -2116,7 +2113,7 @@ def test_impl(A): self.prange_tester(test_impl, A, scheduler_type='unsigned', check_fastmath=True, check_fastmath_result=True) - @skip_unsupported + @skip_parfors_unsupported def test_prange_two_instances_same_reduction_var(self): # issue4922 - multiple uses of same reduction variable def test_impl(n): @@ -2128,7 +2125,7 @@ def test_impl(n): return c self.prange_tester(test_impl, 9) - @skip_unsupported + @skip_parfors_unsupported def test_prange_conflicting_reduction_ops(self): def test_impl(n): c = 0 @@ -2144,7 +2141,7 @@ def test_impl(n): 'operators.') self.assertIn(msg, str(raises.exception)) -# @skip_unsupported +# @skip_parfors_unsupported @test_disabled def test_check_error_model(self): def test_impl(): @@ -2171,7 +2168,7 @@ def test_impl(): self.assertEqual(result[0], np.inf) - @skip_unsupported + @skip_parfors_unsupported def test_check_alias_analysis(self): # check alias analysis reports ok def test_impl(A): @@ -2196,7 +2193,7 @@ def test_impl(A): self.assertEqual(line.count('noalias'), 2) break - @skip_unsupported + @skip_parfors_unsupported def test_prange_raises_invalid_step_size(self): def test_impl(N): acc = 0 @@ -2209,7 +2206,7 @@ def test_impl(N): msg = 'Only constant step size of 1 is supported for prange' self.assertIn(msg, str(raises.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_prange_fastmath_check_works(self): # this function will benefit from `fastmath`, the div will # get optimised to a multiply by reciprocal and the accumulator @@ -2240,7 +2237,7 @@ def test_impl(): break self.assertTrue(fadd_inst.match(splitted[i + 1])) - @skip_unsupported + @skip_parfors_unsupported def test_kde_example(self): def test_impl(X): # KDE example @@ -2260,7 +2257,7 @@ def test_impl(X): X = np.random.ranf(n) self.prange_tester(test_impl, X) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_alias1(self): def test_impl(n): b = np.zeros((n, n)) @@ -2270,7 +2267,7 @@ def test_impl(n): return b.sum() self.prange_tester(test_impl, 4) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_alias2(self): def test_impl(n): b = np.zeros((n, n)) @@ -2281,7 +2278,7 @@ def test_impl(n): return b.sum() self.prange_tester(test_impl, 4) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_alias3(self): def test_impl(n): b = np.zeros((n, n, n)) @@ -2294,7 +2291,7 @@ def test_impl(n): return b.sum() self.prange_tester(test_impl, 4) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_race_1(self): def test_impl(x, y): for j in range(y): @@ -2307,7 +2304,7 @@ def test_impl(x, y): "in non-deterministic or unintended results.") self.assertIn(expected_msg, str(warning_obj.message)) - @skip_unsupported + @skip_parfors_unsupported def test_nested_parfor_push_call_vars(self): """ issue 3686: if a prange has something inside it that causes a nested parfor to be generated and both the inner and outer @@ -2329,7 +2326,7 @@ def test_impl(): return B self.prange_tester(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_copy_global_for_parfor(self): """ issue4903: a global is copied next to a parfor so that it can be inlined into the parfor and thus not have to be @@ -2353,7 +2350,7 @@ def test_impl(zz, tc): tc = np.ones(m, dtype=np.int_) self.prange_tester(test_impl, zz, tc, patch_instance=[0]) - @skip_unsupported + @skip_parfors_unsupported def test_multiple_call_getattr_object(self): def test_impl(n): B = 0 @@ -2365,7 +2362,7 @@ def test_impl(n): return B self.prange_tester(test_impl, 1.0) - @skip_unsupported + @skip_parfors_unsupported def test_argument_alias_recarray_field(self): # Test for issue4007. def test_impl(n): @@ -2388,7 +2385,7 @@ def test_impl(n): self.assertEqual(python_res, njit_res) self.assertEqual(python_res, pa_res) - @skip_unsupported + @skip_parfors_unsupported def test_mutable_list_param(self): """ issue3699: test that mutable variable to call in loop is not hoisted. The call in test_impl forces a manual @@ -2416,7 +2413,7 @@ def test_impl(n): self.assertEqual(python_res, njit_res) self.assertEqual(python_res, pa_res) - @skip_unsupported + @skip_parfors_unsupported def test_list_comprehension_prange(self): # issue4569 def test_impl(x): @@ -2564,7 +2561,7 @@ def will_vectorize(A): @linux_only # needed as 32bit doesn't have equivalent signed/unsigned instruction generation # for this function - @skip_unsupported + @skip_parfors_unsupported def test_signed_vs_unsigned_vec_asm(self): """ This checks vectorization for signed vs unsigned variants of a trivial accumulator, the only meaningful difference should be the @@ -2635,7 +2632,7 @@ def check(self, pyfunc, *args, **kwargs): cfunc, cpfunc = self.compile_all(pyfunc, *args) self.check_parfors_vs_others(pyfunc, cfunc, cpfunc, *args, **kwargs) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice1(self): def test_impl(a): (n,) = a.shape @@ -2644,7 +2641,7 @@ def test_impl(a): self.check(test_impl, np.ones(10)) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice2(self): def test_impl(a, m): (n,) = a.shape @@ -2658,7 +2655,7 @@ def test_impl(a, m): njit(parallel=True)(test_impl)(np.ones(10),10) self.assertIn("do not match", str(raises.exception)) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice3(self): def test_impl(a): (m,n) = a.shape @@ -2667,7 +2664,7 @@ def test_impl(a): self.check(test_impl, np.ones((4,3))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice4(self): def test_impl(a): (m,n) = a.shape @@ -2676,7 +2673,7 @@ def test_impl(a): self.check(test_impl, np.ones((4,3))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice5(self): def test_impl(a): (m,n) = a.shape @@ -2685,7 +2682,7 @@ def test_impl(a): self.check(test_impl, np.ones((4,3))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice6(self): def test_impl(a): b = a.transpose() @@ -2694,7 +2691,7 @@ def test_impl(a): self.check(test_impl, np.ones((4,3))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice7(self): def test_impl(a): b = a.transpose() @@ -2708,7 +2705,7 @@ def test_impl(a): njit(parallel=True)(test_impl)(np.ones((3,4))) self.assertIn("do not match", str(raises.exception)) -# @skip_unsupported +# @skip_parfors_unsupported @test_disabled def test_parfor_slice8(self): def test_impl(a): @@ -2719,7 +2716,7 @@ def test_impl(a): self.check(test_impl, np.arange(9).reshape((3,3))) -# @skip_unsupported +# @skip_parfors_unsupported @test_disabled def test_parfor_slice9(self): def test_impl(a): @@ -2730,7 +2727,7 @@ def test_impl(a): self.check(test_impl, np.arange(12).reshape((3,4))) -# @skip_unsupported +# @skip_parfors_unsupported @test_disabled def test_parfor_slice10(self): def test_impl(a): @@ -2741,7 +2738,7 @@ def test_impl(a): self.check(test_impl, np.arange(9).reshape((3,3))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice11(self): def test_impl(a): (m,n,l) = a.shape @@ -2751,7 +2748,7 @@ def test_impl(a): self.check(test_impl, np.arange(27).reshape((3,3,3))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice12(self): def test_impl(a): (m,n) = a.shape @@ -2761,7 +2758,7 @@ def test_impl(a): self.check(test_impl, np.arange(12).reshape((3,4))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice13(self): def test_impl(a): (m,n) = a.shape @@ -2772,7 +2769,7 @@ def test_impl(a): self.check(test_impl, np.arange(12).reshape((3,4))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice14(self): def test_impl(a): (m,n) = a.shape @@ -2782,7 +2779,7 @@ def test_impl(a): self.check(test_impl, np.arange(12).reshape((3,4))) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice15(self): def test_impl(a): (m,n) = a.shape @@ -2809,7 +2806,7 @@ def test_impl(a, b, n): args = (numba.float64[:], numba.float64[:], numba.int64) self.assertEqual(countParfors(test_impl, args), 2) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice17(self): def test_impl(m, A): B = np.zeros(m) @@ -2819,7 +2816,7 @@ def test_impl(m, A): self.check(test_impl, 10, np.ones(10)) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice18(self): # issue 3534 def test_impl(): @@ -2830,7 +2827,7 @@ def test_impl(): self.check(test_impl) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice19(self): # issues #3561 and #3554, empty slice binop def test_impl(X): @@ -2839,7 +2836,7 @@ def test_impl(X): self.check(test_impl, np.ones(10)) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice20(self): # issue #4075, slice size def test_impl(): @@ -2850,7 +2847,7 @@ def test_impl(): self.check(test_impl, check_scheduling=False) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice21(self): def test_impl(x1, x2): x1 = x1.reshape(x1.size, 1) @@ -2861,7 +2858,7 @@ def test_impl(x1, x2): x2 = np.random.rand(6) self.check(test_impl, x1, x2) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice22(self): def test_impl(x1, x2): b = np.zeros((10,)) @@ -2873,7 +2870,7 @@ def test_impl(x1, x2): x2 = np.array(4) self.check(test_impl, x1, x2) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice23(self): # issue #4630 def test_impl(x): @@ -2882,7 +2879,7 @@ def test_impl(x): self.check(test_impl, np.ones(10)) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice24(self): def test_impl(m, A, n): B = np.zeros(m) @@ -2893,7 +2890,7 @@ def test_impl(m, A, n): for i in range(-15, 15): self.check(test_impl, 10, np.ones(10), i) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice25(self): def test_impl(m, A, n): B = np.zeros(m) @@ -2904,7 +2901,7 @@ def test_impl(m, A, n): for i in range(-15, 15): self.check(test_impl, 10, np.ones(10), i) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_slice26(self): def test_impl(a): (n,) = a.shape @@ -2920,7 +2917,7 @@ def check(self, pyfunc, *args, **kwargs): cfunc, cpfunc = self.compile_all(pyfunc, *args) self.check_parfors_vs_others(pyfunc, cfunc, cpfunc, *args, **kwargs) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_options(self): def test_impl(a): n = a.shape[0] @@ -2962,7 +2959,7 @@ def check(self, pyfunc, *args, **kwargs): cfunc, cpfunc = self.compile_all(pyfunc, *args) self.check_parfors_vs_others(pyfunc, cfunc, cpfunc, *args, **kwargs) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_bitmask1(self): def test_impl(a, n): b = a > n @@ -2971,7 +2968,7 @@ def test_impl(a, n): self.check(test_impl, np.arange(10), 5) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_bitmask2(self): def test_impl(a, b): a[b] = 0 @@ -2981,7 +2978,7 @@ def test_impl(a, b): b = a > 5 self.check(test_impl, a, b) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_bitmask3(self): def test_impl(a, b): a[b] = a[b] @@ -2991,7 +2988,7 @@ def test_impl(a, b): b = a > 5 self.check(test_impl, a, b) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_bitmask4(self): def test_impl(a, b): a[b] = (2 * a)[b] @@ -3001,7 +2998,7 @@ def test_impl(a, b): b = a > 5 self.check(test_impl, a, b) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_bitmask5(self): def test_impl(a, b): a[b] = a[b] * a[b] @@ -3011,7 +3008,7 @@ def test_impl(a, b): b = a > 5 self.check(test_impl, a, b) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_bitmask6(self): def test_impl(a, b, c): a[b] = c @@ -3036,7 +3033,7 @@ def check(self, pyfunc, *args, **kwargs): cfunc, cpfunc = self.compile_all(pyfunc, *args) self.check_parfors_vs_others(pyfunc, cfunc, cpfunc, *args, **kwargs) - @skip_unsupported + @skip_parfors_unsupported def test_no_warn_if_cache_set(self): def pyfunc(): @@ -3058,7 +3055,7 @@ def pyfunc(): for cres in cfunc.overloads.values()] self.assertEqual(has_dynamic_globals, [False]) - @skip_unsupported + @skip_parfors_unsupported def test_statement_reordering_respects_aliasing(self): def impl(): a = np.zeros(10) @@ -3073,7 +3070,7 @@ def impl(): for line in stdout.getvalue().splitlines(): self.assertEqual('a[3]: 2.0', line) - @skip_unsupported + @skip_parfors_unsupported def test_parfor_ufunc_typing(self): def test_impl(A): return np.isinf(A) @@ -3089,7 +3086,7 @@ def test_impl(A): # recover global state numba.parfor.sequential_parfor_lowering = old_seq_flag - @skip_unsupported + @skip_parfors_unsupported def test_init_block_dce(self): # issue4690 def test_impl(): @@ -3103,7 +3100,7 @@ def test_impl(): self.assertTrue(get_init_block_size(test_impl, ()) == 0) - @skip_unsupported + @skip_parfors_unsupported def test_alias_analysis_for_parfor1(self): def test_impl(): acc = 0 @@ -3115,7 +3112,7 @@ def test_impl(): self.check(test_impl) -@skip_unsupported +@skip_parfors_unsupported class TestParforsDiagnostics(TestParforsBase): def check(self, pyfunc, *args, **kwargs): diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index e8863072cf9..9fbf0a599ed 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -8,11 +8,10 @@ from numba.typed import List, Dict from numba.errors import TypingError from .support import (TestCase, MemoryLeakMixin, unittest, override_config, - forbid_codegen) + forbid_codegen, skip_parfors_unsupported) from numba.unsafe.refcount import get_refcount -from .test_parfors import skip_unsupported as parfors_skip_unsupported # global typed-list for testing purposes global_typed_list = List.empty_list(int32) @@ -153,7 +152,7 @@ def test_unsigned_access(self): self.assertEqual(L.pop(ui32_1), 2) self.assertEqual(L.pop(ui32_0), 123) - @parfors_skip_unsupported + @skip_parfors_unsupported def test_unsigned_prange(self): @njit(parallel=True) def foo(a): From c7e2a489b434f0f69d3bdcc936c37cfcead3959b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 11:46:15 +0000 Subject: [PATCH 229/595] sys.version_info pattern removal --- numba/tests/test_builtins.py | 12 +++--------- numba/tests/test_pycc.py | 6 +----- numba/tests/test_range.py | 8 -------- numba/tests/test_sets.py | 16 +--------------- numba/tests/test_svml.py | 7 +++---- numba/tests/test_unicode_literals.py | 28 ---------------------------- 6 files changed, 8 insertions(+), 69 deletions(-) delete mode 100644 numba/tests/test_unicode_literals.py diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index 716e80ff6ac..fdc9242a6cf 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -791,10 +791,6 @@ def test_reduce_npm(self): with self.assertTypingError(): self.test_reduce(flags=no_pyobj_flags) - # Under Windows, the LLVM "round" intrinsic (used for Python 2) - # mistreats signed zeros. - _relax_round = sys.platform == 'win32' and sys.version_info < (3,) - def test_round1(self, flags=enable_pyobj_flags): pyfunc = round_usecase1 @@ -802,8 +798,7 @@ def test_round1(self, flags=enable_pyobj_flags): cr = compile_isolated(pyfunc, (tp,), flags=flags) cfunc = cr.entry_point values = [-1.6, -1.5, -1.4, -0.5, 0.0, 0.1, 0.5, 0.6, 1.4, 1.5, 5.0] - if not self._relax_round: - values += [-0.1, -0.0] + values += [-0.1, -0.0] for x in values: self.assertPreciseEqual(cfunc(x), pyfunc(x)) @@ -823,9 +818,8 @@ def test_round2(self, flags=enable_pyobj_flags): self.assertPreciseEqual(cfunc(x, n), pyfunc(x, n), prec=prec) expected = pyfunc(-x, n) - if not (expected == 0.0 and self._relax_round): - self.assertPreciseEqual(cfunc(-x, n), pyfunc(-x, n), - prec=prec) + self.assertPreciseEqual(cfunc(-x, n), pyfunc(-x, n), + prec=prec) @tag('important') def test_round2_npm(self): diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index 305a61d98a8..e7d36dbee1f 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -201,8 +201,7 @@ def test_cc_properties(self): self.assertTrue(os.path.basename(f).startswith('pycc_test_simple.'), f) if sys.platform.startswith('linux'): self.assertTrue(f.endswith('.so'), f) - if sys.version_info >= (3,): - self.assertIn('.cpython', f) + self.assertIn('.cpython', f) def test_compile(self): with self.check_cc_compiled(self._test_module.cc) as lib: @@ -357,9 +356,6 @@ def run_python(args): run_python(["-c", code]) def test_setup_py_distutils(self): - if sys.version_info < (3,) and sys.platform == "win32": - # See e.g. https://stackoverflow.com/questions/28931875/problems-finding-vcvarsall-bat-when-using-distutils - self.skipTest("must use setuptools to build extensions for Python 2") self.check_setup_py("setup_distutils.py") @unittest.skipIf(setuptools is None, "test needs setuptools") diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index 62cc477a244..d7cbce9e692 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -98,14 +98,6 @@ def test_loop3_int32(self): for args in arglist: self.assertEqual(cfunc(*args), pyfunc(*args)) - @tag('important') - @unittest.skipIf(sys.version_info >= (3,), "test is Python 2-specific") - def test_xrange(self): - pyfunc = xrange_usecase - cres = compile_isolated(pyfunc, (types.int32,)) - cfunc = cres.entry_point - self.assertEqual(cfunc(5), pyfunc(5)) - @tag('important') def test_range_len1(self): pyfunc = range_len1 diff --git a/numba/tests/test_sets.py b/numba/tests/test_sets.py index 3a33cbd495a..bdb096f0666 100644 --- a/numba/tests/test_sets.py +++ b/numba/tests/test_sets.py @@ -278,10 +278,6 @@ def unique_usecase(src): return res -needs_set_literals = unittest.skipIf(sys.version_info < (2, 7), - "set literals unavailable before Python 2.7") - - class BaseTest(MemoryLeakMixin, TestCase): def setUp(self): @@ -338,29 +334,19 @@ def check(*args): class TestSetLiterals(BaseTest): - @needs_set_literals def test_build_set(self, flags=enable_pyobj_flags): pyfunc = set_literal_return_usecase((1, 2, 3, 2)) self.run_nullary_func(pyfunc, flags=flags) - @needs_set_literals def test_build_heterogeneous_set(self, flags=enable_pyobj_flags): pyfunc = set_literal_return_usecase((1, 2.0, 3j, 2)) self.run_nullary_func(pyfunc, flags=flags) pyfunc = set_literal_return_usecase((2.0, 2)) got, expected = self.run_nullary_func(pyfunc, flags=flags) - # Check that items are inserted in the right order (here the - # result will be {2.0}, not {2}) - # Note: http://bugs.python.org/issue26020 changed the previously invalid - # ordering. - if ((sys.version_info[:2] == (2, 7) and sys.version_info[2] >= 13) or - (sys.version_info[:2] == (3, 5) and sys.version_info[2] >= 3) or - (sys.version_info[:2] >= (3, 6))): - self.assertIs(type(got.pop()), type(expected.pop())) + self.assertIs(type(got.pop()), type(expected.pop())) @tag('important') - @needs_set_literals def test_build_set_nopython(self): arg = list(self.sparse_array(50)) pyfunc = set_literal_convert_usecase(arg) diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 99f6fe8f1d4..87ef02a1505 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -234,10 +234,9 @@ def autogenerate(cls): for mode in "scalar", "range", "prange", "numpy": cls._inject_test(dtype, mode, vlen, flags) # mark important - if sys.version_info[0] > 2: - for n in ( "test_int32_range4_usecase", # issue #3016 - ): - setattr(cls, n, tag("important")(getattr(cls, n))) + for n in ( "test_int32_range4_usecase", # issue #3016 + ): + setattr(cls, n, tag("important")(getattr(cls, n))) TestSVMLGeneration.autogenerate() diff --git a/numba/tests/test_unicode_literals.py b/numba/tests/test_unicode_literals.py deleted file mode 100644 index 2924f284474..00000000000 --- a/numba/tests/test_unicode_literals.py +++ /dev/null @@ -1,28 +0,0 @@ -import sys - -import numba.unittest_support as unittest -from numba import jit -from .support import TestCase - - -def docstring_usecase(): - """\u00e9""" - return 1 - - -@unittest.skipIf(sys.version_info >= (3,), "Python 2-specific test") -class TestFutureUnicodeLiterals(TestCase): - """ - Test issues with unicode_literals on Python 2. - """ - - def test_docstring(self): - """ - Test non-ASCII docstring (issue #1908). - """ - cfunc = jit(nopython=True)(docstring_usecase) - self.assertPreciseEqual(cfunc(), 1) - - -if __name__ == '__main__': - unittest.main() From 0a8faa93aa9f11852dc00cd28d12817c9ec83105 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 11:48:07 +0000 Subject: [PATCH 230/595] sys.version_info pattern removal 2 --- numba/bytecode.py | 2 +- numba/targets/literal.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/numba/bytecode.py b/numba/bytecode.py index 42bef84c0bd..cdb33baeb08 100644 --- a/numba/bytecode.py +++ b/numba/bytecode.py @@ -18,7 +18,7 @@ # The following offset is used as a hack to inject a NOP at the start of the # bytecode. So that function starting with `while True` will not have block-0 # as a jump target. The Lowerer puts argument initialization at block-0. -_FIXED_OFFSET = 2 if sys.version_info[0] >= 3 else 0 +_FIXED_OFFSET = 2 def get_function_object(obj): diff --git a/numba/targets/literal.py b/numba/targets/literal.py index 82ce43c3ae9..076ed140838 100644 --- a/numba/targets/literal.py +++ b/numba/targets/literal.py @@ -18,9 +18,6 @@ def _ov_literally(obj): @overload(literal_unroll) def literal_unroll_impl(container): - from numba.errors import UnsupportedError - if sys.version_info[:2] < (3, 6): - raise UnsupportedError("literal_unroll is only support in Python > 3.5") def impl(container): return container From f5ec0df0b58c9a0048994328d1f7e13bf75ef3f6 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 11:50:36 +0000 Subject: [PATCH 231/595] sys.version_info pattern removal 3 --- numba/bytecode.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/numba/bytecode.py b/numba/bytecode.py index cdb33baeb08..df4d15f1eda 100644 --- a/numba/bytecode.py +++ b/numba/bytecode.py @@ -6,7 +6,6 @@ from collections import namedtuple, OrderedDict import dis import inspect -import sys import itertools from types import CodeType, ModuleType @@ -110,15 +109,9 @@ def block_effect(self): return 0 -if sys.version_info[:2] >= (3, 6): - CODE_LEN = 1 - ARG_LEN = 1 - NO_ARG_LEN = 1 -else: - CODE_LEN = 1 - ARG_LEN = 2 - NO_ARG_LEN = 0 - +CODE_LEN = 1 +ARG_LEN = 1 +NO_ARG_LEN = 1 OPCODE_NOP = dis.opname.index('NOP') @@ -129,9 +122,6 @@ def _unpack_opargs(code): Returns a 4-int-tuple of (bytecode offset, opcode, argument, offset of next bytecode). """ - if sys.version_info[0] < 3: - code = list(map(ord, code)) - extended_arg = 0 n = len(code) offset = i = 0 From 5cc8ed78b5e6333b81ff6ca3cde2002204aa8ac1 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 11:58:47 +0000 Subject: [PATCH 232/595] sys.version_info pattern removal 4 --- numba/compiler.py | 7 +++---- numba/npyufunc/array_exprs.py | 5 +---- numba/tests/test_dispatcher.py | 8 +------- numba/tests/test_runtests.py | 2 -- numba/typing/bufproto.py | 15 ++++----------- 5 files changed, 9 insertions(+), 28 deletions(-) diff --git a/numba/compiler.py b/numba/compiler.py index 89203f58968..35e86a34590 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -158,10 +158,9 @@ def compile_result(**kws): for k in missing: kws[k] = None # Avoid keeping alive traceback variables - if sys.version_info >= (3,): - err = kws['typing_error'] - if err is not None: - kws['typing_error'] = err.with_traceback(None) + err = kws['typing_error'] + if err is not None: + kws['typing_error'] = err.with_traceback(None) return CompileResult(**kws) diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index e15bff9050e..582388f3d82 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -287,10 +287,7 @@ def _arr_expr_to_ast(expr): hex(hash(op)).replace("-", "_")) fn_ast_name = ast.Name(fn_name, ast.Load()) env[fn_name] = op # Stash the ufunc or DUFunc in the environment - if sys.version_info >= (3, 5): - ast_call = ast.Call(fn_ast_name, ast_args, []) - else: - ast_call = ast.Call(fn_ast_name, ast_args, [], None, None) + ast_call = ast.Call(fn_ast_name, ast_args, []) return ast_call, env elif isinstance(expr, ir.Var): return ast.Name(expr.name, ast.Load(), diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 84322390a3d..586918a2348 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -990,13 +990,7 @@ def import_module(self): old = sys.modules.pop(self.modname, None) if old is not None: # Make sure cached bytecode is removed - if sys.version_info >= (3,): - cached = [old.__cached__] - else: - if old.__file__.endswith(('.pyc', '.pyo')): - cached = [old.__file__] - else: - cached = [old.__file__ + 'c', old.__file__ + 'o'] + cached = [old.__cached__] for fn in cached: try: os.unlink(fn) diff --git a/numba/tests/test_runtests.py b/numba/tests/test_runtests.py index 9bd6dbbf000..db3a4e42a9c 100755 --- a/numba/tests/test_runtests.py +++ b/numba/tests/test_runtests.py @@ -74,8 +74,6 @@ def test_module(self): def test_subpackage(self): self.check_testsuite_size(['numba.tests.npyufunc'], 50) - @unittest.skipIf(sys.version_info < (3, 4), - "'--random' only supported on Python 3.4 or higher") def test_random(self): self.check_testsuite_size( ['--random', '0.1', 'numba.tests.npyufunc'], 5) diff --git a/numba/typing/bufproto.py b/numba/typing/bufproto.py index 09ddbb50eb5..fbfde99f8b9 100644 --- a/numba/typing/bufproto.py +++ b/numba/typing/bufproto.py @@ -3,7 +3,6 @@ """ import array -import sys from numba import types @@ -23,8 +22,7 @@ } _type_map[memoryview] = types.MemoryView -if sys.version_info >= (3,): - _type_map[bytes] = types.Bytes +_type_map[bytes] = types.Bytes def decode_pep3118_format(fmt, itemsize): @@ -64,11 +62,6 @@ def infer_layout(val): """ Infer layout of the given memoryview *val*. """ - if sys.version_info >= (3,): - return ('C' if val.c_contiguous else - 'F' if val.f_contiguous else - 'A') - # Python 2: best effort heuristic for 1d arrays - if val.ndim == 1 and val.strides[0] == val.itemsize: - return 'C' - return 'A' + return ('C' if val.c_contiguous else + 'F' if val.f_contiguous else + 'A') From 49f2fa1d0b0fb7ec58c1722fd5f43fe6d303c314 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 12:00:24 +0000 Subject: [PATCH 233/595] sys.version_info pattern removal 5 --- numba/tests/test_array_methods.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index fdf6cba4bfc..2a2000a5d93 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -493,9 +493,8 @@ def check(buf): b = bytearray(range(16)) check(b) - if sys.version_info >= (3,): - check(bytes(b)) - check(memoryview(b)) + check(bytes(b)) + check(memoryview(b)) check(np.arange(12)) b = np.arange(12).reshape((3, 4)) check(b) @@ -610,9 +609,8 @@ def check_arr(arr): arr = np.array([v]).reshape(()) check_arr(arr) - if sys.version_info >= (3,): - arr = np.array(["Hello", "", "world"]) - check_arr(arr) + arr = np.array(["Hello", "", "world"]) + check_arr(arr) def test_array_nonzero(self): self.check_nonzero(array_nonzero) From b7d9919f308264e1c22e17f7a86fb77cca724a87 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 12:28:28 +0000 Subject: [PATCH 234/595] Fix failing tests --- numba/tests/matmul_usecase.py | 34 ++++------------------ numba/tests/test_jit_module.py | 2 +- numba/tests/test_operators.py | 51 +++++++-------------------------- numba/tests/test_tracing.py | 5 ++-- numba/tests/true_div_usecase.py | 9 ------ 5 files changed, 20 insertions(+), 81 deletions(-) delete mode 100644 numba/tests/true_div_usecase.py diff --git a/numba/tests/matmul_usecase.py b/numba/tests/matmul_usecase.py index 1a10f030124..18afff08118 100644 --- a/numba/tests/matmul_usecase.py +++ b/numba/tests/matmul_usecase.py @@ -9,36 +9,14 @@ import numba.unittest_support as unittest from numba.numpy_support import version as numpy_version +def matmul_usecase(x, y): + return x @ y -# The "@" operator only compiles on Python 3.5+. -# It is only supported by Numpy 1.10+. -has_matmul = sys.version_info >= (3, 5) and numpy_version >= (1, 10) - -if has_matmul: - code = """if 1: - def matmul_usecase(x, y): - return x @ y - - def imatmul_usecase(x, y): - x @= y - return x - """ - co = compile(code, "", "exec") - ns = {} - eval(co, globals(), ns) - globals().update(ns) - del code, co, ns - -else: - matmul_usecase = None - imatmul_usecase = None - -needs_matmul = unittest.skipUnless( - has_matmul, - "the matrix multiplication operator needs Python 3.5+ and Numpy 1.10+") - -needs_blas = unittest.skipUnless(has_blas, "BLAS needs Scipy 0.16+") +def imatmul_usecase(x, y): + x @= y + return x +needs_blas = unittest.skipUnless(has_blas, "BLAS needs SciPy 1.0+") class DumbMatrix(object): diff --git a/numba/tests/test_jit_module.py b/numba/tests/test_jit_module.py index 3a4f82aa1fb..ffa7e878293 100644 --- a/numba/tests/test_jit_module.py +++ b/numba/tests/test_jit_module.py @@ -7,10 +7,10 @@ import uuid import numpy as np import logging +from io import StringIO import numba.unittest_support as unittest from numba import dispatcher -from numba.utils import StringIO from numba.tests.support import temp_directory, SerialMixin diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index cba69c86997..8904d3ab454 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -10,9 +10,8 @@ from numba.compiler import compile_isolated, Flags from numba import jit, types, typeinfer, utils, errors from .support import TestCase, tag -from .true_div_usecase import truediv_usecase, itruediv_usecase from .matmul_usecase import (matmul_usecase, imatmul_usecase, DumbMatrix, - needs_matmul, needs_blas) + needs_blas) Noflags = Flags() @@ -56,25 +55,23 @@ def imul_usecase(x, y): return x @staticmethod - def div_usecase(x, y): - return x / y + def floordiv_usecase(x, y): + return x // y @staticmethod - def idiv_usecase(x, y): - x /= y + def ifloordiv_usecase(x, y): + x //= y return x @staticmethod - def floordiv_usecase(x, y): - return x // y + def truediv_usecase(x, y): + return x / y @staticmethod - def ifloordiv_usecase(x, y): - x //= y + def itruediv_usecase(x, y): + x /= y return x - truediv_usecase = staticmethod(truediv_usecase) - itruediv_usecase = staticmethod(itruediv_usecase) if matmul_usecase: matmul_usecase = staticmethod(matmul_usecase) imatmul_usecase = staticmethod(imatmul_usecase) @@ -594,7 +591,7 @@ def test_meth(self): }) generate_binop_tests(locals(), - ('div', 'idiv', 'truediv', 'itruediv'), + ('truediv', 'itruediv'), {'ints': 'run_binop_ints', 'floats': 'run_binop_floats', 'complex': 'run_binop_complex', @@ -637,12 +634,6 @@ def test_floordiv_errors(self, flags=force_pyobj_flags): def test_floordiv_errors_npm(self): self.test_floordiv_errors(flags=Noflags) - def test_div_errors(self, flags=force_pyobj_flags): - self.check_div_errors("div_usecase", "division by zero", flags=flags) - - def test_div_errors_npm(self): - self.test_div_errors(flags=Noflags) - def test_mod_errors(self, flags=force_pyobj_flags): self.check_div_errors("mod_usecase", "modulo by zero", flags=flags) @@ -743,22 +734,6 @@ def test_mul_complex(self, flags=force_pyobj_flags): def test_mul_complex_npm(self): self.test_mul_complex(flags=Noflags) - def test_div_complex(self, flags=force_pyobj_flags): - pyfunc = self.op.div_usecase - - x_operands = [1+0j, 1j, -1-1j] - y_operands = [1, 2, 3] - - types_list = [(types.complex64, types.complex64), - (types.complex128, types.complex128),] - - self.run_test_floats(pyfunc, x_operands, y_operands, types_list, - flags=flags) - - @tag('important') - def test_div_complex_npm(self): - self.test_div_complex(flags=Noflags) - def test_truediv_complex(self, flags=force_pyobj_flags): pyfunc = self.op.truediv_usecase @@ -789,7 +764,6 @@ def test_mod_complex_npm(self): # (just check with simple values; computational tests are in test_linalg) # - @needs_matmul def check_matmul_objmode(self, pyfunc, inplace): # Use dummy objects, to work with any Numpy / Scipy version # (and because Numpy 1.10 doesn't implement "@=") @@ -805,16 +779,13 @@ def check_matmul_objmode(self, pyfunc, inplace): self.assertIsNot(got, a) self.assertIsNot(got, b) - @needs_matmul def test_matmul(self): self.check_matmul_objmode(self.op.matmul_usecase, inplace=False) - @needs_matmul def test_imatmul(self): self.check_matmul_objmode(self.op.imatmul_usecase, inplace=True) @needs_blas - @needs_matmul def check_matmul_npm(self, pyfunc): arrty = types.Array(types.float32, 1, 'C') cres = compile_isolated(pyfunc, (arrty, arrty), flags=Noflags) @@ -828,12 +799,10 @@ def check_matmul_npm(self, pyfunc): self.assertIsNot(got, b) @tag('important') - @needs_matmul def test_matmul_npm(self): self.check_matmul_npm(self.op.matmul_usecase) @tag('important') - @needs_matmul def test_imatmul_npm(self): with self.assertTypingError() as raises: self.check_matmul_npm(self.op.imatmul_usecase) diff --git a/numba/tests/test_tracing.py b/numba/tests/test_tracing.py index 3a23b5594ed..c6d80bcab3d 100644 --- a/numba/tests/test_tracing.py +++ b/numba/tests/test_tracing.py @@ -1,7 +1,8 @@ +from io import StringIO +import logging + import numba.unittest_support as unittest from numba import tracing -from numba.utils import StringIO -import logging logger = logging.getLogger('trace') logger.setLevel(logging.INFO) diff --git a/numba/tests/true_div_usecase.py b/numba/tests/true_div_usecase.py deleted file mode 100644 index dd249822e62..00000000000 --- a/numba/tests/true_div_usecase.py +++ /dev/null @@ -1,9 +0,0 @@ -# These functions have their own module in order to be compiled with the right -# __future__ flag (and be tested alongside the 2.x legacy division operator). - -def truediv_usecase(x, y): - return x / y - -def itruediv_usecase(x, y): - x /= y - return x From ecf12960ac37c8c4d869ffeabdece9b7650e6b13 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 12:52:38 +0000 Subject: [PATCH 235/595] Fix @needs_matmul --- numba/tests/test_linalg.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index 3ccedfbfb99..ea45dbf3280 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -12,7 +12,7 @@ from numba import jit, errors from numba.numpy_support import version as numpy_version from .support import TestCase, tag -from .matmul_usecase import matmul_usecase, needs_matmul, needs_blas +from .matmul_usecase import matmul_usecase, needs_blas _is_armv7l = platform.machine() == 'armv7l' @@ -129,7 +129,6 @@ def assert_mismatching_dtypes(self, cfunc, args, func_name="np.dot()"): % (func_name,), str(raises.exception)) - @needs_blas def check_dot_vv(self, pyfunc, func_name): n = 3 cfunc = jit(nopython=True)(pyfunc) @@ -149,19 +148,20 @@ def check_dot_vv(self, pyfunc, func_name): b = self.sample_vector(n, np.float64) self.assert_mismatching_dtypes(cfunc, (a, b), func_name=func_name) + @needs_blas def test_dot_vv(self): """ Test vector * vector np.dot() """ self.check_dot_vv(dot2, "np.dot()") + @needs_blas def test_vdot(self): """ Test np.vdot() """ self.check_dot_vv(vdot, "np.vdot()") - @needs_blas def check_dot_vm(self, pyfunc2, pyfunc3, func_name): m, n = 2, 3 @@ -213,13 +213,13 @@ def samples(m, n): out = np.empty(m, np.float32) self.assert_mismatching_dtypes(cfunc3, (a, b, out), func_name) + @needs_blas def test_dot_vm(self): """ Test vector * matrix and matrix * vector np.dot() """ self.check_dot_vm(dot2, dot3, "np.dot()") - @needs_blas def check_dot_mm(self, pyfunc2, pyfunc3, func_name): def samples(m, n, k): @@ -277,28 +277,28 @@ def samples(m, n, k): out = np.empty((m, n), np.float32) self.assert_mismatching_dtypes(cfunc3, (a, b, out), func_name) - @tag('important') + @needs_blas def test_dot_mm(self): """ Test matrix * matrix np.dot() """ self.check_dot_mm(dot2, dot3, "np.dot()") - @needs_matmul + @needs_blas def test_matmul_vv(self): """ Test vector @ vector """ self.check_dot_vv(matmul_usecase, "'@'") - @needs_matmul + @needs_blas def test_matmul_vm(self): """ Test vector @ matrix and matrix @ vector """ self.check_dot_vm(matmul_usecase, None, "'@'") - @needs_matmul + @needs_blas def test_matmul_mm(self): """ Test matrix @ matrix From a74d8893ff092c1c07564c5b7fea200fdbdff334 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 13:04:04 +0000 Subject: [PATCH 236/595] remove py2 file stripper --- buildscripts/condarecipe.local/bld.bat | 1 - buildscripts/condarecipe.local/build.sh | 2 -- buildscripts/remove_unwanted_files.py | 38 ------------------------- 3 files changed, 41 deletions(-) delete mode 100644 buildscripts/remove_unwanted_files.py diff --git a/buildscripts/condarecipe.local/bld.bat b/buildscripts/condarecipe.local/bld.bat index 5be39e7b60b..6372f3a4d2e 100644 --- a/buildscripts/condarecipe.local/bld.bat +++ b/buildscripts/condarecipe.local/bld.bat @@ -1,4 +1,3 @@ -%PYTHON% buildscripts/remove_unwanted_files.py %PYTHON% setup.py build install --single-version-externally-managed --record=record.txt exit /b %errorlevel% diff --git a/buildscripts/condarecipe.local/build.sh b/buildscripts/condarecipe.local/build.sh index 7338df6ee88..efb071d3961 100644 --- a/buildscripts/condarecipe.local/build.sh +++ b/buildscripts/condarecipe.local/build.sh @@ -1,5 +1,3 @@ #!/bin/bash -$PYTHON buildscripts/remove_unwanted_files.py - MACOSX_DEPLOYMENT_TARGET=10.10 $PYTHON setup.py build install --single-version-externally-managed --record=record.txt diff --git a/buildscripts/remove_unwanted_files.py b/buildscripts/remove_unwanted_files.py deleted file mode 100644 index b9eacd0bc37..00000000000 --- a/buildscripts/remove_unwanted_files.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -Workaround for a conda-build bug where failing to compile some Python files -results in a build failure. - -See https://github.com/conda/conda-build/issues/1001 -""" - -import os -import sys - - -py2_only_files = [] - -py3_only_files = [ - 'numba/tests/annotation_usecases.py', - 'numba/tests/overload_usecases.py', - 'numba/tests/jitclass_usecases.py', - ] - - -def remove_files(basedir): - """ - Remove unwanted files from the current source tree - """ - if sys.version_info >= (3,): - removelist = py2_only_files - msg = "Python 2-only file" - else: - removelist = py3_only_files - msg = "Python 3-only file" - for relpath in removelist: - path = os.path.join(basedir, relpath) - print("Removing %s %r" % (msg, relpath)) - os.remove(path) - - -if __name__ == "__main__": - remove_files('.') From 8f0aebca9b431611d8a456c185fa0a6de1337802 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 13:14:47 +0000 Subject: [PATCH 237/595] more sys.version_info removing 1 --- numba/targets/hashing.py | 4 +- numba/tests/jitclass_usecases.py | 21 -------- numba/tests/support.py | 15 ++---- numba/tests/test_array_manipulation.py | 8 ++- numba/tests/test_buffer_protocol.py | 75 +++++++++----------------- numba/tests/test_cffi.py | 3 -- numba/tests/test_cfunc.py | 5 +- numba/tests/test_jitclasses.py | 23 +++++--- 8 files changed, 51 insertions(+), 103 deletions(-) delete mode 100644 numba/tests/jitclass_usecases.py diff --git a/numba/targets/hashing.py b/numba/targets/hashing.py index 7612bfc56cb..20793d44909 100644 --- a/numba/targets/hashing.py +++ b/numba/targets/hashing.py @@ -14,10 +14,10 @@ from numba.extending import ( overload, overload_method, intrinsic, register_jitable) -from numba import types, errors +from numba import types, errors, utils from numba.unsafe.bytes import grab_byte, grab_uint64_t -_py38_or_later = sys.version_info[:2] >= (3, 8) +_py38_or_later = utils.PYVERSION >= (3, 8) # This is Py_hash_t, which is a Py_ssize_t, which has sizeof(size_t): # https://github.com/python/cpython/blob/d1dd6be613381b996b9071443ef081de8e5f3aff/Include/pyport.h#L91-L96 # noqa: E501 diff --git a/numba/tests/jitclass_usecases.py b/numba/tests/jitclass_usecases.py deleted file mode 100644 index 5eda1978287..00000000000 --- a/numba/tests/jitclass_usecases.py +++ /dev/null @@ -1,21 +0,0 @@ -""" -Usecases with Python 3 syntax in the signatures. This is a separate module -in order to avoid syntax errors with Python 2. -""" - - -class TestClass1(object): - def __init__(self, x, y, z=1, *, a=5): - self.x = x - self.y = y - self.z = z - self.a = a - - -class TestClass2(object): - def __init__(self, x, y, z=1, *args, a=5): - self.x = x - self.y = y - self.z = z - self.args = args - self.a = a diff --git a/numba/tests/support.py b/numba/tests/support.py index 573777d1d6a..73e92a9a56c 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -512,21 +512,15 @@ def tweak_code(func, codestring=None, consts=None): codestring = co.co_code if consts is None: consts = co.co_consts - if sys.version_info >= (3, 8): + if utils.PYVERSION >= (3, 8): new_code = tp(co.co_argcount, co.co_posonlyargcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize, co.co_flags, codestring, consts, co.co_names, co.co_varnames, co.co_filename, co.co_name, co.co_firstlineno, co.co_lnotab) - elif sys.version_info >= (3,): - new_code = tp(co.co_argcount, co.co_kwonlyargcount, co.co_nlocals, - co.co_stacksize, co.co_flags, codestring, - consts, co.co_names, co.co_varnames, - co.co_filename, co.co_name, co.co_firstlineno, - co.co_lnotab) else: - new_code = tp(co.co_argcount, co.co_nlocals, + new_code = tp(co.co_argcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize, co.co_flags, codestring, consts, co.co_names, co.co_varnames, co.co_filename, co.co_name, co.co_firstlineno, @@ -595,9 +589,8 @@ def import_dynamic(modname): Import and return a module of the given name. Care is taken to avoid issues due to Python's internal directory caching. """ - if sys.version_info >= (3, 3): - import importlib - importlib.invalidate_caches() + import importlib + importlib.invalidate_caches() __import__(modname) return sys.modules[modname] diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 5aa39daa7f1..d5b23758602 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -1,10 +1,9 @@ from functools import partial from itertools import permutations -import numba.unittest_support as unittest -import sys import numpy as np +import numba.unittest_support as unittest from numba.numpy_support import version as np_version from numba.compiler import compile_isolated, Flags from numba import jit, njit, types, from_dtype, errors, typeof @@ -841,9 +840,8 @@ def array_like_variations(): yield 2 + 1j # the following are not array-like, but numpy 1.15+ does not raise yield None - if not sys.version_info < (3,): - yield 'a_string' - yield '' + yield 'a_string' + yield '' @unittest.skipUnless(np_version >= (1, 15), "flatnonzero array-like handling per 1.15+") diff --git a/numba/tests/test_buffer_protocol.py b/numba/tests/test_buffer_protocol.py index fccd0e9831c..bad1ab67c92 100644 --- a/numba/tests/test_buffer_protocol.py +++ b/numba/tests/test_buffer_protocol.py @@ -1,5 +1,4 @@ import array -import sys import numpy as np @@ -56,13 +55,6 @@ def attrgetter(attr): shape_usecase = attrgetter("shape") strides_usecase = attrgetter("strides") -# On Python 2, array.array doesn't support the PEP 3118 buffer API -array_supported = sys.version_info >= (3,) -# On Python 2, bytes is really the str object -bytes_supported = sys.version_info >= (3,) -# On Python 2, indexing a memoryview returns bytes -memoryview_structured_indexing = sys.version_info >= (3,) - class TestBufferProtocol(MemoryLeakMixin, TestCase): """ @@ -119,13 +111,11 @@ def _memoryviews(self): yield memoryview(arr) def _readonlies(self): - if bytes_supported: - yield b"xyz" - if memoryview_structured_indexing: - yield memoryview(b"abcdefghi") - arr = np.arange(5) - arr.setflags(write=False) - yield memoryview(arr) + yield b"xyz" + yield memoryview(b"abcdefghi") + arr = np.arange(5) + arr.setflags(write=False) + yield memoryview(arr) def _check_unary(self, jitfunc, *args): pyfunc = jitfunc.py_func @@ -180,50 +170,40 @@ def check_getslice(self, obj): def test_len(self): self.check_len(bytearray(5)) - if bytes_supported: - self.check_len(b"xyz") + self.check_len(b"xyz") for mem in self._memoryviews(): self.check_len(mem) - if array_supported: - for arr in self._arrays(): - self.check_len(arr) + for arr in self._arrays(): + self.check_len(arr) for buf in self._readonlies(): self.check_getitem(buf) def test_getitem(self): self.check_getitem(bytearray(b"abc")) - if bytes_supported: - self.check_getitem(b"xyz") - if memoryview_structured_indexing: - for mem in self._memoryviews(): - self.check_getitem(mem) - if array_supported: - for arr in self._arrays(): - self.check_getitem(arr) + self.check_getitem(b"xyz") + for mem in self._memoryviews(): + self.check_getitem(mem) + for arr in self._arrays(): + self.check_getitem(arr) for buf in self._readonlies(): self.check_getitem(buf) def test_getslice(self): with self.assertTypingError(): self.check_getslice(bytearray(b"abcde")) - if bytes_supported: - self.check_getslice(b"xyzuvw") - if memoryview_structured_indexing: - self.check_getslice(memoryview(b"xyzuvw")) - if array_supported: - with self.assertTypingError(): - self.check_getslice(array.array('i', range(10))) + self.check_getslice(b"xyzuvw") + self.check_getslice(memoryview(b"xyzuvw")) + with self.assertTypingError(): + self.check_getslice(array.array('i', range(10))) for buf in self._readonlies(): self.check_getitem(buf) def test_setitem(self): self.check_setitem(bytearray(b"abcdefghi")) - if array_supported: - for arr in self._arrays(): - self.check_setitem(arr) - if memoryview_structured_indexing: - for mem in self._memoryviews(): - self.check_getitem(mem) + for arr in self._arrays(): + self.check_setitem(arr) + for mem in self._memoryviews(): + self.check_getitem(mem) # Read-only buffers for buf in self._readonlies(): with self.assertTypingError(): @@ -231,13 +211,10 @@ def test_setitem(self): def test_iter(self): self.check_iter(bytearray(b"abc")) - if bytes_supported: - self.check_iter(b"xyz") - if memoryview_structured_indexing: - self.check_iter(memoryview(b"xyz")) - if array_supported: - for arr in self._arrays(): - self.check_iter(arr) + self.check_iter(b"xyz") + self.check_iter(memoryview(b"xyz")) + for arr in self._arrays(): + self.check_iter(arr) for buf in self._readonlies(): self.check_getitem(buf) @@ -294,8 +271,6 @@ def test_readonly(self): m = memoryview(bytearray(b"xyz")) self.assertIs(readonly_usecase(m), False) - @unittest.skipUnless(sys.version_info >= (3,), - "memoryview.*contiguous doesn't exist on 2.7") def test_contiguous(self): m = memoryview(bytearray(b"xyz")) self.assertIs(contiguous_usecase(m), True) diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index 1205bb30686..3fde5059f8b 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -1,6 +1,5 @@ import array import numpy as np -import sys from numba import unittest_support as unittest from numba import jit, cffi_support, types, errors @@ -122,8 +121,6 @@ def test_from_buffer_struct(self): imag_cfunc(x, y) np.testing.assert_equal(x.imag, y) - @unittest.skipIf(sys.version_info < (3,), - "buffer protocol on array.array needs Python 3+") def test_from_buffer_pyarray(self): pyfunc = mod.vector_sin_float32 cfunc = jit(nopython=True)(pyfunc) diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index 5894d663e95..cfa815e6e63 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -162,10 +162,7 @@ def test_errors(self): self.assertPreciseEqual(res, 0.0) err = err.getvalue() self.assertIn("ZeroDivisionError:", err) - if sys.version_info >= (3,): - self.assertIn("Exception ignored", err) - else: - self.assertIn(" ignored", err) + self.assertIn("Exception ignored", err) def test_llvm_ir(self): f = cfunc(add_sig)(add_usecase) diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index 942d251a69a..47ddb54a0f2 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -1,7 +1,6 @@ from collections import OrderedDict import ctypes import random -import sys import pickle import numpy as np @@ -16,9 +15,22 @@ from numba.runtime.nrt import MemInfo from numba.errors import LoweringError -# there are some python 3 specific syntax tests -if sys.version_info >= (3,): - from .jitclass_usecases import TestClass1, TestClass2 + +class TestClass1(object): + def __init__(self, x, y, z=1, *, a=5): + self.x = x + self.y = y + self.z = z + self.a = a + + +class TestClass2(object): + def __init__(self, x, y, z=1, *args, a=5): + self.x = x + self.y = y + self.z = z + self.args = args + self.a = a def _get_meminfo(box): @@ -568,7 +580,6 @@ def access_dunder(inst): access_dunder.py_func(inst) self.assertIn('_TestJitClass__value', str(raises.exception)) - @unittest.skipIf(sys.version_info < (3,), "Python 3-specific test") def test_annotations(self): """ Methods with annotations should compile fine (issue #1911). @@ -647,7 +658,6 @@ def __init__(self, x, y, z=1): self.assertEqual(tc.y, 2) self.assertEqual(tc.z, 5) - @unittest.skipIf(sys.version_info < (3,), "Python 3-specific test") def test_default_args_keyonly(self): spec = [('x', int32), ('y', int32), @@ -680,7 +690,6 @@ def test_default_args_keyonly(self): self.assertEqual(tc.z, 1) self.assertEqual(tc.a, 5) - @unittest.skipIf(sys.version_info < (3,), "Python 3-specific test") def test_default_args_starargs_and_keyonly(self): spec = [('x', int32), ('y', int32), From 2fd4bd00f54f663e11af004382245ca398bffb04 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 13:17:56 +0000 Subject: [PATCH 238/595] more sys.version_info removing 2 --- numba/tests/test_lists.py | 4 ---- numba/tests/test_nrt.py | 4 ---- numba/tests/test_parfors.py | 7 +++---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 119c3ff3150..1d14bc7fe91 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -636,13 +636,9 @@ def test_count(self): for v in range(5): self.assertPreciseEqual(cfunc(18, v), pyfunc(18, v)) - @unittest.skipUnless(sys.version_info >= (3, 3), - "list.clear() needs Python 3.3+") def test_clear(self): self.check_unary_with_size(list_clear) - @unittest.skipUnless(sys.version_info >= (3, 3), - "list.copy() needs Python 3.3+") def test_copy(self): self.check_unary_with_size(list_copy) diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 2ea5120bb8c..d89fd8f42f9 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -117,7 +117,6 @@ def test_meminfo_refct_2(self): del mi self.assertEqual(Dummy.alive, 0) - @unittest.skipIf(sys.version_info < (3,), "memoryview not supported") def test_fake_memoryview(self): d = Dummy() self.assertEqual(Dummy.alive, 1) @@ -140,7 +139,6 @@ def test_fake_memoryview(self): del mview self.assertEqual(Dummy.alive, 0) - @unittest.skipIf(sys.version_info < (3,), "memoryview not supported") def test_memoryview(self): from ctypes import c_uint32, c_void_p, POINTER, cast @@ -219,8 +217,6 @@ def test_buffer(self): # consumed by another thread. -@unittest.skipUnless(sys.version_info >= (3, 4), - "need Python 3.4+ for the tracemalloc module") class TestTracemalloc(unittest.TestCase): """ Test NRT-allocated memory can be tracked by tracemalloc. diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index c4957750649..fcd48b95916 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -20,7 +20,7 @@ import numba from numba import unittest_support as unittest -from numba import njit, prange, stencil, inline_closurecall +from numba import njit, prange, stencil, inline_closurecall, utils from numba import compiler, typing, errors, typed_passes from numba.targets import cpu from numba import types @@ -1623,10 +1623,9 @@ def generate_prange_func(self, pyfunc, patch_instance): # create new code parts co_args = [pyfunc_code.co_argcount] - if sys.version_info >= (3, 8): + if utils.PYVERSION >= (3, 8): co_args.append(pyfunc_code.co_posonlyargcount) - if sys.version_info > (3, 0): - co_args.append(pyfunc_code.co_kwonlyargcount) + co_args.append(pyfunc_code.co_kwonlyargcount) co_args.extend([pyfunc_code.co_nlocals, pyfunc_code.co_stacksize, pyfunc_code.co_flags, From 21078a5c12c1cc3cb2ac7a9466bbe623b050bb08 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 13:22:52 +0000 Subject: [PATCH 239/595] more sys.version_info removing 3 --- numba/tests/test_pycc.py | 3 +- numba/tests/test_random.py | 135 ++++++++++++++----------------------- 2 files changed, 53 insertions(+), 85 deletions(-) diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index e7d36dbee1f..778378b9beb 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -17,6 +17,7 @@ import llvmlite.binding as ll from numba import unittest_support as unittest +from numba import utils from numba.pycc import main from numba.pycc.decorators import clear_export_registry from numba.pycc.platform import find_shared_ending, find_pyext_ending @@ -234,7 +235,7 @@ def test_compile_for_cpu_host(self): @tag('important') @unittest.skipIf(sys.platform == 'darwin' and - sys.version_info[:2] == (3, 8), + utils.PYVERSION == (3, 8), 'distutils incorrectly using gcc on python 3.8 builds') def test_compile_helperlib(self): with self.check_cc_compiled(self._test_module.cc_helperlib) as lib: diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index 78d8019e7c2..436162da507 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -401,24 +401,22 @@ def _check_randrange(self, func1, func2, func3, ptr, max_width, is_numpy, tp=Non if func3 is not None: ints.append(func3(5, 500000000, 3)) self.assertEqual(len(ints), len(set(ints)), ints) - # Our implementation follows Python 3's. - if sys.version_info >= (3,): - if is_numpy: - rr = self._follow_numpy(ptr).randint - else: - rr = self._follow_cpython(ptr).randrange - widths = [w for w in [1, 5, 8, 5000, 2**40, 2**62 + 2**61] if w < max_width] - pydtype = tp if is_numpy and np.__version__ >= '1.11.0' else None - for width in widths: - self._check_dist(func1, rr, [(width,)], niters=10, - pydtype=pydtype) - self._check_dist(func2, rr, [(-2, 2 +width)], niters=10, - pydtype=pydtype) - if func3 is not None: - self.assertPreciseEqual(func3(-2, 2 + width, 6), - rr(-2, 2 + width, 6)) - self.assertPreciseEqual(func3(2 + width, 2, -3), - rr(2 + width, 2, -3)) + if is_numpy: + rr = self._follow_numpy(ptr).randint + else: + rr = self._follow_cpython(ptr).randrange + widths = [w for w in [1, 5, 8, 5000, 2**40, 2**62 + 2**61] if w < max_width] + pydtype = tp if is_numpy else None + for width in widths: + self._check_dist(func1, rr, [(width,)], niters=10, + pydtype=pydtype) + self._check_dist(func2, rr, [(-2, 2 +width)], niters=10, + pydtype=pydtype) + if func3 is not None: + self.assertPreciseEqual(func3(-2, 2 + width, 6), + rr(-2, 2 + width, 6)) + self.assertPreciseEqual(func3(2 + width, 2, -3), + rr(2 + width, 2, -3)) # Empty ranges self.assertRaises(ValueError, func1, 0) self.assertRaises(ValueError, func1, -5) @@ -456,13 +454,12 @@ def _check_randint(self, func, ptr, max_width): for i in range(10): ints.append(func(5, 500000000)) self.assertEqual(len(ints), len(set(ints)), ints) - # Our implementation follows Python 3's. - if sys.version_info >= (3,): - r = self._follow_cpython(ptr) - for args in [(1, 5), (13, 5000), (20, 2**62 + 2**61)]: - if args[1] > max_width: - continue - self._check_dist(func, r.randint, [args], niters=10) + + r = self._follow_cpython(ptr) + for args in [(1, 5), (13, 5000), (20, 2**62 + 2**61)]: + if args[1] > max_width: + continue + self._check_dist(func, r.randint, [args], niters=10) # Empty ranges self.assertRaises(ValueError, func, 5, 4) self.assertRaises(ValueError, func, 5, 2) @@ -567,7 +564,6 @@ def _check_vonmisesvariate(self, func, ptr): """ Check a vonmisesvariate()-like function. """ - # Our implementation follows Python 2.7+'s. r = self._follow_cpython(ptr) self._check_dist(func, r.vonmisesvariate, [(0.5, 2.5)]) @@ -584,7 +580,6 @@ def _check_expovariate(self, func, ptr): Check a expovariate()-like function. Note the second argument is inversed compared to np.random.exponential(). """ - # Our implementation follows Numpy's (and Python 2.7+'s). r = self._follow_numpy(ptr) for lambd in (0.2, 0.5, 1.5): for i in range(3): @@ -598,7 +593,6 @@ def _check_exponential(self, func1, func0, ptr): """ Check a exponential()-like function. """ - # Our implementation follows Numpy's (and Python 2.7+'s). r = self._follow_numpy(ptr) if func1 is not None: self._check_dist(func1, r.exponential, [(0.5,), (1.0,), (1.5,)]) @@ -853,31 +847,19 @@ def _check_shuffle(self, func, ptr, is_numpy): """ Check a shuffle()-like function for arrays. """ - # Our implementation follows Python 3's. arrs = [np.arange(20), np.arange(32).reshape((8, 4))] - if sys.version_info >= (3,): - if is_numpy: - r = self._follow_numpy(ptr) - else: - r = self._follow_cpython(ptr) - for a in arrs: - for i in range(3): - got = a.copy() - expected = a.copy() - func(got) - if is_numpy or len(a.shape) == 1: - r.shuffle(expected) - self.assertPreciseEqual(got, expected) + if is_numpy: + r = self._follow_numpy(ptr) else: - # Sanity check - for a in arrs: - for i in range(3): - b = a.copy() - func(b) - self.assertFalse(np.array_equal(a, b)) - self.assertTrue(np.array_equal(np.sort(a, axis=0), - np.sort(b, axis=0))) - a = b + r = self._follow_cpython(ptr) + for a in arrs: + for i in range(3): + got = a.copy() + expected = a.copy() + func(got) + if is_numpy or len(a.shape) == 1: + r.shuffle(expected) + self.assertPreciseEqual(got, expected) # Test with an arbitrary buffer-providing object a = arrs[0] b = a.copy() @@ -929,40 +911,25 @@ def test_numpy_gauss_startup(self): self._check_startup_randomness("numpy_normal", (1.0, 1.0)) def test_numpy_random_permutation(self): - # Our implementation follows Python 3's. func = jit_unary("np.random.permutation") - if sys.version_info >= (3,): - r = self._follow_numpy(get_np_state_ptr()) - for s in [5, 10, 15, 20]: - a = np.arange(s) - b = a.copy() - # Test array version - self.assertPreciseEqual(func(a), r.permutation(a)) - # Test int version - self.assertPreciseEqual(func(s), r.permutation(s)) - # Permutation should not modify its argument - self.assertPreciseEqual(a, b) - # Check multi-dimensional arrays - arrs = [np.arange(10).reshape(2, 5), - np.arange(27).reshape(3, 3, 3), - np.arange(36).reshape(2, 3, 3, 2)] - for a in arrs: - b = a.copy() - self.assertPreciseEqual(func(a), r.permutation(a)) - self.assertPreciseEqual(a, b) - else: - # Sanity check - arrs = [np.arange(20), np.arange(20).reshape(5, 2, 2)] - for a in arrs: - checked = 0 - while checked < 3: - b = func(a) - # check that permuted arrays are equal when sorted - # account for the possibility of the identity permutation - if not np.array_equal(a, b): - self.assertTrue(np.array_equal(np.sort(a, axis=0), - np.sort(b, axis=0))) - checked += 1 + r = self._follow_numpy(get_np_state_ptr()) + for s in [5, 10, 15, 20]: + a = np.arange(s) + b = a.copy() + # Test array version + self.assertPreciseEqual(func(a), r.permutation(a)) + # Test int version + self.assertPreciseEqual(func(s), r.permutation(s)) + # Permutation should not modify its argument + self.assertPreciseEqual(a, b) + # Check multi-dimensional arrays + arrs = [np.arange(10).reshape(2, 5), + np.arange(27).reshape(3, 3, 3), + np.arange(36).reshape(2, 3, 3, 2)] + for a in arrs: + b = a.copy() + self.assertPreciseEqual(func(a), r.permutation(a)) + self.assertPreciseEqual(a, b) class TestRandomArrays(BaseTest): From b5f26fe7eb9b7ed1829c58132be66d360e207a6e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 13:27:35 +0000 Subject: [PATCH 240/595] more sys.version_info removing 4 --- numba/tests/test_typeof.py | 46 ++++++++++++++++--------------------- numba/tests/test_unicode.py | 11 +++------ 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 8a2a77dce3c..3010f9ea7e5 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -1,13 +1,10 @@ """ Tests for the typeof() machinery. """ - - import array from collections import namedtuple import enum import mmap -import sys import numpy as np @@ -142,18 +139,17 @@ def check(arr, dtype, ndim, layout, aligned): check(arr, rec_ty, 1, "C", True) def test_buffers(self): - if sys.version_info >= (3,): - b = b"xx" - ty = typeof(b) - self.assertEqual(ty, types.Bytes(types.uint8, 1, "C")) - self.assertFalse(ty.mutable) - ty = typeof(memoryview(b)) - self.assertEqual(ty, types.MemoryView(types.uint8, 1, "C", - readonly=True)) - self.assertFalse(ty.mutable) - ty = typeof(array.array('i', [0, 1, 2])) - self.assertEqual(ty, types.PyArray(types.int32, 1, "C")) - self.assertTrue(ty.mutable) + b = b"xx" + ty = typeof(b) + self.assertEqual(ty, types.Bytes(types.uint8, 1, "C")) + self.assertFalse(ty.mutable) + ty = typeof(memoryview(b)) + self.assertEqual(ty, types.MemoryView(types.uint8, 1, "C", + readonly=True)) + self.assertFalse(ty.mutable) + ty = typeof(array.array('i', [0, 1, 2])) + self.assertEqual(ty, types.PyArray(types.int32, 1, "C")) + self.assertTrue(ty.mutable) b = bytearray(10) ty = typeof(b) @@ -458,14 +454,13 @@ def test_buffers(self): m_uint8_1d = compute_fingerprint(memoryview(bytearray())) distinct.add(m_uint8_1d) - if sys.version_info >= (3,): - arr = array.array('B', [42]) + arr = array.array('B', [42]) + distinct.add(compute_fingerprint(arr)) + self.assertEqual(compute_fingerprint(memoryview(arr)), m_uint8_1d) + for array_code in 'bi': + arr = array.array(array_code, [0, 1, 2]) distinct.add(compute_fingerprint(arr)) - self.assertEqual(compute_fingerprint(memoryview(arr)), m_uint8_1d) - for array_code in 'bi': - arr = array.array(array_code, [0, 1, 2]) - distinct.add(compute_fingerprint(arr)) - distinct.add(compute_fingerprint(memoryview(arr))) + distinct.add(compute_fingerprint(memoryview(arr))) arr = np.empty(16, dtype=np.uint8) distinct.add(compute_fingerprint(arr)) @@ -480,10 +475,9 @@ def test_buffers(self): distinct.add(compute_fingerprint(arr)) distinct.add(compute_fingerprint(memoryview(arr))) - if sys.version_info >= (3,): - m = mmap.mmap(-1, 16384) - distinct.add(compute_fingerprint(m)) - self.assertEqual(compute_fingerprint(memoryview(m)), m_uint8_1d) + m = mmap.mmap(-1, 16384) + distinct.add(compute_fingerprint(m)) + self.assertEqual(compute_fingerprint(memoryview(m)), m_uint8_1d) def test_dtype(self): distinct = DistinctChecker() diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 92e7931a1f1..356e18a2e47 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -1,19 +1,14 @@ # -*- coding: utf-8 -*- - -# This file tests Python 3.4 style unicode strings -# Tests should be skipped on Python < 3.4 - - -import sys from itertools import product from itertools import permutations -from numba import njit, types +from numba import njit, types, utils import numba.unittest_support as unittest from .support import (TestCase, no_pyobj_flags, MemoryLeakMixin) from numba.errors import TypingError -_py37_or_later = sys.version_info[:2] >= (3, 7) + +_py37_or_later = utils.PYVERSION >= (3, 7) def isascii(s): From 236c0b9ff292a8ad52b3dac436c0ac9994ae4e03 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 13:29:32 +0000 Subject: [PATCH 241/595] more sys.version_info removing 5 --- numba/unicode.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/numba/unicode.py b/numba/unicode.py index f5b113d795e..9ad867c1c68 100644 --- a/numba/unicode.py +++ b/numba/unicode.py @@ -19,8 +19,7 @@ from numba.targets.imputils import (lower_constant, lower_cast, lower_builtin, iternext_impl, impl_ret_new_ref, RefType) from numba.datamodel import register_default, StructModel -from numba import cgutils -from numba import types +from numba import cgutils, utils, types from numba.pythonapi import ( PY_UNICODE_1BYTE_KIND, PY_UNICODE_2BYTE_KIND, @@ -50,7 +49,7 @@ _PyUnicode_IsDecimalDigit) -_py38_or_later = sys.version_info[:2] >= (3, 8) +_py38_or_later = utils.PYVERSION >= (3, 8) # DATA MODEL @@ -1841,7 +1840,7 @@ def impl(a): return impl -if sys.version_info[:2] >= (3, 7): +if utils.PYVERSION >= (3, 7): @overload_method(types.UnicodeType, 'isascii') def unicode_isascii(data): """Implements UnicodeType.isascii()""" From d6beb3dd63add52ccdea3370a6907577716a9fa4 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Thu, 23 Jan 2020 06:54:04 -0800 Subject: [PATCH 242/595] CUDA: Add a way to get the default stream The default stream is obtained with `cuda.default_stream()` - passing the default stream as the `stream` parameter to `numba.cuda` functions which accept them enables asynchronous execution for them on the default stream. --- numba/cuda/api.py | 8 ++++++++ numba/cuda/cudadrv/driver.py | 11 +++++++++-- numba/cuda/tests/cudadrv/test_cuda_driver.py | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/numba/cuda/api.py b/numba/cuda/api.py index db8e95e6833..1b2a2a3d471 100644 --- a/numba/cuda/api.py +++ b/numba/cuda/api.py @@ -270,6 +270,14 @@ def stream(): """ return current_context().create_stream() +@require_context +def default_stream(): + """default_stream() + + Get the default CUDA stream. + """ + return current_context().get_default_stream() + # Page lock @require_context @contextlib.contextmanager diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index 4d949d1eb98..e6b36b8746b 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -892,6 +892,9 @@ def create_module_image(self, image): def unload_module(self, module): del self.modules[module.handle.value] + def get_default_stream(self): + return Stream(weakref.proxy(self), drvapi.cu_stream(0), None) + def create_stream(self): handle = drvapi.cu_stream() driver.cuStreamCreate(byref(handle), 0) @@ -1408,10 +1411,14 @@ def __init__(self, context, handle, finalizer): weakref.finalize(self, finalizer) def __int__(self): - return self.handle.value + # The default stream's handle.value is 0, which gives `None` + return self.handle.value or 0 def __repr__(self): - return "" % (self.handle.value, self.context) + if self.handle.value: + return "" % (self.handle.value, self.context) + else: + return "" % self.context def synchronize(self): ''' diff --git a/numba/cuda/tests/cudadrv/test_cuda_driver.py b/numba/cuda/tests/cudadrv/test_cuda_driver.py index d74a3433685..cea5862a9b4 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_driver.py +++ b/numba/cuda/tests/cudadrv/test_cuda_driver.py @@ -93,7 +93,7 @@ def test_cuda_driver_basic(self): module.unload() - def test_cuda_driver_stream(self): + def test_cuda_driver_stream_operations(self): module = self.context.create_module_ptx(self.ptx) function = module.get_function('_Z10helloworldPi') @@ -113,6 +113,21 @@ def test_cuda_driver_stream(self): for i, v in enumerate(array): self.assertEqual(i, v) + def test_cuda_driver_default_stream(self): + # Test properties of the default stream + ds = self.context.get_default_stream() + self.assertIn("Default CUDA stream", repr(ds)) + self.assertEqual(0, int(ds)) + self.assertTrue(ds) + + def test_cuda_driver_stream(self): + # Test properties of non-default streams + s = self.context.create_stream() + self.assertIn("CUDA stream", repr(s)) + self.assertNotIn("Default", repr(s)) + self.assertNotEqual(0, int(s)) + self.assertTrue(s) + def test_cuda_driver_occupancy(self): module = self.context.create_module_ptx(self.ptx) function = module.get_function('_Z10helloworldPi') From 0c2cd5efa4ef1410a0cfefabe5079e0e33baddd8 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Thu, 23 Jan 2020 15:33:31 +0000 Subject: [PATCH 243/595] Add documentation for the default stream --- docs/source/cuda-reference/host.rst | 6 +++++- docs/source/cuda/memory.rst | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/source/cuda-reference/host.rst b/docs/source/cuda-reference/host.rst index 1a8887430ba..c19b9ebed96 100644 --- a/docs/source/cuda-reference/host.rst +++ b/docs/source/cuda-reference/host.rst @@ -141,10 +141,14 @@ transfers and kernel execution. For further details on streams, see the `CUDA C Programming Guide Streams section `_. -To create a stream: +To create a new stream: .. autofunction:: numba.cuda.stream +To get the default stream: + +.. autofunction:: numba.cuda.default_stream + Streams are instances of :class:`numba.cuda.cudadrv.driver.Stream`: .. autoclass:: numba.cuda.cudadrv.driver.Stream diff --git a/docs/source/cuda/memory.rst b/docs/source/cuda/memory.rst index c9770f352b9..df61ff061f3 100644 --- a/docs/source/cuda/memory.rst +++ b/docs/source/cuda/memory.rst @@ -56,9 +56,16 @@ Pinned memory Streams ======= +Streams can be passed to functions that accept them (e.g. copies between the +host and device) and into kernel launch configurations so that the operations +are executed asynchronously. + .. autofunction:: numba.cuda.stream :noindex: +.. autofunction:: numba.cuda.default_stream + :noindex: + CUDA streams have the following methods: .. autoclass:: numba.cuda.cudadrv.driver.Stream @@ -184,4 +191,4 @@ Sometimes, it is desired to defer resource deallocation until a code section ends. Most often, users want to avoid any implicit synchronization due to deallocation. This can be done by using the following context manager: -.. autofunction:: numba.cuda.defer_cleanup \ No newline at end of file +.. autofunction:: numba.cuda.defer_cleanup From 23aaad9106ae276f97ea973226dd9f07e7e7dd57 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 15:55:25 +0000 Subject: [PATCH 244/595] Fix up C code --- numba/_dispatcher.c | 5 -- numba/_dynfunc.c | 15 ---- numba/_helperlib.c | 53 +------------- numba/_helpermod.c | 2 - numba/_math_c99.h | 3 +- numba/_typeof.c | 24 ++----- numba/jitclass/_box.c | 5 -- numba/mviewbuf.c | 134 +++++++----------------------------- numba/npyufunc/_internal.c | 14 ---- numba/pycc/modulemixin.c | 26 ++----- numba/runtime/_nrt_python.c | 39 ----------- 11 files changed, 40 insertions(+), 280 deletions(-) diff --git a/numba/_dispatcher.c b/numba/_dispatcher.c index da7c9b0feba..892076c2116 100644 --- a/numba/_dispatcher.c +++ b/numba/_dispatcher.c @@ -608,12 +608,7 @@ static PyMemberDef Dispatcher_members[] = { static PyTypeObject DispatcherType = { -#if (PY_MAJOR_VERSION < 3) - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#else PyVarObject_HEAD_INIT(NULL, 0) -#endif "_dispatcher.Dispatcher", /* tp_name */ sizeof(DispatcherObject), /* tp_basicsize */ 0, /* tp_itemsize */ diff --git a/numba/_dynfunc.c b/numba/_dynfunc.c index b3f689df9b3..ed01f8606c3 100644 --- a/numba/_dynfunc.c +++ b/numba/_dynfunc.c @@ -87,12 +87,7 @@ env_new(PyTypeObject* type, PyObject* args, PyObject* kwds) static PyTypeObject EnvironmentType = { -#if (PY_MAJOR_VERSION < 3) - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#else PyVarObject_HEAD_INIT(NULL, 0) -#endif "_dynfunc.Environment", /*tp_name*/ sizeof(EnvironmentObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -183,12 +178,7 @@ closure_dealloc(ClosureObject *clo) } static PyTypeObject ClosureType = { -#if (PY_MAJOR_VERSION < 3) - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#else PyVarObject_HEAD_INIT(NULL, 0) -#endif "_dynfunc._Closure", /*tp_name*/ sizeof(ClosureObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -385,12 +375,7 @@ generator_iternext(GeneratorObject *gen) } static PyTypeObject GeneratorType = { -#if (PY_MAJOR_VERSION < 3) - PyObject_HEAD_INIT(NULL) - 0, /* ob_size*/ -#else PyVarObject_HEAD_INIT(NULL, 0) -#endif "_dynfunc._Generator", /* tp_name*/ offsetof(GeneratorObject, state), /* tp_basicsize*/ 1, /* tp_itemsize*/ diff --git a/numba/_helperlib.c b/numba/_helperlib.c index 1cbd220d43f..ba00b705b44 100644 --- a/numba/_helperlib.c +++ b/numba/_helperlib.c @@ -255,36 +255,8 @@ numba_extract_record_data(PyObject *recordobj, Py_buffer *pbuf) { if (!attrdata) return NULL; if (-1 == PyObject_GetBuffer(attrdata, pbuf, 0)){ - #if PY_MAJOR_VERSION >= 3 - Py_DECREF(attrdata); - return NULL; - #else - /* HACK!!! */ - /* In Python 2.6, it will report no buffer interface for record - even though it should */ - PyBufferObject_Hack *hack; - - /* Clear the error */ - PyErr_Clear(); - - hack = (PyBufferObject_Hack*) attrdata; - - if (hack->b_base == NULL) { - ptr = hack->b_ptr; - } else { - PyBufferProcs *bp; - readbufferproc proc = NULL; - - bp = hack->b_base->ob_type->tp_as_buffer; - /* FIXME Ignoring any flag. Just give me the pointer */ - proc = (readbufferproc)bp->bf_getreadbuffer; - if ((*proc)(hack->b_base, 0, &ptr) <= 0) { - Py_DECREF(attrdata); - return NULL; - } - ptr = (char*)ptr + hack->b_offset; - } - #endif + Py_DECREF(attrdata); + return NULL; } else { ptr = pbuf->buf; } @@ -810,12 +782,6 @@ NUMBA_EXPORT_FUNC(int) numba_fatal_error(void) { PyGILState_Ensure(); -#if PY_MAJOR_VERSION < 3 - /* Py_FatalError doesn't print the current error on Python 2, do it - ourselves. */ - if (PyErr_Occurred()) - PyErr_Print(); -#endif Py_FatalError("in Numba-compiled function"); return 0; /* unreachable */ } @@ -858,13 +824,7 @@ static void traceback_add(const char *funcname, const char *filename, int lineno return; error: -#if PY_MAJOR_VERSION >= 3 _PyErr_ChainExceptions(exc, val, tb); -#else - Py_XDECREF(globals); - Py_XDECREF(code); - Py_XDECREF(frame); -#endif } /* Logic for raising an arbitrary object. Adapted from CPython's ceval.c. @@ -1040,11 +1000,7 @@ numba_unpickle(const char *data, int n) /* Caching the pickle.loads function shaves a couple µs here. */ if (loads == NULL) { PyObject *picklemod; -#if PY_MAJOR_VERSION >= 3 picklemod = PyImport_ImportModule("pickle"); -#else - picklemod = PyImport_ImportModule("cPickle"); -#endif if (picklemod == NULL) return NULL; loads = PyObject_GetAttrString(picklemod, "loads"); @@ -1094,7 +1050,6 @@ numba_unpickle(const char *data, int n) NUMBA_EXPORT_FUNC(void *) numba_extract_unicode(PyObject *obj, Py_ssize_t *length, int *kind, unsigned int *ascii, Py_ssize_t *hash) { -#if (PY_MAJOR_VERSION >= 3) && (PY_MINOR_VERSION >= 3) if (!PyUnicode_READY(obj)) { *length = PyUnicode_GET_LENGTH(obj); *kind = PyUnicode_KIND(obj); @@ -1120,10 +1075,6 @@ numba_extract_unicode(PyObject *obj, Py_ssize_t *length, int *kind, } else { return NULL; } -#else - /* this function only works in Python 3 */ - return NULL; -#endif } /* this is late included as it #defines e.g. SHIFT that should not impact diff --git a/numba/_helpermod.c b/numba/_helpermod.c index 1520b836aa6..a8240db71d5 100644 --- a/numba/_helpermod.c +++ b/numba/_helpermod.c @@ -292,12 +292,10 @@ MOD_INIT(_helperlib) { PyModule_AddIntConstant(m, "long_max", LONG_MAX); PyModule_AddIntConstant(m, "py_buffer_size", sizeof(Py_buffer)); PyModule_AddIntConstant(m, "py_gil_state_size", sizeof(PyGILState_STATE)); -#if (PY_MAJOR_VERSION >= 3) && (PY_MINOR_VERSION >= 3) PyModule_AddIntConstant(m, "py_unicode_1byte_kind", PyUnicode_1BYTE_KIND); PyModule_AddIntConstant(m, "py_unicode_2byte_kind", PyUnicode_2BYTE_KIND); PyModule_AddIntConstant(m, "py_unicode_4byte_kind", PyUnicode_4BYTE_KIND); PyModule_AddIntConstant(m, "py_unicode_wchar_kind", PyUnicode_WCHAR_KIND); -#endif numba_rnd_ensure_global_init(); return MOD_SUCCESS_VAL(m); diff --git a/numba/_math_c99.h b/numba/_math_c99.h index fec8ac08a5f..9ea7dd9b001 100644 --- a/numba/_math_c99.h +++ b/numba/_math_c99.h @@ -3,8 +3,7 @@ #include "_numba_common.h" -/* We require C99 on POSIX, but have to be tolerant on Windows since - Python < 3.5 is compiled with old MSVC versions */ +/* We require C99 on POSIX */ #if !defined(_MSC_VER) || _MSC_VER >= 1800 /* Visual Studio 2013 */ #define HAVE_C99_MATH 1 diff --git a/numba/_typeof.c b/numba/_typeof.c index 4b339b8893e..a4a97657717 100644 --- a/numba/_typeof.c +++ b/numba/_typeof.c @@ -801,28 +801,16 @@ typeof_typecode(PyObject *dispatcher, PyObject *val) } -#if PY_MAJOR_VERSION >= 3 - static - void* wrap_import_array(void) { - import_array(); /* import array returns NULL on failure */ - return (void*)1; - } -#else - static - void wrap_import_array(void) { - import_array(); - } -#endif +static +void* wrap_import_array(void) { + import_array(); /* import array returns NULL on failure */ + return (void*)1; +} static int init_numpy(void) { - #if PY_MAJOR_VERSION >= 3 - return wrap_import_array() != NULL; - #else - wrap_import_array(); - return 1; /* always succeed */ - #endif + return wrap_import_array() != NULL; } diff --git a/numba/jitclass/_box.c b/numba/jitclass/_box.c index 09aa7a7cd1e..19ebe004a07 100644 --- a/numba/jitclass/_box.c +++ b/numba/jitclass/_box.c @@ -51,12 +51,7 @@ static const char Box_doc[] = "A box for numba created jit-class instance"; static PyTypeObject BoxType = { -#if (PY_MAJOR_VERSION < 3) - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#else PyVarObject_HEAD_INIT(NULL, 0) -#endif "_box.Box", /*tp_name*/ sizeof(BoxObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ diff --git a/numba/mviewbuf.c b/numba/mviewbuf.c index 9944342d961..846ff98a43e 100644 --- a/numba/mviewbuf.c +++ b/numba/mviewbuf.c @@ -282,116 +282,39 @@ get_bufinfo(PyObject *self, Py_ssize_t *psize, void **pptr) } -#if PY_MAJOR_VERSION >= 3 - - - static int - MemAllocObject_getbuffer(PyObject *self, Py_buffer *view, int flags) - { - Py_ssize_t size = 0; - void *ptr = 0; - int readonly; - - if(-1 == get_bufinfo(self, &size, &ptr)) - return -1; - - readonly = (PyBUF_WRITABLE & flags) != PyBUF_WRITABLE; - - /* fill buffer */ - if (-1 == PyBuffer_FillInfo(view, self, (void*)ptr, size, readonly, flags)) - return -1; - - return 0; - } - - static void - MemAllocObject_releasebuffer(PyObject *self, Py_buffer *view) - { - /* Do nothing */ - } - - static PyBufferProcs MemAlloc_as_buffer = { - MemAllocObject_getbuffer, - MemAllocObject_releasebuffer, - }; -#else - static int - MemAllocObject_getbufferproc(PyObject *self, Py_buffer *view, int flags) - { - Py_ssize_t size = 0; - void *ptr = 0; - int readonly; - - if(-1 == get_bufinfo(self, &size, &ptr)) - return -1; - - readonly = (PyBUF_WRITABLE & flags) != PyBUF_WRITABLE; - - /* fill buffer */ - if (-1 == PyBuffer_FillInfo(view, self, (void*)ptr, size, readonly, flags)) - return -1; - - return 0; - } +static int +MemAllocObject_getbuffer(PyObject *self, Py_buffer *view, int flags) +{ + Py_ssize_t size = 0; + void *ptr = 0; + int readonly; - static Py_ssize_t - MemAllocObject_writebufferproc(PyObject *self, Py_ssize_t segment, - void **ptrptr) - { - Py_ssize_t size = 0; - if (segment != 0) { - PyErr_SetString(PyExc_ValueError, "invalid segment"); - return -1; - } + if(-1 == get_bufinfo(self, &size, &ptr)) + return -1; - if(-1 == get_bufinfo(self, &size, ptrptr)) - return -1; - return size; - } + readonly = (PyBUF_WRITABLE & flags) != PyBUF_WRITABLE; - static Py_ssize_t - MemAllocObject_readbufferproc(PyObject *self, Py_ssize_t segment, - void **ptrptr) - { - return MemAllocObject_writebufferproc(self, segment, ptrptr); - } + /* fill buffer */ + if (-1 == PyBuffer_FillInfo(view, self, (void*)ptr, size, readonly, flags)) + return -1; + return 0; +} - static Py_ssize_t - MemAllocObject_segcountproc(PyObject *self, Py_ssize_t *lenp) - { - void *ptr = 0; - if (lenp){ - if(-1 == get_bufinfo(self, lenp, &ptr)) return 0; - } - return 1; - } +static void +MemAllocObject_releasebuffer(PyObject *self, Py_buffer *view) +{ + /* Do nothing */ +} - static Py_ssize_t - MemAllocObject_charbufferproc(PyObject *self, Py_ssize_t segment, - char **ptrptr) - { - return MemAllocObject_writebufferproc(self, segment, (void*)ptrptr); - } +static PyBufferProcs MemAlloc_as_buffer = { + MemAllocObject_getbuffer, + MemAllocObject_releasebuffer, +}; - static PyBufferProcs MemAlloc_as_buffer = { - MemAllocObject_readbufferproc, /*bf_getreadbuffer*/ - MemAllocObject_writebufferproc, /*bf_getwritebuffer*/ - MemAllocObject_segcountproc, /*bf_getsegcount*/ - MemAllocObject_charbufferproc, /*bf_getcharbuffer*/ - /* new buffer protocol */ - MemAllocObject_getbufferproc, /*bf_getbuffer*/ - NULL, /*bf_releasebuffer*/ - }; -#endif static PyTypeObject MemAllocType = { -#if PY_MAJOR_VERSION >= 3 PyVarObject_HEAD_INIT(NULL, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif "mviewbuf.MemAlloc", /* tp_name */ sizeof(MemAllocObject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -415,14 +338,7 @@ static PyTypeObject MemAllocType = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ &MemAlloc_as_buffer, /*tp_as_buffer*/ - (Py_TPFLAGS_DEFAULT -#if PY_MAJOR_VERSION < 3 - | Py_TPFLAGS_CHECKTYPES -#endif -#if (PY_VERSION_HEX >= 0x02060000) && (PY_VERSION_HEX < 0x03000000) - | Py_TPFLAGS_HAVE_NEWBUFFER -#endif - | Py_TPFLAGS_BASETYPE), /* tp_flags */ + (Py_TPFLAGS_DEFAULT| Py_TPFLAGS_BASETYPE), /* tp_flags */ 0, /* tp_doc */ 0, /* tp_traverse */ @@ -450,9 +366,7 @@ static PyTypeObject MemAllocType = { 0, /* tp_subclasses */ 0, /* tp_weaklist */ 0, /* tp_del */ -#if PY_VERSION_HEX >= 0x02060000 0, /* tp_version_tag */ -#endif }; diff --git a/numba/npyufunc/_internal.c b/numba/npyufunc/_internal.c index b18db15feb9..d3ca1319b6d 100644 --- a/numba/npyufunc/_internal.c +++ b/numba/npyufunc/_internal.c @@ -41,12 +41,7 @@ cleaner_dealloc(PyUFuncCleaner *self) } PyTypeObject PyUFuncCleaner_Type = { -#if PY_MAJOR_VERSION >= 3 PyVarObject_HEAD_INIT(NULL, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif "numba._UFuncCleaner", /* tp_name*/ sizeof(PyUFuncCleaner), /* tp_basicsize*/ 0, /* tp_itemsize */ @@ -165,11 +160,7 @@ _get_nin(PyObject * py_func_obj) inspect = PyImport_ImportModule("inspect"); if (!inspect) goto _get_nin_cleanup; -#if PY_MAJOR_VERSION >= 3 getargspec = PyObject_GetAttrString(inspect, "getfullargspec"); -#else - getargspec = PyObject_GetAttrString(inspect, "getargspec"); -#endif if (!getargspec) goto _get_nin_cleanup; argspec = PyObject_CallFunctionObjArgs(getargspec, py_func_obj, NULL); if (!argspec) goto _get_nin_cleanup; @@ -608,12 +599,7 @@ static PyGetSetDef dufunc_getsets[] = { }; PyTypeObject PyDUFunc_Type = { -#if PY_MAJOR_VERSION >= 3 PyVarObject_HEAD_INIT(NULL, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif "numba._DUFunc", /* tp_name*/ sizeof(PyDUFuncObject), /* tp_basicsize*/ 0, /* tp_itemsize */ diff --git a/numba/pycc/modulemixin.c b/numba/pycc/modulemixin.c index 82fd40badd3..6b45e85e92c 100644 --- a/numba/pycc/modulemixin.c +++ b/numba/pycc/modulemixin.c @@ -23,29 +23,17 @@ /* NOTE: import_array() is macro, not a function. It returns NULL on - failure on py3, but nothing on py2. */ -#if PY_MAJOR_VERSION >= 3 - static void * - wrap_import_array(void) { - import_array(); - return (void *) 1; - } -#else - static void - wrap_import_array(void) { - import_array(); - } -#endif + failure */ +static void * +wrap_import_array(void) { + import_array(); + return (void *) 1; +} static int init_numpy(void) { - #if PY_MAJOR_VERSION >= 3 - return wrap_import_array() != NULL; - #else - wrap_import_array(); - return 1; /* always succeed */ - #endif + return wrap_import_array() != NULL; } diff --git a/numba/runtime/_nrt_python.c b/numba/runtime/_nrt_python.c index 93eebef2653..0a270dfaba7 100644 --- a/numba/runtime/_nrt_python.c +++ b/numba/runtime/_nrt_python.c @@ -61,32 +61,6 @@ int MemInfo_init(MemInfoObject *self, PyObject *args, PyObject *kwds) { } -#if PY_MAJOR_VERSION < 3 -static Py_ssize_t -MemInfo_rdwrbufferproc(PyObject *self, Py_ssize_t segment, void **ptrptr) -{ - MemInfoObject *mio = (MemInfoObject *)self; - NRT_MemInfo *mi = mio->meminfo; - if (segment != 0) { - PyErr_SetString(PyExc_TypeError, "MemInfo only has 1 segment"); - return -1; - } - *ptrptr = NRT_MemInfo_data(mi); - return NRT_MemInfo_size(mi); -} - -static Py_ssize_t -MemInfo_segcountproc(PyObject *self, Py_ssize_t *lenp) { - MemInfoObject *mio = (MemInfoObject *)self; - NRT_MemInfo *mi = mio->meminfo; - if (lenp) { - *lenp = NRT_MemInfo_size(mi); - } - return 1; -} - -#else /* PY_MAJOR_VERSION < 3 */ - static int MemInfo_getbuffer(PyObject *exporter, Py_buffer *view, int flags) { Py_ssize_t len; @@ -100,16 +74,8 @@ MemInfo_getbuffer(PyObject *exporter, Py_buffer *view, int flags) { len = NRT_MemInfo_size(mi); return PyBuffer_FillInfo(view, exporter, buf, len, readonly, flags); } -#endif /* PY_MAJOR_VERSION < 3 */ -#if PY_MAJOR_VERSION < 3 -static PyBufferProcs MemInfo_bufferProcs = {MemInfo_rdwrbufferproc, - MemInfo_rdwrbufferproc, - MemInfo_segcountproc, - NULL}; -#else static PyBufferProcs MemInfo_bufferProcs = {MemInfo_getbuffer, NULL}; -#endif static PyObject* @@ -174,12 +140,7 @@ static PyGetSetDef MemInfo_getsets[] = { static PyTypeObject MemInfoType = { -#if (PY_MAJOR_VERSION < 3) - PyObject_HEAD_INIT(NULL) - 0, /* ob_size*/ -#else PyVarObject_HEAD_INIT(NULL, 0) -#endif "_nrt_python._MemInfo", /* tp_name*/ sizeof(MemInfoObject), /* tp_basicsize*/ 0, /* tp_itemsize*/ From 0156f2386ab829b78a717b3f239891198e491074 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 16:21:08 +0000 Subject: [PATCH 245/595] Fix missing import --- numba/tests/test_annotations.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/tests/test_annotations.py b/numba/tests/test_annotations.py index 80700d9e06e..0bb31205615 100644 --- a/numba/tests/test_annotations.py +++ b/numba/tests/test_annotations.py @@ -4,6 +4,7 @@ import numba from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags +from numba import types try: import jinja2 From dfde36d6cb32513ef3e915ce8ec9bcb3355dd03a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 16:22:20 +0000 Subject: [PATCH 246/595] Fix missing import 2 --- numba/tests/test_codegen.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/numba/tests/test_codegen.py b/numba/tests/test_codegen.py index eb1267f488e..959d5e9164e 100644 --- a/numba/tests/test_codegen.py +++ b/numba/tests/test_codegen.py @@ -14,7 +14,6 @@ import llvmlite.binding as ll import numba.unittest_support as unittest -from numba import utils from numba.targets.codegen import JITCPUCodegen from numba.compiler_lock import global_compiler_lock from .support import TestCase @@ -89,7 +88,7 @@ def _check_unserialize_sum(cls, state): def test_get_pointer_to_function(self): library = self.compile_module(asm_sum) ptr = library.get_pointer_to_function("sum") - self.assertIsInstance(ptr, utils.integer_types) + self.assertIsInstance(ptr, int) cfunc = ctypes_sum_ty(ptr) self.assertEqual(cfunc(2, 3), 5) # Note: With llvm3.9.1, deleting `library` will cause memory error in @@ -100,7 +99,7 @@ def test_get_pointer_to_function(self): # Same, but with dependency on another library library2 = self.compile_module(asm_sum_outer, asm_sum_inner) ptr = library2.get_pointer_to_function("sum") - self.assertIsInstance(ptr, utils.integer_types) + self.assertIsInstance(ptr, int) cfunc = ctypes_sum_ty(ptr) self.assertEqual(cfunc(2, 3), 5) From 54df447c738dc40152ed0fad4b4cc10fb14c00db Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 17:02:55 +0000 Subject: [PATCH 247/595] Fix missing truediv impl --- numba/tests/test_dispatcher.py | 7 ++++--- numba/tests/test_operators.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 586918a2348..425f499a4ee 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -11,6 +11,7 @@ import pickle import weakref from itertools import chain +from io import StringIO try: import jinja2 @@ -25,7 +26,7 @@ import numpy as np from numba import unittest_support as unittest -from numba import utils, jit, generated_jit, types, typeof, errors +from numba import jit, generated_jit, types, typeof, errors from numba import _dispatcher from numba.compiler import compile_isolated from numba.errors import NumbaWarning @@ -867,7 +868,7 @@ def foo(a, b): foo(1, 2) # Exercise the method - foo.inspect_types(utils.StringIO()) + foo.inspect_types(StringIO()) # Test output expected = str(foo.overloads[foo.signatures[0]].type_annotation) @@ -917,7 +918,7 @@ def foo(a, b): # check that file+pretty kwarg combo raises with self.assertRaises(ValueError) as raises: - foo.inspect_types(file=utils.StringIO(), pretty=True) + foo.inspect_types(file=StringIO(), pretty=True) self.assertIn("`file` must be None if `pretty=True`", str(raises.exception)) diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 8904d3ab454..50d43de9501 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -1320,8 +1320,9 @@ def control_signed(a, b): samples, signed_pairs) def test_truediv(self): + def control(a, b): - return truediv_usecase(float(a), float(b)) + return float(a) / float(b) samples = [x for x in self.int_samples if x != 0] pyfunc = self.op.truediv_usecase From 95421facfb43e0e5ebba50c15e6b64ee9e683446 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 17:28:10 +0000 Subject: [PATCH 248/595] Flake8 --- numba/compiler.py | 1 - numba/compiler_machinery.py | 3 +-- numba/lowering.py | 3 +-- numba/npyufunc/parallel.py | 2 +- numba/numpy_support.py | 2 +- numba/object_mode_passes.py | 3 +-- numba/targets/descriptors.py | 1 - numba/targets/externals.py | 3 +-- numba/targets/literal.py | 2 -- numba/tests/test_closure.py | 2 +- numba/tests/test_dictobject.py | 2 +- numba/tests/test_help.py | 4 ++-- numba/tests/test_listobject.py | 2 +- numba/tests/test_parallel_backend.py | 2 +- numba/tests/test_practical_lowering_issues.py | 2 -- numba/tests/test_typedlist.py | 2 +- numba/tests/test_unicode_names.py | 2 +- numba/typed_passes.py | 2 +- numba/utils.py | 5 +++++ 19 files changed, 20 insertions(+), 25 deletions(-) diff --git a/numba/compiler.py b/numba/compiler.py index 35e86a34590..623b056352d 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -1,5 +1,4 @@ from collections import namedtuple -import sys import copy import warnings from .tracing import event diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index d1c94e8a019..64b9c8c9ed1 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -2,10 +2,9 @@ from abc import abstractmethod, ABCMeta from collections import namedtuple, OrderedDict import inspect -import traceback from numba.compiler_lock import global_compiler_lock from numba import errors -from . import config, utils, transforms +from . import config, transforms from numba.utils import add_metaclass from .tracing import event from .postproc import PostProcessor diff --git a/numba/lowering.py b/numba/lowering.py index c826b610d26..ee2146be9ce 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -1,6 +1,5 @@ import weakref -import time -from collections import namedtuple, deque +from collections import namedtuple import operator from functools import partial diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 853fb35910f..225f4d041d7 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -24,7 +24,7 @@ from numba.npyufunc import ufuncbuilder from numba.numpy_support import as_dtype -from numba import types, config, utils +from numba import types, config from numba.npyufunc.wrappers import _wrapper_info diff --git a/numba/numpy_support.py b/numba/numpy_support.py index bf48d89211c..35bd067c106 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -4,7 +4,7 @@ import numpy as np -from . import errors, types, config, utils +from . import errors, types, utils # re-export from numba.cgutils import is_nonelike # noqa: F401 diff --git a/numba/object_mode_passes.py b/numba/object_mode_passes.py index 19e32834a1f..9ae9c0363f8 100644 --- a/numba/object_mode_passes.py +++ b/numba/object_mode_passes.py @@ -1,7 +1,6 @@ from contextlib import contextmanager import warnings -from . import (config, errors, types, funcdesc, utils, typing, pylowering, - transforms) +from . import (config, errors, types, funcdesc, typing, pylowering, transforms) from .compiler_machinery import FunctionPass, LoweringPass, register_pass from collections import defaultdict diff --git a/numba/targets/descriptors.py b/numba/targets/descriptors.py index 52a41e2de38..2995e1b27d6 100644 --- a/numba/targets/descriptors.py +++ b/numba/targets/descriptors.py @@ -3,6 +3,5 @@ """ - class TargetDescriptor(object): pass diff --git a/numba/targets/externals.py b/numba/targets/externals.py index 699f8abcdc0..522854d9b52 100644 --- a/numba/targets/externals.py +++ b/numba/targets/externals.py @@ -3,12 +3,11 @@ """ import sys -import ctypes from llvmlite import ir import llvmlite.binding as ll -from numba import utils, config +from numba import utils from numba import _helperlib from . import intrinsics diff --git a/numba/targets/literal.py b/numba/targets/literal.py index 076ed140838..ffcfcddd935 100644 --- a/numba/targets/literal.py +++ b/numba/targets/literal.py @@ -1,5 +1,3 @@ -import sys - from numba.extending import overload from numba import types from numba.special import literally, literal_unroll diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 548be0eed2a..58d44862a89 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -3,7 +3,7 @@ import numpy import numba.unittest_support as unittest -from numba import njit, jit, testing, utils +from numba import njit, jit, testing from numba.errors import TypingError, UnsupportedError from .support import TestCase, tag diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index dbb085d6068..7fed08c58ed 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -11,7 +11,7 @@ import numpy as np -from numba import njit, utils, jitclass +from numba import njit, jitclass from numba import int32, int64, float32, float64, types from numba import dictobject, typeof from numba.typed import Dict diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index d71bf07c2fd..64bdd36f149 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -6,7 +6,7 @@ import numpy as np import builtins -from numba import types, utils +from numba import types from .support import TestCase, temp_directory from numba.help.inspector import inspect_function, inspect_module @@ -89,4 +89,4 @@ def test_inspect_cli(self): with self.assertRaises(subprocess.CalledProcessError) as raises: subprocess.check_output(cmds, stderr=subprocess.STDOUT) self.assertIn("\'foo\' is not supported", - raises.exception.stdout.decode('ascii')) + raises.exception.stdout.decode('ascii')) diff --git a/numba/tests/test_listobject.py b/numba/tests/test_listobject.py index 3b926a48caf..be37aa7773d 100644 --- a/numba/tests/test_listobject.py +++ b/numba/tests/test_listobject.py @@ -15,7 +15,7 @@ from numba import int32, types from numba.errors import TypingError from numba import listobject -from .support import (TestCase, MemoryLeakMixin, unittest, override_config, +from .support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen) diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 9d20e6fa209..be07d50f1cd 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -13,7 +13,7 @@ import numpy as np -from numba import config, utils +from numba import config from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index 8bf82f1f2c6..8caac1c05e6 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -2,8 +2,6 @@ Tests for practical lowering specific errors. """ - - import numpy as np from numba import njit, types, ir from numba.compiler import CompilerBase, DefaultPassBuilder diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 9fbf0a599ed..42a9623de95 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -7,7 +7,7 @@ from numba import jitclass, typeof from numba.typed import List, Dict from numba.errors import TypingError -from .support import (TestCase, MemoryLeakMixin, unittest, override_config, +from .support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen, skip_parfors_unsupported) from numba.unsafe.refcount import get_refcount diff --git a/numba/tests/test_unicode_names.py b/numba/tests/test_unicode_names.py index 9017520f83c..3979f5313a1 100644 --- a/numba/tests/test_unicode_names.py +++ b/numba/tests/test_unicode_names.py @@ -47,7 +47,7 @@ def test_normalize_ir_text(self): # try encoding to latin out.encode('latin1') - def test_normalize_ir_text(self): + def test_normalize_ir_text_unicode(self): # unicode input out = cgutils.normalize_ir_text(unicode_name2) # str returned diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 59a6c744674..05217f9463c 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -2,7 +2,7 @@ import warnings from . import (config, errors, types, rewrites, typeinfer, funcdesc, lowering, - utils, typing, ir) + typing, ir) from .parfor import PreParforPass as _parfor_PreParforPass from .parfor import ParforPass as _parfor_ParforPass diff --git a/numba/utils.py b/numba/utils.py index b11e6976bec..01eb5b50769 100644 --- a/numba/utils.py +++ b/numba/utils.py @@ -52,6 +52,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. + def add_metaclass(metaclass): """Class decorator for creating a class with a metaclass.""" def wrapper(cls): @@ -75,17 +76,21 @@ def reraise(tp, value, tb=None): raise value.with_traceback(tb) raise value + def iteritems(d, **kw): return iter(d.items(**kw)) + def itervalues(d, **kw): return iter(d.values(**kw)) + get_function_globals = operator.attrgetter("__globals__") # End: Originally from `numba.six` under the following license # ------------------------------------------------------------------------------ + def erase_traceback(exc_value): """ Erase the traceback and hanging locals from the given exception instance. From aef85db4c79d5b3935318bb04a76edf3aaa57e1b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 17:33:09 +0000 Subject: [PATCH 249/595] remove missing ref in docs --- docs/source/developer/repomap.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/developer/repomap.rst b/docs/source/developer/repomap.rst index 9937cc42c02..f3b683b8c49 100644 --- a/docs/source/developer/repomap.rst +++ b/docs/source/developer/repomap.rst @@ -26,8 +26,6 @@ Build and Packaging fixed and removed from the exception list as time allows. - :ghfile:`.pre-commit-config.yaml` - Configuration file for pre-commit hooks. - :ghfile:`buildscripts/condarecipe.local` - Conda build recipe -- :ghfile:`buildscripts/remove_unwanted_files.py` - Helper script to remove - files that will not compile under Python 2. Used by build recipes. - :ghfile:`buildscripts/condarecipe_clone_icc_rt` - Recipe to build a standalone icc_rt package. From e61dce1d8961f4b5da287bc832809e30dc6a352b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 23 Jan 2020 19:47:09 +0000 Subject: [PATCH 250/595] fix CUDA --- numba/cuda/tests/cudapy/test_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/tests/cudapy/test_inspect.py b/numba/cuda/tests/cudapy/test_inspect.py index 19226632c61..f6a05f94faf 100644 --- a/numba/cuda/tests/cudapy/test_inspect.py +++ b/numba/cuda/tests/cudapy/test_inspect.py @@ -1,7 +1,7 @@ +from io import StringIO from numba import cuda, float64, intp from numba.cuda.testing import unittest, SerialMixin from numba.cuda.testing import skip_on_cudasim -from numba.utils import StringIO @skip_on_cudasim('Simulator does not generate code to be inspected') From ec380192ed99e75d3cce70a3d2cfa1b728217ee8 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Thu, 23 Jan 2020 12:52:34 -0800 Subject: [PATCH 251/595] Describe motivation for testing that the default stream is True-ish --- numba/cuda/tests/cudadrv/test_cuda_driver.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numba/cuda/tests/cudadrv/test_cuda_driver.py b/numba/cuda/tests/cudadrv/test_cuda_driver.py index cea5862a9b4..5470e2604d1 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_driver.py +++ b/numba/cuda/tests/cudadrv/test_cuda_driver.py @@ -118,6 +118,9 @@ def test_cuda_driver_default_stream(self): ds = self.context.get_default_stream() self.assertIn("Default CUDA stream", repr(ds)) self.assertEqual(0, int(ds)) + # bool(stream) is the check that is done in memcpy to decide if async + # version should be used. So the default (0) stream should be true-ish + # even though 0 is usually false-ish in Python. self.assertTrue(ds) def test_cuda_driver_stream(self): From 25346ad0c6a3f543c295edf69d839cd6241b3786 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 11:41:18 +0000 Subject: [PATCH 252/595] sort out BLAS/LAPACK --- numba/tests/matmul_usecase.py | 15 ++------------- numba/tests/support.py | 20 ++++++++++++++++++++ numba/tests/test_array_methods.py | 4 ++-- numba/tests/test_debug.py | 5 +++-- numba/tests/test_dispatcher.py | 3 +-- numba/tests/test_linalg.py | 15 ++------------- numba/tests/test_np_functions.py | 4 ++-- numba/tests/test_operators.py | 5 ++--- numba/tests/test_parfors.py | 5 ++--- numba/tests/test_polynomial.py | 3 +-- numba/tests/test_profiler.py | 2 +- numba/tests/test_remove_dead.py | 3 +-- 12 files changed, 39 insertions(+), 45 deletions(-) diff --git a/numba/tests/matmul_usecase.py b/numba/tests/matmul_usecase.py index 18afff08118..84af4ef308e 100644 --- a/numba/tests/matmul_usecase.py +++ b/numba/tests/matmul_usecase.py @@ -1,14 +1,5 @@ -import sys - -try: - import scipy.linalg.cython_blas - has_blas = True -except ImportError: - has_blas = False - -import numba.unittest_support as unittest -from numba.numpy_support import version as numpy_version - +"""Use cases for testing matmul (@) +""" def matmul_usecase(x, y): return x @ y @@ -16,8 +7,6 @@ def imatmul_usecase(x, y): x @= y return x -needs_blas = unittest.skipUnless(has_blas, "BLAS needs SciPy 1.0+") - class DumbMatrix(object): def __init__(self, value): diff --git a/numba/tests/support.py b/numba/tests/support.py index 73e92a9a56c..b10cac05b5c 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -8,6 +8,7 @@ import errno import gc import math +import platform import os import shutil import subprocess @@ -68,6 +69,25 @@ _lnx_reason = 'linux only test' linux_only = unittest.skipIf(not sys.platform.startswith('linux'), _lnx_reason) +_is_armv7l = platform.machine() == 'armv7l' + +try: + import scipy.linalg.cython_lapack + has_lapack = True +except ImportError: + has_lapack = False + +needs_lapack = unittest.skipUnless(has_lapack, + "LAPACK needs SciPy 1.0+") + +try: + import scipy.linalg.cython_blas + has_blas = True +except ImportError: + has_blas = False + +needs_blas = unittest.skipUnless(has_blas, "BLAS needs SciPy 1.0+") + class CompilationCache(object): """ diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index 2a2000a5d93..e5476719d39 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -11,8 +11,8 @@ from numba.numpy_support import (as_dtype, strict_ufunc_typing, version as numpy_version) from .support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, - tag) -from .matmul_usecase import needs_blas + tag, needs_blas) + def np_around_array(arr, decimals, out): np.around(arr, decimals, out) diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 1a0ca3e509b..3ddd7259d12 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -7,14 +7,15 @@ import numpy as np from .support import (TestCase, override_config, override_env_config, - captured_stdout, forbid_codegen, skip_parfors_unsupported) + captured_stdout, forbid_codegen, skip_parfors_unsupported, + needs_blas) from numba import unittest_support as unittest from numba import jit, jitclass, types from numba.compiler import compile_isolated, Flags from numba.targets.cpu import ParallelOptions from numba.errors import NumbaPerformanceWarning from numba import compiler, prange -from .matmul_usecase import needs_blas + def simple_nopython(somearg): retval = somearg + 1 diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 425f499a4ee..80f7a6c6b00 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -37,8 +37,7 @@ from numba.caching import _UserWideCacheLocator from numba.dispatcher import Dispatcher from numba import parfor -from .test_linalg import needs_lapack -from .support import skip_parfors_unsupported +from .support import skip_parfors_unsupported, needs_lapack import llvmlite.binding as ll diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index ea45dbf3280..0600989af5f 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -11,19 +11,8 @@ from numba import unittest_support as unittest from numba import jit, errors from numba.numpy_support import version as numpy_version -from .support import TestCase, tag -from .matmul_usecase import matmul_usecase, needs_blas - -_is_armv7l = platform.machine() == 'armv7l' - -try: - import scipy.linalg.cython_lapack - has_lapack = True -except ImportError: - has_lapack = False - -needs_lapack = unittest.skipUnless(has_lapack, - "LAPACK needs Scipy 0.16+") +from .support import TestCase, tag, needs_lapack, needs_blas, _is_armv7l +from .matmul_usecase import matmul_usecase def dot2(a, b): diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index d22ae5d2fba..cb97ad1fb7e 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -15,8 +15,8 @@ from numba.config import IS_WIN32, IS_32BITS from numba.utils import pysignature from numba.targets.arraymath import cross2d -from .support import TestCase, CompilationCache, MemoryLeakMixin -from .matmul_usecase import needs_blas +from .support import TestCase, CompilationCache, MemoryLeakMixin, needs_blas + no_pyobj_flags = Flags() no_pyobj_flags.set("nrt") diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 50d43de9501..20a6209371f 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -9,9 +9,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import jit, types, typeinfer, utils, errors -from .support import TestCase, tag -from .matmul_usecase import (matmul_usecase, imatmul_usecase, DumbMatrix, - needs_blas) +from .support import TestCase, tag, needs_blas +from .matmul_usecase import (matmul_usecase, imatmul_usecase, DumbMatrix,) Noflags = Flags() diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index fcd48b95916..960598e77e9 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -34,11 +34,10 @@ from numba.unsafe.ndarray import empty_inferred as unsafe_empty from numba.compiler import compile_isolated, Flags from numba.bytecode import ByteCodeIter -from .matmul_usecase import needs_blas -from .test_linalg import needs_lapack from .support import (TestCase, captured_stdout, MemoryLeakMixin, override_env_config, linux_only, tag, - skip_parfors_unsupported, _32bit) + skip_parfors_unsupported, _32bit, needs_blas, + needs_lapack) import cmath diff --git a/numba/tests/test_polynomial.py b/numba/tests/test_polynomial.py index 9a5bbfac00a..2d210e04112 100644 --- a/numba/tests/test_polynomial.py +++ b/numba/tests/test_polynomial.py @@ -5,8 +5,7 @@ from numba import unittest_support as unittest from numba import jit -from .support import TestCase, tag -from .test_linalg import needs_lapack +from .support import TestCase, tag, needs_lapack def roots_fn(p): diff --git a/numba/tests/test_profiler.py b/numba/tests/test_profiler.py index 31b222ae399..a95a8a34e0e 100644 --- a/numba/tests/test_profiler.py +++ b/numba/tests/test_profiler.py @@ -8,7 +8,7 @@ from numba import jit from numba import unittest_support as unittest -from .test_linalg import needs_blas +from .support import needs_blas def dot(a, b): diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 0bda7202caa..6fd359e907c 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -28,8 +28,7 @@ IRLegalization, NoPythonBackend) from numba import unittest_support as unittest import numpy as np -from .matmul_usecase import needs_blas -from .support import skip_parfors_unsupported +from .support import skip_parfors_unsupported, needs_blas def test_will_propagate(b, z, w): From a9eebb86f0e716f40f2da9884764a028e644ca2a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 11:48:18 +0000 Subject: [PATCH 253/595] Enfore critical dep versions --- numba/__init__.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index b886e2e1fcc..085bd012a32 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -106,20 +106,29 @@ def _ensure_llvm(): check_jit_execution() -def _ensure_pynumpy(): +def _ensure_critical_deps(): """ - Make sure Python and Numpy have supported versions. + Make sure Python, NumPy and SciPy have supported versions. """ - import warnings from . import numpy_support + from .utils import PYVERSION - pyver = sys.version_info[:2] - if pyver < (2, 7) or ((3,) <= pyver < (3, 4)): - raise ImportError("Numba needs Python 2.7 or greater, or 3.4 or greater") + if PYVERSION < (3, 6): + raise ImportError("Numba needs Python 3.6 or greater") np_version = numpy_support.version[:2] - if np_version < (1, 7): - raise ImportError("Numba needs Numpy 1.7 or greater") + if np_version < (1, 15): + raise ImportError("Numba needs NumPy 1.15 or greater") + + try: + import scipy + except ImportError: + pass + else: + sp_version = tuple(map(int, scipy.__version__.split('.')[:2])) + if sp_version < (1, 0): + raise ImportError("Numba requires SciPy version 1.0 or greater") + def _try_enable_svml(): """ @@ -169,7 +178,7 @@ def _try_enable_svml(): return False _ensure_llvm() -_ensure_pynumpy() +_ensure_critical_deps() # we know llvmlite is working as the above tests passed, import it now as SVML # needs to mutate runtime options (sets the `-vector-library`). From 1fb9286ed26d867a90040a89c912f4c3fecf1411 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 12:40:03 +0000 Subject: [PATCH 254/595] Remove np <115 --- numba/__init__.py | 2 +- numba/numpy_support.py | 4 +- numba/targets/arraymath.py | 755 +++++++++++------------ numba/targets/arrayobj.py | 111 ++-- numba/targets/linalg.py | 812 ++++++++++++------------- numba/targets/npdatetime.py | 8 +- numba/targets/ufunc_db.py | 74 +-- numba/tests/test_array_analysis.py | 46 +- numba/tests/test_array_manipulation.py | 32 +- numba/tests/test_array_methods.py | 23 +- numba/tests/test_dyn_array.py | 3 - numba/tests/test_linalg.py | 74 +-- numba/typing/npydecl.py | 113 ++-- numba/typing/randomdecl.py | 4 +- 14 files changed, 946 insertions(+), 1115 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index 085bd012a32..8232dda757a 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -116,7 +116,7 @@ def _ensure_critical_deps(): if PYVERSION < (3, 6): raise ImportError("Numba needs Python 3.6 or greater") - np_version = numpy_support.version[:2] + np_version = numpy_support.numpy_version[:2] if np_version < (1, 15): raise ImportError("Numba needs NumPy 1.15 or greater") diff --git a/numba/numpy_support.py b/numba/numpy_support.py index 35bd067c106..8d9d7887a17 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -9,11 +9,11 @@ from numba.cgutils import is_nonelike # noqa: F401 -version = tuple(map(int, np.__version__.split('.')[:2])) +numpy_version = tuple(map(int, np.__version__.split('.')[:2])) # Starting from Numpy 1.10, ufuncs accept argument conversion according # to the "same_kind" rule (used to be "unsafe"). -strict_ufunc_typing = version >= (1, 10) +strict_ufunc_typing = numpy_version >= (1, 10) FROM_DTYPE = { diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index c0551dd7ebf..a6e9c9918de 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -15,7 +15,7 @@ from numba import types, cgutils, generated_jit from numba.extending import overload, overload_method, register_jitable from numba.numpy_support import as_dtype, type_can_asarray -from numba.numpy_support import version as numpy_version +from numba.numpy_support import numpy_version from numba.numpy_support import is_nonelike from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) @@ -557,11 +557,8 @@ def array_max_impl(arry): @lower_builtin("array.argmin", types.Array) def array_argmin(context, builder, sig, args): ty = sig.args[0].dtype - # NOTE: Under Numpy < 1.10, argmin() is inconsistent with min() - # on NaT values: https://github.com/numpy/numpy/issues/6030 - if (numpy_version >= (1, 10) and - isinstance(ty, (types.NPDatetime, types.NPTimedelta))): + if (isinstance(ty, (types.NPDatetime, types.NPTimedelta))): # NaT is smaller than every other value, but it is # ignored as far as argmin() is concerned. nat = ty('NaT') @@ -754,59 +751,58 @@ def np_nanmax(a): return real_nanmax -if numpy_version >= (1, 8): - @overload(np.nanmean) - def np_nanmean(a): - if not isinstance(a, types.Array): - return - isnan = get_isnan(a.dtype) +@overload(np.nanmean) +def np_nanmean(a): + if not isinstance(a, types.Array): + return + isnan = get_isnan(a.dtype) - def nanmean_impl(a): - c = 0.0 - count = 0 - for view in np.nditer(a): - v = view.item() - if not isnan(v): - c += v.item() - count += 1 - # np.divide() doesn't raise ZeroDivisionError - return np.divide(c, count) - - return nanmean_impl - - @overload(np.nanvar) - def np_nanvar(a): - if not isinstance(a, types.Array): - return - isnan = get_isnan(a.dtype) - - def nanvar_impl(a): - # Compute the mean - m = np.nanmean(a) - - # Compute the sum of square diffs - ssd = 0.0 - count = 0 - for view in np.nditer(a): - v = view.item() - if not isnan(v): - val = (v.item() - m) - ssd += np.real(val * np.conj(val)) - count += 1 - # np.divide() doesn't raise ZeroDivisionError - return np.divide(ssd, count) + def nanmean_impl(a): + c = 0.0 + count = 0 + for view in np.nditer(a): + v = view.item() + if not isnan(v): + c += v.item() + count += 1 + # np.divide() doesn't raise ZeroDivisionError + return np.divide(c, count) - return nanvar_impl + return nanmean_impl - @overload(np.nanstd) - def np_nanstd(a): - if not isinstance(a, types.Array): - return +@overload(np.nanvar) +def np_nanvar(a): + if not isinstance(a, types.Array): + return + isnan = get_isnan(a.dtype) - def nanstd_impl(a): - return np.nanvar(a) ** 0.5 + def nanvar_impl(a): + # Compute the mean + m = np.nanmean(a) - return nanstd_impl + # Compute the sum of square diffs + ssd = 0.0 + count = 0 + for view in np.nditer(a): + v = view.item() + if not isnan(v): + val = (v.item() - m) + ssd += np.real(val * np.conj(val)) + count += 1 + # np.divide() doesn't raise ZeroDivisionError + return np.divide(ssd, count) + + return nanvar_impl + +@overload(np.nanstd) +def np_nanstd(a): + if not isinstance(a, types.Array): + return + + def nanstd_impl(a): + return np.nanvar(a) ** 0.5 + + return nanstd_impl @overload(np.nansum) @@ -831,76 +827,75 @@ def nansum_impl(a): return nansum_impl -if numpy_version >= (1, 10): - @overload(np.nanprod) - def np_nanprod(a): - if not isinstance(a, types.Array): - return - if isinstance(a.dtype, types.Integer): - retty = types.intp - else: - retty = a.dtype +@overload(np.nanprod) +def np_nanprod(a): + if not isinstance(a, types.Array): + return + if isinstance(a.dtype, types.Integer): + retty = types.intp + else: + retty = a.dtype + one = retty(1) + isnan = get_isnan(a.dtype) + + def nanprod_impl(a): + c = one + for view in np.nditer(a): + v = view.item() + if not isnan(v): + c *= v + return c + + return nanprod_impl + + +@overload(np.nancumprod) +def np_nancumprod(a): + if not isinstance(a, types.Array): + return + + if isinstance(a.dtype, (types.Boolean, types.Integer)): + # dtype cannot possibly contain NaN + return lambda a: np.cumprod(a) + else: + retty = a.dtype + is_nan = get_isnan(retty) one = retty(1) - isnan = get_isnan(a.dtype) - def nanprod_impl(a): + def nancumprod_impl(a): + out = np.empty(a.size, retty) c = one - for view in np.nditer(a): - v = view.item() - if not isnan(v): + for idx, v in enumerate(a.flat): + if ~is_nan(v): c *= v - return c - - return nanprod_impl + out[idx] = c + return out -if numpy_version >= (1, 12): - @overload(np.nancumprod) - def np_nancumprod(a): - if not isinstance(a, types.Array): - return + return nancumprod_impl - if isinstance(a.dtype, (types.Boolean, types.Integer)): - # dtype cannot possibly contain NaN - return lambda a: np.cumprod(a) - else: - retty = a.dtype - is_nan = get_isnan(retty) - one = retty(1) - - def nancumprod_impl(a): - out = np.empty(a.size, retty) - c = one - for idx, v in enumerate(a.flat): - if ~is_nan(v): - c *= v - out[idx] = c - return out - - return nancumprod_impl - - @overload(np.nancumsum) - def np_nancumsum(a): - if not isinstance(a, types.Array): - return - - if isinstance(a.dtype, (types.Boolean, types.Integer)): - # dtype cannot possibly contain NaN - return lambda a: np.cumsum(a) - else: - retty = a.dtype - is_nan = get_isnan(retty) - zero = retty(0) +@overload(np.nancumsum) +def np_nancumsum(a): + if not isinstance(a, types.Array): + return - def nancumsum_impl(a): - out = np.empty(a.size, retty) - c = zero - for idx, v in enumerate(a.flat): - if ~is_nan(v): - c += v - out[idx] = c - return out + if isinstance(a.dtype, (types.Boolean, types.Integer)): + # dtype cannot possibly contain NaN + return lambda a: np.cumsum(a) + else: + retty = a.dtype + is_nan = get_isnan(retty) + zero = retty(0) + + def nancumsum_impl(a): + out = np.empty(a.size, retty) + c = zero + for idx, v in enumerate(a.flat): + if ~is_nan(v): + c += v + out[idx] = c + return out - return nancumsum_impl + return nancumsum_impl @register_jitable @@ -1263,68 +1258,63 @@ def np_percentile_impl(a, q): return np_percentile_impl -if numpy_version >= (1, 10): - @overload(np.percentile) - def np_percentile(a, q): - # Note: np.percentile behaviour in the case of an array containing one - # or more NaNs was changed in numpy 1.10 to return an array of np.NaN of - # length equal to q, hence version guard. - return _percentile_quantile_inner( - a, q, skip_nan=False, factor=1.0, check_q=percentile_is_valid - ) - - -if numpy_version >= (1, 11): - @overload(np.nanpercentile) - def np_nanpercentile(a, q): - # Note: np.nanpercentile return type in the case of an all-NaN slice - # was changed in 1.11 to be an array of np.NaN of length equal to q, - # hence version guard. - return _percentile_quantile_inner( - a, q, skip_nan=True, factor=1.0, check_q=percentile_is_valid - ) - - -if numpy_version >= (1, 15): - @overload(np.quantile) - def np_quantile(a, q): - return _percentile_quantile_inner( - a, q, skip_nan=False, factor=100.0, check_q=quantile_is_valid - ) - - -if numpy_version >= (1, 15): - @overload(np.nanquantile) - def np_nanquantile(a, q): - return _percentile_quantile_inner( - a, q, skip_nan=True, factor=100.0, check_q=quantile_is_valid - ) - - -if numpy_version >= (1, 9): - @overload(np.nanmedian) - def np_nanmedian(a): - if not isinstance(a, types.Array): - return - isnan = get_isnan(a.dtype) - - def nanmedian_impl(a): - # Create a temporary workspace with only non-NaN values - temp_arry = np.empty(a.size, a.dtype) - n = 0 - for view in np.nditer(a): - v = view.item() - if not isnan(v): - temp_arry[n] = v - n += 1 +@overload(np.percentile) +def np_percentile(a, q): + # Note: np.percentile behaviour in the case of an array containing one + # or more NaNs was changed in numpy 1.10 to return an array of np.NaN of + # length equal to q, hence version guard. + return _percentile_quantile_inner( + a, q, skip_nan=False, factor=1.0, check_q=percentile_is_valid + ) - # all NaNs - if n == 0: - return np.nan - return _median_inner(temp_arry, n) +@overload(np.nanpercentile) +def np_nanpercentile(a, q): + # Note: np.nanpercentile return type in the case of an all-NaN slice + # was changed in 1.11 to be an array of np.NaN of length equal to q, + # hence version guard. + return _percentile_quantile_inner( + a, q, skip_nan=True, factor=1.0, check_q=percentile_is_valid + ) - return nanmedian_impl + +@overload(np.quantile) +def np_quantile(a, q): + return _percentile_quantile_inner( + a, q, skip_nan=False, factor=100.0, check_q=quantile_is_valid + ) + + +@overload(np.nanquantile) +def np_nanquantile(a, q): + return _percentile_quantile_inner( + a, q, skip_nan=True, factor=100.0, check_q=quantile_is_valid + ) + + +@overload(np.nanmedian) +def np_nanmedian(a): + if not isinstance(a, types.Array): + return + isnan = get_isnan(a.dtype) + + def nanmedian_impl(a): + # Create a temporary workspace with only non-NaN values + temp_arry = np.empty(a.size, a.dtype) + n = 0 + for view in np.nditer(a): + v = view.item() + if not isnan(v): + temp_arry[n] = v + n += 1 + + # all NaNs + if n == 0: + return np.nan + + return _median_inner(temp_arry, n) + + return nanmedian_impl @register_jitable @@ -1605,63 +1595,62 @@ def _dtype_of_compound(inobj): return as_dtype(dt) -if numpy_version >= (1, 12): # replicate behaviour of NumPy 1.12 bugfix release - @overload(np.ediff1d) - def np_ediff1d(ary, to_end=None, to_begin=None): - - if isinstance(ary, types.Array): - if isinstance(ary.dtype, types.Boolean): - raise TypeError("Boolean dtype is unsupported (as per NumPy)") - # Numpy tries to do this: return ary[1:] - ary[:-1] which - # results in a TypeError exception being raised - - # since np 1.16 there are casting checks for to_end and to_begin to make - # sure they are compatible with the ary - if numpy_version >= (1, 16): - ary_dt = _dtype_of_compound(ary) - to_begin_dt = None - if not(is_nonelike(to_begin)): - to_begin_dt = _dtype_of_compound(to_begin) - to_end_dt = None - if not(is_nonelike(to_end)): - to_end_dt = _dtype_of_compound(to_end) - - if to_begin_dt is not None and not np.can_cast(to_begin_dt, ary_dt): - msg = "dtype of to_begin must be compatible with input ary" - raise TypeError(msg) - - if to_end_dt is not None and not np.can_cast(to_end_dt, ary_dt): - msg = "dtype of to_end must be compatible with input ary" - raise TypeError(msg) - - def np_ediff1d_impl(ary, to_end=None, to_begin=None): - # transform each input into an equivalent 1d array - start = _prepare_array(to_begin) - mid = _prepare_array(ary) - end = _prepare_array(to_end) - - out_dtype = mid.dtype - # output array dtype determined by ary dtype, per NumPy - # (for the most part); an exception to the rule is a zero length - # array-like, where NumPy falls back to np.float64; this behaviour - # is *not* replicated - - if len(mid) > 0: - out = np.empty((len(start) + len(mid) + len(end) - 1), - dtype=out_dtype) - start_idx = len(start) - mid_idx = len(start) + len(mid) - 1 - out[:start_idx] = start - out[start_idx:mid_idx] = np.diff(mid) - out[mid_idx:] = end - else: - out = np.empty((len(start) + len(end)), dtype=out_dtype) - start_idx = len(start) - out[:start_idx] = start - out[start_idx:] = end - return out +@overload(np.ediff1d) +def np_ediff1d(ary, to_end=None, to_begin=None): + + if isinstance(ary, types.Array): + if isinstance(ary.dtype, types.Boolean): + raise TypeError("Boolean dtype is unsupported (as per NumPy)") + # Numpy tries to do this: return ary[1:] - ary[:-1] which + # results in a TypeError exception being raised + + # since np 1.16 there are casting checks for to_end and to_begin to make + # sure they are compatible with the ary + if numpy_version >= (1, 16): + ary_dt = _dtype_of_compound(ary) + to_begin_dt = None + if not(is_nonelike(to_begin)): + to_begin_dt = _dtype_of_compound(to_begin) + to_end_dt = None + if not(is_nonelike(to_end)): + to_end_dt = _dtype_of_compound(to_end) + + if to_begin_dt is not None and not np.can_cast(to_begin_dt, ary_dt): + msg = "dtype of to_begin must be compatible with input ary" + raise TypeError(msg) + + if to_end_dt is not None and not np.can_cast(to_end_dt, ary_dt): + msg = "dtype of to_end must be compatible with input ary" + raise TypeError(msg) + + def np_ediff1d_impl(ary, to_end=None, to_begin=None): + # transform each input into an equivalent 1d array + start = _prepare_array(to_begin) + mid = _prepare_array(ary) + end = _prepare_array(to_end) + + out_dtype = mid.dtype + # output array dtype determined by ary dtype, per NumPy + # (for the most part); an exception to the rule is a zero length + # array-like, where NumPy falls back to np.float64; this behaviour + # is *not* replicated + + if len(mid) > 0: + out = np.empty((len(start) + len(mid) + len(end) - 1), + dtype=out_dtype) + start_idx = len(start) + mid_idx = len(start) + len(mid) - 1 + out[:start_idx] = start + out[start_idx:mid_idx] = np.diff(mid) + out[mid_idx:] = end + else: + out = np.empty((len(start) + len(end)), dtype=out_dtype) + start_idx = len(start) + out[:start_idx] = start + out[start_idx:] = end + return out - return np_ediff1d_impl + return np_ediff1d_impl def _select_element(arr): @@ -2295,88 +2284,82 @@ def impl(x, xp, fp, dtype): return impl -if numpy_version >= (1, 10): - np_interp_impl_inner_post_np117 = register_jitable( - np_interp_impl_inner_factory(np117_nan_handling=True) - ) - np_interp_impl_complex_inner_post_np117 = register_jitable( - np_interp_impl_complex_fp_inner_factory(np117_nan_handling=True) - ) - np_interp_impl_inner_pre_np117 = register_jitable( - np_interp_impl_inner_factory(np117_nan_handling=False) - ) - np_interp_impl_complex_inner_pre_np117 = register_jitable( - np_interp_impl_complex_fp_inner_factory(np117_nan_handling=False) +np_interp_impl_inner_post_np117 = register_jitable( + np_interp_impl_inner_factory(np117_nan_handling=True) +) +np_interp_impl_complex_inner_post_np117 = register_jitable( + np_interp_impl_complex_fp_inner_factory(np117_nan_handling=True) +) +np_interp_impl_inner_pre_np117 = register_jitable( + np_interp_impl_inner_factory(np117_nan_handling=False) +) +np_interp_impl_complex_inner_pre_np117 = register_jitable( + np_interp_impl_complex_fp_inner_factory(np117_nan_handling=False) +) + + +@overload(np.interp) +def np_interp(x, xp, fp): + # NOTE: there is considerable duplication present in the functions: + # np_interp_impl_complex_fp_inner_116 + # np_interp_impl_complex_fp_inner + # np_interp_impl_inner_116 + # np_interp_impl_inner + # + # This is because: + # 1. Replicating basic interp is relatively simple, however matching the + # behaviour of NumPy for edge cases is really quite hard, after a + # couple of attempts trying to avoid translation of the C source it + # was deemed unavoidable. + # 2. Due to 1. it is much easier to keep track of changes if the Numba + # source reflects the NumPy C source, so the duplication is kept. + # 3. There are significant changes that happened in the NumPy 1.16 + # release series, hence functions with `np116` appended, they behave + # slightly differently! + + if hasattr(xp, 'ndim') and xp.ndim > 1: + raise TypingError('xp must be 1D') + if hasattr(fp, 'ndim') and fp.ndim > 1: + raise TypingError('fp must be 1D') + + complex_dtype_msg = ( + "Cannot cast array data from complex dtype to float64 dtype" ) - # replicate behaviour change of 1.10+ - @overload(np.interp) - def np_interp(x, xp, fp): - # NOTE: there is considerable duplication present in the functions: - # np_interp_impl_complex_fp_inner_116 - # np_interp_impl_complex_fp_inner - # np_interp_impl_inner_116 - # np_interp_impl_inner - # - # This is because: - # 1. Replicating basic interp is relatively simple, however matching the - # behaviour of NumPy for edge cases is really quite hard, after a - # couple of attempts trying to avoid translation of the C source it - # was deemed unavoidable. - # 2. Due to 1. it is much easier to keep track of changes if the Numba - # source reflects the NumPy C source, so the duplication is kept. - # 3. There are significant changes that happened in the NumPy 1.16 - # release series, hence functions with `np116` appended, they behave - # slightly differently! - - if hasattr(xp, 'ndim') and xp.ndim > 1: - raise TypingError('xp must be 1D') - if hasattr(fp, 'ndim') and fp.ndim > 1: - raise TypingError('fp must be 1D') - - complex_dtype_msg = ( - "Cannot cast array data from complex dtype to float64 dtype" - ) - - xp_dt = determine_dtype(xp) - if np.issubdtype(xp_dt, np.complexfloating): - raise TypingError(complex_dtype_msg) + xp_dt = determine_dtype(xp) + if np.issubdtype(xp_dt, np.complexfloating): + raise TypingError(complex_dtype_msg) - if numpy_version < (1, 12): - fp_dt = determine_dtype(fp) - if np.issubdtype(fp_dt, np.complexfloating): - raise TypingError(complex_dtype_msg) - - if numpy_version >= (1, 17): - impl = np_interp_impl_inner_post_np117 - impl_complex = np_interp_impl_complex_inner_post_np117 - elif numpy_version >= (1, 16): - impl = np_interp_impl_inner_pre_np117 - impl_complex = np_interp_impl_complex_inner_pre_np117 - else: - impl = np_interp_impl_inner - impl_complex = np_interp_impl_complex_fp_inner + if numpy_version >= (1, 17): + impl = np_interp_impl_inner_post_np117 + impl_complex = np_interp_impl_complex_inner_post_np117 + elif numpy_version >= (1, 16): + impl = np_interp_impl_inner_pre_np117 + impl_complex = np_interp_impl_complex_inner_pre_np117 + else: + impl = np_interp_impl_inner + impl_complex = np_interp_impl_complex_fp_inner - fp_dt = determine_dtype(fp) - dtype = np.result_type(fp_dt, np.float64) + fp_dt = determine_dtype(fp) + dtype = np.result_type(fp_dt, np.float64) - if np.issubdtype(dtype, np.complexfloating): - inner = impl_complex - else: - inner = impl + if np.issubdtype(dtype, np.complexfloating): + inner = impl_complex + else: + inner = impl - def np_interp_impl(x, xp, fp): - return inner(x, xp, fp, dtype) + def np_interp_impl(x, xp, fp): + return inner(x, xp, fp, dtype) - def np_interp_scalar_impl(x, xp, fp): - return inner(x, xp, fp, dtype).flat[0] + def np_interp_scalar_impl(x, xp, fp): + return inner(x, xp, fp, dtype).flat[0] - if isinstance(x, types.Number): - if isinstance(x, types.Complex): - raise TypingError(complex_dtype_msg) - return np_interp_scalar_impl + if isinstance(x, types.Number): + if isinstance(x, types.Complex): + raise TypingError(complex_dtype_msg) + return np_interp_scalar_impl - return np_interp_impl + return np_interp_impl #---------------------------------------------------------------------------- @@ -2564,98 +2547,96 @@ def _clip_complex(x): return real + 1j * imag -# replicate behaviour post numpy 1.10 bugfix release -if numpy_version >= (1, 10): - @overload(np.cov) - def np_cov(m, y=None, rowvar=True, bias=False, ddof=None): +@overload(np.cov) +def np_cov(m, y=None, rowvar=True, bias=False, ddof=None): - # reject problem if m and / or y are more than 2D - check_dimensions(m, 'm') - check_dimensions(y, 'y') + # reject problem if m and / or y are more than 2D + check_dimensions(m, 'm') + check_dimensions(y, 'y') - # reject problem if ddof invalid (either upfront if type is - # obviously invalid, or later if value found to be non-integral) - if ddof in (None, types.none): + # reject problem if ddof invalid (either upfront if type is + # obviously invalid, or later if value found to be non-integral) + if ddof in (None, types.none): + _DDOF_HANDLER = _handle_ddof_nop + else: + if isinstance(ddof, (types.Integer, types.Boolean)): _DDOF_HANDLER = _handle_ddof_nop + elif isinstance(ddof, types.Float): + _DDOF_HANDLER = _handle_ddof else: - if isinstance(ddof, (types.Integer, types.Boolean)): - _DDOF_HANDLER = _handle_ddof_nop - elif isinstance(ddof, types.Float): - _DDOF_HANDLER = _handle_ddof - else: - raise TypingError('ddof must be a real numerical scalar type') - - # special case for 2D array input with 1 row of data - select - # handler function which we'll call later when we have access - # to the shape of the input array - _M_DIM_HANDLER = _handle_m_dim_nop - if isinstance(m, types.Array): - _M_DIM_HANDLER = _handle_m_dim_change - - # infer result dtype - m_dt = determine_dtype(m) - y_dt = determine_dtype(y) - dtype = np.result_type(m_dt, y_dt, np.float64) - - def np_cov_impl(m, y=None, rowvar=True, bias=False, ddof=None): - X = _prepare_cov_input(m, y, rowvar, dtype, ddof, _DDOF_HANDLER, - _M_DIM_HANDLER).astype(dtype) - - if np.any(np.array(X.shape) == 0): - return np.full((X.shape[0], X.shape[0]), - fill_value=np.nan, - dtype=dtype) - else: - return np_cov_impl_inner(X, bias, ddof) + raise TypingError('ddof must be a real numerical scalar type') - def np_cov_impl_single_variable(m, y=None, rowvar=True, bias=False, - ddof=None): - X = _prepare_cov_input(m, y, rowvar, ddof, dtype, _DDOF_HANDLER, - _M_DIM_HANDLER).astype(dtype) + # special case for 2D array input with 1 row of data - select + # handler function which we'll call later when we have access + # to the shape of the input array + _M_DIM_HANDLER = _handle_m_dim_nop + if isinstance(m, types.Array): + _M_DIM_HANDLER = _handle_m_dim_change - if np.any(np.array(X.shape) == 0): - variance = np.nan - else: - variance = np_cov_impl_inner(X, bias, ddof).flat[0] + # infer result dtype + m_dt = determine_dtype(m) + y_dt = determine_dtype(y) + dtype = np.result_type(m_dt, y_dt, np.float64) - return np.array(variance) + def np_cov_impl(m, y=None, rowvar=True, bias=False, ddof=None): + X = _prepare_cov_input(m, y, rowvar, dtype, ddof, _DDOF_HANDLER, + _M_DIM_HANDLER).astype(dtype) - if scalar_result_expected(m, y): - return np_cov_impl_single_variable + if np.any(np.array(X.shape) == 0): + return np.full((X.shape[0], X.shape[0]), + fill_value=np.nan, + dtype=dtype) else: - return np_cov_impl - - @overload(np.corrcoef) - def np_corrcoef(x, y=None, rowvar=True): + return np_cov_impl_inner(X, bias, ddof) - x_dt = determine_dtype(x) - y_dt = determine_dtype(y) - dtype = np.result_type(x_dt, y_dt, np.float64) + def np_cov_impl_single_variable(m, y=None, rowvar=True, bias=False, + ddof=None): + X = _prepare_cov_input(m, y, rowvar, ddof, dtype, _DDOF_HANDLER, + _M_DIM_HANDLER).astype(dtype) - if dtype == np.complex: - clip_fn = _clip_complex + if np.any(np.array(X.shape) == 0): + variance = np.nan else: - clip_fn = _clip_corr + variance = np_cov_impl_inner(X, bias, ddof).flat[0] - def np_corrcoef_impl(x, y=None, rowvar=True): - c = np.cov(x, y, rowvar) - d = np.diag(c) - stddev = np.sqrt(d.real) + return np.array(variance) - for i in range(c.shape[0]): - c[i, :] /= stddev - c[:, i] /= stddev + if scalar_result_expected(m, y): + return np_cov_impl_single_variable + else: + return np_cov_impl - return clip_fn(c) +@overload(np.corrcoef) +def np_corrcoef(x, y=None, rowvar=True): - def np_corrcoef_impl_single_variable(x, y=None, rowvar=True): - c = np.cov(x, y, rowvar) - return c / c + x_dt = determine_dtype(x) + y_dt = determine_dtype(y) + dtype = np.result_type(x_dt, y_dt, np.float64) - if scalar_result_expected(x, y): - return np_corrcoef_impl_single_variable - else: - return np_corrcoef_impl + if dtype == np.complex: + clip_fn = _clip_complex + else: + clip_fn = _clip_corr + + def np_corrcoef_impl(x, y=None, rowvar=True): + c = np.cov(x, y, rowvar) + d = np.diag(c) + stddev = np.sqrt(d.real) + + for i in range(c.shape[0]): + c[i, :] /= stddev + c[:, i] /= stddev + + return clip_fn(c) + + def np_corrcoef_impl_single_variable(x, y=None, rowvar=True): + c = np.cov(x, y, rowvar) + return c / c + + if scalar_result_expected(x, y): + return np_corrcoef_impl_single_variable + else: + return np_corrcoef_impl #---------------------------------------------------------------------------- @@ -2681,12 +2662,6 @@ def impl(a): @overload(np.flatnonzero) def np_flatnonzero(a): - if numpy_version < (1, 15): - if not isinstance(a, types.Array): - raise TypingError("Argument 'a' must be an array") - # numpy raises an Attribute error with: - # 'xxx' object has no attribute 'ravel' - if type_can_asarray(a): def impl(a): arr = np.asarray(a) @@ -3171,9 +3146,6 @@ def np_count_nonzero(arr, axis=None): if not type_can_asarray(arr): raise TypingError("The argument to np.count_nonzero must be array-like") - if (numpy_version < (1, 12)): - raise TypingError("axis is not supported for NumPy versions < 1.12.0") - if is_nonelike(axis): def impl(arr, axis=None): arr2 = np.ravel(arr) @@ -3652,16 +3624,13 @@ def histogram_impl(a, bins=10, range=None): # finfo _finfo_supported = ('eps', 'epsneg', 'iexp', 'machep', 'max', 'maxexp', 'min', 'minexp', 'negep', 'nexp', 'nmant', 'precision', - 'resolution', 'tiny',) -if numpy_version >= (1, 12): - _finfo_supported = ('bits',) + _finfo_supported + 'resolution', 'tiny', 'bits',) + finfo = namedtuple('finfo', _finfo_supported) # iinfo -_iinfo_supported = ('min', 'max') -if numpy_version >= (1, 12): - _iinfo_supported = _iinfo_supported + ('bits',) +_iinfo_supported = ('min', 'max', 'bits',) iinfo = namedtuple('iinfo', _iinfo_supported) diff --git a/numba/targets/arrayobj.py b/numba/targets/arrayobj.py index 40c4f25629e..7213f936c04 100644 --- a/numba/targets/arrayobj.py +++ b/numba/targets/arrayobj.py @@ -17,9 +17,7 @@ from numba import types, cgutils, typing, utils, extending, pndindex, errors from numba.numpy_support import (as_dtype, carray, farray, is_contiguous, is_fortran) -from numba.numpy_support import version as numpy_version -from numba.numpy_support import type_can_asarray -from numba.numpy_support import is_nonelike +from numba.numpy_support import type_can_asarray, is_nonelike from numba.targets.imputils import (lower_builtin, lower_getattr, lower_getattr_generic, lower_setattr_generic, @@ -3517,62 +3515,53 @@ def numpy_zeros_like_nd(context, builder, sig, args): return impl_ret_new_ref(context, builder, sig.return_type, ary._getvalue()) -if numpy_version >= (1, 8): - @lower_builtin(np.full, types.Any, types.Any) - def numpy_full_nd(context, builder, sig, args): - if numpy_version < (1, 12): - # np < 1.12 returns float64 full regardless of value type - def full(shape, value): - arr = np.empty(shape) - val = np.float64(value.real) - for idx in np.ndindex(arr.shape): - arr[idx] = val - return arr - else: - def full(shape, value): - arr = np.empty(shape, type(value)) - for idx in np.ndindex(arr.shape): - arr[idx] = value - return arr - - res = context.compile_internal(builder, full, sig, args) - return impl_ret_new_ref(context, builder, sig.return_type, res) - - @lower_builtin(np.full, types.Any, types.Any, types.DTypeSpec) - def numpy_full_dtype_nd(context, builder, sig, args): - - def full(shape, value, dtype): - arr = np.empty(shape, dtype) - for idx in np.ndindex(arr.shape): - arr[idx] = value - return arr +@lower_builtin(np.full, types.Any, types.Any) +def numpy_full_nd(context, builder, sig, args): - res = context.compile_internal(builder, full, sig, args) - return impl_ret_new_ref(context, builder, sig.return_type, res) + def full(shape, value): + arr = np.empty(shape, type(value)) + for idx in np.ndindex(arr.shape): + arr[idx] = value + return arr - @lower_builtin(np.full_like, types.Any, types.Any) - def numpy_full_like_nd(context, builder, sig, args): + res = context.compile_internal(builder, full, sig, args) + return impl_ret_new_ref(context, builder, sig.return_type, res) - def full_like(arr, value): - arr = np.empty_like(arr) - for idx in np.ndindex(arr.shape): - arr[idx] = value - return arr +@lower_builtin(np.full, types.Any, types.Any, types.DTypeSpec) +def numpy_full_dtype_nd(context, builder, sig, args): - res = context.compile_internal(builder, full_like, sig, args) - return impl_ret_new_ref(context, builder, sig.return_type, res) + def full(shape, value, dtype): + arr = np.empty(shape, dtype) + for idx in np.ndindex(arr.shape): + arr[idx] = value + return arr - @lower_builtin(np.full_like, types.Any, types.Any, types.DTypeSpec) - def numpy_full_like_nd_type_spec(context, builder, sig, args): + res = context.compile_internal(builder, full, sig, args) + return impl_ret_new_ref(context, builder, sig.return_type, res) - def full_like(arr, value, dtype): - arr = np.empty_like(arr, dtype) - for idx in np.ndindex(arr.shape): - arr[idx] = value - return arr +@lower_builtin(np.full_like, types.Any, types.Any) +def numpy_full_like_nd(context, builder, sig, args): - res = context.compile_internal(builder, full_like, sig, args) - return impl_ret_new_ref(context, builder, sig.return_type, res) + def full_like(arr, value): + arr = np.empty_like(arr) + for idx in np.ndindex(arr.shape): + arr[idx] = value + return arr + + res = context.compile_internal(builder, full_like, sig, args) + return impl_ret_new_ref(context, builder, sig.return_type, res) + +@lower_builtin(np.full_like, types.Any, types.Any, types.DTypeSpec) +def numpy_full_like_nd_type_spec(context, builder, sig, args): + + def full_like(arr, value, dtype): + arr = np.empty_like(arr, dtype) + for idx in np.ndindex(arr.shape): + arr[idx] = value + return arr + + res = context.compile_internal(builder, full_like, sig, args) + return impl_ret_new_ref(context, builder, sig.return_type, res) @lower_builtin(np.ones, types.Any) @@ -4774,16 +4763,16 @@ def _np_stack_common(context, builder, sig, args, axis): axis) -if numpy_version >= (1, 10): - @lower_builtin(np.stack, types.BaseTuple) - def np_stack(context, builder, sig, args): - axis = context.get_constant(types.intp, 0) - return _np_stack_common(context, builder, sig, args, axis) +@lower_builtin(np.stack, types.BaseTuple) +def np_stack(context, builder, sig, args): + axis = context.get_constant(types.intp, 0) + return _np_stack_common(context, builder, sig, args, axis) - @lower_builtin(np.stack, types.BaseTuple, types.Integer) - def np_stack_axis(context, builder, sig, args): - axis = context.cast(builder, args[1], sig.args[1], types.intp) - return _np_stack_common(context, builder, sig, args, axis) + +@lower_builtin(np.stack, types.BaseTuple, types.Integer) +def np_stack_axis(context, builder, sig, args): + axis = context.cast(builder, args[1], sig.args[1], types.intp) + return _np_stack_common(context, builder, sig, args, axis) @lower_builtin(np.hstack, types.BaseTuple) diff --git a/numba/targets/linalg.py b/numba/targets/linalg.py index dd1f48e3257..dfe4c2a227c 100644 --- a/numba/targets/linalg.py +++ b/numba/targets/linalg.py @@ -16,7 +16,6 @@ impl_ret_new_ref, impl_ret_untracked) from numba.typing import signature from numba.extending import overload, register_jitable -from numba.numpy_support import version as numpy_version from numba import types from numba import numpy_support as np_support from .arrayobj import make_array, _empty_nd_impl, array_copy @@ -844,479 +843,478 @@ def _check_linalg_1_or_2d_matrix(a, func_name, la_prefix=True): raise TypingError("%s.%s() only supported on " "float and complex arrays." % interp) -if numpy_version >= (1, 8): - @overload(np.linalg.cholesky) +@overload(np.linalg.cholesky) +def cho_impl(a): + ensure_lapack() + + _check_linalg_matrix(a, "cholesky") + + numba_xxpotrf = _LAPACK().numba_xxpotrf(a.dtype) + + kind = ord(get_blas_kind(a.dtype, "cholesky")) + UP = ord('U') + LO = ord('L') + def cho_impl(a): - ensure_lapack() + n = a.shape[-1] + if a.shape[-2] != n: + msg = "Last 2 dimensions of the array must be square." + raise np.linalg.LinAlgError(msg) + + # The output is allocated in C order + out = a.copy() - _check_linalg_matrix(a, "cholesky") - - numba_xxpotrf = _LAPACK().numba_xxpotrf(a.dtype) - - kind = ord(get_blas_kind(a.dtype, "cholesky")) - UP = ord('U') - LO = ord('L') - - def cho_impl(a): - n = a.shape[-1] - if a.shape[-2] != n: - msg = "Last 2 dimensions of the array must be square." - raise np.linalg.LinAlgError(msg) - - # The output is allocated in C order - out = a.copy() - - if n == 0: - return out - - # Pass UP since xxpotrf() operates in F order - # The semantics ensure this works fine - # (out is really its Hermitian in F order, but UP instructs - # xxpotrf to compute the Hermitian of the upper triangle - # => they cancel each other) - r = numba_xxpotrf(kind, UP, n, out.ctypes, n) - if r != 0: - if r < 0: - fatal_error_func() - assert 0 # unreachable - if r > 0: - raise np.linalg.LinAlgError( - "Matrix is not positive definite.") - # Zero out upper triangle, in F order - for col in range(n): - out[:col, col] = 0 + if n == 0: return out - return cho_impl + # Pass UP since xxpotrf() operates in F order + # The semantics ensure this works fine + # (out is really its Hermitian in F order, but UP instructs + # xxpotrf to compute the Hermitian of the upper triangle + # => they cancel each other) + r = numba_xxpotrf(kind, UP, n, out.ctypes, n) + if r != 0: + if r < 0: + fatal_error_func() + assert 0 # unreachable + if r > 0: + raise np.linalg.LinAlgError( + "Matrix is not positive definite.") + # Zero out upper triangle, in F order + for col in range(n): + out[:col, col] = 0 + return out - @overload(np.linalg.eig) - def eig_impl(a): - ensure_lapack() + return cho_impl - _check_linalg_matrix(a, "eig") +@overload(np.linalg.eig) +def eig_impl(a): + ensure_lapack() - numba_ez_rgeev = _LAPACK().numba_ez_rgeev(a.dtype) - numba_ez_cgeev = _LAPACK().numba_ez_cgeev(a.dtype) + _check_linalg_matrix(a, "eig") - kind = ord(get_blas_kind(a.dtype, "eig")) + numba_ez_rgeev = _LAPACK().numba_ez_rgeev(a.dtype) + numba_ez_cgeev = _LAPACK().numba_ez_cgeev(a.dtype) - JOBVL = ord('N') - JOBVR = ord('V') + kind = ord(get_blas_kind(a.dtype, "eig")) - F_layout = a.layout == 'F' + JOBVL = ord('N') + JOBVR = ord('V') - def real_eig_impl(a): - """ - eig() implementation for real arrays. - """ - n = a.shape[-1] - if a.shape[-2] != n: - msg = "Last 2 dimensions of the array must be square." - raise np.linalg.LinAlgError(msg) + F_layout = a.layout == 'F' - _check_finite_matrix(a) + def real_eig_impl(a): + """ + eig() implementation for real arrays. + """ + n = a.shape[-1] + if a.shape[-2] != n: + msg = "Last 2 dimensions of the array must be square." + raise np.linalg.LinAlgError(msg) - if F_layout: - acpy = np.copy(a) - else: - acpy = np.asfortranarray(a) - - ldvl = 1 - ldvr = n - wr = np.empty(n, dtype=a.dtype) - wi = np.empty(n, dtype=a.dtype) - vl = np.empty((n, ldvl), dtype=a.dtype) - vr = np.empty((n, ldvr), dtype=a.dtype) - - if n == 0: - return (wr, vr.T) - - r = numba_ez_rgeev(kind, - JOBVL, - JOBVR, - n, - acpy.ctypes, - n, - wr.ctypes, - wi.ctypes, - vl.ctypes, - ldvl, - vr.ctypes, - ldvr) - _handle_err_maybe_convergence_problem(r) - - # By design numba does not support dynamic return types, however, - # Numpy does. Numpy uses this ability in the case of returning - # eigenvalues/vectors of a real matrix. The return type of - # np.linalg.eig(), when operating on a matrix in real space - # depends on the values present in the matrix itself (recalling - # that eigenvalues are the roots of the characteristic polynomial - # of the system matrix, which will by construction depend on the - # values present in the system matrix). As numba cannot handle - # the case of a runtime decision based domain change relative to - # the input type, if it is required numba raises as below. - if np.any(wi): - raise ValueError( - "eig() argument must not cause a domain change.") - - # put these in to help with liveness analysis, - # `.ctypes` doesn't keep the vars alive - _dummy_liveness_func([acpy.size, vl.size, vr.size, wr.size, wi.size]) + _check_finite_matrix(a) + + if F_layout: + acpy = np.copy(a) + else: + acpy = np.asfortranarray(a) + + ldvl = 1 + ldvr = n + wr = np.empty(n, dtype=a.dtype) + wi = np.empty(n, dtype=a.dtype) + vl = np.empty((n, ldvl), dtype=a.dtype) + vr = np.empty((n, ldvr), dtype=a.dtype) + + if n == 0: return (wr, vr.T) - def cmplx_eig_impl(a): - """ - eig() implementation for complex arrays. - """ - n = a.shape[-1] - if a.shape[-2] != n: - msg = "Last 2 dimensions of the array must be square." - raise np.linalg.LinAlgError(msg) + r = numba_ez_rgeev(kind, + JOBVL, + JOBVR, + n, + acpy.ctypes, + n, + wr.ctypes, + wi.ctypes, + vl.ctypes, + ldvl, + vr.ctypes, + ldvr) + _handle_err_maybe_convergence_problem(r) - _check_finite_matrix(a) + # By design numba does not support dynamic return types, however, + # Numpy does. Numpy uses this ability in the case of returning + # eigenvalues/vectors of a real matrix. The return type of + # np.linalg.eig(), when operating on a matrix in real space + # depends on the values present in the matrix itself (recalling + # that eigenvalues are the roots of the characteristic polynomial + # of the system matrix, which will by construction depend on the + # values present in the system matrix). As numba cannot handle + # the case of a runtime decision based domain change relative to + # the input type, if it is required numba raises as below. + if np.any(wi): + raise ValueError( + "eig() argument must not cause a domain change.") + + # put these in to help with liveness analysis, + # `.ctypes` doesn't keep the vars alive + _dummy_liveness_func([acpy.size, vl.size, vr.size, wr.size, wi.size]) + return (wr, vr.T) + + def cmplx_eig_impl(a): + """ + eig() implementation for complex arrays. + """ + n = a.shape[-1] + if a.shape[-2] != n: + msg = "Last 2 dimensions of the array must be square." + raise np.linalg.LinAlgError(msg) - if F_layout: - acpy = np.copy(a) - else: - acpy = np.asfortranarray(a) - - ldvl = 1 - ldvr = n - w = np.empty(n, dtype=a.dtype) - vl = np.empty((n, ldvl), dtype=a.dtype) - vr = np.empty((n, ldvr), dtype=a.dtype) - - if n == 0: - return (w, vr.T) - - r = numba_ez_cgeev(kind, - JOBVL, - JOBVR, - n, - acpy.ctypes, - n, - w.ctypes, - vl.ctypes, - ldvl, - vr.ctypes, - ldvr) - _handle_err_maybe_convergence_problem(r) - - # put these in to help with liveness analysis, - # `.ctypes` doesn't keep the vars alive - _dummy_liveness_func([acpy.size, vl.size, vr.size, w.size]) - return (w, vr.T) + _check_finite_matrix(a) - if isinstance(a.dtype, types.scalars.Complex): - return cmplx_eig_impl + if F_layout: + acpy = np.copy(a) else: - return real_eig_impl + acpy = np.asfortranarray(a) - @overload(np.linalg.eigvals) - def eigvals_impl(a): - ensure_lapack() + ldvl = 1 + ldvr = n + w = np.empty(n, dtype=a.dtype) + vl = np.empty((n, ldvl), dtype=a.dtype) + vr = np.empty((n, ldvr), dtype=a.dtype) + + if n == 0: + return (w, vr.T) + + r = numba_ez_cgeev(kind, + JOBVL, + JOBVR, + n, + acpy.ctypes, + n, + w.ctypes, + vl.ctypes, + ldvl, + vr.ctypes, + ldvr) + _handle_err_maybe_convergence_problem(r) - _check_linalg_matrix(a, "eigvals") + # put these in to help with liveness analysis, + # `.ctypes` doesn't keep the vars alive + _dummy_liveness_func([acpy.size, vl.size, vr.size, w.size]) + return (w, vr.T) - numba_ez_rgeev = _LAPACK().numba_ez_rgeev(a.dtype) - numba_ez_cgeev = _LAPACK().numba_ez_cgeev(a.dtype) + if isinstance(a.dtype, types.scalars.Complex): + return cmplx_eig_impl + else: + return real_eig_impl - kind = ord(get_blas_kind(a.dtype, "eigvals")) +@overload(np.linalg.eigvals) +def eigvals_impl(a): + ensure_lapack() - JOBVL = ord('N') - JOBVR = ord('N') + _check_linalg_matrix(a, "eigvals") - F_layout = a.layout == 'F' + numba_ez_rgeev = _LAPACK().numba_ez_rgeev(a.dtype) + numba_ez_cgeev = _LAPACK().numba_ez_cgeev(a.dtype) - def real_eigvals_impl(a): - """ - eigvals() implementation for real arrays. - """ - n = a.shape[-1] - if a.shape[-2] != n: - msg = "Last 2 dimensions of the array must be square." - raise np.linalg.LinAlgError(msg) + kind = ord(get_blas_kind(a.dtype, "eigvals")) - _check_finite_matrix(a) + JOBVL = ord('N') + JOBVR = ord('N') - if F_layout: - acpy = np.copy(a) - else: - acpy = np.asfortranarray(a) - - ldvl = 1 - ldvr = 1 - wr = np.empty(n, dtype=a.dtype) - - if n == 0: - return wr - - wi = np.empty(n, dtype=a.dtype) - - # not referenced but need setting for MKL null check - vl = np.empty((1), dtype=a.dtype) - vr = np.empty((1), dtype=a.dtype) - - r = numba_ez_rgeev(kind, - JOBVL, - JOBVR, - n, - acpy.ctypes, - n, - wr.ctypes, - wi.ctypes, - vl.ctypes, - ldvl, - vr.ctypes, - ldvr) - _handle_err_maybe_convergence_problem(r) - - # By design numba does not support dynamic return types, however, - # Numpy does. Numpy uses this ability in the case of returning - # eigenvalues/vectors of a real matrix. The return type of - # np.linalg.eigvals(), when operating on a matrix in real space - # depends on the values present in the matrix itself (recalling - # that eigenvalues are the roots of the characteristic polynomial - # of the system matrix, which will by construction depend on the - # values present in the system matrix). As numba cannot handle - # the case of a runtime decision based domain change relative to - # the input type, if it is required numba raises as below. - if np.any(wi): - raise ValueError( - "eigvals() argument must not cause a domain change.") - - # put these in to help with liveness analysis, - # `.ctypes` doesn't keep the vars alive - _dummy_liveness_func([acpy.size, vl.size, vr.size, wr.size, wi.size]) + F_layout = a.layout == 'F' + + def real_eigvals_impl(a): + """ + eigvals() implementation for real arrays. + """ + n = a.shape[-1] + if a.shape[-2] != n: + msg = "Last 2 dimensions of the array must be square." + raise np.linalg.LinAlgError(msg) + + _check_finite_matrix(a) + + if F_layout: + acpy = np.copy(a) + else: + acpy = np.asfortranarray(a) + + ldvl = 1 + ldvr = 1 + wr = np.empty(n, dtype=a.dtype) + + if n == 0: return wr - def cmplx_eigvals_impl(a): - """ - eigvals() implementation for complex arrays. - """ - n = a.shape[-1] - if a.shape[-2] != n: - msg = "Last 2 dimensions of the array must be square." - raise np.linalg.LinAlgError(msg) + wi = np.empty(n, dtype=a.dtype) + + # not referenced but need setting for MKL null check + vl = np.empty((1), dtype=a.dtype) + vr = np.empty((1), dtype=a.dtype) + + r = numba_ez_rgeev(kind, + JOBVL, + JOBVR, + n, + acpy.ctypes, + n, + wr.ctypes, + wi.ctypes, + vl.ctypes, + ldvl, + vr.ctypes, + ldvr) + _handle_err_maybe_convergence_problem(r) - _check_finite_matrix(a) + # By design numba does not support dynamic return types, however, + # Numpy does. Numpy uses this ability in the case of returning + # eigenvalues/vectors of a real matrix. The return type of + # np.linalg.eigvals(), when operating on a matrix in real space + # depends on the values present in the matrix itself (recalling + # that eigenvalues are the roots of the characteristic polynomial + # of the system matrix, which will by construction depend on the + # values present in the system matrix). As numba cannot handle + # the case of a runtime decision based domain change relative to + # the input type, if it is required numba raises as below. + if np.any(wi): + raise ValueError( + "eigvals() argument must not cause a domain change.") + + # put these in to help with liveness analysis, + # `.ctypes` doesn't keep the vars alive + _dummy_liveness_func([acpy.size, vl.size, vr.size, wr.size, wi.size]) + return wr + + def cmplx_eigvals_impl(a): + """ + eigvals() implementation for complex arrays. + """ + n = a.shape[-1] + if a.shape[-2] != n: + msg = "Last 2 dimensions of the array must be square." + raise np.linalg.LinAlgError(msg) - if F_layout: - acpy = np.copy(a) - else: - acpy = np.asfortranarray(a) - - ldvl = 1 - ldvr = 1 - w = np.empty(n, dtype=a.dtype) - - if n == 0: - return w - - vl = np.empty((1), dtype=a.dtype) - vr = np.empty((1), dtype=a.dtype) - - r = numba_ez_cgeev(kind, - JOBVL, - JOBVR, - n, - acpy.ctypes, - n, - w.ctypes, - vl.ctypes, - ldvl, - vr.ctypes, - ldvr) - _handle_err_maybe_convergence_problem(r) - - # put these in to help with liveness analysis, - # `.ctypes` doesn't keep the vars alive - _dummy_liveness_func([acpy.size, vl.size, vr.size, w.size]) - return w + _check_finite_matrix(a) - if isinstance(a.dtype, types.scalars.Complex): - return cmplx_eigvals_impl + if F_layout: + acpy = np.copy(a) else: - return real_eigvals_impl + acpy = np.asfortranarray(a) - @overload(np.linalg.eigh) - def eigh_impl(a): - ensure_lapack() + ldvl = 1 + ldvr = 1 + w = np.empty(n, dtype=a.dtype) + + if n == 0: + return w - _check_linalg_matrix(a, "eigh") + vl = np.empty((1), dtype=a.dtype) + vr = np.empty((1), dtype=a.dtype) + + r = numba_ez_cgeev(kind, + JOBVL, + JOBVR, + n, + acpy.ctypes, + n, + w.ctypes, + vl.ctypes, + ldvl, + vr.ctypes, + ldvr) + _handle_err_maybe_convergence_problem(r) - F_layout = a.layout == 'F' + # put these in to help with liveness analysis, + # `.ctypes` doesn't keep the vars alive + _dummy_liveness_func([acpy.size, vl.size, vr.size, w.size]) + return w - # convert typing floats to numpy floats for use in the impl - w_type = getattr(a.dtype, "underlying_float", a.dtype) - w_dtype = np_support.as_dtype(w_type) + if isinstance(a.dtype, types.scalars.Complex): + return cmplx_eigvals_impl + else: + return real_eigvals_impl - numba_ez_xxxevd = _LAPACK().numba_ez_xxxevd(a.dtype) +@overload(np.linalg.eigh) +def eigh_impl(a): + ensure_lapack() - kind = ord(get_blas_kind(a.dtype, "eigh")) + _check_linalg_matrix(a, "eigh") - JOBZ = ord('V') - UPLO = ord('L') + F_layout = a.layout == 'F' - def eigh_impl(a): - n = a.shape[-1] + # convert typing floats to numpy floats for use in the impl + w_type = getattr(a.dtype, "underlying_float", a.dtype) + w_dtype = np_support.as_dtype(w_type) - if a.shape[-2] != n: - msg = "Last 2 dimensions of the array must be square." - raise np.linalg.LinAlgError(msg) + numba_ez_xxxevd = _LAPACK().numba_ez_xxxevd(a.dtype) - _check_finite_matrix(a) + kind = ord(get_blas_kind(a.dtype, "eigh")) - if F_layout: - acpy = np.copy(a) - else: - acpy = np.asfortranarray(a) + JOBZ = ord('V') + UPLO = ord('L') - w = np.empty(n, dtype=w_dtype) + def eigh_impl(a): + n = a.shape[-1] - if n == 0: - return (w, acpy) + if a.shape[-2] != n: + msg = "Last 2 dimensions of the array must be square." + raise np.linalg.LinAlgError(msg) - r = numba_ez_xxxevd(kind, # kind - JOBZ, # jobz - UPLO, # uplo - n, # n - acpy.ctypes, # a - n, # lda - w.ctypes # w - ) - _handle_err_maybe_convergence_problem(r) + _check_finite_matrix(a) - # help liveness analysis - _dummy_liveness_func([acpy.size, w.size]) + if F_layout: + acpy = np.copy(a) + else: + acpy = np.asfortranarray(a) + + w = np.empty(n, dtype=w_dtype) + + if n == 0: return (w, acpy) - return eigh_impl + r = numba_ez_xxxevd(kind, # kind + JOBZ, # jobz + UPLO, # uplo + n, # n + acpy.ctypes, # a + n, # lda + w.ctypes # w + ) + _handle_err_maybe_convergence_problem(r) - @overload(np.linalg.eigvalsh) - def eigvalsh_impl(a): - ensure_lapack() + # help liveness analysis + _dummy_liveness_func([acpy.size, w.size]) + return (w, acpy) - _check_linalg_matrix(a, "eigvalsh") + return eigh_impl - F_layout = a.layout == 'F' +@overload(np.linalg.eigvalsh) +def eigvalsh_impl(a): + ensure_lapack() - # convert typing floats to numpy floats for use in the impl - w_type = getattr(a.dtype, "underlying_float", a.dtype) - w_dtype = np_support.as_dtype(w_type) + _check_linalg_matrix(a, "eigvalsh") - numba_ez_xxxevd = _LAPACK().numba_ez_xxxevd(a.dtype) + F_layout = a.layout == 'F' - kind = ord(get_blas_kind(a.dtype, "eigvalsh")) + # convert typing floats to numpy floats for use in the impl + w_type = getattr(a.dtype, "underlying_float", a.dtype) + w_dtype = np_support.as_dtype(w_type) - JOBZ = ord('N') - UPLO = ord('L') + numba_ez_xxxevd = _LAPACK().numba_ez_xxxevd(a.dtype) - def eigvalsh_impl(a): - n = a.shape[-1] + kind = ord(get_blas_kind(a.dtype, "eigvalsh")) - if a.shape[-2] != n: - msg = "Last 2 dimensions of the array must be square." - raise np.linalg.LinAlgError(msg) + JOBZ = ord('N') + UPLO = ord('L') - _check_finite_matrix(a) + def eigvalsh_impl(a): + n = a.shape[-1] - if F_layout: - acpy = np.copy(a) - else: - acpy = np.asfortranarray(a) + if a.shape[-2] != n: + msg = "Last 2 dimensions of the array must be square." + raise np.linalg.LinAlgError(msg) - w = np.empty(n, dtype=w_dtype) + _check_finite_matrix(a) - if n == 0: - return w + if F_layout: + acpy = np.copy(a) + else: + acpy = np.asfortranarray(a) - r = numba_ez_xxxevd(kind, # kind - JOBZ, # jobz - UPLO, # uplo - n, # n - acpy.ctypes, # a - n, # lda - w.ctypes # w - ) - _handle_err_maybe_convergence_problem(r) + w = np.empty(n, dtype=w_dtype) - # help liveness analysis - _dummy_liveness_func([acpy.size, w.size]) + if n == 0: return w - return eigvalsh_impl + r = numba_ez_xxxevd(kind, # kind + JOBZ, # jobz + UPLO, # uplo + n, # n + acpy.ctypes, # a + n, # lda + w.ctypes # w + ) + _handle_err_maybe_convergence_problem(r) - @overload(np.linalg.svd) - def svd_impl(a, full_matrices=1): - ensure_lapack() + # help liveness analysis + _dummy_liveness_func([acpy.size, w.size]) + return w + + return eigvalsh_impl + +@overload(np.linalg.svd) +def svd_impl(a, full_matrices=1): + ensure_lapack() - _check_linalg_matrix(a, "svd") + _check_linalg_matrix(a, "svd") - F_layout = a.layout == 'F' + F_layout = a.layout == 'F' - # convert typing floats to numpy floats for use in the impl - s_type = getattr(a.dtype, "underlying_float", a.dtype) - s_dtype = np_support.as_dtype(s_type) + # convert typing floats to numpy floats for use in the impl + s_type = getattr(a.dtype, "underlying_float", a.dtype) + s_dtype = np_support.as_dtype(s_type) - numba_ez_gesdd = _LAPACK().numba_ez_gesdd(a.dtype) + numba_ez_gesdd = _LAPACK().numba_ez_gesdd(a.dtype) - kind = ord(get_blas_kind(a.dtype, "svd")) + kind = ord(get_blas_kind(a.dtype, "svd")) - JOBZ_A = ord('A') - JOBZ_S = ord('S') + JOBZ_A = ord('A') + JOBZ_S = ord('S') - def svd_impl(a, full_matrices=1): - n = a.shape[-1] - m = a.shape[-2] + def svd_impl(a, full_matrices=1): + n = a.shape[-1] + m = a.shape[-2] - if n == 0 or m == 0: - raise np.linalg.LinAlgError("Arrays cannot be empty") + if n == 0 or m == 0: + raise np.linalg.LinAlgError("Arrays cannot be empty") - _check_finite_matrix(a) + _check_finite_matrix(a) - if F_layout: - acpy = np.copy(a) - else: - acpy = np.asfortranarray(a) + if F_layout: + acpy = np.copy(a) + else: + acpy = np.asfortranarray(a) - ldu = m - minmn = min(m, n) + ldu = m + minmn = min(m, n) - if full_matrices: - JOBZ = JOBZ_A - ucol = m - ldvt = n - else: - JOBZ = JOBZ_S - ucol = minmn - ldvt = minmn - - u = np.empty((ucol, ldu), dtype=a.dtype) - s = np.empty(minmn, dtype=s_dtype) - vt = np.empty((n, ldvt), dtype=a.dtype) - - r = numba_ez_gesdd( - kind, # kind - JOBZ, # jobz - m, # m - n, # n - acpy.ctypes, # a - m, # lda - s.ctypes, # s - u.ctypes, # u - ldu, # ldu - vt.ctypes, # vt - ldvt # ldvt - ) - _handle_err_maybe_convergence_problem(r) - - # help liveness analysis - _dummy_liveness_func([acpy.size, vt.size, u.size, s.size]) - return (u.T, s, vt.T) - - return svd_impl + if full_matrices: + JOBZ = JOBZ_A + ucol = m + ldvt = n + else: + JOBZ = JOBZ_S + ucol = minmn + ldvt = minmn + + u = np.empty((ucol, ldu), dtype=a.dtype) + s = np.empty(minmn, dtype=s_dtype) + vt = np.empty((n, ldvt), dtype=a.dtype) + + r = numba_ez_gesdd( + kind, # kind + JOBZ, # jobz + m, # m + n, # n + acpy.ctypes, # a + m, # lda + s.ctypes, # s + u.ctypes, # u + ldu, # ldu + vt.ctypes, # vt + ldvt # ldvt + ) + _handle_err_maybe_convergence_problem(r) + + # help liveness analysis + _dummy_liveness_func([acpy.size, vt.size, u.size, s.size]) + return (u.T, s, vt.T) + + return svd_impl @overload(np.linalg.qr) @@ -2650,32 +2648,18 @@ def outer_impl(a, b, out): return outer_impl -if numpy_version >= (1, 9): - @overload(np.outer) - def outer_impl(a, b, out=None): - - _check_scalar_or_lt_2d_mat(a, "outer", la_prefix=False) - _check_scalar_or_lt_2d_mat(b, "outer", la_prefix=False) +@overload(np.outer) +def outer_impl(a, b, out=None): - impl = _get_outer_impl(a, b, out) + _check_scalar_or_lt_2d_mat(a, "outer", la_prefix=False) + _check_scalar_or_lt_2d_mat(b, "outer", la_prefix=False) - def outer_impl(a, b, out=None): - return impl(a, b, out) + impl = _get_outer_impl(a, b, out) - return outer_impl -else: - @overload(np.outer) - def outer_impl(a, b): - - _check_scalar_or_lt_2d_mat(a, "outer", la_prefix=False) - _check_scalar_or_lt_2d_mat(b, "outer", la_prefix=False) - - impl = _get_outer_impl(a, b, None) - - def outer_impl(a, b): - return impl(a, b, None) + def outer_impl(a, b, out=None): + return impl(a, b, out) - return outer_impl + return outer_impl def _kron_normaliser_impl(x): diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index 5df652e97a9..d70f14c4d4c 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -291,7 +291,7 @@ def timedelta_over_timedelta(context, builder, sig, args): return impl_ret_untracked(context, builder, sig.return_type, res) -if numpy_support.version >= (1, 16): +if numpy_support.numpy_version >= (1, 16): # np 1.16 added support for: # * np.floor_divide on mm->q # * np.remainder on mm->m @@ -384,7 +384,7 @@ def impl(context, builder, sig, args): else: builder.store(builder.icmp(ll_op, norm_a, norm_b), ret) with otherwise: - if numpy_support.version < (1, 16): + if numpy_support.numpy_version < (1, 16): # No scaling when comparing NaTs builder.store(builder.icmp(ll_op, va, vb), ret) else: @@ -411,7 +411,7 @@ def impl(context, builder, sig, args): context, builder, va, vb, ta, tb) builder.store(builder.icmp(ll_op, norm_a, norm_b), ret) with otherwise: - if numpy_support.version < (1, 16): + if numpy_support.numpy_version < (1, 16): # No scaling when comparing NaT with something else # (i.e. NaT is <= everything else, since it's the smallest # int64 value) @@ -674,7 +674,7 @@ def impl(context, builder, sig, args): ret_val = builder.icmp(ll_op, norm_a, norm_b) builder.store(ret_val, ret) with otherwise: - if numpy_support.version < (1, 16): + if numpy_support.numpy_version < (1, 16): # No scaling when comparing NaTs ret_val = builder.icmp(ll_op, va, vb) else: diff --git a/numba/targets/ufunc_db.py b/numba/targets/ufunc_db.py index e537c9b952a..452e5734502 100644 --- a/numba/targets/ufunc_db.py +++ b/numba/targets/ufunc_db.py @@ -48,9 +48,7 @@ def _fill_ufunc_db(ufunc_db): # imports if done at global scope when importing the numba # module. from . import numbers, npyfuncs, mathimpl, cmathimpl - from numba import numpy_support - - v = numpy_support.version + from numba.numpy_support import numpy_version ufunc_db[np.negative] = { '?->?': numbers.int_invert_impl, @@ -271,32 +269,31 @@ def _fill_ufunc_db(ufunc_db): 'DD->D': npyfuncs.np_complex_power_impl, } - if v >= (1, 15): - ufunc_db[np.gcd] = { - 'bb->b': npyfuncs.np_gcd_impl, - 'BB->B': npyfuncs.np_gcd_impl, - 'hh->h': npyfuncs.np_gcd_impl, - 'HH->H': npyfuncs.np_gcd_impl, - 'ii->i': npyfuncs.np_gcd_impl, - 'II->I': npyfuncs.np_gcd_impl, - 'll->l': npyfuncs.np_gcd_impl, - 'LL->L': npyfuncs.np_gcd_impl, - 'qq->q': npyfuncs.np_gcd_impl, - 'QQ->Q': npyfuncs.np_gcd_impl, - } - - ufunc_db[np.lcm] = { - 'bb->b': npyfuncs.np_lcm_impl, - 'BB->B': npyfuncs.np_lcm_impl, - 'hh->h': npyfuncs.np_lcm_impl, - 'HH->H': npyfuncs.np_lcm_impl, - 'ii->i': npyfuncs.np_lcm_impl, - 'II->I': npyfuncs.np_lcm_impl, - 'll->l': npyfuncs.np_lcm_impl, - 'LL->L': npyfuncs.np_lcm_impl, - 'qq->q': npyfuncs.np_lcm_impl, - 'QQ->Q': npyfuncs.np_lcm_impl, - } + ufunc_db[np.gcd] = { + 'bb->b': npyfuncs.np_gcd_impl, + 'BB->B': npyfuncs.np_gcd_impl, + 'hh->h': npyfuncs.np_gcd_impl, + 'HH->H': npyfuncs.np_gcd_impl, + 'ii->i': npyfuncs.np_gcd_impl, + 'II->I': npyfuncs.np_gcd_impl, + 'll->l': npyfuncs.np_gcd_impl, + 'LL->L': npyfuncs.np_gcd_impl, + 'qq->q': npyfuncs.np_gcd_impl, + 'QQ->Q': npyfuncs.np_gcd_impl, + } + + ufunc_db[np.lcm] = { + 'bb->b': npyfuncs.np_lcm_impl, + 'BB->B': npyfuncs.np_lcm_impl, + 'hh->h': npyfuncs.np_lcm_impl, + 'HH->H': npyfuncs.np_lcm_impl, + 'ii->i': npyfuncs.np_lcm_impl, + 'II->I': npyfuncs.np_lcm_impl, + 'll->l': npyfuncs.np_lcm_impl, + 'LL->L': npyfuncs.np_lcm_impl, + 'qq->q': npyfuncs.np_lcm_impl, + 'QQ->Q': npyfuncs.np_lcm_impl, + } ufunc_db[np.rint] = { 'f->f': npyfuncs.np_real_rint_impl, @@ -426,8 +423,7 @@ def _fill_ufunc_db(ufunc_db): 'D->D': npyfuncs.np_complex_cos_impl, } - tan_impl = cmathimpl.tan_impl if v >= ( - 1, 10) else npyfuncs.np_complex_tan_impl + tan_impl = cmathimpl.tan_impl ufunc_db[np.tan] = { 'f->f': npyfuncs.np_real_tan_impl, @@ -436,8 +432,7 @@ def _fill_ufunc_db(ufunc_db): 'D->D': tan_impl, } - arcsin_impl = cmathimpl.asin_impl if v >= ( - 1, 10) else npyfuncs.np_complex_asin_impl + arcsin_impl = cmathimpl.asin_impl ufunc_db[np.arcsin] = { 'f->f': npyfuncs.np_real_asin_impl, @@ -453,8 +448,7 @@ def _fill_ufunc_db(ufunc_db): 'D->D': cmathimpl.acos_impl, } - arctan_impl = cmathimpl.atan_impl if v >= ( - 1, 10) else npyfuncs.np_complex_atan_impl + arctan_impl = cmathimpl.atan_impl ufunc_db[np.arctan] = { 'f->f': npyfuncs.np_real_atan_impl, @@ -494,8 +488,7 @@ def _fill_ufunc_db(ufunc_db): 'D->D': npyfuncs.np_complex_tanh_impl, } - arcsinh_impl = cmathimpl.asinh_impl if v >= ( - 1, 10) else npyfuncs.np_complex_asinh_impl + arcsinh_impl = cmathimpl.asinh_impl ufunc_db[np.arcsinh] = { 'f->f': npyfuncs.np_real_asinh_impl, @@ -511,8 +504,7 @@ def _fill_ufunc_db(ufunc_db): 'D->D': npyfuncs.np_complex_acosh_impl, } - arctanh_impl = cmathimpl.atanh_impl if v >= ( - 1, 10) else npyfuncs.np_complex_atanh_impl + arctanh_impl = cmathimpl.atanh_impl ufunc_db[np.arctanh] = { 'f->f': npyfuncs.np_real_atanh_impl, @@ -1037,7 +1029,7 @@ def _fill_ufunc_db(ufunc_db): 'md->m': npdatetime.timedelta_over_number, }) - if numpy_support.version >= (1, 16): + if numpy_version >= (1, 16): ufunc_db[np.floor_divide].update({ 'mm->q': npdatetime.timedelta_floor_div_timedelta, }) @@ -1085,7 +1077,7 @@ def _fill_ufunc_db(ufunc_db): 'mm->m': npdatetime.timedelta_min_impl, }) - if numpy_support.version >= (1, 16): + if numpy_version >= (1, 16): ufunc_db[np.remainder].update({ 'mm->m': npdatetime.timedelta_mod_timedelta, }) diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index de47501af2e..956bad4dab9 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -12,7 +12,6 @@ from numba.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager from numba.targets import cpu, registry -from numba.numpy_support import version as numpy_version from numba.ir_utils import remove_dead from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, @@ -850,29 +849,28 @@ def test_vsd_stack(): self.with_equiv('v', (2, 3, 8)), ]) - if numpy_version >= (1, 10): - def test_stack(m, n): - a = np.ones(m) - b = np.ones(n) - c = np.stack((a, b)) - d = np.ones((m, n)) - e = np.ones((m, n)) - f = np.stack((d, e)) - g = np.stack((d, e), axis=0) - h = np.stack((d, e), axis=1) - i = np.stack((d, e), axis=2) - j = np.stack((d, e), axis=-1) - - self._compile_and_test(test_stack, (types.intp, types.intp), - equivs=[self.with_equiv('m', 'n'), - self.with_equiv('c', (2, 'm')), - self.with_equiv( - 'f', 'g', (2, 'm', 'n')), - self.with_equiv( - 'h', ('m', 2, 'n')), - self.with_equiv( - 'i', 'j', ('m', 'n', 2)), - ]) + def test_stack(m, n): + a = np.ones(m) + b = np.ones(n) + c = np.stack((a, b)) + d = np.ones((m, n)) + e = np.ones((m, n)) + f = np.stack((d, e)) + g = np.stack((d, e), axis=0) + h = np.stack((d, e), axis=1) + i = np.stack((d, e), axis=2) + j = np.stack((d, e), axis=-1) + + self._compile_and_test(test_stack, (types.intp, types.intp), + equivs=[self.with_equiv('m', 'n'), + self.with_equiv('c', (2, 'm')), + self.with_equiv( + 'f', 'g', (2, 'm', 'n')), + self.with_equiv( + 'h', ('m', 2, 'n')), + self.with_equiv( + 'i', 'j', ('m', 'n', 2)), + ]) def test_linspace(m, n): a = np.linspace(m, n) diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index d5b23758602..8fc43e509e1 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -4,7 +4,6 @@ import numpy as np import numba.unittest_support as unittest -from numba.numpy_support import version as np_version from numba.compiler import compile_isolated, Flags from numba import jit, njit, types, from_dtype, errors, typeof from numba.errors import TypingError @@ -781,7 +780,6 @@ def check(x): str(raises.exception)) def test_flatnonzero_basic(self): - # these tests should pass in all numpy versions pyfunc = numpy_flatnonzero cfunc = jit(nopython=True)(pyfunc) @@ -838,15 +836,13 @@ def array_like_variations(): yield True yield (True, False, True) yield 2 + 1j - # the following are not array-like, but numpy 1.15+ does not raise + # the following are not array-like, but NumPy does not raise yield None yield 'a_string' yield '' - @unittest.skipUnless(np_version >= (1, 15), - "flatnonzero array-like handling per 1.15+") - def test_flatnonzero_array_like_115_and_on(self): - # these tests should pass where numpy version is >= 1.15 + + def test_flatnonzero_array_like(self): pyfunc = numpy_flatnonzero cfunc = jit(nopython=True)(pyfunc) @@ -855,26 +851,6 @@ def test_flatnonzero_array_like_115_and_on(self): got = cfunc(a) self.assertPreciseEqual(expected, got) - @unittest.skipUnless(np_version < (1, 15), - "flatnonzero array-like handling pre 1.15") - def test_flatnonzero_array_like_pre_115(self): - # these tests should pass where numpy version is < 1.15 - pyfunc = numpy_flatnonzero - cfunc = jit(nopython=True)(pyfunc) - - for a in self.array_like_variations(): - with self.assertTypingError() as e: - cfunc(a) - - self.assertIn("Argument 'a' must be an array", str(e.exception)) - - # numpy raises an Attribute error with: - # 'xxx' object has no attribute 'ravel' - with self.assertRaises(AttributeError) as e: - pyfunc(a) - - self.assertIn("object has no attribute 'ravel'", str(e.exception)) - def test_argwhere_array_like(self): pyfunc = numpy_argwhere cfunc = jit(nopython=True)(pyfunc) @@ -882,7 +858,7 @@ def test_argwhere_array_like(self): expected = pyfunc(a) got = cfunc(a) self.assertPreciseEqual(expected, got) - + if __name__ == '__main__': unittest.main() diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index e5476719d39..3d002a3333b 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -8,8 +8,7 @@ from numba import jit, typeof, types from numba.compiler import compile_isolated from numba.errors import TypingError, LoweringError -from numba.numpy_support import (as_dtype, strict_ufunc_typing, - version as numpy_version) +from numba.numpy_support import as_dtype, strict_ufunc_typing from .support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, tag, needs_blas) @@ -513,8 +512,7 @@ def test_np_frombuffer(self): def test_np_frombuffer_dtype(self): self.check_np_frombuffer(np_frombuffer_dtype) - def check_layout_dependent_func(self, pyfunc, fac=np.arange, - check_sameness=True): + def check_layout_dependent_func(self, pyfunc, fac=np.arange): def is_same(a, b): return a.ctypes.data == b.ctypes.data def check_arr(arr): @@ -522,8 +520,7 @@ def check_arr(arr): expected = pyfunc(arr) got = cres.entry_point(arr) self.assertPreciseEqual(expected, got) - if check_sameness: - self.assertEqual(is_same(expected, arr), is_same(got, arr)) + self.assertEqual(is_same(expected, arr), is_same(got, arr)) arr = fac(24) check_arr(arr) check_arr(arr.reshape((3, 8))) @@ -550,12 +547,10 @@ def test_np_copy(self): self.check_layout_dependent_func(np_copy) def test_np_asfortranarray(self): - self.check_layout_dependent_func(np_asfortranarray, - check_sameness=numpy_version >= (1, 8)) + self.check_layout_dependent_func(np_asfortranarray) def test_np_ascontiguousarray(self): - self.check_layout_dependent_func(np_ascontiguousarray, - check_sameness=numpy_version > (1, 11)) + self.check_layout_dependent_func(np_ascontiguousarray) def check_np_frombuffer_allocated(self, pyfunc): def run(shape): @@ -650,13 +645,7 @@ def check_arr(arr, layout=False): cres = compile_isolated(pyfunc, (typeof(arr), typeof(x), typeof(y))) expected = pyfunc(arr, x, y) got = cres.entry_point(arr, x, y) - # Contiguity of result varies across Numpy versions, only - # check contents. NumPy 1.11+ seems to stabilize. - if numpy_version < (1, 11): - self.assertEqual(got.dtype, expected.dtype) - np.testing.assert_array_equal(got, expected) - else: - self.assertPreciseEqual(got, expected) + self.assertPreciseEqual(got, expected) def check_scal(scal): x = 4 diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 786eb5959d4..e85d3e2ccdd 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -11,7 +11,6 @@ from numba import njit from numba import types from numba import utils -from numba.numpy_support import version as numpy_version from .support import MemoryLeakMixin, TestCase, tag @@ -667,7 +666,6 @@ def setUp(self): self.pyfunc = np.ones -@unittest.skipIf(numpy_version < (1, 8), "test requires Numpy 1.8 or later") class TestNdFull(ConstructorBaseTest, TestCase): def check_result_value(self, ret, expected): @@ -874,7 +872,6 @@ def test_like_dtype_structured(self): super(TestNdOnesLike, self).test_like_dtype_structured() -@unittest.skipIf(numpy_version < (1, 8), "test requires Numpy 1.8 or later") class TestNdFullLike(ConstructorLikeBaseTest, TestCase): def check_result_value(self, ret, expected): diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index 0600989af5f..6591e818855 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -10,7 +10,6 @@ from numba import unittest_support as unittest from numba import jit, errors -from numba.numpy_support import version as numpy_version from .support import TestCase, tag, needs_lapack, needs_blas, _is_armv7l from .matmul_usecase import matmul_usecase @@ -395,12 +394,8 @@ def trace_matrix_no_offset(a): return np.trace(a) -if numpy_version >= (1, 9): - def outer_matrix(a, b, out=None): - return np.outer(a, b, out=out) -else: - def outer_matrix(a, b): - return np.outer(a, b) +def outer_matrix(a, b, out=None): + return np.outer(a, b, out=out) def kron_matrix(a, b): @@ -512,20 +507,6 @@ def specific_sample_matrix( return Q - def shape_with_0_input(self, *args): - """ - returns True if an input argument has a dimension that is zero - and Numpy version is < 1.13, else False. This is due to behaviour - changes in handling dimension zero arrays: - https://github.com/numpy/numpy/issues/10573 - """ - if numpy_version < (1, 13): - for x in args: - if isinstance(x, np.ndarray): - if 0 in x.shape: - return True - return False - def assert_error(self, cfunc, args, msg, err=ValueError): with self.assertRaises(err) as raises: cfunc(*args) @@ -811,11 +792,6 @@ def test_linalg_cholesky(self): cfunc = jit(nopython=True)(cholesky_matrix) def check(a): - if self.shape_with_0_input(a): - # has shape with 0 on input, numpy will fail, - # just make sure Numba runs without error - cfunc(a) - return expected = cholesky_matrix(a) got = cfunc(a) use_reconstruction = False @@ -898,11 +874,6 @@ def checker_for_linalg_eig( cfunc = jit(nopython=True)(func) def check(a): - if self.shape_with_0_input(a): - # has shape with 0 on input, numpy will fail, - # just make sure Numba runs without error - cfunc(a) - return expected = func(a) got = cfunc(a) # check that the returned tuple is same length @@ -1658,11 +1629,6 @@ def test_linalg_pinv(self): cfunc = jit(nopython=True)(pinv_matrix) def check(a, **kwargs): - if self.shape_with_0_input(a): - # has shape with 0 on input, numpy will fail, - # just make sure Numba runs without error - cfunc(a, **kwargs) - return expected = pinv_matrix(a, **kwargs) got = cfunc(a, **kwargs) @@ -1781,11 +1747,6 @@ class TestLinalgDetAndSlogdet(TestLinalgBase): """ def check_det(self, cfunc, a, **kwargs): - if self.shape_with_0_input(a): - # has shape with 0 on input, numpy will fail, - # just make sure Numba runs without error - cfunc(a, **kwargs) - return expected = det_matrix(a, **kwargs) got = cfunc(a, **kwargs) @@ -1799,11 +1760,6 @@ def check_det(self, cfunc, a, **kwargs): cfunc(a, **kwargs) def check_slogdet(self, cfunc, a, **kwargs): - if self.shape_with_0_input(a): - # has shape with 0 on input, numpy will fail, - # just make sure Numba runs without error - cfunc(a, **kwargs) - return expected = slogdet_matrix(a, **kwargs) got = cfunc(a, **kwargs) @@ -2040,26 +1996,17 @@ def check(a, **kwargs): self.assert_raise_on_empty(cfunc, (np.empty(sz),)) # singular systems to trip divide-by-zero - # only for np > 1.14, before this norm was computed via inversion which - # will fail with numpy.linalg.linalg.LinAlgError: Singular matrix - if numpy_version > (1, 14): - x = np.array([[1, 0], [0, 0]], dtype=np.float64) - check(x) - check(x, p=2) - x = np.array([[0, 0], [0, 0]], dtype=np.float64) - check(x, p=-2) + x = np.array([[1, 0], [0, 0]], dtype=np.float64) + check(x) + check(x, p=2) + x = np.array([[0, 0], [0, 0]], dtype=np.float64) + check(x, p=-2) # try an ill-conditioned system with 2-norm, make sure np raises an # overflow warning as the result is `+inf` and that the result from # numba matches. with warnings.catch_warnings(): a = np.array([[1.e308, 0], [0, 0.1]], dtype=np.float64) - if numpy_version < (1, 15): - # overflow warning is silenced in np >= 1.15 - warnings.simplefilter("error", RuntimeWarning) - self.assertRaisesRegexp(RuntimeWarning, - 'overflow encountered in.*', - check, a) warnings.simplefilter("ignore", RuntimeWarning) check(a) @@ -2406,10 +2353,9 @@ def check(a, b, **kwargs): product(self.sizes, self.sizes, self.dtypes): (a, b) = self._get_input(size1, size2, dtype) check(a, b) - if numpy_version >= (1, 9): - c = np.empty((np.asarray(a).size, np.asarray(b).size), - dtype=np.asarray(a).dtype) - check(a, b, out=c) + c = np.empty((np.asarray(a).size, np.asarray(b).size), + dtype=np.asarray(a).dtype) + check(a, b, out=c) self._assert_wrong_dim("outer", cfunc) diff --git a/numba/typing/npydecl.py b/numba/typing/npydecl.py index a97a394b4f5..6ad8e1489ad 100644 --- a/numba/typing/npydecl.py +++ b/numba/typing/npydecl.py @@ -11,7 +11,6 @@ supported_ufunc_loop, as_dtype, from_dtype, as_dtype, resolve_output_type, carray, farray) -from ..numpy_support import version as numpy_version from ..errors import TypingError, NumbaPerformanceWarning from numba import pndindex @@ -275,10 +274,7 @@ def generic(self, args, kws): "rint", "sign", "conjugate", "exp", "exp2", "log", "log2", "log10", "expm1", "log1p", "sqrt", "square", "reciprocal", - "divide", "mod", "abs", "fabs" ] - -if numpy_version >= (1, 15): - _math_operations += ["gcd", "lcm"] + "divide", "mod", "abs", "fabs" , "gcd", "lcm"] _trigonometric_functions = [ "sin", "cos", "tan", "arcsin", "arccos", "arctan", "arctan2", @@ -562,48 +558,44 @@ def typer(arg, dtype=None): infer_global(np.ones_like)(NdConstructorLike) -if numpy_version >= (1, 8): - @infer_global(np.full) - class NdFull(CallableTemplate): +@infer_global(np.full) +class NdFull(CallableTemplate): - def generic(self): - def typer(shape, fill_value, dtype=None): - if dtype is None: - if numpy_version < (1, 12): - nb_dtype = types.float64 - else: - nb_dtype = fill_value - else: - nb_dtype = _parse_dtype(dtype) - - ndim = _parse_shape(shape) - if nb_dtype is not None and ndim is not None: - return types.Array(dtype=nb_dtype, ndim=ndim, layout='C') - - return typer - - @infer_global(np.full_like) - class NdFullLike(CallableTemplate): - - def generic(self): - """ - np.full_like(array, val) -> array of the same shape and layout - np.full_like(scalar, val) -> 0-d array of the scalar type - """ - def typer(arg, fill_value, dtype=None): - if dtype is not None: - nb_dtype = _parse_dtype(dtype) - elif isinstance(arg, types.Array): - nb_dtype = arg.dtype + def generic(self): + def typer(shape, fill_value, dtype=None): + if dtype is None: + nb_dtype = fill_value + else: + nb_dtype = _parse_dtype(dtype) + + ndim = _parse_shape(shape) + if nb_dtype is not None and ndim is not None: + return types.Array(dtype=nb_dtype, ndim=ndim, layout='C') + + return typer + +@infer_global(np.full_like) +class NdFullLike(CallableTemplate): + + def generic(self): + """ + np.full_like(array, val) -> array of the same shape and layout + np.full_like(scalar, val) -> 0-d array of the scalar type + """ + def typer(arg, fill_value, dtype=None): + if dtype is not None: + nb_dtype = _parse_dtype(dtype) + elif isinstance(arg, types.Array): + nb_dtype = arg.dtype + else: + nb_dtype = arg + if nb_dtype is not None: + if isinstance(arg, types.Array): + return arg.copy(dtype=nb_dtype, readonly=False) else: - nb_dtype = arg - if nb_dtype is not None: - if isinstance(arg, types.Array): - return arg.copy(dtype=nb_dtype, readonly=False) - else: - return types.Array(dtype=nb_dtype, ndim=0, layout='C') + return types.Array(dtype=nb_dtype, ndim=0, layout='C') - return typer + return typer @infer_global(np.identity) @@ -824,28 +816,27 @@ def typer(arrays, axis=None): return typer -if numpy_version >= (1, 10): - @infer_global(np.stack) - class NdStack(CallableTemplate): +@infer_global(np.stack) +class NdStack(CallableTemplate): - def generic(self): - def typer(arrays, axis=None): - if axis is not None and not isinstance(axis, types.Integer): - # Note Numpy allows axis=None, but it isn't documented: - # https://github.com/numpy/numpy/issues/7968 - return + def generic(self): + def typer(arrays, axis=None): + if axis is not None and not isinstance(axis, types.Integer): + # Note Numpy allows axis=None, but it isn't documented: + # https://github.com/numpy/numpy/issues/7968 + return - dtype, ndim = _sequence_of_arrays(self.context, - "np.stack", arrays) + dtype, ndim = _sequence_of_arrays(self.context, + "np.stack", arrays) - # This diverges from Numpy's behaviour, which simply inserts - # a new stride at the requested axis (therefore can return - # a 'A' array). - layout = 'F' if all(a.layout == 'F' for a in arrays) else 'C' + # This diverges from Numpy's behaviour, which simply inserts + # a new stride at the requested axis (therefore can return + # a 'A' array). + layout = 'F' if all(a.layout == 'F' for a in arrays) else 'C' - return types.Array(dtype, ndim + 1, layout) + return types.Array(dtype, ndim + 1, layout) - return typer + return typer class BaseStackTemplate(CallableTemplate): diff --git a/numba/typing/randomdecl.py b/numba/typing/randomdecl.py index 2d244df79e3..bdda70966fc 100644 --- a/numba/typing/randomdecl.py +++ b/numba/typing/randomdecl.py @@ -5,7 +5,7 @@ from .. import types from .templates import (ConcreteTemplate, AbstractTemplate, AttributeTemplate, CallableTemplate, Registry, signature) -from ..numpy_support import version as np_version +from ..numpy_support import numpy_version registry = Registry() @@ -105,7 +105,7 @@ def typer(size=None): return self.array_typer(size)() return typer -if np_version >= (1, 17): +if numpy_version >= (1, 17): infer_global( np.random.random_sample, typing_key="np.random.random_sample", From d82d4592dbca77b491341cf04a74eb1946390a32 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 13:16:54 +0000 Subject: [PATCH 255/595] Remove fixup from removals 1 --- numba/targets/arraymath.py | 11 ++- numba/tests/support.py | 2 +- numba/tests/test_indexing.py | 10 +-- numba/tests/test_np_functions.py | 131 ++++++++----------------------- 4 files changed, 48 insertions(+), 106 deletions(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index a6e9c9918de..dee598d6be6 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -3805,8 +3805,17 @@ def op_nop(x): a_op = op_conj b_op = op_nop + _NP_PRED = numpy_version > (1, 17) + def impl(a, v): - if len(a) < len(v): + la = len(a) + lv = len(v) + if _NP_PRED is True: + if la == 0: + raise ValueError("'a' cannot be empty") + if lv == 0: + raise ValueError("'v' cannot be empty") + if la < lv: return _np_correlate_core(b_op(v), a_op(a), Mode.VALID, -1) else: return _np_correlate_core(a_op(a), b_op(v), Mode.VALID, 1) diff --git a/numba/tests/support.py b/numba/tests/support.py index b10cac05b5c..bb23789d98f 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -444,7 +444,7 @@ def _assertNumberEqual(first, second, delta=None): _assertNumberEqual(first.imag, second.imag, delta) elif isinstance(first, (np.timedelta64, np.datetime64)): # Since Np 1.16 NaT == NaT is False, so special comparison needed - if numpy_support.version >= (1, 16) and np.isnat(first): + if numpy_support.numpy_version >= (1, 16) and np.isnat(first): self.assertEqual(np.isnat(first), np.isnat(second)) else: _assertNumberEqual(first, second, delta) diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index 7f2a4a7d838..c9a5350be62 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -5,7 +5,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, utils, njit, errors, typeof, numpy_support +from numba import types, utils, njit, errors, typeof from .support import TestCase, tag @@ -831,11 +831,9 @@ def check_1d_slicing_set_sequence(self, flags, seqty, seq): got = cfunc(arg.copy(), *args) self.assertPreciseEqual(expected, got) - if numpy_support.version != (1, 7): - # Numpy 1.7 doesn't always raise an error here (object mode) - args = (seq, 1, -N + k, 1) - with self.assertRaises(ValueError) as raises: - cfunc(arg.copy(), *args) + args = (seq, 1, -N + k, 1) + with self.assertRaises(ValueError) as raises: + cfunc(arg.copy(), *args) def test_1d_slicing_set_tuple(self, flags=enable_pyobj_flags): """ diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index cb97ad1fb7e..1bcb81230ba 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -10,7 +10,7 @@ from numba import unittest_support as unittest from numba.compiler import Flags from numba import jit, njit, typeof, types -from numba.numpy_support import version as np_version +from numba.numpy_support import numpy_version from numba.errors import TypingError from numba.config import IS_WIN32, IS_32BITS from numba.utils import pysignature @@ -477,7 +477,6 @@ def test_array_equal_exception(self): str(raises.exception) ) - @unittest.skipIf(np_version < (1, 12), "NumPy Unsupported") def test_count_nonzero(self): def arrays(): @@ -496,18 +495,6 @@ def arrays(): got = cfunc(arr, axis) self.assertPreciseEqual(expected, got) - @unittest.skipUnless(np_version < (1, 12), "NumPy Unsupported") - def test_count_nonzero_exception(self): - pyfunc = count_nonzero - cfunc = jit(nopython=True)(pyfunc) - - with self.assertRaises(TypingError) as raises: - cfunc(np.arange(3 * 4).reshape(3, 4), 0) - self.assertIn( - "axis is not supported for NumPy versions < 1.12.0", - str(raises.exception) - ) - def test_np_append(self): def arrays(): yield 2, 2, None @@ -818,13 +805,9 @@ def check(*args): bins2 = np.float64([1, 3, 4.5, 8, float('inf'), float('-inf')]) bins3 = np.float64([1, 3, 4.5, 8, float('inf'), float('-inf')] + [float('nan')] * 10) - if np_version >= (1, 10): - all_bins = [bins1, bins2, bins3] - xs = [values, values.reshape((3, 4))] - else: - # Numpy < 1.10 had trouble with NaNs and N-d arrays - all_bins = [bins1, bins2] - xs = [values] + + all_bins = [bins1, bins2, bins3] + xs = [values, values.reshape((3, 4))] # 2-ary digitize() for bins in all_bins: @@ -909,26 +892,24 @@ def _test_correlate_convolve(self, pyfunc): def test_correlate(self): self._test_correlate_convolve(correlate) - # correlate supports 0 dimension arrays - _a = np.ones(shape=(0,)) - _b = np.arange(5) - cfunc = jit(nopython=True)(correlate) - for x, y in [(_a, _b), (_b, _a), (_a, _a)]: - expected = correlate(x, y) - got = cfunc(x, y) - self.assertPreciseEqual(expected, got) - - def test_convolve(self): - self._test_correlate_convolve(convolve) + if numpy_version < (1, 18): + # correlate supported 0 dimension arrays until 1.18 + _a = np.ones(shape=(0,)) + _b = np.arange(5) + cfunc = jit(nopython=True)(correlate) + for x, y in [(_a, _b), (_b, _a), (_a, _a)]: + expected = correlate(x, y) + got = cfunc(x, y) + self.assertPreciseEqual(expected, got) - def test_convolve_exceptions(self): + def _test_correlate_convolve_exceptions(self, fn): # Exceptions leak references self.disable_leak_check() # convolve raises if either array has a 0 dimension _a = np.ones(shape=(0,)) _b = np.arange(5) - cfunc = jit(nopython=True)(convolve) + cfunc = jit(nopython=True)(fn) for x, y in [(_a, _b), (_b, _a)]: with self.assertRaises(ValueError) as raises: cfunc(x, y) @@ -937,6 +918,17 @@ def test_convolve_exceptions(self): else: self.assertIn("'v' cannot be empty", str(raises.exception)) + @unittest.skipIf(numpy_version < (1, 18), "NumPy > 1.17 required") + def test_correlate_exceptions(self): + # correlate supported 0 dimension arrays until 1.18 + self._test_correlate_convolve_exceptions(correlate) + + def test_convolve(self): + self._test_correlate_convolve(convolve) + + def test_convolve_exceptions(self): + self._test_correlate_convolve_exceptions(convolve) + def _check_output(self, pyfunc, cfunc, params, abs_tol=None): expected = pyfunc(**params) got = cfunc(**params) @@ -1691,7 +1683,6 @@ def test_partition_boolean_inputs(self): for kth in True, False, -1, 0, 1: self.partition_sanity_check(pyfunc, cfunc, d, kth) - @unittest.skipUnless(np_version >= (1, 10), "cov needs Numpy 1.10+") @needs_blas def test_cov_invalid_ddof(self): pyfunc = cov @@ -1755,19 +1746,16 @@ def input_variations(): for input_arr in input_variations(): _check({first_arg_name: input_arr}) - @unittest.skipUnless(np_version >= (1, 10), "corrcoef needs Numpy 1.10+") @needs_blas def test_corrcoef_basic(self): pyfunc = corrcoef self.corr_corrcoef_basic(pyfunc, first_arg_name='x') - @unittest.skipUnless(np_version >= (1, 10), "cov needs Numpy 1.10+") @needs_blas def test_cov_basic(self): pyfunc = cov self.corr_corrcoef_basic(pyfunc, first_arg_name='m') - @unittest.skipUnless(np_version >= (1, 10), "cov needs Numpy 1.10+") @needs_blas def test_cov_explicit_arguments(self): pyfunc = cov @@ -1787,7 +1775,6 @@ def test_cov_explicit_arguments(self): 'bias': bias, 'rowvar': rowvar} _check(params) - @unittest.skipUnless(np_version >= (1, 10), "corrcoef needs Numpy 1.10+") @needs_blas def test_corrcoef_explicit_arguments(self): pyfunc = corrcoef @@ -1864,7 +1851,6 @@ def cov_corrcoef_edge_cases(self, pyfunc, first_arg_name): params = {first_arg_name: y, 'y': m, 'rowvar': rowvar} _check(params) - @unittest.skipUnless(np_version >= (1, 10), "corrcoef needs Numpy 1.10+") @needs_blas def test_corrcoef_edge_cases(self): pyfunc = corrcoef @@ -1877,7 +1863,6 @@ def test_corrcoef_edge_cases(self): params = {'x': x} _check(params) - @unittest.skipUnless(np_version >= (1, 11), "behaviour per Numpy 1.11+") @needs_blas def test_corrcoef_edge_case_extreme_values(self): pyfunc = corrcoef @@ -1889,19 +1874,6 @@ def test_corrcoef_edge_case_extreme_values(self): params = {'x': x} _check(params) - # Note - # ---- - # Numpy 1.10 output is: - # [[ 0. -0.] - # [-0. 0.]] - # - # Numpy 1.11+ output is: - # [[ 1. -1.] - # [-1. 1.]] - # - # Numba implementation replicates Numpy 1.11+ behaviour - - @unittest.skipUnless(np_version >= (1, 10), "cov needs Numpy 1.10+") @needs_blas def test_cov_edge_cases(self): pyfunc = cov @@ -1915,7 +1887,6 @@ def test_cov_edge_cases(self): params = {'m': m, 'ddof': 5} _check(params) - @unittest.skipUnless(np_version >= (1, 10), "cov needs Numpy 1.10+") @needs_blas def test_cov_exceptions(self): pyfunc = cov @@ -1966,7 +1937,6 @@ def _check_y(m, y): self.assertIn('2D array containing a single row is unsupported', str(raises.exception)) - @unittest.skipUnless(np_version >= (1, 12), "ediff1d needs Numpy 1.12+") def test_ediff1d_basic(self): pyfunc = ediff1d cfunc = jit(nopython=True)(pyfunc) @@ -1997,7 +1967,6 @@ def ary_variations(a): params = {'ary': ary, 'to_begin': a, 'to_end': b} _check(params) - @unittest.skipUnless(np_version >= (1, 12), "ediff1d needs Numpy 1.12+") def test_ediff1d_edge_cases(self): # NOTE: NumPy 1.16 has a variety of behaviours for type conversion, see # https://github.com/numpy/numpy/issues/13103, as this is not resolved @@ -2025,7 +1994,7 @@ def input_variations(): yield [4, 5, 6] yield np.array([]) yield () - if np_version < (1, 16): + if numpy_version < (1, 16): yield np.array([np.nan, np.inf, 4, -np.inf, 3.142]) parts = np.array([np.nan, 2, np.nan, 4, 5, 6, 7, 8, 9]) a = parts + 1j * parts[::-1] @@ -2043,7 +2012,7 @@ def input_variations(): ## fixed here: https://github.com/numpy/numpy/pull/12713 for np 1.16 to_begin = np.array([1, 2, 3.142, np.nan, 5, 6, 7, -8, np.nan]) params = {'ary': np.arange(-4, 6), 'to_begin': to_begin} - if np_version < (1, 16): + if numpy_version < (1, 16): _check(params) else: # np 1.16 raises, cannot cast float64 array to intp array @@ -2054,7 +2023,7 @@ def input_variations(): _check(params) params = {'ary': 3, 'to_begin': 3.142} - if np_version < (1, 16): + if numpy_version < (1, 16): _check(params) else: _check_raises_type_error(params, 'to_begin') @@ -2063,7 +2032,7 @@ def input_variations(): _check(params) params = {'ary': np.arange(-4, 6), 'to_begin': -5, 'to_end': False} - if IS_WIN32 and not IS_32BITS and np_version >= (1, 16): + if IS_WIN32 and not IS_32BITS and numpy_version >= (1, 16): # XFAIL on 64-bits windows + numpy 1.16. See #3898 with self.assertRaises(TypingError) as raises: _check(params) @@ -2077,7 +2046,6 @@ def input_variations(): # params = {'ary': np.array([5, 6], dtype=np.int16), 'to_end': [1e100]} # _check(params) - @unittest.skipUnless(np_version >= (1, 12), "ediff1d needs Numpy 1.12+") def test_ediff1d_exceptions(self): pyfunc = ediff1d cfunc = jit(nopython=True)(pyfunc) @@ -2462,7 +2430,6 @@ def check_not_ok(params): self.assertIn('y cannot be a scalar', str(e.exception)) - @unittest.skipUnless(np_version >= (1, 10), "interp needs Numpy 1.10+") def test_interp_basic(self): pyfunc = interp cfunc = jit(nopython=True)(pyfunc) @@ -2682,7 +2649,6 @@ def arrays(self, ndata): # random_grid yield self.rnd.rand(1 + ndata * 2) * 4.0 + 1.3 - @unittest.skipUnless(np_version >= (1, 10), "interp needs Numpy 1.10+") def test_interp_stress_tests(self): pyfunc = interp cfunc = jit(nopython=True)(pyfunc) @@ -2732,7 +2698,6 @@ def test_interp_stress_tests(self): got = cfunc(x, xp, fp) self.assertPreciseEqual(expected, got, abs_tol=atol) - @unittest.skipUnless(np_version >= (1, 12), "complex interp: Numpy 1.12+") def test_interp_complex_stress_tests(self): pyfunc = interp cfunc = jit(nopython=True)(pyfunc) @@ -2760,7 +2725,6 @@ def test_interp_complex_stress_tests(self): self.rnd.shuffle(fp) np.testing.assert_allclose(expected, got, equal_nan=True) - @unittest.skipUnless(np_version >= (1, 10), "interp needs Numpy 1.10+") def test_interp_exceptions(self): pyfunc = interp cfunc = jit(nopython=True)(pyfunc) @@ -2830,29 +2794,6 @@ def test_interp_exceptions(self): self.assertIn(complex_dtype_msg, str(e.exception)) - @unittest.skipUnless((1, 10) <= np_version < (1, 12), - 'complex interp: Numpy 1.12+') - def test_interp_pre_112_exceptions(self): - pyfunc = interp - cfunc = jit(nopython=True)(pyfunc) - - # Exceptions leak references - self.disable_leak_check() - - x = np.arange(6) - xp = np.arange(6) - fp = np.arange(6) * 1j - - with self.assertTypingError() as e: - cfunc(x, xp, fp) - - complex_dtype_msg = ( - "Cannot cast array data from complex dtype " - "to float64 dtype" - ) - self.assertIn(complex_dtype_msg, str(e.exception)) - - @unittest.skipUnless(np_version >= (1, 10), "interp needs Numpy 1.10+") def test_interp_non_finite_calibration(self): # examples from # https://github.com/numpy/numpy/issues/12951 @@ -2872,7 +2813,6 @@ def test_interp_non_finite_calibration(self): params = {'x': x, 'xp': xp, 'fp': fp} _check(params) - @unittest.skipUnless(np_version >= (1, 10), "interp needs Numpy 1.10+") def test_interp_supplemental_tests(self): # inspired by class TestInterp # https://github.com/numpy/numpy/blob/f5b6850f231/numpy/lib/tests/test_function_base.py # noqa: E501 @@ -2914,7 +2854,6 @@ def test_interp_supplemental_tests(self): fp = np.sin(xp) np.testing.assert_almost_equal(cfunc(np.pi, xp, fp), 0.0) - @unittest.skipUnless(np_version >= (1, 12), "complex interp: Numpy 1.10+") def test_interp_supplemental_complex_tests(self): # inspired by class TestInterp # https://github.com/numpy/numpy/blob/f5b6850f231/numpy/lib/tests/test_function_base.py # noqa: E501 @@ -2927,7 +2866,6 @@ def test_interp_supplemental_complex_tests(self): y0 = x0 + (1 + x0) * 1.0j np.testing.assert_almost_equal(cfunc(x0, x, y), y0) - @unittest.skipUnless(np_version >= (1, 10), "interp needs Numpy 1.10+") def test_interp_float_precision_handled_per_numpy(self): # test cases from https://github.com/numba/numba/issues/4890 pyfunc = interp @@ -3494,8 +3432,6 @@ def foo(): return np.%s(ty) ''' - bits = ('bits',) if np_version >= (1, 12) else () - def check(self, func, attrs, *args): pyfunc = func cfunc = jit(nopython=True)(pyfunc) @@ -3525,9 +3461,8 @@ def test_MachAr(self): def test_finfo(self): types = [np.float32, np.float64, np.complex64, np.complex128] - attrs = self.bits + ('eps', 'epsneg', 'iexp', 'machep', 'max', - 'maxexp', 'negep', 'nexp', 'nmant', 'precision', - 'resolution', 'tiny',) + attrs = ('eps', 'epsneg', 'iexp', 'machep', 'max', 'maxexp', 'negep', + 'nexp', 'nmant', 'precision', 'resolution', 'tiny', 'bits',) for ty in types: self.check(finfo, attrs, ty(1)) hc_func = self.create_harcoded_variant(np.finfo, ty) @@ -3549,7 +3484,7 @@ def test_iinfo(self): # check types and instances of types types = [np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64] - attrs = ('min', 'max') + self.bits + attrs = ('min', 'max', 'bits',) for ty in types: self.check(iinfo, attrs, ty(1)) hc_func = self.create_harcoded_variant(np.iinfo, ty) From a6e8a77d407d047e53922591c32196ef3393ddf8 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 13:21:10 +0000 Subject: [PATCH 256/595] Remove more np removals 1 --- numba/tests/npyufunc/test_errors.py | 7 ------- numba/tests/test_record_dtype.py | 2 +- numba/tests/test_ufuncs.py | 13 +++++-------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/numba/tests/npyufunc/test_errors.py b/numba/tests/npyufunc/test_errors.py index d02bf3c3e80..0fd5bdbf8e3 100644 --- a/numba/tests/npyufunc/test_errors.py +++ b/numba/tests/npyufunc/test_errors.py @@ -5,7 +5,6 @@ from numba import unittest_support as unittest from numba import vectorize, guvectorize -from numba.numpy_support import version as np_version from ..support import TestCase, CheckWarningsMixin @@ -34,11 +33,6 @@ def remainder(a, b): def power(a, b): return a ** b -# See https://github.com/numpy/numpy/pull/3691 -skipIfFPStatusBug = unittest.skipIf( - sys.platform == 'win32' and np_version < (1, 8) and sys.maxsize < 2 ** 32, - "test disabled because of FPU state handling issue on Numpy < 1.8") - class TestExceptions(TestCase): """ @@ -84,7 +78,6 @@ class TestFloatingPointExceptions(TestCase, CheckWarningsMixin): Note the warnings emitted by Numpy reflect IEEE-754 semantics. """ - @skipIfFPStatusBug def check_truediv_real(self, dtype): """ Test 1 / 0 and 0 / 0. diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index e9c2c1df156..4bda27801df 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -7,7 +7,7 @@ from numba.compiler import compile_isolated from numba.itanium_mangler import mangle_type from numba.config import IS_WIN32 -from numba.numpy_support import version as numpy_version +from numba.numpy_support import numpy_version from .support import tag diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index b8ae6163926..ab62f501196 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -11,7 +11,7 @@ import numba.unittest_support as unittest from numba import types, typing, utils, typeof, numpy_support, njit from numba.compiler import compile_isolated, Flags, DEFAULT_FLAGS -from numba.numpy_support import from_dtype, version as numpy_version +from numba.numpy_support import from_dtype from numba import jit, vectorize from numba.errors import LoweringError, TypingError from .support import TestCase, CompilationCache, MemoryLeakMixin, tag @@ -19,7 +19,6 @@ is32bits = tuple.__itemsize__ == 4 iswindows = sys.platform.startswith('win32') -after_numpy_112 = numpy_version >= (1, 12) # NOTE: to test the implementation of Numpy ufuncs, we disable rewriting # of array expressions. @@ -367,15 +366,13 @@ def test_negative_ufunc(self, flags=no_pyobj_flags): @tag('important') def test_power_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.power, flags=flags, - positive_only=after_numpy_112) + positive_only=True) def test_gcd_ufunc(self, flags=no_pyobj_flags): - if numpy_support.version >= (1, 15): - self.binary_ufunc_test(np.gcd, flags=flags, kinds="iu") + self.binary_ufunc_test(np.gcd, flags=flags, kinds="iu") def test_lcm_ufunc(self, flags=no_pyobj_flags): - if numpy_support.version >= (1, 15): - self.binary_ufunc_test(np.lcm, flags=flags, kinds="iu") + self.binary_ufunc_test(np.lcm, flags=flags, kinds="iu") @tag('important') def test_remainder_ufunc(self, flags=no_pyobj_flags): @@ -1244,7 +1241,7 @@ def test_remainder_array_op(self): @tag('important') def test_power_array_op(self): - self.binary_op_test('**', positive_rhs=after_numpy_112) + self.binary_op_test('**', positive_rhs=True) @tag('important') def test_left_shift_array_op(self): From 8992bd59753a97e2e0a4fbc50bc0eee181d1abdd Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 13:27:15 +0000 Subject: [PATCH 257/595] Remove more np removals 2 --- numba/tests/test_array_reductions.py | 36 ++++++---------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index 34b427737d6..517d1e204c2 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -5,7 +5,6 @@ from numba import unittest_support as unittest from numba import jit, typeof from numba.compiler import compile_isolated -from numba.numpy_support import version as np_version from .support import TestCase, MemoryLeakMixin, tag @@ -190,7 +189,7 @@ def setUp(self): super(TestArrayReductions, self).setUp() np.random.seed(42) - def check_reduction_basic(self, pyfunc, all_nans=True, **kwargs): + def check_reduction_basic(self, pyfunc, **kwargs): # Basic reduction checks on 1-d float64 arrays cfunc = jit(nopython=True)(pyfunc) def check(arr): @@ -210,10 +209,9 @@ def check(arr): check(arr) arr = np.float64(['nan', -1.5, 2.5, 'nan', 'inf', '-inf', 3.0]) check(arr) - if all_nans: - # Only NaNs - arr = np.float64(['nan', 'nan']) - check(arr) + # Only NaNs + arr = np.float64(['nan', 'nan']) + check(arr) @tag('important') def test_all_basic(self, pyfunc=array_all): @@ -290,29 +288,22 @@ def test_nanmax_basic(self): self.check_reduction_basic(array_nanmax) @tag('important') - @unittest.skipUnless(np_version >= (1, 8), "nanmean needs Numpy 1.8+") def test_nanmean_basic(self): self.check_reduction_basic(array_nanmean) @tag('important') def test_nansum_basic(self): - # Note Numpy < 1.9 has different behaviour for all NaNs: - # it returns Nan while later Numpy returns 0. - self.check_reduction_basic(array_nansum, - all_nans=np_version >= (1, 9)) + self.check_reduction_basic(array_nansum) @tag('important') - @unittest.skipUnless(np_version >= (1, 10), "nanprod needs Numpy 1.10+") def test_nanprod_basic(self): self.check_reduction_basic(array_nanprod) @tag('important') - @unittest.skipUnless(np_version >= (1, 8), "nanstd needs Numpy 1.8+") def test_nanstd_basic(self): self.check_reduction_basic(array_nanstd) @tag('important') - @unittest.skipUnless(np_version >= (1, 8), "nanvar needs Numpy 1.8+") def test_nanvar_basic(self): self.check_reduction_basic(array_nanvar, prec='double') @@ -529,37 +520,30 @@ def check_err(a, q): self.assertIn('Not supported for complex dtype', str(e.exception)) - @unittest.skipUnless(np_version >= (1, 10), "percentile needs Numpy 1.10+") def test_percentile_basic(self): pyfunc = array_percentile_global self.check_percentile_and_quantile(pyfunc, q_upper_bound=100) self.check_percentile_edge_cases(pyfunc, q_upper_bound=100) self.check_percentile_exceptions(pyfunc) - @unittest.skipUnless(np_version >= (1, 11), - "nanpercentile needs Numpy 1.11+") def test_nanpercentile_basic(self): pyfunc = array_nanpercentile_global self.check_percentile_and_quantile(pyfunc, q_upper_bound=100) self.check_percentile_edge_cases(pyfunc, q_upper_bound=100) self.check_percentile_exceptions(pyfunc) - @unittest.skipUnless(np_version >= (1, 15), "quantile needs Numpy 1.15+") def test_quantile_basic(self): pyfunc = array_quantile_global self.check_percentile_and_quantile(pyfunc, q_upper_bound=1) self.check_percentile_edge_cases(pyfunc, q_upper_bound=1) self.check_quantile_exceptions(pyfunc) - @unittest.skipUnless(np_version >= (1, 15), - "nanquantile needs Numpy 1.15+") def test_nanquantile_basic(self): pyfunc = array_nanquantile_global self.check_percentile_and_quantile(pyfunc, q_upper_bound=1) self.check_percentile_edge_cases(pyfunc, q_upper_bound=1) self.check_quantile_exceptions(pyfunc) - @unittest.skipUnless(np_version >= (1, 9), "nanmedian needs Numpy 1.9+") def test_nanmedian_basic(self): pyfunc = array_nanmedian_global self.check_median_basic(pyfunc, self._array_variations) @@ -660,7 +644,6 @@ def test_cumsum_magnitude(self): self.check_aggregation_magnitude(array_cumsum) self.check_aggregation_magnitude(array_cumsum_global) - @unittest.skipUnless(np_version >= (1, 12), "nancumsum needs Numpy 1.12+") def test_nancumsum_magnitude(self): self.check_aggregation_magnitude(array_nancumsum, is_prod=True) @@ -672,7 +655,6 @@ def test_cumprod_magnitude(self): self.check_aggregation_magnitude(array_cumprod, is_prod=True) self.check_aggregation_magnitude(array_cumprod_global, is_prod=True) - @unittest.skipUnless(np_version >= (1, 12), "nancumprod needs Numpy 1.12+") def test_nancumprod_magnitude(self): self.check_aggregation_magnitude(array_nancumprod, is_prod=True) @@ -778,12 +760,10 @@ def a_variations(): a = a.reshape(3, 3) check(a) - @unittest.skipUnless(np_version >= (1, 12), "nancumprod needs Numpy 1.12+") def test_nancumprod_basic(self): self.check_cumulative(array_nancumprod) self.check_nan_cumulative(array_nancumprod) - @unittest.skipUnless(np_version >= (1, 12), "nancumsum needs Numpy 1.12+") def test_nancumsum_basic(self): self.check_cumulative(array_nancumsum) self.check_nan_cumulative(array_nancumsum) @@ -976,10 +956,8 @@ def install_generated_tests(cls): reduction_funcs_rspace = [array_argmin, array_argmin_global, array_argmax, array_argmax_global] - if np_version >= (1, 8): - reduction_funcs += [array_nanmean, array_nanstd, array_nanvar] - if np_version >= (1, 10): - reduction_funcs += [array_nanprod] + reduction_funcs += [array_nanmean, array_nanstd, array_nanvar] + reduction_funcs += [array_nanprod] dtypes_to_test = [np.int32, np.float32, np.bool_, np.complex64] From 20277b60bb9a800e5d5a72e6718f5d87ca117f5c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 13:41:57 +0000 Subject: [PATCH 258/595] Remove more np removals 3 --- numba/cuda/tests/cudapy/test_record_dtype.py | 6 +----- numba/tests/test_npdatetime.py | 12 ++++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/numba/cuda/tests/cudapy/test_record_dtype.py b/numba/cuda/tests/cudapy/test_record_dtype.py index 47b2ed42b42..5729985c9ef 100644 --- a/numba/cuda/tests/cudapy/test_record_dtype.py +++ b/numba/cuda/tests/cudapy/test_record_dtype.py @@ -129,11 +129,7 @@ def _test_set_equal(self, pyfunc, value, valuetype): # Force the argument to the pure Python function to be # a recarray, as attribute access isn't supported on # structured arrays. - if numpy_support.version <= (1, 9): - expect = np.recarray(got.shape, got.dtype) - expect[:] = got - else: - expect = got.copy().view(np.recarray) + expect = got.copy().view(np.recarray) cfunc(got, i, value) pyfunc(expect, i, value) diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 929d220041f..996f14738e0 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -13,7 +13,7 @@ import numba.unittest_support as unittest from numba import config, jit, npdatetime, types, vectorize, numpy_support -from numba.numpy_support import version as numpy_version +from numba.numpy_support import numpy_version from numba.errors import TypingError from .support import TestCase, tag @@ -383,7 +383,7 @@ def check(a, b, expected): expected_val = expected not_expected_val = not expected - if numpy_support.version >= (1, 16): + if numpy_version >= (1, 16): # since np 1.16 all NaT == comparisons are False, including # NaT==NaT, conversely != is True if np.isnat(a) or np.isnat(a): @@ -419,7 +419,7 @@ def check(a, b, expected): expected_val = expected not_expected_val = not expected - if numpy_support.version >= (1, 16): + if numpy_version >= (1, 16): # since np 1.16 all NaT magnitude comparisons including equality # are False (as NaT == NaT is now False) if np.isnat(a) or np.isnat(a): @@ -459,7 +459,7 @@ def check(a, b, expected): expected_val = expected not_expected_val = not expected - if numpy_support.version >= (1, 16): + if numpy_version >= (1, 16): # since np 1.16 all NaT magnitude comparisons including equality # are False (as NaT == NaT is now False) if np.isnat(a) or np.isnat(a): @@ -688,7 +688,7 @@ def check_eq(a, b, expected): expected_val = expected not_expected_val = not expected - if numpy_support.version >= (1, 16): + if numpy_version >= (1, 16): # since np 1.16 all NaT comparisons bar != are False, including # NaT==NaT if np.isnat(a) or np.isnat(b): @@ -726,7 +726,7 @@ def check_lt(a, b, expected): expected_val = expected not_expected_val = not expected - if numpy_support.version >= (1, 16): + if numpy_version >= (1, 16): # since np 1.16 all NaT magnitude comparisons including equality # are False (as NaT == NaT is now False) if np.isnat(a) or np.isnat(b): From 753d0c2b394292736ee199ee92f28f2406e6d0b5 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 14:36:16 +0000 Subject: [PATCH 259/595] Remove more np removals 4 --- numba/numpy_support.py | 6 +---- numba/tests/npyufunc/test_errors.py | 2 -- numba/tests/test_array_methods.py | 7 ++--- numba/tests/test_npdatetime.py | 41 ++--------------------------- numba/tests/test_ufuncs.py | 26 ++++-------------- 5 files changed, 10 insertions(+), 72 deletions(-) diff --git a/numba/numpy_support.py b/numba/numpy_support.py index 8d9d7887a17..57b220103e8 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -11,10 +11,6 @@ numpy_version = tuple(map(int, np.__version__.split('.')[:2])) -# Starting from Numpy 1.10, ufuncs accept argument conversion according -# to the "same_kind" rule (used to be "unsafe"). -strict_ufunc_typing = numpy_version >= (1, 10) - FROM_DTYPE = { np.dtype('bool'): types.boolean, @@ -411,7 +407,7 @@ def choose_types(numba_types, ufunc_letters): has_mixed_inputs, 'safe'): found = False break - if found and strict_ufunc_typing: + if found: # Can we cast the inner result to the outer result type? for outer, inner in zip(np_output_types, ufunc_outputs): if (outer.char not in 'mM' and not diff --git a/numba/tests/npyufunc/test_errors.py b/numba/tests/npyufunc/test_errors.py index 0fd5bdbf8e3..f1267623abe 100644 --- a/numba/tests/npyufunc/test_errors.py +++ b/numba/tests/npyufunc/test_errors.py @@ -97,7 +97,6 @@ def test_truediv_float(self): def test_truediv_integer(self): self.check_truediv_real(np.int32) - @skipIfFPStatusBug def check_divmod_float(self, pyfunc, values, messages): """ Test 1 // 0 and 0 // 0. @@ -140,7 +139,6 @@ def test_floordiv_int(self): def test_remainder_int(self): self.check_divmod_int(remainder, [0, 0, 0, 1]) - @skipIfFPStatusBug def test_power_float(self): """ Test 0 ** -1 and 2 ** . diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index 3d002a3333b..be77a1f0b01 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -8,7 +8,7 @@ from numba import jit, typeof, types from numba.compiler import compile_isolated from numba.errors import TypingError, LoweringError -from numba.numpy_support import as_dtype, strict_ufunc_typing +from numba.numpy_support import as_dtype from .support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, tag, needs_blas) @@ -325,10 +325,7 @@ def check_types(argtypes, outtypes, values): values = np.array([-3.0, -2.5, -2.25, -1.5, 1.5, 2.25, 2.5, 2.75]) - if strict_ufunc_typing: - argtypes = (types.float64, types.float32) - else: - argtypes = (types.float64, types.float32, types.int32) + argtypes = (types.float64, types.float32) check_types(argtypes, argtypes, values) argtypes = (types.complex64, types.complex128) diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 996f14738e0..d256353b726 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -271,9 +271,6 @@ def check(a, b, expected): check(TD(1), TD(2), TD(3)) check(TD(1, 's'), TD(2, 's'), TD(3, 's')) # Implicit unit promotion - if not numpy_support.strict_ufunc_typing: - check(TD(1), TD(2, 's'), TD(3, 's')) - check(TD(1), TD(2, 'ms'), TD(3, 'ms')) check(TD(1, 's'), TD(2, 'us'), TD(1000002, 'us')) check(TD(1, 'W'), TD(2, 'D'), TD(9, 'D')) # NaTs @@ -294,9 +291,6 @@ def check(a, b, expected): check(TD(3), TD(2), TD(1)) check(TD(3, 's'), TD(2, 's'), TD(1, 's')) # Implicit unit promotion - if not numpy_support.strict_ufunc_typing: - check(TD(3), TD(2, 's'), TD(1, 's')) - check(TD(3), TD(2, 'ms'), TD(1, 'ms')) check(TD(3, 's'), TD(2, 'us'), TD(2999998, 'us')) check(TD(1, 'W'), TD(2, 'D'), TD(5, 'D')) # NaTs @@ -360,8 +354,6 @@ def check(a, b, expected): # timedelta64 / timedelta64 check(TD(7), TD(3), 7. / 3.) - if not numpy_support.strict_ufunc_typing: - check(TD(7), TD(3, 'ms'), 7. / 3.) check(TD(7, 'us'), TD(3, 'ms'), 7. / 3000.) check(TD(7, 'ms'), TD(3, 'us'), 7000. / 3.) check(TD(7), TD(0), float('+inf')) @@ -567,32 +559,21 @@ def check(a, b, expected): self.assertPreciseEqual(a + b, expected) # Y + ... - if not numpy_support.strict_ufunc_typing: - check(DT('2014'), TD(2), DT('2016')) check(DT('2014'), TD(2, 'Y'), DT('2016')) check(DT('2014'), TD(2, 'M'), DT('2014-03')) check(DT('2014'), TD(3, 'W'), DT('2014-01-16', 'W')) check(DT('2014'), TD(4, 'D'), DT('2014-01-05')) check(DT('2000'), TD(365, 'D'), DT('2000-12-31')) - if not numpy_support.strict_ufunc_typing: - check(DT('2001'), TD(61, 'm'), DT('2001-01-01T01:01Z')) - check(DT('2001'), TD(61, 's'), DT('2001-01-01T00:01:01Z')) # M + ... - if not numpy_support.strict_ufunc_typing: - check(DT('2014-02'), TD(2), DT('2014-04')) check(DT('2014-02'), TD(2, 'Y'), DT('2016-02')) check(DT('2014-02'), TD(2, 'M'), DT('2014-04')) check(DT('2014-02'), TD(2, 'D'), DT('2014-02-03')) - if not numpy_support.strict_ufunc_typing: - check(DT('2014-02'), TD(61, 's'), DT('2014-02-01T00:01:01Z')) # W + ... check(DT('2014-01-07', 'W'), TD(2, 'W'), DT('2014-01-16', 'W')) # D + ... check(DT('2014-02-02'), TD(27, 'D'), DT('2014-03-01')) check(DT('2012-02-02'), TD(27, 'D'), DT('2012-02-29')) check(DT('2012-02-02'), TD(2, 'W'), DT('2012-02-16')) - if not numpy_support.strict_ufunc_typing: - check(DT('2014-02-02'), TD(73, 'h'), DT('2014-02-05T01Z')) # s + ... check(DT('2000-01-01T01:02:03Z'), TD(2, 'h'), DT('2000-01-01T03:02:03Z')) check(DT('2000-01-01T01:02:03Z'), TD(2, 'ms'), DT('2000-01-01T01:02:03.002Z')) @@ -615,16 +596,10 @@ def check(a, b, expected): # NaTs check(DT('NaT'), TD(2), DT('NaT')) - if not numpy_support.strict_ufunc_typing: - check(DT('NaT', 's'), TD(2), DT('NaT', 's')) check(DT('NaT', 's'), TD(2, 'h'), DT('NaT', 's')) check(DT('NaT', 's'), TD(2, 'ms'), DT('NaT', 'ms')) - if not numpy_support.strict_ufunc_typing: - check(DT('2014'), TD('NaT'), DT('NaT', 'Y')) check(DT('2014'), TD('NaT', 'W'), DT('NaT', 'W')) check(DT('2014-01-01'), TD('NaT', 'W'), DT('NaT', 'D')) - if not numpy_support.strict_ufunc_typing: - check(DT('NaT', 's'), TD('NaT'), DT('NaT', 's')) check(DT('NaT', 's'), TD('NaT', 'ms'), DT('NaT', 'ms')) # Cannot add datetime days and timedelta months or years @@ -659,8 +634,6 @@ def check(a, b, expected=None): check(DT('2014-02'), DT('2017-01'), TD(-35, 'M')) check(DT('2014-02-28'), DT('2015-03-01'), TD(-366, 'D')) # NaTs - if not numpy_support.strict_ufunc_typing: - check(DT('NaT'), DT('2000'), TD('NaT', 'Y')) check(DT('NaT', 'M'), DT('2000'), TD('NaT', 'M')) check(DT('NaT', 'M'), DT('2000-01-01'), TD('NaT', 'D')) check(DT('NaT'), DT('NaT'), TD('NaT')) @@ -668,9 +641,7 @@ def check(a, b, expected=None): with self.silence_numpy_warnings(): dts = self.datetime_samples() for a, b in itertools.product(dts, dts): - if (numpy_support.strict_ufunc_typing - and not npdatetime.same_kind(value_unit(a), - value_unit(b))): + if (not npdatetime.same_kind(value_unit(a), value_unit(b))): continue self.assertPreciseEqual(sub(a, b), a - b, (a, b)) @@ -759,15 +730,8 @@ def check_lt(a, b, expected): check_eq(DT('2014-01-01T00:01:01Z', 's'), DT('2014-01-01T00:01Z', 'm'), False) # NaTs - if not numpy_support.strict_ufunc_typing: - check_lt(DT('NaT'), DT('2017'), True) check_lt(DT('NaT', 'Y'), DT('2017'), True) - if not numpy_support.strict_ufunc_typing: - check_lt(DT('NaT', 'ms'), DT('2017'), True) check_eq(DT('NaT'), DT('NaT'), True) - if not numpy_support.strict_ufunc_typing: - check_eq(DT('NaT', 'Y'), DT('NaT'), True) - check_eq(DT('NaT', 'ms'), DT('NaT', 'M'), True) # Check comparison between various units dts = self.datetime_samples() @@ -779,8 +743,7 @@ def check_lt(a, b, expected): for unit in units: # Force conversion b = a.astype('M8[%s]' % unit) - if (numpy_support.strict_ufunc_typing - and not npdatetime.same_kind(value_unit(a), + if (not npdatetime.same_kind(value_unit(a), value_unit(b))): continue check_eq(a, b, True) diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index ab62f501196..75e497338c5 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -199,10 +199,8 @@ def unary_ufunc_test(self, ufunc, flags=no_pyobj_flags, if input_type in skip_inputs: continue - # Some ufuncs don't allow all kinds of arguments, and implicit - # conversion has become stricter in 1.10. - if (numpy_support.strict_ufunc_typing and - input_operand.dtype.kind not in kinds): + # Some ufuncs don't allow all kinds of arguments + if (input_operand.dtype.kind not in kinds): continue output_type = self._determine_output_type( @@ -279,10 +277,8 @@ def binary_ufunc_test(self, ufunc, flags=no_pyobj_flags, if positive_only and np.any(lhs < 0): continue - # Some ufuncs don't allow all kinds of arguments, and implicit - # conversion has become stricter in 1.10. - if (numpy_support.strict_ufunc_typing and - lhs.dtype.kind not in kinds): + # Some ufuncs don't allow all kinds of arguments + if (lhs.dtype.kind not in kinds): continue output_type = self._determine_output_type( @@ -773,10 +769,6 @@ def binary_ufunc_mixed_types_test(self, ufunc, flags=no_pyobj_flags): else 'double') self.assertPreciseEqual(expected, result, prec=prec) - def test_mixed_types(self): - if not numpy_support.strict_ufunc_typing: - self.binary_ufunc_mixed_types_test(np.divide, flags=no_pyobj_flags) - @tag('important') def test_broadcasting(self): @@ -1596,9 +1588,7 @@ class TestLoopTypesSubtractAndNegativeNoPython(_LoopTypesTester): _compile_flags = no_pyobj_flags _ufuncs = [np.subtract, np.negative] _required_types = '?bBhHiIlLqQfdFD' - _skip_types = 'mMO' + _LoopTypesTester._skip_types - if after_numpy_112: # np1.13 deprecated/not supported - _skip_types += '?' + _skip_types = 'mMO' + _LoopTypesTester._skip_types + '?' TestLoopTypesSubtractAndNegativeNoPython.autogenerate() @@ -1766,9 +1756,6 @@ def test_add(self): # heterogeneous inputs self._check_ufunc_with_dtypes(fn, ufunc, ['m8[s]', 'm8[m]', 'm8[s]']) self._check_ufunc_with_dtypes(fn, ufunc, ['m8[m]', 'm8[s]', 'm8[s]']) - if not numpy_support.strict_ufunc_typing: - self._check_ufunc_with_dtypes(fn, ufunc, ['m8[m]', 'm8', 'm8[m]']) - self._check_ufunc_with_dtypes(fn, ufunc, ['m8', 'm8[m]', 'm8[m]']) # heterogeneous inputs, scaled output self._check_ufunc_with_dtypes(fn, ufunc, ['m8[s]', 'm8[m]', 'm8[ms]']) self._check_ufunc_with_dtypes(fn, ufunc, ['m8[m]', 'm8[s]', 'm8[ms]']) @@ -1827,9 +1814,6 @@ def _check_comparison(self, ufunc): # timedelta self._check_ufunc_with_dtypes(fn, ufunc, ['m8[m]', 'm8[s]', '?']) self._check_ufunc_with_dtypes(fn, ufunc, ['m8[s]', 'm8[m]', '?']) - if not numpy_support.strict_ufunc_typing: - self._check_ufunc_with_dtypes(fn, ufunc, ['m8[m]', 'm8', '?']) - self._check_ufunc_with_dtypes(fn, ufunc, ['m8', 'm8[m]', '?']) # datetime self._check_ufunc_with_dtypes(fn, ufunc, ['M8[m]', 'M8[s]', '?']) self._check_ufunc_with_dtypes(fn, ufunc, ['M8[s]', 'M8[m]', '?']) From 3d88cf5f413d4dc4e332461ef29671f481af4515 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 14:51:49 +0000 Subject: [PATCH 260/595] Remove more np removals 5 --- numba/__init__.py | 5 ++--- numba/tests/test_array_attr.py | 16 ++++++---------- numba/tests/test_array_methods.py | 2 -- numba/tests/test_np_functions.py | 1 - numba/tests/test_numpy_support.py | 32 +++++++++++++++---------------- 5 files changed, 24 insertions(+), 32 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index 8232dda757a..e642b78a0e5 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -110,14 +110,13 @@ def _ensure_critical_deps(): """ Make sure Python, NumPy and SciPy have supported versions. """ - from . import numpy_support + from .numpy_support import numpy_version from .utils import PYVERSION if PYVERSION < (3, 6): raise ImportError("Numba needs Python 3.6 or greater") - np_version = numpy_support.numpy_version[:2] - if np_version < (1, 15): + if numpy_version < (1, 15): raise ImportError("Numba needs NumPy 1.15 or greater") try: diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index 65820a65074..58f171a8ac0 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -4,7 +4,7 @@ from numba import jitclass from numba.compiler import compile_isolated from numba.numpy_support import from_dtype -from numba import types, njit, typeof, numpy_support +from numba import types, njit, typeof from .support import (TestCase, CompilationCache, MemoryLeakMixin, tag, skip_parfors_unsupported) from numba.errors import TypingError @@ -102,8 +102,7 @@ def check_unary(self, pyfunc, arr): cfunc = self.get_cfunc(pyfunc, (aryty.copy(layout='A'),)) self.assertPreciseEqual(cfunc(arr), expected) - def check_unary_with_arrays(self, pyfunc, - use_reshaped_empty_array=True): + def check_unary_with_arrays(self, pyfunc,): self.check_unary(pyfunc, self.a) self.check_unary(pyfunc, self.a.T) self.check_unary(pyfunc, self.a[::2]) @@ -113,8 +112,9 @@ def check_unary_with_arrays(self, pyfunc, # array with an empty dimension arr = np.zeros(0) self.check_unary(pyfunc, arr) - if use_reshaped_empty_array: - self.check_unary(pyfunc, arr.reshape((1, 0, 2))) + + # check with reshape + self.check_unary(pyfunc, arr.reshape((1, 0, 2))) def get_cfunc(self, pyfunc, argspec): cres = self.ccache.compile(pyfunc, argspec) @@ -166,11 +166,7 @@ def test_flags_c_contiguous(self): self.check_unary_with_arrays(array_flags_c_contiguous) def test_flags_f_contiguous(self): - # Numpy 1.12+ is more opportunistic when computing contiguousness - # of empty arrays. - use_reshaped_empty_array = numpy_support.version > (1, 11) - self.check_unary_with_arrays(array_flags_f_contiguous, - use_reshaped_empty_array=use_reshaped_empty_array) + self.check_unary_with_arrays(array_flags_f_contiguous) class TestNestedArrayAttr(MemoryLeakMixin, unittest.TestCase): diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index be77a1f0b01..e6cc85f8b68 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -579,8 +579,6 @@ def fac(N): def check_arr(arr): cres = compile_isolated(pyfunc, (typeof(arr),)) expected = pyfunc(arr) - # NOTE: Numpy 1.9 returns readonly arrays for multidimensional - # arrays. Workaround this by copying the results. expected = [a.copy() for a in expected] self.assertPreciseEqual(cres.entry_point(arr), expected) diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 1bcb81230ba..f5cfc843df1 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -1836,7 +1836,6 @@ def cov_corrcoef_edge_cases(self, pyfunc, first_arg_name): params = {first_arg_name: m, 'y': y} _check(params) - # The following tests pass with numpy version >= 1.10, but fail with 1.9 m = np.array([-2.1, -1, 4.3]) y = np.array([[3, 1.1, 0.12], [3, 1.1, 0.12]]) params = {first_arg_name: m, 'y': y} diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index d7fd772d0ee..4a6605952b7 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -411,22 +411,22 @@ def check_arr(arr): # middle axis is shape 1 check_arr(arr.reshape((2, 3, 4))[:, ::3]) check_arr(arr.reshape((2, 3, 4)).T[:, ::3]) - if numpy_support.version > (1, 11): - # leading axis is shape 1 - check_arr(arr.reshape((2, 3, 4))[::2]) - check_arr(arr.reshape((2, 3, 4)).T[:, :, ::2]) - # 2 leading axis are shape 1 - check_arr(arr.reshape((2, 3, 4))[::2, ::3]) - check_arr(arr.reshape((2, 3, 4)).T[:, ::3, ::2]) - # single item slices for all axis - check_arr(arr.reshape((2, 3, 4))[::2, ::3, ::4]) - check_arr(arr.reshape((2, 3, 4)).T[::4, ::3, ::2]) - # 4D - check_arr(arr.reshape((2, 2, 3, 2))[::2, ::2, ::3]) - check_arr(arr.reshape((2, 2, 3, 2)).T[:, ::3, ::2, ::2]) - # outer zero dims - check_arr(arr.reshape((2, 2, 3, 2))[::5, ::2, ::3]) - check_arr(arr.reshape((2, 2, 3, 2)).T[:, ::3, ::2, ::5]) + + # leading axis is shape 1 + check_arr(arr.reshape((2, 3, 4))[::2]) + check_arr(arr.reshape((2, 3, 4)).T[:, :, ::2]) + # 2 leading axis are shape 1 + check_arr(arr.reshape((2, 3, 4))[::2, ::3]) + check_arr(arr.reshape((2, 3, 4)).T[:, ::3, ::2]) + # single item slices for all axis + check_arr(arr.reshape((2, 3, 4))[::2, ::3, ::4]) + check_arr(arr.reshape((2, 3, 4)).T[::4, ::3, ::2]) + # 4D + check_arr(arr.reshape((2, 2, 3, 2))[::2, ::2, ::3]) + check_arr(arr.reshape((2, 2, 3, 2)).T[:, ::3, ::2, ::2]) + # outer zero dims + check_arr(arr.reshape((2, 2, 3, 2))[::5, ::2, ::3]) + check_arr(arr.reshape((2, 2, 3, 2)).T[:, ::3, ::2, ::5]) if __name__ == '__main__': From af88544b2e19cdbf91a2edd731700b92d3541bf7 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 14:55:36 +0000 Subject: [PATCH 261/595] Remove more np removals 6 --- numba/targets/arraymath.py | 6 ------ numba/tests/test_array_methods.py | 2 -- numba/tests/test_dyn_array.py | 3 +-- numba/tests/test_operators.py | 3 +-- numba/tests/test_ufuncs.py | 2 +- 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index dee598d6be6..20236045910 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -1260,9 +1260,6 @@ def np_percentile_impl(a, q): @overload(np.percentile) def np_percentile(a, q): - # Note: np.percentile behaviour in the case of an array containing one - # or more NaNs was changed in numpy 1.10 to return an array of np.NaN of - # length equal to q, hence version guard. return _percentile_quantile_inner( a, q, skip_nan=False, factor=1.0, check_q=percentile_is_valid ) @@ -1270,9 +1267,6 @@ def np_percentile(a, q): @overload(np.nanpercentile) def np_nanpercentile(a, q): - # Note: np.nanpercentile return type in the case of an all-NaN slice - # was changed in 1.11 to be an array of np.NaN of length equal to q, - # hence version guard. return _percentile_quantile_inner( a, q, skip_nan=True, factor=1.0, check_q=percentile_is_valid ) diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index e6cc85f8b68..4467245ed08 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -1182,8 +1182,6 @@ def foo(arr): self.assertIn(errmsg, str(raises.exception)) with self.assertRaises(ValueError) as raises: foo.py_func(a) - # Numpy 1.13 has a different error message than prior numpy - # Just check for the "out of bounds" phrase in it. self.assertIn("out of bounds", str(raises.exception)) def test_cumsum(self): diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index e85d3e2ccdd..07b2ea702aa 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -708,8 +708,7 @@ def func(m, n): return np.full((m, n), np.int32(1)) self.check_2d(func) - # tests meta issues from #2862, that np < 1.12 always - # returns float64. Complex uses `.real`, imaginary part dropped + # Complex uses `.real`, imaginary part dropped def func(m, n): return np.full((m, n), np.complex128(1)) self.check_2d(func) diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 20a6209371f..2e50975eea4 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -764,8 +764,7 @@ def test_mod_complex_npm(self): # def check_matmul_objmode(self, pyfunc, inplace): - # Use dummy objects, to work with any Numpy / Scipy version - # (and because Numpy 1.10 doesn't implement "@=") + # Use dummy objects, to work with any NumPy / SciPy version cres = compile_isolated(pyfunc, (), flags=force_pyobj_flags) cfunc = cres.entry_point a = DumbMatrix(3) diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index 75e497338c5..daa5b665db4 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -1575,7 +1575,7 @@ class TestLoopTypesIntNoPython(_LoopTypesTester): _ufuncs.remove(np.reciprocal) _ufuncs.remove(np.left_shift) # has its own test class _ufuncs.remove(np.right_shift) # has its own test class - # special test for bool subtract/negative, np1.13 deprecated/not supported + # special test for bool subtract/negative _ufuncs.remove(np.subtract) _ufuncs.remove(np.negative) _required_types = '?bBhHiIlLqQ' From 77f00fbccf5ba6998529f1eacc64a81f828a4016 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 15:11:34 +0000 Subject: [PATCH 262/595] Remove @tag('important') --- numba/tests/npyufunc/test_gufunc.py | 4 -- numba/tests/npyufunc/test_ufunc.py | 3 - numba/tests/npyufunc/test_ufuncbuilding.py | 7 -- numba/tests/npyufunc/test_vectorize_decor.py | 4 -- numba/tests/test_api.py | 1 - numba/tests/test_array_analysis.py | 2 - numba/tests/test_array_attr.py | 2 - numba/tests/test_array_iterators.py | 6 -- numba/tests/test_array_manipulation.py | 2 - numba/tests/test_array_methods.py | 2 - numba/tests/test_array_reductions.py | 20 ------ numba/tests/test_builtins.py | 17 ----- numba/tests/test_cffi.py | 2 - numba/tests/test_cfunc.py | 6 -- numba/tests/test_closure.py | 5 -- numba/tests/test_complex.py | 3 - numba/tests/test_comprehension.py | 17 ----- numba/tests/test_ctypes.py | 6 -- numba/tests/test_debuginfo.py | 1 - numba/tests/test_dispatcher.py | 6 -- numba/tests/test_dyn_array.py | 13 ---- numba/tests/test_exceptions.py | 4 -- numba/tests/test_extending.py | 6 -- numba/tests/test_fancy_indexing.py | 1 - numba/tests/test_flow_control.py | 16 ----- numba/tests/test_generators.py | 9 --- numba/tests/test_gil.py | 1 - numba/tests/test_hashing.py | 3 - numba/tests/test_indexing.py | 4 -- numba/tests/test_intwidth.py | 2 - numba/tests/test_iteration.py | 5 -- numba/tests/test_jitclasses.py | 5 -- numba/tests/test_linalg.py | 1 - numba/tests/test_lists.py | 11 --- numba/tests/test_looplifting.py | 2 - numba/tests/test_mathlib.py | 27 ------- numba/tests/test_nested_calls.py | 5 -- numba/tests/test_npdatetime.py | 5 -- numba/tests/test_numberctor.py | 5 -- numba/tests/test_numpy_support.py | 8 --- numba/tests/test_operators.py | 19 ----- numba/tests/test_parfors.py | 9 --- numba/tests/test_print.py | 5 -- numba/tests/test_pycc.py | 2 - numba/tests/test_random.py | 21 ------ numba/tests/test_range.py | 10 --- numba/tests/test_recarray_usecases.py | 1 - numba/tests/test_record_dtype.py | 7 -- numba/tests/test_recursion.py | 3 - numba/tests/test_serialize.py | 5 -- numba/tests/test_sets.py | 12 ---- numba/tests/test_sort.py | 7 -- numba/tests/test_stencils.py | 10 --- numba/tests/test_svml.py | 1 - numba/tests/test_tuples.py | 17 ----- numba/tests/test_typeinfer.py | 18 ----- numba/tests/test_typeof.py | 18 ----- numba/tests/test_types.py | 4 -- numba/tests/test_ufuncs.py | 75 -------------------- numba/tests/test_unpack_sequence.py | 5 -- numba/tests/test_usecases.py | 5 -- 61 files changed, 503 deletions(-) diff --git a/numba/tests/npyufunc/test_gufunc.py b/numba/tests/npyufunc/test_gufunc.py index e2ed9970aa8..089b410b3bf 100644 --- a/numba/tests/npyufunc/test_gufunc.py +++ b/numba/tests/npyufunc/test_gufunc.py @@ -34,7 +34,6 @@ def check_matmul_gufunc(self, gufunc): np.testing.assert_allclose(C, Gold, rtol=1e-5, atol=1e-8) - @tag('important') def test_gufunc(self): gufunc = GUVectorize(matmulcore, '(m,n),(n,p)->(m,p)', target=self.target) @@ -43,7 +42,6 @@ def test_gufunc(self): self.check_matmul_gufunc(gufunc) - @tag('important') def test_guvectorize_decor(self): gufunc = guvectorize([void(float32[:,:], float32[:,:], float32[:,:])], '(m,n),(n,p)->(m,p)', @@ -76,7 +74,6 @@ class TestGUVectorizeScalar(TestCase): """ target = 'cpu' - @tag('important') def test_scalar_output(self): """ Note that scalar output is a 0-dimension array that acts as @@ -102,7 +99,6 @@ def sum_row(inp, out): for i in range(inp.shape[0]): assert out[i] == inp[i].sum() - @tag('important') def test_scalar_input(self): @guvectorize(['int32[:], int32[:], int32[:]'], '(n),()->(n)', diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index 1c89b6570c4..d76c1962c45 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -69,7 +69,6 @@ def _test_broadcasting(self, cls, a, b, c, d): info = (cls, a.shape) self.assertPreciseEqual(ufunc(a, b, c, d), a + b + c + d, msg=info) - @tag('important') def test_ufunc_attributes(self): for v in vectorizers: # 1D self._test_ufunc_attributes(v, a[0], b[0]) @@ -79,7 +78,6 @@ def test_ufunc_attributes(self): self._test_ufunc_attributes(v, a[:, np.newaxis, :], b[np.newaxis, :, :]) - @tag('important') def test_broadcasting(self): for v in vectorizers: # 1D self._test_broadcasting(v, a[0], b[0], c[0], d[0]) @@ -89,7 +87,6 @@ def test_broadcasting(self): self._test_broadcasting(v, a[:, np.newaxis, :], b[np.newaxis, :, :], c[:, np.newaxis, :], d[np.newaxis, :, :]) - @tag('important') def test_implicit_broadcasting(self): for v in vectorizers: vectorizer = v(add) diff --git a/numba/tests/npyufunc/test_ufuncbuilding.py b/numba/tests/npyufunc/test_ufuncbuilding.py index 932cf813d38..4903d6db999 100644 --- a/numba/tests/npyufunc/test_ufuncbuilding.py +++ b/numba/tests/npyufunc/test_ufuncbuilding.py @@ -71,7 +71,6 @@ def guerror(a, b, c): class TestUfuncBuilding(TestCase): - @tag('important') def test_basic_ufunc(self): ufb = UFuncBuilder(add) cres = ufb.add("int32(int32, int32)") @@ -175,7 +174,6 @@ def test_basic_gufunc(self): self.assertEqual(ufunc.__name__, "guadd") self.assertIn("A generalized addition", ufunc.__doc__) - @tag('important') def test_gufunc_struct(self): gufb = GUFuncBuilder(guadd, "(x, y),(x, y)->(x, y)") cres = gufb.add("void(complex64[:,:], complex64[:,:], complex64[:,:])") @@ -227,14 +225,12 @@ def test_vectorize_objmode(self): b = ufunc(a, a) self.assertPreciseEqual(a + a, b) - @tag('important') def test_vectorize_bool_return(self): ufunc = vectorize(['bool_(int32, int32)'])(equals) a = np.arange(10, dtype='int32') r = ufunc(a,a) self.assertPreciseEqual(r, np.ones(r.shape, dtype=np.bool_)) - @tag('important') def test_vectorize_identity(self): sig = 'int32(int32, int32)' for identity in self._supported_identities: @@ -287,7 +283,6 @@ def check(ufunc): check(ufunc) # compiling check(ufunc) # after compiling - @tag('important') def test_guvectorize(self): ufunc = guvectorize(['(int32[:,:], int32[:,:], int32[:,:])'], "(x,y),(x,y)->(x,y)")(guadd) @@ -295,7 +290,6 @@ def test_guvectorize(self): b = ufunc(a, a) self.assertPreciseEqual(a + a, b) - @tag('important') def test_guvectorize_no_output(self): ufunc = guvectorize(['(int32[:,:], int32[:,:], int32[:,:])'], "(x,y),(x,y),(x,y)")(guadd) @@ -328,7 +322,6 @@ def test_guvectorize_error_in_objectmode(self): with self.assertRaises(MyException): ufunc(a, a) - @tag('important') def test_guvectorize_identity(self): args = (['(int32[:,:], int32[:,:], int32[:,:])'], "(x,y),(x,y)->(x,y)") for identity in self._supported_identities: diff --git a/numba/tests/npyufunc/test_vectorize_decor.py b/numba/tests/npyufunc/test_vectorize_decor.py index cb61ea1eae3..ad50534af80 100644 --- a/numba/tests/npyufunc/test_vectorize_decor.py +++ b/numba/tests/npyufunc/test_vectorize_decor.py @@ -45,21 +45,18 @@ def _run_and_compare(cls, func, sig, A, *args, **kwargs): gold = numpy_func(A, *args) np.testing.assert_allclose(result, gold, **kwargs) - @tag('important') def test_1(self): sig = ['float64(float64)', 'float32(float32)'] func = self.funcs['func1'] A = np.arange(100, dtype=np.float64) self._run_and_compare(func, sig, A) - @tag('important') def test_2(self): sig = [float64(float64), float32(float32)] func = self.funcs['func1'] A = np.arange(100, dtype=np.float64) self._run_and_compare(func, sig, A) - @tag('important') def test_3(self): sig = ['float64(float64, uint32)'] func = self.funcs['func2'] @@ -67,7 +64,6 @@ def test_3(self): scale = np.uint32(3) self._run_and_compare(func, sig, A, scale, atol=1e-8) - @tag('important') def test_4(self): sig = [ int32(int32, int32), diff --git a/numba/tests/test_api.py b/numba/tests/test_api.py index 138d0d2bef2..52e413c0163 100644 --- a/numba/tests/test_api.py +++ b/numba/tests/test_api.py @@ -13,7 +13,6 @@ def check_member(self, name): self.assertTrue(hasattr(numba, name), name) self.assertIn(name, numba.__all__) - @tag('important') def test_numba_module(self): # jit self.check_member("jit") diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 956bad4dab9..5921eed1725 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -40,7 +40,6 @@ class TestEquivSet(TestCase): """ Test array_analysis.EquivSet. """ - @tag('important') def test_insert_equiv(self): s1 = EquivSet() s1.insert_equiv('a', 'b') @@ -53,7 +52,6 @@ def test_insert_equiv(self): self.assertTrue(s1.is_equiv('a', 'b', 'c', 'd')) self.assertFalse(s1.is_equiv('a', 'e')) - @tag('important') def test_intersect(self): s1 = EquivSet() s2 = EquivSet() diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index 58f171a8ac0..b4fdb5fbd37 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -120,7 +120,6 @@ def get_cfunc(self, pyfunc, argspec): cres = self.ccache.compile(pyfunc, argspec) return cres.entry_point - @tag('important') def test_shape(self): pyfunc = array_shape cfunc = self.get_cfunc(pyfunc, (types.int32[:,:], types.int32)) @@ -180,7 +179,6 @@ def get_cfunc(self, pyfunc): cres = compile_isolated(pyfunc, (self.nbrecord,)) return cres.entry_point - @tag('important') def test_shape(self): pyfunc = nested_array_shape cfunc = self.get_cfunc(pyfunc) diff --git a/numba/tests/test_array_iterators.py b/numba/tests/test_array_iterators.py index 7c073824dc1..eae161e4e0a 100644 --- a/numba/tests/test_array_iterators.py +++ b/numba/tests/test_array_iterators.py @@ -162,7 +162,6 @@ def check_array_flat_sum(self, arr, arrty): def check_array_ndenumerate_sum(self, arr, arrty): self.check_array_unary(arr, arrty, array_ndenumerate_sum) - @tag('important') def test_array_iter(self): # Test iterating over a 1d array arr = np.arange(6) @@ -184,7 +183,6 @@ def test_array_view_iter(self): arr = np.bool_([1, 0, 0, 1]).reshape((2, 2)) self.check_array_view_iter(arr, 1) - @tag('important') def test_array_flat_3d(self): arr = np.arange(24).reshape(4, 2, 3) @@ -315,7 +313,6 @@ def test_array_flat_premature_free(self): self.assertTrue(got.sum()) self.assertPreciseEqual(expect, got) - @tag('important') def test_array_ndenumerate_2d(self): arr = np.arange(12).reshape(4, 3) arrty = typeof(arr) @@ -376,7 +373,6 @@ def test_np_ndindex(self): self.assertPreciseEqual(cfunc(0, 3), func(0, 3)) self.assertPreciseEqual(cfunc(0, 0), func(0, 0)) - @tag('important') def test_np_ndindex_array(self): func = np_ndindex_array arr = np.arange(12, dtype=np.int32) + 10 @@ -392,7 +388,6 @@ def test_np_ndindex_empty(self): cfunc = cres.entry_point self.assertPreciseEqual(cfunc(), func()) - @tag('important') def test_iter_next(self): # This also checks memory management with iter() and next() func = iter_next @@ -443,7 +438,6 @@ def test_nditer1(self): got = cfunc(a) self.check_result(got, expected) - @tag('important') def test_nditer2(self): pyfunc = np_nditer2 cfunc = jit(nopython=True)(pyfunc) diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 8fc43e509e1..22182682efc 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -170,7 +170,6 @@ def setUp(self): super(TestArrayManipulation, self).setUp() self.ccache = CompilationCache() - @tag('important') def test_array_reshape(self): pyfuncs_to_use = [array_reshape, numpy_array_reshape] @@ -377,7 +376,6 @@ def check_issue_4708(pyfunc, m, n): self.assertIn("np.transpose does not accept tuples", str(e.exception)) - @tag('important') def test_expand_dims(self): pyfunc = expand_dims diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index 4467245ed08..542080cdcd0 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -532,11 +532,9 @@ def check_arr(arr): def test_array_transpose(self): self.check_layout_dependent_func(array_transpose) - @tag('important') def test_array_T(self): self.check_layout_dependent_func(array_T) - @tag('important') def test_array_copy(self): self.check_layout_dependent_func(array_copy) diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index 517d1e204c2..dc2f0504bc6 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -213,7 +213,6 @@ def check(arr): arr = np.float64(['nan', 'nan']) check(arr) - @tag('important') def test_all_basic(self, pyfunc=array_all): cfunc = jit(nopython=True)(pyfunc) def check(arr): @@ -229,7 +228,6 @@ def check(arr): check(arr) check(arr[::-1]) - @tag('important') def test_any_basic(self, pyfunc=array_any): cfunc = jit(nopython=True)(pyfunc) def check(arr): @@ -247,63 +245,48 @@ def check(arr): check(arr) check(arr[::-1]) - @tag('important') def test_sum_basic(self): self.check_reduction_basic(array_sum) - @tag('important') def test_mean_basic(self): self.check_reduction_basic(array_mean) - @tag('important') def test_var_basic(self): self.check_reduction_basic(array_var, prec='double') - @tag('important') def test_std_basic(self): self.check_reduction_basic(array_std) - @tag('important') def test_min_basic(self): self.check_reduction_basic(array_min) - @tag('important') def test_max_basic(self): self.check_reduction_basic(array_max) - @tag('important') def test_argmin_basic(self): self.check_reduction_basic(array_argmin) - @tag('important') def test_argmax_basic(self): self.check_reduction_basic(array_argmax) - @tag('important') def test_nanmin_basic(self): self.check_reduction_basic(array_nanmin) - @tag('important') def test_nanmax_basic(self): self.check_reduction_basic(array_nanmax) - @tag('important') def test_nanmean_basic(self): self.check_reduction_basic(array_nanmean) - @tag('important') def test_nansum_basic(self): self.check_reduction_basic(array_nansum) - @tag('important') def test_nanprod_basic(self): self.check_reduction_basic(array_nanprod) - @tag('important') def test_nanstd_basic(self): self.check_reduction_basic(array_nanstd) - @tag('important') def test_nanvar_basic(self): self.check_reduction_basic(array_nanvar, prec='double') @@ -347,7 +330,6 @@ def _array_variations(a): a[:] = np.nan yield a - @tag('important') def test_median_basic(self): pyfunc = array_median_global @@ -603,14 +585,12 @@ def check_cumulative(self, pyfunc): expected, got = run_comparative(pyfunc, arr) self.assertPreciseEqual(got, expected) - @tag('important') def test_array_cumsum(self): self.check_cumulative(array_cumsum) def test_array_cumsum_global(self): self.check_cumulative(array_cumsum_global) - @tag('important') def test_array_cumprod(self): self.check_cumulative(array_cumprod) diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index fdc9242a6cf..cfb52f65fa9 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -252,7 +252,6 @@ def test_abs(self, flags=enable_pyobj_flags): for x in unsigned_values: self.assertPreciseEqual(cfunc(x), pyfunc(x)) - @tag('important') def test_abs_npm(self): self.test_abs(flags=no_pyobj_flags) @@ -343,7 +342,6 @@ def test_complex(self, flags=enable_pyobj_flags): for x, y in itertools.product(x_operands, y_operands): self.assertPreciseEqual(cfunc(x, y), pyfunc(x, y)) - @tag('important') def test_complex_npm(self): self.test_complex(flags=no_pyobj_flags) @@ -374,7 +372,6 @@ def truncate_result(x, bits=64): with self.assertRaises(ZeroDivisionError): cfunc(x, 0) - @tag('important') def test_divmod_ints_npm(self): self.test_divmod_ints(flags=no_pyobj_flags) @@ -397,7 +394,6 @@ def test_divmod_floats(self, flags=enable_pyobj_flags): with self.assertRaises(ZeroDivisionError): cfunc(x, 0.0) - @tag('important') def test_divmod_floats_npm(self): self.test_divmod_floats(flags=no_pyobj_flags) @@ -463,7 +459,6 @@ def test_float(self, flags=enable_pyobj_flags): for x in ['-1.1', '0.0', '1.1']: self.assertPreciseEqual(cfunc(x), pyfunc(x)) - @tag('important') def test_float_npm(self): with self.assertTypingError(): self.test_float(flags=no_pyobj_flags) @@ -541,7 +536,6 @@ def test_int(self, flags=enable_pyobj_flags): for x, y in itertools.product(x_operands, y_operands): self.assertPreciseEqual(cfunc(x, y), pyfunc(x, y)) - @tag('important') def test_int_npm(self): with self.assertTypingError(): self.test_int(flags=no_pyobj_flags) @@ -559,7 +553,6 @@ def test_iter_next(self, flags=enable_pyobj_flags): with self.assertRaises(StopIteration): cfunc((1,)) - @tag('important') def test_iter_next_npm(self): self.test_iter_next(flags=no_pyobj_flags) @@ -616,11 +609,9 @@ def test_min_1(self, flags=enable_pyobj_flags): """ self.check_minmax_1(min_usecase1, flags) - @tag('important') def test_max_npm_1(self): self.test_max_1(flags=no_pyobj_flags) - @tag('important') def test_min_npm_1(self): self.test_min_1(flags=no_pyobj_flags) @@ -677,11 +668,9 @@ def test_min_3(self, flags=enable_pyobj_flags): """ self.check_minmax_3(min_usecase3, flags) - @tag('important') def test_max_npm_3(self): self.test_max_3(flags=no_pyobj_flags) - @tag('important') def test_min_npm_3(self): self.test_min_3(flags=no_pyobj_flags) @@ -821,7 +810,6 @@ def test_round2(self, flags=enable_pyobj_flags): self.assertPreciseEqual(cfunc(-x, n), pyfunc(-x, n), prec=prec) - @tag('important') def test_round2_npm(self): self.test_round2(flags=no_pyobj_flags) @@ -869,21 +857,18 @@ def check(*args): def test_zip(self, flags=forceobj_flags): self.run_nullary_func(zip_usecase, flags) - @tag('important') def test_zip_npm(self): self.test_zip(flags=no_pyobj_flags) def test_zip_1(self, flags=forceobj_flags): self.run_nullary_func(zip_1_usecase, flags) - @tag('important') def test_zip_1_npm(self): self.test_zip_1(flags=no_pyobj_flags) def test_zip_3(self, flags=forceobj_flags): self.run_nullary_func(zip_3_usecase, flags) - @tag('important') def test_zip_3_npm(self): self.test_zip_3(flags=no_pyobj_flags) @@ -900,7 +885,6 @@ def test_zip_first_exhausted(self, flags=forceobj_flags): """ self.run_nullary_func(zip_first_exhausted, flags) - @tag('important') def test_zip_first_exhausted_npm(self): self.test_zip_first_exhausted(flags=nrt_no_pyobj_flags) @@ -918,7 +902,6 @@ def test_pow_op_usecase(self): r = cres.entry_point(x, y) self.assertPreciseEqual(r, pow_op_usecase(x, y)) - @tag('important') def test_pow_usecase(self): args = [ (2, 3), diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index 3fde5059f8b..f8476d2ecdc 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -49,7 +49,6 @@ def test_bool_function_ool(self): self.assertEqual(pyfunc(), True) self.assertEqual(cfunc(), True) - @tag('important') def test_sin_function_npm(self): self._test_function(mod.use_cffi_sin, flags=no_pyobj_flags) @@ -103,7 +102,6 @@ def _test_from_buffer_numpy_array(self, pyfunc, dtype): cfunc = jit(nopython=True)(pyfunc) self.check_vector_sin(cfunc, x, y) - @tag('important') def test_from_buffer_float32(self): self._test_from_buffer_numpy_array(mod.vector_sin_float32, np.float32) diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index cfa815e6e63..f7f3ff3c806 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -107,7 +107,6 @@ def cfarray_usecase(in_ptr, out_ptr, m, n): class TestCFunc(TestCase): - @tag('important') def test_basic(self): """ Basic usage and properties of a cfunc. @@ -130,7 +129,6 @@ def test_basic(self): self.assertPreciseEqual(ct(2.0, 3.5), 5.5) - @tag('important') @skip_cffi_unsupported def test_cffi(self): from . import cffi_usecases @@ -147,7 +145,6 @@ def test_locals(self): f = cfunc(div_sig, locals={'c': types.int64})(div_usecase) self.assertPreciseEqual(f.ctypes(8, 3), 2.0) - @tag('important') def test_errors(self): f = cfunc(div_sig)(div_usecase) @@ -214,7 +211,6 @@ def run_in_separate_process(self): def check_module(self, mod): mod.self_test() - @tag('important') def test_caching(self): self.check_pycache(0) mod = self.import_module() @@ -304,7 +300,6 @@ def eq(got, expected): self.assertIn("mismatching dtype 'int32' for pointer", str(raises.exception)) - @tag('important') def test_carray(self): """ Test pure Python carray(). @@ -352,7 +347,6 @@ def check_numba_carray_farray(self, usecase, dtype_usecase): f = cfunc(sig)(pyfunc) self.check_carray_usecase(self.make_float32_pointer, pyfunc, f.ctypes) - @tag('important') def test_numba_carray(self): """ Test Numba-compiled carray() against pure Python carray() diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 58d44862a89..4353d10e0d4 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -113,7 +113,6 @@ class TestInlinedClosure(TestCase): at compile time. """ - @tag('important') def test_inner_function(self): def outer(x): @@ -126,7 +125,6 @@ def inner(x): cfunc = njit(outer) self.assertEqual(cfunc(10), outer(10)) - @tag('important') def test_inner_function_with_closure(self): def outer(x): @@ -140,7 +138,6 @@ def inner(x): cfunc = njit(outer) self.assertEqual(cfunc(10), outer(10)) - @tag('important') def test_inner_function_with_closure_2(self): def outer(x): @@ -175,7 +172,6 @@ def inner(x): cfunc = njit(ns['outer']) self.assertEqual(cfunc(10), ns['outer'](10)) - @tag('important') def test_inner_function_nested(self): def outer(x): @@ -195,7 +191,6 @@ def innermost(z): cfunc = njit(outer) self.assertEqual(cfunc(10), outer(10)) - @tag('important') def test_bulk_use_cases(self): """ Tests the large number of use cases defined below """ diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index 614e7a00797..54950f3d031 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -120,7 +120,6 @@ def test_div(self, flags=enable_pyobj_flags): (types.complex64, types.complex64)] self.run_binary(div_usecase, value_types, values, flags=flags) - @tag('important') def test_div_npm(self): self.test_div(flags=no_pyobj_flags) @@ -175,14 +174,12 @@ def test_rect_npm(self): def test_isnan(self, flags=enable_pyobj_flags): self.check_predicate_func(isnan_usecase, enable_pyobj_flags) - @tag('important') def test_isnan_npm(self): self.check_predicate_func(isnan_usecase, no_pyobj_flags) def test_isinf(self, flags=enable_pyobj_flags): self.check_predicate_func(isinf_usecase, enable_pyobj_flags) - @tag('important') def test_isinf_npm(self): self.check_predicate_func(isinf_usecase, no_pyobj_flags) diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index ce173a6a69e..69db5c2c5e8 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -26,7 +26,6 @@ def comp_list(n): class TestListComprehension(TestCase): - @tag('important') def test_comp_list(self): pyfunc = comp_list cres = compile_isolated(pyfunc, [types.intp]) @@ -35,7 +34,6 @@ def test_comp_list(self): self.assertEqual(cfunc(0), pyfunc(0)) self.assertEqual(cfunc(-1), pyfunc(-1)) - @tag('important') def test_bulk_use_cases(self): """ Tests the large number of use cases defined below """ @@ -251,7 +249,6 @@ def check(self, pyfunc, *args, **kwargs): if run_parallel: self.assertIn('@do_scheduling', cfunc.inspect_llvm(cfunc.signatures[0])) - @tag('important') def test_comp_with_array_1(self): def comp_with_array_1(n): m = n * 2 @@ -262,7 +259,6 @@ def comp_with_array_1(n): if PARALLEL_SUPPORTED: self.check(comp_with_array_1, 5, run_parallel=True) - @tag('important') def test_comp_with_array_2(self): def comp_with_array_2(n, threshold): A = np.arange(-n, n) @@ -270,7 +266,6 @@ def comp_with_array_2(n, threshold): self.check(comp_with_array_2, 5, 0) - @tag('important') def test_comp_with_array_noinline(self): def comp_with_array_noinline(n): m = n * 2 @@ -284,7 +279,6 @@ def comp_with_array_noinline(n): finally: ic.enable_inline_arraycall = True - @tag('important') def test_comp_nest_with_array(self): def comp_nest_with_array(n): l = np.array([[i * j for j in range(n)] for i in range(n)]) @@ -294,7 +288,6 @@ def comp_nest_with_array(n): if PARALLEL_SUPPORTED: self.check(comp_nest_with_array, 5, run_parallel=True) - @tag('important') def test_comp_nest_with_array_3(self): def comp_nest_with_array_3(n): l = np.array([[[i * j * k for k in range(n)] for j in range(n)] for i in range(n)]) @@ -304,7 +297,6 @@ def comp_nest_with_array_3(n): if PARALLEL_SUPPORTED: self.check(comp_nest_with_array_3, 5, run_parallel=True) - @tag('important') def test_comp_nest_with_array_noinline(self): def comp_nest_with_array_noinline(n): l = np.array([[i * j for j in range(n)] for i in range(n)]) @@ -318,7 +310,6 @@ def comp_nest_with_array_noinline(n): finally: ic.enable_inline_arraycall = True - @tag('important') def test_comp_with_array_range(self): def comp_with_array_range(m, n): l = np.array([i for i in range(m, n)]) @@ -326,7 +317,6 @@ def comp_with_array_range(m, n): self.check(comp_with_array_range, 5, 10) - @tag('important') def test_comp_with_array_range_and_step(self): def comp_with_array_range_and_step(m, n): l = np.array([i for i in range(m, n, 2)]) @@ -334,7 +324,6 @@ def comp_with_array_range_and_step(m, n): self.check(comp_with_array_range_and_step, 5, 10) - @tag('important') def test_comp_with_array_conditional(self): def comp_with_array_conditional(n): l = np.array([i for i in range(n) if i % 2 == 1]) @@ -342,7 +331,6 @@ def comp_with_array_conditional(n): # arraycall inline would not happen when conditional is present self.check(comp_with_array_conditional, 10, assert_allocate_list=True) - @tag('important') def test_comp_nest_with_array_conditional(self): def comp_nest_with_array_conditional(n): l = np.array([[i * j for j in range(n)] for i in range(n) if i % 2 == 1]) @@ -350,7 +338,6 @@ def comp_nest_with_array_conditional(n): self.check(comp_nest_with_array_conditional, 5, assert_allocate_list=True) - @tag('important') def test_comp_nest_with_dependency(self): def comp_nest_with_dependency(n): l = np.array([[i * j for j in range(i+1)] for i in range(n)]) @@ -361,7 +348,6 @@ def comp_nest_with_dependency(n): self.assertIn('Invalid use of Function', str(raises.exception)) self.assertIn('array(undefined,', str(raises.exception)) - @tag('important') def test_no_array_comp(self): def no_array_comp1(n): l = [1,2,3,4] @@ -376,7 +362,6 @@ def no_array_comp2(n): return a self.check(no_array_comp2, 10, assert_allocate_list=True) - @tag('important') def test_nested_array(self): def nested_array(n): l = np.array([ np.array([x for x in range(n)]) for y in range(n)]) @@ -384,7 +369,6 @@ def nested_array(n): self.check(nested_array, 10) - @tag('important') def test_nested_array_with_const(self): def nested_array(n): l = np.array([ np.array([x for x in range(3)]) for y in range(4)]) @@ -392,7 +376,6 @@ def nested_array(n): self.check(nested_array, 0) - @tag('important') def test_array_comp_with_iter(self): def array_comp(a): l = np.array([ x * x for x in a ]) diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index 11028992446..fb042e8347e 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -29,7 +29,6 @@ def _conversion_tests(self, check): check(None, types.void) - @tag('important') def test_from_ctypes(self): """ Test converting a ctypes type to a Numba type. @@ -45,7 +44,6 @@ def check(cty, ty): ctypes_utils.from_ctypes(c_wchar_p) self.assertIn("Unsupported ctypes type", str(raises.exception)) - @tag('important') def test_to_ctypes(self): """ Test converting a Numba type to a ctypes type. @@ -65,7 +63,6 @@ def check(cty, ty): class TestCTypesUseCases(MemoryLeakMixin, TestCase): - @tag('important') def test_c_sin(self): pyfunc = use_c_sin cres = compile_isolated(pyfunc, [types.double]) @@ -179,7 +176,6 @@ def run(func, arr, repeat): for got in outputs: self.assertEqual(expected, got) - @tag('important') def test_passing_array_ctypes_data(self): """ Test the ".ctypes.data" attribute of an array can be passed @@ -206,7 +202,6 @@ def check_array_ctypes(self, pyfunc): self.assertPreciseEqual(expected, got) return cfunc - @tag('important') def test_passing_array_ctypes_voidptr(self): """ Test the ".ctypes" attribute of an array can be passed @@ -214,7 +209,6 @@ def test_passing_array_ctypes_voidptr(self): """ self.check_array_ctypes(use_c_vsquare) - @tag('important') def test_passing_array_ctypes_voidptr_pass_ptr(self): """ Test the ".ctypes" attribute of an array can be passed diff --git a/numba/tests/test_debuginfo.py b/numba/tests/test_debuginfo.py index 244b6f8180b..cf891d9373d 100644 --- a/numba/tests/test_debuginfo.py +++ b/numba/tests/test_debuginfo.py @@ -26,7 +26,6 @@ def foo(x): self._check(foo, sig=(types.int32,), expect=False) - @tag('important') def test_debuginfo_in_asm(self): @jit(nopython=True, debug=True) def foo(x): diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 80f7a6c6b00..8d4b4ac5268 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -583,7 +583,6 @@ class TestSignatureHandling(BaseTest): Test support for various parameter passing styles. """ - @tag('important') def test_named_args(self): """ Test passing named arguments to a dispatcher. @@ -671,7 +670,6 @@ class TestGeneratedDispatcher(TestCase): Tests for @generated_jit. """ - @tag('important') def test_generated(self): f = generated_jit(nopython=True)(generated_usecase) self.assertEqual(f(8), 8 - 5) @@ -681,7 +679,6 @@ def test_generated(self): self.assertEqual(f(1j, 42), 42 + 1j) self.assertEqual(f(x=1j, y=7), 7 + 1j) - @tag('important') def test_generated_dtype(self): f = generated_jit(nopython=True)(dtype_generated_usecase) a = np.ones((10,), dtype=np.float32) @@ -746,7 +743,6 @@ def foo(x): self.assertPreciseEqual(foo(1), 3) self.assertPreciseEqual(foo(1.5), 3) - @tag('important') def test_inspect_llvm(self): # Create a jited function @jit @@ -1073,7 +1069,6 @@ def check_hits(self, func, hits, misses=None): class TestCache(BaseCacheUsecasesTest): - @tag('important') def test_caching(self): self.check_pycache(0) mod = self.import_module() @@ -1108,7 +1103,6 @@ def test_caching(self): # Check the code runs ok from another process self.run_in_separate_process() - @tag('important') def test_caching_nrt_pruned(self): self.check_pycache(0) mod = self.import_module() diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 07b2ea702aa..8f0f86e2a6e 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -127,7 +127,6 @@ def pyfunc(m, n): del got_arr - @tag('important') def test_empty_3d(self): def pyfunc(m, n, p): arr = np.empty((m, n, p), np.int32) @@ -153,7 +152,6 @@ def pyfunc(m, n, p): del got_arr - @tag('important') def test_empty_2d_sliced(self): def pyfunc(m, n, p): arr = np.empty((m, n), np.int32) @@ -178,7 +176,6 @@ def pyfunc(m, n, p): del got_arr - @tag('important') def test_return_global_array(self): y = np.ones(4, dtype=np.float32) initrefct = sys.getrefcount(y) @@ -206,7 +203,6 @@ def return_external_array(): # y is no longer referenced by cfunc self.assertEqual(initrefct, sys.getrefcount(y)) - @tag('important') def test_return_global_array_sliced(self): y = np.ones(4, dtype=np.float32) @@ -237,7 +233,6 @@ def pyfunc(y): self.assertIs(expected, arr) self.assertIs(expected, got) - @tag('important') def test_array_pass_through_sliced(self): def pyfunc(y): return y[y.size // 2:] @@ -642,7 +637,6 @@ def func2(m, n): with self.assertRaises(ValueError): cfunc(np.int64(1 << (32 - 1)), 1) - @tag('important') def test_2d_dtype_kwarg(self): pyfunc = self.pyfunc def func(m, n): @@ -1144,7 +1138,6 @@ def pyfunc(arg): ((),), ]) - @tag('important') def test_2d(self): def pyfunc(arg): return np.array(arg) @@ -1224,7 +1217,6 @@ def assert_invalid_sizes_over_dim(self, axis): self.assertIn("input sizes over dimension %d do not match" % axis, str(raises.exception)) - @tag('important') def test_3d(self): pyfunc = np_concatenate2 cfunc = nrtjit(pyfunc) @@ -1407,7 +1399,6 @@ def check_runtime_errors(self, cfunc, generate_starargs): args = next(generate_starargs()) cfunc(a[:-1], b, c, *args) - @tag('important') def test_3d(self): """ stack(3d arrays, axis) @@ -1463,7 +1454,6 @@ def generate_starargs(): c = np.array(True) self.check_stack(pyfunc, cfunc, (a, b, a)) - @tag('important') def test_hstack(self): pyfunc = np_hstack cfunc = nrtjit(pyfunc) @@ -1478,7 +1468,6 @@ def test_hstack(self): b = np.arange(8).reshape((2, 4)) + 100 self.check_stack(pyfunc, cfunc, (a, b, a)) - @tag('important') def test_vstack(self): pyfunc = np_vstack cfunc = nrtjit(pyfunc) @@ -1493,7 +1482,6 @@ def test_vstack(self): b = np.arange(8).reshape((4, 2)) + 100 self.check_stack(pyfunc, cfunc, (a, b, b)) - @tag('important') def test_dstack(self): pyfunc = np_dstack cfunc = nrtjit(pyfunc) @@ -1508,7 +1496,6 @@ def test_dstack(self): b = a + 100 self.check_stack(pyfunc, cfunc, (a, b, b)) - @tag('important') def test_column_stack(self): pyfunc = np_column_stack cfunc = nrtjit(pyfunc) diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index 78c01a0538d..fc4966b2e48 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -169,7 +169,6 @@ def check_raise_class(self, flags): self.check_against_python(flags, pyfunc, cfunc, np.linalg.linalg.LinAlgError, 3) - @tag('important') def test_raise_class_nopython(self): self.check_raise_class(flags=no_pyobj_flags) @@ -192,7 +191,6 @@ def check_raise_instance(self, flags): def test_raise_instance_objmode(self): self.check_raise_instance(flags=force_pyobj_flags) - @tag('important') def test_raise_instance_nopython(self): self.check_raise_instance(flags=no_pyobj_flags) @@ -214,7 +212,6 @@ def check_raise_nested(self, flags, **jit_args): def test_raise_nested_objmode(self): self.check_raise_nested(force_pyobj_flags, forceobj=True) - @tag('important') def test_raise_nested_nopython(self): self.check_raise_nested(no_pyobj_flags, nopython=True) @@ -244,7 +241,6 @@ def impl(): def test_reraise_objmode(self): self.check_reraise(flags=force_pyobj_flags) - @tag('important') def test_reraise_nopython(self): self.check_reraise(flags=no_pyobj_flags) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 7baa0676fa3..3f32a992a6c 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -516,14 +516,12 @@ def test_index_is_monotonic(self): got = cfunc(i) self.assertEqual(got, expected) - @tag('important') def test_series_len(self): i = Index(np.int32([2, 4, 3])) s = Series(np.float64([1.5, 4.0, 2.5]), i) cfunc = jit(nopython=True)(len_usecase) self.assertPreciseEqual(cfunc(s), 3) - @tag('important') def test_series_get_index(self): i = Index(np.int32([2, 4, 3])) s = Series(np.float64([1.5, 4.0, 2.5]), i) @@ -545,7 +543,6 @@ def test_series_ufunc(self): self.assertIs(ss._index._data, i._data) self.assertPreciseEqual(ss._values, np.cos(np.sin(s._values))) - @tag('important') def test_series_constructor(self): i = Index(np.int32([42, 8, -5])) d = np.float64([1.5, 4.0, 2.5]) @@ -556,7 +553,6 @@ def test_series_constructor(self): self.assertIs(got._index._data, i._data) self.assertIs(got._values, d) - @tag('important') def test_series_clip(self): i = Index(np.int32([42, 8, -5])) s = Series(np.float64([1.5, 4.0, 2.5]), i) @@ -573,7 +569,6 @@ class TestHighLevelExtending(TestCase): Test the high-level combined API. """ - @tag('important') def test_where(self): """ Test implementing a function with @overload. @@ -597,7 +592,6 @@ def check(*args, **kwargs): self.assertIn("x and y should have the same dtype", str(raises.exception)) - @tag('important') def test_len(self): """ Test re-implementing len() for a custom type with @overload. diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index 36694535bfe..34f98250234 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -125,7 +125,6 @@ def foo(arr, v): foo(arr, 1) self.assertEqual(arr[0], arr[1]) - @tag('important') def test_getitem_array(self): # Test advanced indexing with a single array index N = 4 diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index bd21c32650b..19b9bfcaa00 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -248,7 +248,6 @@ def run_test(self, pyfunc, x_operands, y_operands, def test_for_loop1(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase1, [-10, 0, 10], [0], flags=flags) - @tag('important') def test_for_loop1_npm(self): self.test_for_loop1(flags=no_pyobj_flags) @@ -256,7 +255,6 @@ def test_for_loop2(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase2, [-10, 0, 10], [-10, 0, 10], flags=flags) - @tag('important') def test_for_loop2_npm(self): self.test_for_loop2(flags=no_pyobj_flags) @@ -273,49 +271,42 @@ def test_for_loop3_npm(self): def test_for_loop4(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase4, [10], [10], flags=flags) - @tag('important') def test_for_loop4_npm(self): self.test_for_loop4(flags=no_pyobj_flags) def test_for_loop5(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase5, [100], [50], flags=flags) - @tag('important') def test_for_loop5_npm(self): self.test_for_loop5(flags=no_pyobj_flags) def test_for_loop6(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase6, [100], [50], flags=flags) - @tag('important') def test_for_loop6_npm(self): self.test_for_loop6(flags=no_pyobj_flags) def test_for_loop7(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase7, [5], [0], flags=flags) - @tag('important') def test_for_loop7_npm(self): self.test_for_loop7(flags=no_pyobj_flags) def test_for_loop8(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase8, [0, 1], [0, 2, 10], flags=flags) - @tag('important') def test_for_loop8_npm(self): self.test_for_loop8(flags=no_pyobj_flags) def test_for_loop9(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase9, [0, 1], [0, 2, 10], flags=flags) - @tag('important') def test_for_loop9_npm(self): self.test_for_loop9(flags=no_pyobj_flags) def test_for_loop10(self, flags=enable_pyobj_flags): self.run_test(for_loop_usecase10, [5], [2, 7], flags=flags) - @tag('important') def test_for_loop10_npm(self): self.test_for_loop10(flags=no_pyobj_flags) @@ -334,21 +325,18 @@ def test_while_loop2_npm(self): def test_while_loop3(self, flags=enable_pyobj_flags): self.run_test(while_loop_usecase3, [10], [10], flags=flags) - @tag('important') def test_while_loop3_npm(self): self.test_while_loop3(flags=no_pyobj_flags) def test_while_loop4(self, flags=enable_pyobj_flags): self.run_test(while_loop_usecase4, [10], [0], flags=flags) - @tag('important') def test_while_loop4_npm(self): self.test_while_loop4(flags=no_pyobj_flags) def test_while_loop5(self, flags=enable_pyobj_flags): self.run_test(while_loop_usecase5, [0, 5, 10], [0, 5, 10], flags=flags) - @tag('important') def test_while_loop5_npm(self): self.test_while_loop5(flags=no_pyobj_flags) @@ -361,21 +349,18 @@ def test_ifelse1_npm(self): def test_ifelse2(self, flags=enable_pyobj_flags): self.run_test(ifelse_usecase2, [-1, 0, 1], [-1, 0, 1], flags=flags) - @tag('important') def test_ifelse2_npm(self): self.test_ifelse2(flags=no_pyobj_flags) def test_ifelse3(self, flags=enable_pyobj_flags): self.run_test(ifelse_usecase3, [-1, 0, 1], [-1, 0, 1], flags=flags) - @tag('important') def test_ifelse3_npm(self): self.test_ifelse3(flags=no_pyobj_flags) def test_ifelse4(self, flags=enable_pyobj_flags): self.run_test(ifelse_usecase4, [-1, 0, 1], [-1, 0, 1], flags=flags) - @tag('important') def test_ifelse4_npm(self): self.test_ifelse4(flags=no_pyobj_flags) @@ -383,7 +368,6 @@ def test_ternary_ifelse1(self, flags=enable_pyobj_flags): self.run_test(ternary_ifelse_usecase1, [-1, 0, 1], [-1, 0, 1], flags=flags) - @tag('important') def test_ternary_ifelse1_npm(self): self.test_ternary_ifelse1(flags=no_pyobj_flags) diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index 86ca2f030b1..f3e2dc497c0 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -146,7 +146,6 @@ def check_gen1(self, flags=no_pyobj_flags): cgen = cr.entry_point(8) self.check_generator(pygen, cgen) - @tag('important') def test_gen1(self): self.check_gen1() @@ -160,7 +159,6 @@ def check_gen2(self, flags=no_pyobj_flags): cgen = cr.entry_point(8) self.check_generator(pygen, cgen) - @tag('important') def test_gen2(self): self.check_gen2() @@ -174,7 +172,6 @@ def check_gen3(self, flags=no_pyobj_flags): cgen = cr.entry_point(8) self.check_generator(pygen, cgen) - @tag('important') def test_gen3(self): self.check_gen3() @@ -188,7 +185,6 @@ def check_gen4(self, flags=no_pyobj_flags): cgen = cr.entry_point(5, 6, 7) self.check_generator(pygen, cgen) - @tag('important') def test_gen4(self): self.check_gen4() @@ -217,7 +213,6 @@ def check_gen6(self, flags=no_pyobj_flags): l.append(next(cgen)) self.assertEqual(l, [14] * 3) - @tag('important') def test_gen6(self): self.check_gen6() @@ -233,7 +228,6 @@ def check_gen7(self, flags=no_pyobj_flags): cgen = cr.entry_point(arr) self.check_generator(pygen, cgen) - @tag('important') def test_gen7(self): self.check_gen7() @@ -253,7 +247,6 @@ def check(*args, **kwargs): check(y=5) check(x=6, b=True) - @tag('important') def test_gen8(self): self.check_gen8(nopython=True) @@ -267,7 +260,6 @@ def check_gen9(self, flags=no_pyobj_flags): cgen = cr.entry_point() self.check_generator(pygen, cgen) - @tag('important') def test_gen9(self): self.check_gen9(flags=no_pyobj_flags) @@ -288,7 +280,6 @@ def test_consume_gen1(self): def test_consume_gen2(self): self.check_consume_generator(gen2) - @tag('important') def test_consume_gen3(self): self.check_consume_generator(gen3) diff --git a/numba/tests/test_gil.py b/numba/tests/test_gil.py index 8635b7ddefe..f25f8ea634e 100644 --- a/numba/tests/test_gil.py +++ b/numba/tests/test_gil.py @@ -116,7 +116,6 @@ def test_gil_held(self): cfunc = jit(f_sig, nopython=True)(f) self.check_gil_held(cfunc) - @tag('important') def test_gil_released(self): """ Test releasing the GIL, by checking parallel runs produce diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index 5639e71dbda..f5b6158e30b 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -97,12 +97,10 @@ def check_complex(self, typ, float_ty): self.assertEqual(a.dtype, np.dtype(typ)) self.check_hash_values(a) - @tag('important') def test_floats(self): self.check_floats(np.float32) self.check_floats(np.float64) - @tag('important') def test_complex(self): self.check_complex(np.complex64, np.float32) self.check_complex(np.complex128, np.float64) @@ -198,7 +196,6 @@ def split3(i): self.check_hash_values([(7,), (0,), (0, 0), (0.5,), (0.5, (7,), (-2, 3, (4, 6)))]) - @tag('important') def test_heterogeneous_tuples(self): modulo = 2**63 diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index c9a5350be62..ed1f0a16804 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -469,7 +469,6 @@ def test_3d_slicing(self, flags=enable_pyobj_flags): for arg in args: self.assertEqual(pyfunc(a, *arg), cfunc(a, *arg)) - @tag('important') def test_3d_slicing_npm(self): self.test_3d_slicing(flags=Noflags) @@ -565,7 +564,6 @@ def test_integer_indexing_1d_for_2d(self, flags=enable_pyobj_flags): a = np.arange(20, dtype='i4').reshape(5, 4)[::2] self.assertPreciseEqual(pyfunc(a, 0), cfunc(a, 0)) - @tag('important') def test_integer_indexing_1d_for_2d_npm(self): self.test_integer_indexing_1d_for_2d(flags=Noflags) @@ -609,7 +607,6 @@ def test_2d_integer_indexing(self, flags=enable_pyobj_flags, j = np.array(j).astype(np.int32) self.assertEqual(pyfunc(a, i, j), cfunc(a, i, j)) - @tag('important') def test_2d_integer_indexing_npm(self): self.test_2d_integer_indexing(flags=Noflags) @@ -901,7 +898,6 @@ def test_1d_slicing_broadcast_npm(self): def test_1d_slicing_add_npm(self): self.test_1d_slicing_add(flags=Noflags) - @tag('important') def test_2d_slicing_set(self, flags=enable_pyobj_flags): """ 2d to 2d slice assignment diff --git a/numba/tests/test_intwidth.py b/numba/tests/test_intwidth.py index d400a98d6bd..9a4bf067312 100644 --- a/numba/tests/test_intwidth.py +++ b/numba/tests/test_intwidth.py @@ -46,7 +46,6 @@ def test_constant_uint64(self, nopython=False): pyfunc = usecase_uint64_constant self.check_nullary_func(pyfunc, nopython=nopython) - @tag('important') def test_constant_uint64_npm(self): self.test_constant_uint64(nopython=True) @@ -76,7 +75,6 @@ def test_bit_length(self): self.assertEqual(f(0xffffffffffffffff), 64) self.assertEqual(f(0x10000000000000000), 65) - @tag('important') def test_constant_int64(self, nopython=False): self.check_nullary_func(usecase_int64_pos, nopython=nopython) self.check_nullary_func(usecase_int64_neg, nopython=nopython) diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index e64278c9bbe..6a77e6ba502 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -94,7 +94,6 @@ def run_nullary_func(self, pyfunc, flags): def test_int_tuple_iter(self, flags=force_pyobj_flags): self.run_nullary_func(int_tuple_iter_usecase, flags) - @tag('important') def test_int_tuple_iter_npm(self): self.test_int_tuple_iter(flags=no_pyobj_flags) @@ -110,21 +109,18 @@ def test_float_tuple_iter_npm(self): def test_tuple_tuple_iter(self, flags=force_pyobj_flags): self.run_nullary_func(tuple_tuple_iter_usecase, flags) - @tag('important') def test_tuple_tuple_iter_npm(self): self.test_tuple_tuple_iter(flags=no_pyobj_flags) def test_enumerate_nested_tuple(self, flags=force_pyobj_flags): self.run_nullary_func(enumerate_nested_tuple_usecase, flags) - @tag('important') def test_enumerate_nested_tuple_npm(self): self.test_enumerate_nested_tuple(flags=no_pyobj_flags) def test_nested_enumerate(self, flags=force_pyobj_flags): self.run_nullary_func(nested_enumerate_usecase, flags) - @tag('important') def test_nested_enumerate_npm(self): self.test_nested_enumerate(flags=no_pyobj_flags) @@ -153,7 +149,6 @@ def test_array_1d_float_npm(self): def test_array_1d_complex(self, flags=force_pyobj_flags): self.run_array_1d(types.complex128, np.arange(5.0) * 1.0j, flags) - @tag('important') def test_array_1d_complex_npm(self): self.test_array_1d_complex(no_pyobj_flags) diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index 47ddb54a0f2..ca993d2a274 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -121,7 +121,6 @@ def __init__(self, x, y): return Vector2 - @tag('important') def test_jit_class_1(self): Float2AndArray = self._make_Float2AndArray() Vector2 = self._make_Vector2() @@ -144,7 +143,6 @@ def foo(a): self.assertEqual(b, 3 + 4) self.assertPreciseEqual(c, inp) - @tag('important') def test_jitclass_usage_from_python(self): Float2AndArray = self._make_Float2AndArray() @@ -213,7 +211,6 @@ def __init__(self, val): self.assertTrue(Foo(True).val) self.assertFalse(Foo(False).val) - @tag('important') def test_deferred_type(self): node_type = deferred_type() @@ -360,7 +357,6 @@ def __init__(self): self.assertEqual(str(raises.exception), "class members are not yet supported: constant") - @tag('important') def test_user_getter_setter(self): @jitclass([('attr', int32)]) class Foo(object): @@ -491,7 +487,6 @@ def create_my_class(value): d = create_my_class(np.array([12.3])) np.testing.assert_equal(d.value, [12.3]) - @tag('important') def test_protected_attrs(self): spec = { 'value': int32, diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index 6591e818855..6cd6c622138 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -709,7 +709,6 @@ class TestLinalgInv(TestLinalgBase): Tests for np.linalg.inv. """ - @tag('important') @needs_lapack def test_linalg_inv(self): """ diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 1d14bc7fe91..0bca472d87f 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -440,21 +440,18 @@ def test_constructor_empty_but_typeable(self): def test_append(self): self.check_unary_with_size(list_append) - @tag('important') def test_append_heterogeneous(self): self.check_unary_with_size(list_append_heterogeneous, precise=False) def test_extend(self): self.check_unary_with_size(list_extend) - @tag('important') def test_extend_heterogeneous(self): self.check_unary_with_size(list_extend_heterogeneous, precise=False) def test_pop0(self): self.check_unary_with_size(list_pop0) - @tag('important') def test_pop1(self): pyfunc = list_pop1 cfunc = jit(nopython=True)(pyfunc) @@ -486,11 +483,9 @@ def test_insert(self): def test_len(self): self.check_unary_with_size(list_len) - @tag('important') def test_getitem(self): self.check_unary_with_size(list_getitem) - @tag('important') def test_setitem(self): self.check_unary_with_size(list_setitem) @@ -516,7 +511,6 @@ def test_setslice2(self): expected = pyfunc(n, n_src, start, stop) self.assertPreciseEqual(cfunc(n, n_src, start, stop), expected) - @tag('important') def test_getslice3(self): pyfunc = list_getslice3 cfunc = jit(nopython=True)(pyfunc) @@ -527,7 +521,6 @@ def test_getslice3(self): expected = pyfunc(n, start, stop, step) self.assertPreciseEqual(cfunc(n, start, stop, step), expected) - @tag('important') def test_setslice3(self): pyfunc = list_setslice3 cfunc = jit(nopython=True)(pyfunc) @@ -556,7 +549,6 @@ def test_delslice0(self): def test_delslice1(self): self.check_slicing2(list_delslice1) - @tag('important') def test_delslice2(self): self.check_slicing2(list_delslice2) @@ -571,7 +563,6 @@ def test_invalid_slice(self): def test_iteration(self): self.check_unary_with_size(list_iteration) - @tag('important') def test_reverse(self): self.check_unary_with_size(list_reverse) @@ -792,7 +783,6 @@ def test_tuples(self): check([(1, 2j), (3, 4j)]) check([(), (), ()]) - @tag('important') def test_list_inside_tuple(self): check = self.check_unary(unbox_usecase3) check((1, [2, 3, 4])) @@ -870,7 +860,6 @@ def test_reflect_exception(self): cfunc(l) self.assertPreciseEqual(l, [1, 2, 3, 42]) - @tag('important') def test_reflect_same_list(self): """ When the same list object is reflected twice, behaviour should diff --git a/numba/tests/test_looplifting.py b/numba/tests/test_looplifting.py index cb33267a59b..ac97a73f113 100644 --- a/numba/tests/test_looplifting.py +++ b/numba/tests/test_looplifting.py @@ -203,7 +203,6 @@ def test_lift2(self): def test_lift3(self): self.check_lift_ok(lift3, (types.intp,), (123,)) - @tag('important') def test_lift4(self): self.check_lift_ok(lift4, (types.intp,), (123,)) @@ -213,7 +212,6 @@ def test_lift5(self): def test_lift_issue2561(self): self.check_no_lift(lift_issue2561, (), ()) - @tag('important') def test_lift_gen1(self): self.check_lift_generator_ok(lift_gen1, (types.intp,), (123,)) diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index b209d40ff22..1e2128be310 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -220,7 +220,6 @@ def test_sin(self, flags=enable_pyobj_flags): x_values = [-2, -1, -2, 2, 1, 2, .1, .2] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_sin_npm(self): self.test_sin(flags=no_pyobj_flags) @@ -234,7 +233,6 @@ def test_cos(self, flags=enable_pyobj_flags): x_values = [-2, -1, -2, 2, 1, 2, .1, .2] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_cos_npm(self): self.test_cos(flags=no_pyobj_flags) @@ -246,7 +244,6 @@ def test_tan(self, flags=enable_pyobj_flags): x_values = [-2, -1, -2, 2, 1, 2, .1, .2] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_tan_npm(self): self.test_tan(flags=no_pyobj_flags) @@ -258,7 +255,6 @@ def test_sqrt(self, flags=enable_pyobj_flags): x_values = [2, 1, 2, 2, 1, 2, .1, .2] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_sqrt_npm(self): self.test_sqrt(flags=no_pyobj_flags) @@ -284,7 +280,6 @@ def test_exp(self, flags=enable_pyobj_flags): x_values = [-2, -1, -2, 2, 1, 2, .1, .2] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_exp_npm(self): self.test_exp(flags=no_pyobj_flags) @@ -296,7 +291,6 @@ def test_expm1(self, flags=enable_pyobj_flags): x_values = [-2, -1, -2, 2, 1, 2, .1, .2] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_expm1_npm(self): self.test_expm1(flags=no_pyobj_flags) @@ -308,7 +302,6 @@ def test_log(self, flags=enable_pyobj_flags): x_values = [1, 10, 100, 1000, 100000, 1000000, 0.1, 1.1] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_log_npm(self): self.test_log(flags=no_pyobj_flags) @@ -320,7 +313,6 @@ def test_log1p(self, flags=enable_pyobj_flags): x_values = [1, 10, 100, 1000, 100000, 1000000, 0.1, 1.1] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_log1p_npm(self): self.test_log1p(flags=no_pyobj_flags) @@ -332,7 +324,6 @@ def test_log10(self, flags=enable_pyobj_flags): x_values = [1, 10, 100, 1000, 100000, 1000000, 0.1, 1.1] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_log10_npm(self): self.test_log10(flags=no_pyobj_flags) @@ -344,7 +335,6 @@ def test_asin(self, flags=enable_pyobj_flags): x_values = [1, 1, 1, 1, 1, 1, 1., 1.] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_asin_npm(self): self.test_asin(flags=no_pyobj_flags) @@ -356,7 +346,6 @@ def test_acos(self, flags=enable_pyobj_flags): x_values = [1, 1, 1, 1, 1, 1, 1., 1.] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_acos_npm(self): self.test_acos(flags=no_pyobj_flags) @@ -368,7 +357,6 @@ def test_atan(self, flags=enable_pyobj_flags): x_values = [-2, -1, -2, 2, 1, 2, .1, .2] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_atan_npm(self): self.test_atan(flags=no_pyobj_flags) @@ -381,7 +369,6 @@ def test_atan2(self, flags=enable_pyobj_flags): y_values = [x * 2 for x in x_values] self.run_binary(pyfunc, x_types, x_values, y_values, flags) - @tag('important') def test_atan2_npm(self): self.test_atan2(flags=no_pyobj_flags) @@ -393,7 +380,6 @@ def test_asinh(self, flags=enable_pyobj_flags): x_values = [1, 1, 1, 1, 1, 1, 1., 1.] self.run_unary(pyfunc, x_types, x_values, flags, prec='double') - @tag('important') def test_asinh_npm(self): self.test_asinh(flags=no_pyobj_flags) @@ -405,7 +391,6 @@ def test_acosh(self, flags=enable_pyobj_flags): x_values = [1, 1, 1, 1, 1, 1, 1., 1.] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_acosh_npm(self): self.test_acosh(flags=no_pyobj_flags) @@ -417,7 +402,6 @@ def test_atanh(self, flags=enable_pyobj_flags): x_values = [0, 0, 0, 0, 0, 0, 0.1, 0.1] self.run_unary(pyfunc, x_types, x_values, flags, prec='double') - @tag('important') def test_atanh_npm(self): self.test_atanh(flags=no_pyobj_flags) @@ -429,7 +413,6 @@ def test_sinh(self, flags=enable_pyobj_flags): x_values = [1, 1, 1, 1, 1, 1, 1., 1.] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_sinh_npm(self): self.test_sinh(flags=no_pyobj_flags) @@ -441,7 +424,6 @@ def test_cosh(self, flags=enable_pyobj_flags): x_values = [1, 1, 1, 1, 1, 1, 1., 1.] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_cosh_npm(self): self.test_cosh(flags=no_pyobj_flags) @@ -453,7 +435,6 @@ def test_tanh(self, flags=enable_pyobj_flags): x_values = [0, 0, 0, 0, 0, 0, 0.1, 0.1] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_tanh_npm(self): self.test_tanh(flags=no_pyobj_flags) @@ -465,7 +446,6 @@ def test_floor(self, flags=enable_pyobj_flags): x_values = [0, 0, 0, 0, 0, 0, 0.1, 1.9] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_floor_npm(self): self.test_floor(flags=no_pyobj_flags) @@ -477,7 +457,6 @@ def test_ceil(self, flags=enable_pyobj_flags): x_values = [0, 0, 0, 0, 0, 0, 0.1, 1.9] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_ceil_npm(self): self.test_ceil(flags=no_pyobj_flags) @@ -489,21 +468,18 @@ def test_trunc(self, flags=enable_pyobj_flags): x_values = [0, 0, 0, 0, 0, 0, 0.1, 1.9] self.run_unary(pyfunc, x_types, x_values, flags) - @tag('important') def test_trunc_npm(self): self.test_trunc(flags=no_pyobj_flags) def test_isnan(self): self.check_predicate_func(isnan, flags=enable_pyobj_flags) - @tag('important') def test_isnan_npm(self): self.check_predicate_func(isnan, flags=no_pyobj_flags) def test_isinf(self): self.check_predicate_func(isinf, flags=enable_pyobj_flags) - @tag('important') def test_isinf_npm(self): self.check_predicate_func(isinf, flags=no_pyobj_flags) @@ -542,7 +518,6 @@ def naive_hypot(x, y): 'overflow encountered in .*_scalars', naive_hypot, val, val) - @tag('important') def test_hypot_npm(self): self.test_hypot(flags=no_pyobj_flags) @@ -634,7 +609,6 @@ def test_gcd(self, flags=enable_pyobj_flags): def test_gcd_npm(self): self.test_gcd(flags=no_pyobj_flags) - @tag('important') def test_pow_npm(self): self.test_pow(flags=no_pyobj_flags) @@ -647,7 +621,6 @@ def test_copysign(self, flags=enable_pyobj_flags): *itertools.product(value_types, values, values))) self.run_binary(pyfunc, x_types, x_values, y_values, flags) - @tag('important') def test_copysign_npm(self): self.test_copysign(flags=no_pyobj_flags) diff --git a/numba/tests/test_nested_calls.py b/numba/tests/test_nested_calls.py index a1a96d9aecd..677519d8255 100644 --- a/numba/tests/test_nested_calls.py +++ b/numba/tests/test_nested_calls.py @@ -84,7 +84,6 @@ def outer(x): self.assertFalse(outer(True)) self.assertTrue(outer(False)) - @tag('important') def test_named_args(self, objmode=False): """ Test a nested function call with named (keyword) arguments. @@ -96,7 +95,6 @@ def test_named_args(self, objmode=False): def test_named_args_objmode(self): self.test_named_args(objmode=True) - @tag('important') def test_default_args(self, objmode=False): """ Test a nested function call using default argument values. @@ -108,7 +106,6 @@ def test_default_args(self, objmode=False): def test_default_args_objmode(self): self.test_default_args(objmode=True) - @tag('important') def test_star_args(self): """ Test a nested function call to a function with *args in its signature. @@ -116,7 +113,6 @@ def test_star_args(self): cfunc, check = self.compile_func(star) check(1, 2, 3) - @tag('important') def test_star_call(self, objmode=False): """ Test a function call with a *args. @@ -136,7 +132,6 @@ def test_argcast(self): check(1, 0) check(1, 1) - @tag('important') def test_call_generated(self): """ Test a nested function call to a generated jit function. diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index d256353b726..0c75e3f4ef2 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -261,7 +261,6 @@ class TestTimedeltaArithmetic(TestCase): def jit(self, pyfunc): return jit(**self.jitargs)(pyfunc) - @tag('important') def test_add(self): f = self.jit(add_usecase) def check(a, b, expected): @@ -281,7 +280,6 @@ def check(a, b, expected): with self.assertRaises((TypeError, TypingError)): f(TD(1, 'M'), TD(1, 'D')) - @tag('important') def test_sub(self): f = self.jit(sub_usecase) def check(a, b, expected): @@ -367,7 +365,6 @@ def check(a, b, expected): with self.assertRaises((TypeError, TypingError)): div(TD(1, 'M'), TD(1, 'D')) - @tag('important') def test_eq_ne(self): eq = self.jit(eq_usecase) ne = self.jit(ne_usecase) @@ -543,7 +540,6 @@ def silence_numpy_warnings(self): category=DeprecationWarning) yield - @tag('important') def test_add_sub_timedelta(self): """ Test `datetime64 + timedelta64` and `datetime64 - timedelta64`. @@ -645,7 +641,6 @@ def check(a, b, expected=None): continue self.assertPreciseEqual(sub(a, b), a - b, (a, b)) - @tag('important') def test_comparisons(self): # Test all datetime comparisons all at once eq = self.jit(eq_usecase) diff --git a/numba/tests/test_numberctor.py b/numba/tests/test_numberctor.py index d78f0e2d3b4..71bb71f32d7 100644 --- a/numba/tests/test_numberctor.py +++ b/numba/tests/test_numberctor.py @@ -71,15 +71,12 @@ def check_int_constructor(self, pyfunc): cfunc = cres.entry_point self.assertPreciseEqual(pyfunc(x), cfunc(x)) - @tag('important') def test_bool(self): self.check_int_constructor(dobool) - @tag('important') def test_int(self): self.check_int_constructor(doint) - @tag('important') def test_float(self): pyfunc = dofloat @@ -94,7 +91,6 @@ def test_float(self): self.assertPreciseEqual(pyfunc(x), cfunc(x), prec='single' if ty is types.float32 else 'exact') - @tag('important') def test_complex(self): pyfunc = docomplex @@ -124,7 +120,6 @@ def test_complex(self): cfunc = cres.entry_point self.assertGreater(cfunc(x), 1.0) - @tag('important') def test_complex2(self): pyfunc = docomplex2 diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index 4a6605952b7..a4ac585f315 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -16,7 +16,6 @@ class TestFromDtype(TestCase): - @tag('important') def test_number_types(self): """ Test from_dtype() and as_dtype() with the various scalar number types. @@ -93,21 +92,18 @@ def check(dtype, numba_type, code): # Unit-less ("generic") type check(np.dtype(letter), nb_class(''), 14) - @tag('important') def test_datetime_types(self): """ Test from_dtype() and as_dtype() with the datetime types. """ self.check_datetime_types('M', types.NPDatetime) - @tag('important') def test_timedelta_types(self): """ Test from_dtype() and as_dtype() with the timedelta types. """ self.check_datetime_types('m', types.NPTimedelta) - @tag('important') def test_struct_types(self): def check(dtype, fields, size, aligned): tp = numpy_support.from_dtype(dtype) @@ -136,7 +132,6 @@ def check(dtype, fields, size, aligned): 'n': (types.CharSeq(5), 4, None, None)}, size=9, aligned=False) - @tag('important') def test_enum_type(self): def check(base_inst, enum_def, type_class): @@ -213,14 +208,12 @@ def check_timedelta_values(self, func): class TestArrayScalars(ValueTypingTestBase, TestCase): - @tag('important') def test_number_values(self): """ Test map_arrayscalar_type() with scalar number values. """ self.check_number_values(numpy_support.map_arrayscalar_type) - @tag('important') def test_datetime_values(self): """ Test map_arrayscalar_type() with np.datetime64 values. @@ -232,7 +225,6 @@ def test_datetime_values(self): with self.assertRaises(NotImplementedError): f(t) - @tag('important') def test_timedelta_values(self): """ Test map_arrayscalar_type() with np.timedelta64 values. diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 2e50975eea4..18fa76e52e2 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -455,42 +455,36 @@ def run_test_scalar_compare(self, pyfunc, flags=force_pyobj_flags, def test_lt_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.lt_usecase, flags) - @tag('important') def test_lt_scalar_npm(self): self.test_lt_scalar(flags=Noflags) def test_le_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.le_usecase, flags) - @tag('important') def test_le_scalar_npm(self): self.test_le_scalar(flags=Noflags) def test_gt_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.gt_usecase, flags) - @tag('important') def test_gt_scalar_npm(self): self.test_gt_scalar(flags=Noflags) def test_ge_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.ge_usecase, flags) - @tag('important') def test_ge_scalar_npm(self): self.test_ge_scalar(flags=Noflags) def test_eq_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.eq_usecase, flags, ordered=False) - @tag('important') def test_eq_scalar_npm(self): self.test_eq_scalar(flags=Noflags) def test_ne_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.ne_usecase, flags, ordered=False) - @tag('important') def test_ne_scalar_npm(self): self.test_ne_scalar(flags=Noflags) @@ -697,7 +691,6 @@ def test_add_complex(self, flags=force_pyobj_flags): self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) - @tag('important') def test_add_complex_npm(self): self.test_add_complex(flags=Noflags) @@ -713,7 +706,6 @@ def test_sub_complex(self, flags=force_pyobj_flags): self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) - @tag('important') def test_sub_complex_npm(self): self.test_sub_complex(flags=Noflags) @@ -729,7 +721,6 @@ def test_mul_complex(self, flags=force_pyobj_flags): self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) - @tag('important') def test_mul_complex_npm(self): self.test_mul_complex(flags=Noflags) @@ -745,7 +736,6 @@ def test_truediv_complex(self, flags=force_pyobj_flags): self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) - @tag('important') def test_truediv_complex_npm(self): self.test_truediv_complex(flags=Noflags) @@ -754,7 +744,6 @@ def test_mod_complex(self, flags=force_pyobj_flags): with self.assertTypingError(): cres = compile_isolated(pyfunc, (types.complex64, types.complex64)) - @tag('important') def test_mod_complex_npm(self): self.test_mod_complex(flags=Noflags) @@ -796,11 +785,9 @@ def check_matmul_npm(self, pyfunc): self.assertIsNot(got, a) self.assertIsNot(got, b) - @tag('important') def test_matmul_npm(self): self.check_matmul_npm(self.op.matmul_usecase) - @tag('important') def test_imatmul_npm(self): with self.assertTypingError() as raises: self.check_matmul_npm(self.op.imatmul_usecase) @@ -978,7 +965,6 @@ def test_bitwise_not(self, flags=force_pyobj_flags): for val in values: self.assertPreciseEqual(pyfunc(val), cfunc(val)) - @tag('important') def test_bitwise_not_npm(self): self.test_bitwise_not(flags=Noflags) @@ -1032,7 +1018,6 @@ def test_not(self): for val in values: self.assertEqual(pyfunc(val), cfunc(val)) - @tag('important') def test_not_npm(self): pyfunc = self.op.not_usecase # test native mode @@ -1058,7 +1043,6 @@ def test_not_npm(self): # XXX test_negate should check for negative and positive zeros and infinities - @tag('important') def test_negate_npm(self): pyfunc = self.op.negate_usecase # test native mode @@ -1273,15 +1257,12 @@ def run_arith_binop(self, pyfunc, opname, samples, self.run_binary(pyfunc, self.get_control_unsigned(opname), samples, self.unsigned_pairs, expected_type) - @tag('important') def test_add(self): self.run_arith_binop(self.op.add_usecase, 'add', self.int_samples) - @tag('important') def test_sub(self): self.run_arith_binop(self.op.sub_usecase, 'sub', self.int_samples) - @tag('important') def test_mul(self): self.run_arith_binop(self.op.mul_usecase, 'mul', self.int_samples) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 960598e77e9..90b8674252e 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -491,7 +491,6 @@ def check(self, pyfunc, *args, **kwargs): self.check_parfors_vs_others(pyfunc, cfunc, cpfunc, *args, **kwargs) @skip_parfors_unsupported - @tag('important') def test_arraymap(self): def test_impl(a, x, y): return a * x + y @@ -504,7 +503,6 @@ def test_impl(a, x, y): @skip_parfors_unsupported @needs_blas - @tag('important') def test_mvdot(self): def test_impl(a, v): return np.dot(a, v) @@ -515,7 +513,6 @@ def test_impl(a, v): self.check(test_impl, A, v) @skip_parfors_unsupported - @tag('important') def test_0d_broadcast(self): def test_impl(): X = np.array(1) @@ -525,7 +522,6 @@ def test_impl(): self.assertTrue(countParfors(test_impl, ()) == 1) @skip_parfors_unsupported - @tag('important') def test_2d_parfor(self): def test_impl(): X = np.ones((10, 12)) @@ -535,7 +531,6 @@ def test_impl(): self.assertTrue(countParfors(test_impl, ()) == 1) @skip_parfors_unsupported - @tag('important') def test_pi(self): def test_impl(n): x = 2 * np.random.ranf(n) - 1 @@ -547,7 +542,6 @@ def test_impl(n): self.assertTrue(countArrays(test_impl, (types.intp,)) == 0) @skip_parfors_unsupported - @tag('important') def test_fuse_argmin_argmax_max_min(self): for op in [np.argmin, np.argmax, np.min, np.max]: def test_impl(n): @@ -560,7 +554,6 @@ def test_impl(n): self.assertTrue(countArrays(test_impl, (types.intp,)) == 0) @skip_parfors_unsupported - @tag('important') def test_blackscholes(self): # blackscholes takes 5 1D float array args args = (numba.float64[:], ) * 5 @@ -568,7 +561,6 @@ def test_blackscholes(self): @skip_parfors_unsupported @needs_blas - @tag('important') def test_logistic_regression(self): args = (numba.float64[:], numba.float64[:,:], numba.float64[:], numba.int64) @@ -576,7 +568,6 @@ def test_logistic_regression(self): self.assertTrue(countArrayAllocs(lr_impl, args) == 1) @skip_parfors_unsupported - @tag('important') def test_kmeans(self): np.random.seed(0) N = 1024 diff --git a/numba/tests/test_print.py b/numba/tests/test_print.py index 03ec4b7e23a..578c2c145ce 100644 --- a/numba/tests/test_print.py +++ b/numba/tests/test_print.py @@ -44,7 +44,6 @@ def print_closure(): class TestPrint(TestCase): - @tag('important') def test_print_values(self): """ Test printing a single argument value. @@ -95,7 +94,6 @@ def check_values(typ, values): self.assertEqual(sys.stdout.getvalue(), '[0 1 2 3 4 5 6 7 8 9]\n') - @tag('important') def test_print_array_item(self): """ Test printing a Numpy character sequence @@ -110,7 +108,6 @@ def test_print_array_item(self): cfunc(arr, i) self.assertEqual(sys.stdout.getvalue(), str(arr[i]['x']) + '\n') - @tag('important') def test_print_multiple_values(self): pyfunc = print_values cr = compile_isolated(pyfunc, (types.int32,) * 3) @@ -126,7 +123,6 @@ def test_print_nogil(self): cfunc(1, 2, 3) self.assertEqual(sys.stdout.getvalue(), '1 2 3\n') - @tag('important') def test_print_empty(self): pyfunc = print_empty cr = compile_isolated(pyfunc, ()) @@ -135,7 +131,6 @@ def test_print_empty(self): cfunc() self.assertEqual(sys.stdout.getvalue(), '\n') - @tag('important') def test_print_strings(self): pyfunc = print_string cr = compile_isolated(pyfunc, (types.int32,)) diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index 778378b9beb..c15c3755daf 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -233,7 +233,6 @@ def test_compile_for_cpu_host(self): # Compiling for the host CPU should always succeed self.check_compile_for_cpu("host") - @tag('important') @unittest.skipIf(sys.platform == 'darwin' and utils.PYVERSION == (3, 8), 'distutils incorrectly using gcc on python 3.8 builds') @@ -269,7 +268,6 @@ def test_compile_helperlib(self): """ % {'expected': expected} self.check_cc_compiled_in_subprocess(lib, code) - @tag('important') def test_compile_nrt(self): with self.check_cc_compiled(self._test_module.cc_nrt) as lib: # Sanity check diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index 436162da507..f6b1418fcae 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -247,11 +247,9 @@ def _check_random_seed(self, seedfunc, randomfunc): for j in range(N + 10): self.assertPreciseEqual(randomfunc(), r.uniform(0.0, 1.0)) - @tag('important') def test_random_random(self): self._check_random_seed(random_seed, random_random) - @tag('important') def test_numpy_random(self): self._check_random_seed(numpy_seed, numpy_random) # Test aliases @@ -303,7 +301,6 @@ def _check_getrandbits(self, func, ptr): self.assertRaises(OverflowError, func, 9999999) self.assertRaises(OverflowError, func, -1) - @tag('important') def test_random_getrandbits(self): self._check_getrandbits(jit_unary("random.getrandbits"), get_py_state_ptr()) @@ -337,7 +334,6 @@ def _check_gauss(self, func2, func1, func0, ptr): if func0 is not None: self._check_dist(func0, r.normal, [()]) - @tag('important') def test_random_gauss(self): self._check_gauss(jit_binary("random.gauss"), None, None, get_py_state_ptr()) @@ -347,19 +343,16 @@ def test_random_normalvariate(self): self._check_gauss(jit_binary("random.normalvariate"), None, None, get_py_state_ptr()) - @tag('important') def test_numpy_normal(self): self._check_gauss(jit_binary("np.random.normal"), jit_unary("np.random.normal"), jit_nullary("np.random.normal"), get_np_state_ptr()) - @tag('important') def test_numpy_standard_normal(self): self._check_gauss(None, None, jit_nullary("np.random.standard_normal"), get_np_state_ptr()) - @tag('important') def test_numpy_randn(self): self._check_gauss(None, None, jit_nullary("np.random.randn"), get_np_state_ptr()) @@ -426,7 +419,6 @@ def _check_randrange(self, func1, func2, func3, ptr, max_width, is_numpy, tp=Non self.assertRaises(ValueError, func3, 5, 7, -1) self.assertRaises(ValueError, func3, 7, 5, 1) - @tag('important') def test_random_randrange(self): for tp, max_width in [(types.int64, 2**63), (types.int32, 2**31)]: cr1 = compile_isolated(random_randrange1, (tp,)) @@ -436,7 +428,6 @@ def test_random_randrange(self): cr3.entry_point, get_py_state_ptr(), max_width, False) - @tag('important') def test_numpy_randint(self): for tp, np_tp, max_width in [(types.int64, np.int64, 2**63), (types.int32, np.int32, 2**31)]: @@ -464,7 +455,6 @@ def _check_randint(self, func, ptr, max_width): self.assertRaises(ValueError, func, 5, 4) self.assertRaises(ValueError, func, 5, 2) - @tag('important') def test_random_randint(self): for tp, max_width in [(types.int64, 2**63), (types.int32, 2**31)]: cr = compile_isolated(random_randint, (tp, tp)) @@ -479,11 +469,9 @@ def _check_uniform(self, func, ptr): self._check_dist(func, r.uniform, [(1.5, 1e6), (-2.5, 1e3), (1.5, -2.5)]) - @tag('important') def test_random_uniform(self): self._check_uniform(jit_binary("random.uniform"), get_py_state_ptr()) - @tag('important') def test_numpy_uniform(self): self._check_uniform(jit_binary("np.random.uniform"), get_np_state_ptr()) @@ -646,7 +634,6 @@ def test_numpy_weibull(self): self._check_weibullvariate(None, jit_unary("np.random.weibull"), get_np_state_ptr()) - @tag('important') def test_numpy_binomial(self): # We follow Numpy's algorithm up to n*p == 30 binomial = jit_binary("np.random.binomial") @@ -672,7 +659,6 @@ def test_numpy_binomial(self): self.assertRaises(ValueError, binomial, 10, -0.1) self.assertRaises(ValueError, binomial, 10, 1.1) - @tag('important') def test_numpy_chisquare(self): chisquare = jit_unary("np.random.chisquare") r = self._follow_cpython(get_np_state_ptr()) @@ -740,7 +726,6 @@ def test_numpy_laplace(self): [(0.0,), (-1.5,)]) self._check_dist(jit_nullary("np.random.laplace"), r.laplace, [()]) - @tag('important') def test_numpy_logistic(self): r = self._follow_numpy(get_np_state_ptr()) self._check_dist(jit_binary("np.random.logistic"), r.logistic, @@ -793,7 +778,6 @@ def test_numpy_negative_binomial(self): self.assertRaises(ValueError, negbin, 10, -0.1) self.assertRaises(ValueError, negbin, 10, 1.1) - @tag('important') def test_numpy_power(self): r = self._follow_numpy(get_np_state_ptr()) power = jit_unary("np.random.power") @@ -870,11 +854,9 @@ def _check_shuffle(self, func, ptr, is_numpy): with self.assertTypingError(): func(memoryview(b"xyz")) - @tag('important') def test_random_shuffle(self): self._check_shuffle(jit_unary("random.shuffle"), get_py_state_ptr(), False) - @tag('important') def test_numpy_shuffle(self): self._check_shuffle(jit_unary("np.random.shuffle"), get_np_state_ptr(), True) @@ -1016,7 +998,6 @@ def test_numpy_lognormal(self): def test_numpy_logseries(self): self._check_array_dist("logseries", (0.8,)) - @tag('important') def test_numpy_normal(self): self._check_array_dist("normal", (0.5, 2.0)) @@ -1026,14 +1007,12 @@ def test_numpy_poisson(self): def test_numpy_power(self): self._check_array_dist("power", (0.8,)) - @tag('important') def test_numpy_rand(self): cfunc = jit(nopython=True)(numpy_check_rand) expected, got = cfunc(42, 2, 3) self.assertEqual(got.shape, (2, 3)) self.assertPreciseEqual(expected, got) - @tag('important') def test_numpy_randn(self): cfunc = jit(nopython=True)(numpy_check_randn) expected, got = cfunc(42, 2, 3) diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index d7cbce9e692..5bd0a491df1 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -70,21 +70,18 @@ def range_contains(val, start, stop, step): class TestRange(unittest.TestCase): - @tag('important') def test_loop1_int16(self): pyfunc = loop1 cres = compile_isolated(pyfunc, [types.int16]) cfunc = cres.entry_point self.assertTrue(cfunc(5), pyfunc(5)) - @tag('important') def test_loop2_int16(self): pyfunc = loop2 cres = compile_isolated(pyfunc, [types.int16, types.int16]) cfunc = cres.entry_point self.assertTrue(cfunc(1, 6), pyfunc(1, 6)) - @tag('important') def test_loop3_int32(self): pyfunc = loop3 cres = compile_isolated(pyfunc, [types.int32] * 3) @@ -98,7 +95,6 @@ def test_loop3_int32(self): for args in arglist: self.assertEqual(cfunc(*args), pyfunc(*args)) - @tag('important') def test_range_len1(self): pyfunc = range_len1 typelist = [types.int16, types.int32, types.int64] @@ -109,7 +105,6 @@ def test_range_len1(self): for arg in arglist: self.assertEqual(cfunc(typ(arg)), pyfunc(typ(arg))) - @tag('important') def test_range_len2(self): pyfunc = range_len2 typelist = [types.int16, types.int32, types.int64] @@ -121,7 +116,6 @@ def test_range_len2(self): args_ = tuple(typ(x) for x in args) self.assertEqual(cfunc(*args_), pyfunc(*args_)) - @tag('important') def test_range_len3(self): pyfunc = range_len3 typelist = [types.int16, types.int32, types.int64] @@ -138,7 +132,6 @@ def test_range_len3(self): args_ = tuple(typ(x) for x in args) self.assertEqual(cfunc(*args_), pyfunc(*args_)) - @tag('important') def test_range_iter_len1(self): range_func = range_len1 range_iter_func = range_iter_len1 @@ -150,7 +143,6 @@ def test_range_iter_len1(self): for arg in arglist: self.assertEqual(cfunc(typ(arg)), range_func(typ(arg))) - @tag('important') def test_range_iter_list(self): range_iter_func = range_iter_len2 cres = compile_isolated(range_iter_func, [types.List(types.intp)]) @@ -158,7 +150,6 @@ def test_range_iter_list(self): arglist = [1, 2, 3, 4, 5] self.assertEqual(cfunc(arglist), len(arglist)) - @tag('important') def test_range_attrs(self): pyfunc = range_attrs arglist = [(0, 0, 1), @@ -173,7 +164,6 @@ def test_range_attrs(self): for arg in arglist: self.assertEqual(cfunc(*arg), pyfunc(*arg)) - @tag('important') def test_range_contains(self): pyfunc = range_contains arglist = [(0, 0, 1), diff --git a/numba/tests/test_recarray_usecases.py b/numba/tests/test_recarray_usecases.py index 0270c323992..8cf7792bb0a 100644 --- a/numba/tests/test_recarray_usecases.py +++ b/numba/tests/test_recarray_usecases.py @@ -67,7 +67,6 @@ def setUp(self): self.unaligned_dtype = np.dtype(fields) self.aligned_dtype = np.dtype(fields, align=True) - @tag('important') def test_usecase1(self): pyfunc = usecase1 diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 4bda27801df..7e326838135 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -432,7 +432,6 @@ def _test_get_equal(self, pyfunc): self.assertEqual(pyfunc(self.refsample1d, i), cfunc(self.nbsample1d, i)) - @tag('important') def test_get_a(self): self._test_get_equal(get_a) self._test_get_equal(get_a_subarray) @@ -499,7 +498,6 @@ def _test_set_equal(self, pyfunc, value, valuetype): # Match the entire array to ensure no memory corruption np.testing.assert_equal(expect, got) - @tag('important') def test_set_a(self): def check(pyfunc): self._test_set_equal(pyfunc, 3.1415, types.float64) @@ -520,7 +518,6 @@ def check(pyfunc): check(setitem_b) check(setitem_b_subarray) - @tag('important') def test_set_c(self): def check(pyfunc): self._test_set_equal(pyfunc, 43j, types.complex64) @@ -531,7 +528,6 @@ def check(pyfunc): check(setitem_c) check(setitem_c_subarray) - @tag('important') def test_set_record(self): pyfunc = set_record rec = numpy_support.from_dtype(recordtype) @@ -655,7 +651,6 @@ def test_record_write_array(self): expected[0].h[1] = 4.0 np.testing.assert_equal(expected, nbval) - @tag('important') def test_record_write_2d_array(self): ''' Test writing to a 2D array within a structured type @@ -687,7 +682,6 @@ def test_record_read_array(self): res = cfunc(nbval[0]) np.testing.assert_equal(res, nbval[0].h[1]) - @tag('important') def test_record_read_2d_array(self): ''' Test reading from a 2D array within a structured type @@ -708,7 +702,6 @@ def test_record_read_2d_array(self): res = cfunc(nbval[0]) np.testing.assert_equal(res, nbval[0].j[1, 0]) - @tag('important') def test_record_return(self): """ Testing scalar record value as return value. diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index c7db9781e1a..ac58d6d4263 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -18,14 +18,12 @@ def setUp(self): def check_fib(self, cfunc): self.assertPreciseEqual(cfunc(10), 55) - @tag('important') def test_global_explicit_sig(self): self.check_fib(self.mod.fib1) def test_inner_explicit_sig(self): self.check_fib(self.mod.fib2) - @tag('important') def test_global_implicit_sig(self): self.check_fib(self.mod.fib3) @@ -86,7 +84,6 @@ def test_runaway(self): self.assertIn("cannot type infer runaway recursion", str(raises.exception)) - @tag('important') def test_type_change(self): pfunc = self.mod.make_type_change_mutual() cfunc = self.mod.make_type_change_mutual(jit(nopython=True)) diff --git a/numba/tests/test_serialize.py b/numba/tests/test_serialize.py index 93958ec3ae6..01bf7207e0f 100644 --- a/numba/tests/test_serialize.py +++ b/numba/tests/test_serialize.py @@ -45,20 +45,17 @@ def check_result(func): new_func = pickle.loads(pickled) check_result(new_func) - @tag('important') def test_call_with_sig(self): self.run_with_protocols(self.check_call, add_with_sig, 5, (1, 4)) # Compilation has been disabled => float inputs will be coerced to int self.run_with_protocols(self.check_call, add_with_sig, 5, (1.2, 4.2)) - @tag('important') def test_call_without_sig(self): self.run_with_protocols(self.check_call, add_without_sig, 5, (1, 4)) self.run_with_protocols(self.check_call, add_without_sig, 5.5, (1.2, 4.3)) # Object mode is enabled self.run_with_protocols(self.check_call, add_without_sig, "abc", ("a", "bc")) - @tag('important') def test_call_nopython(self): self.run_with_protocols(self.check_call, add_nopython, 5.5, (1.2, 4.3)) # Object mode is disabled @@ -114,7 +111,6 @@ def test_call_generated(self): self.run_with_protocols(self.check_call, generated_add, 1j + 7, (1j, 2)) - @tag('important') def test_other_process(self): """ Check that reconstructing doesn't depend on resources already @@ -132,7 +128,6 @@ def test_other_process(self): """.format(**locals()) subprocess.check_call([sys.executable, "-c", code]) - @tag('important') def test_reuse(self): """ Check that deserializing the same function multiple times re-uses diff --git a/numba/tests/test_sets.py b/numba/tests/test_sets.py index bdb096f0666..ac250fa43b1 100644 --- a/numba/tests/test_sets.py +++ b/numba/tests/test_sets.py @@ -346,7 +346,6 @@ def test_build_heterogeneous_set(self, flags=enable_pyobj_flags): self.assertIs(type(got.pop()), type(expected.pop())) - @tag('important') def test_build_set_nopython(self): arg = list(self.sparse_array(50)) pyfunc = set_literal_convert_usecase(arg) @@ -373,7 +372,6 @@ def check(arg): check(self.duplicates_array(200)) check(self.sparse_array(200)) - @tag('important') def test_set_return(self): pyfunc = set_return_usecase cfunc = jit(nopython=True)(pyfunc) @@ -381,7 +379,6 @@ def test_set_return(self): arg = (1, 2, 3, 2, 7) self.assertEqual(cfunc(arg), set(arg)) - @tag('important') def test_iterator(self): pyfunc = iterator_usecase check = self.unordered_checker(pyfunc) @@ -390,7 +387,6 @@ def test_iterator(self): check(self.duplicates_array(200)) check(self.sparse_array(200)) - @tag('important') def test_update(self): pyfunc = update_usecase check = self.unordered_checker(pyfunc) @@ -429,7 +425,6 @@ def test_remove_error(self): with self.assertRaises(KeyError) as raises: cfunc((1, 2, 3), (5, )) - @tag('important') def test_discard(self): pyfunc = discard_usecase check = self.unordered_checker(pyfunc) @@ -452,7 +447,6 @@ def test_add_discard(self): check = self.unordered_checker(pyfunc) check((1,), 5, 5) - @tag('important') def test_pop(self): pyfunc = pop_usecase check = self.unordered_checker(pyfunc) @@ -460,7 +454,6 @@ def test_pop(self): check((2, 3, 55, 11, 8, 42)) check(self.sparse_array(50)) - @tag('important') def test_contains(self): pyfunc = contains_usecase cfunc = jit(nopython=True)(pyfunc) @@ -626,7 +619,6 @@ def test_iterator(self): check(self.duplicates_array(200)) check(self.sparse_array(200)) - @tag('important') def test_update(self): pyfunc = update_usecase check = self.unordered_checker(pyfunc) @@ -680,7 +672,6 @@ def check(arg): self.assertPreciseEqual(got, expected) return check - @tag('important') def test_numbers(self): check = self.check_unary(unbox_usecase) check(set([1, 2])) @@ -693,7 +684,6 @@ def test_tuples(self): check(set([(1, 2), (3, 4)])) check(set([(1, 2j), (3, 4j)])) - @tag('important') def test_set_inside_tuple(self): check = self.check_unary(unbox_usecase3) check((1, set([2, 3, 4]))) @@ -768,7 +758,6 @@ def test_reflect_exception(self): cfunc(s) self.assertPreciseEqual(s, set([1, 2, 3, 42])) - @tag('important') def test_reflect_same_set(self): """ When the same set object is reflected twice, behaviour should @@ -801,7 +790,6 @@ class TestExamples(BaseTest): Examples of using sets. """ - @tag('important') def test_unique(self): pyfunc = unique_usecase check = self.unordered_checker(pyfunc) diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index 909237ecb49..56bddf4f09e 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -172,7 +172,6 @@ def merge_init(self, keys): f = self.timsort.merge_init return f(keys) - @tag('important') def test_binarysort(self): n = 20 def check(l, n, start=0): @@ -258,7 +257,6 @@ def check(l, lo, hi): for i in range(len(l) - 1): check(l, i, n) - @tag('important') def test_gallop_left(self): n = 20 f = self.timsort.gallop_left @@ -647,7 +645,6 @@ def check(l, n): l = self.duprandom_list(n) check(l, n) - @tag('important') def test_run_quicksort(self): f = self.quicksort.run_quicksort @@ -781,7 +778,6 @@ def test_array_sort_int(self): for orig in self.int_arrays(): self.check_sort_inplace(pyfunc, cfunc, orig) - @tag('important') def test_array_sort_float(self): pyfunc = sort_usecase cfunc = jit(nopython=True)(pyfunc) @@ -826,7 +822,6 @@ def check(pyfunc, is_stable): check(argsort_kind_usecase, is_stable=False) check(np_argsort_kind_usecase, is_stable=False) - @tag('important') def test_argsort_float(self): def check(pyfunc): cfunc = jit(nopython=True)(pyfunc) @@ -836,7 +831,6 @@ def check(pyfunc): check(argsort_usecase) check(np_argsort_usecase) - @tag('important') def test_argsort_float(self): def check(pyfunc, is_stable): cfunc = jit(nopython=True)(pyfunc) @@ -852,7 +846,6 @@ def check(pyfunc, is_stable): class TestPythonSort(TestCase): - @tag('important') def test_list_sort(self): pyfunc = list_sort_usecase cfunc = jit(nopython=True)(pyfunc) diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index 3b35275ad27..0b702c8145b 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -139,7 +139,6 @@ def __init__(self, *args, **kwargs): super(TestStencil, self).__init__(*args, **kwargs) @skip_unsupported - @tag('important') def test_stencil1(self): """Tests whether the optional out argument to stencil calls works. """ @@ -168,7 +167,6 @@ def test_impl_seq(n): self.check(test_impl_seq, test_without_out, n) @skip_unsupported - @tag('important') def test_stencil2(self): """Tests whether the optional neighborhood argument to the stencil decorate works. @@ -254,7 +252,6 @@ def stencil2_kernel(a, w): self.assertIn('@do_scheduling', cpfunc.library.get_llvm_str()) @skip_unsupported - @tag('important') def test_stencil3(self): """Tests whether a non-zero optional cval argument to the stencil decorator works. Also tests integer result type. @@ -277,7 +274,6 @@ def test_seq(n): self.assertTrue(par_res[0, 0] == 1.0 and par_res[4, 4] == 1.0) @skip_unsupported - @tag('important') def test_stencil_standard_indexing_1d(self): """Tests standard indexing with a 1d array. """ @@ -300,7 +296,6 @@ def test_impl_seq(n): self.check(test_impl_seq, test_seq, n) @skip_unsupported - @tag('important') def test_stencil_standard_indexing_2d(self): """Tests standard indexing with a 2d array and multiple stencil calls. """ @@ -331,7 +326,6 @@ def test_impl_seq(n): self.check(test_impl_seq, test_seq, n) @skip_unsupported - @tag('important') def test_stencil_multiple_inputs(self): """Tests whether multiple inputs of the same size work. """ @@ -367,7 +361,6 @@ def test_seq(n): self.check(test_impl_seq, test_seq, n) @skip_unsupported - @tag('important') def test_stencil_call(self): """Tests 2D numba.stencil calls. """ @@ -401,7 +394,6 @@ def test_impl_seq(n): self.check(test_impl_seq, test_impl2, n) @skip_unsupported - @tag('important') def test_stencil_call_1D(self): """Tests 1D numba.stencil calls. """ @@ -422,7 +414,6 @@ def test_impl_seq(n): self.check(test_impl_seq, test_impl, n) @skip_unsupported - @tag('important') def test_stencil_call_const(self): """Tests numba.stencil call that has an index that can be inferred as constant from a unary expr. Otherwise, this would raise an error since @@ -503,7 +494,6 @@ def test_impl_seq(n): "'neighborhood' option required", str(e.exception)) @skip_unsupported - @tag('important') def test_stencil_parallel_off(self): """Tests 1D numba.stencil calls without parallel translation turned off. diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 87ef02a1505..6b4b43340fb 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -335,7 +335,6 @@ def test_scalar_context(self): self.check(math_sin_scalar, 7., std_pattern=pat) self.check(math_sin_scalar, 7., fast_pattern=pat) - @tag('important') def test_svml(self): # loops both with and without fastmath should use SVML. # The high accuracy routines are dropped if `fastmath` is set diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index 635b207acf4..6e24814c59f 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -141,7 +141,6 @@ def test_tuple_types_exception(self): class TestTupleReturn(TestCase): - @tag('important') def test_array_tuple(self): aryty = types.Array(types.float64, 1, 'C') cres = compile_isolated(tuple_return_usecase, (aryty, aryty)) @@ -160,7 +159,6 @@ def test_scalar_tuple(self): self.assertEqual(ra, a) self.assertEqual(rb, b) - @tag('important') def test_hetero_tuple(self): alltypes = [] allvalues = [] @@ -182,7 +180,6 @@ def test_hetero_tuple(self): class TestTuplePassing(TestCase): - @tag('important') def test_unituple(self): tuple_type = types.UniTuple(types.int32, 2) cr_first = compile_isolated(tuple_first, (tuple_type,)) @@ -190,7 +187,6 @@ def test_unituple(self): self.assertPreciseEqual(cr_first.entry_point((4, 5)), 4) self.assertPreciseEqual(cr_second.entry_point((4, 5)), 5) - @tag('important') def test_hetero_tuple(self): tuple_type = types.Tuple((types.int64, types.float32)) cr_first = compile_isolated(tuple_first, (tuple_type,)) @@ -210,7 +206,6 @@ def test_size_mismatch(self): class TestOperations(TestCase): - @tag('important') def test_len(self): pyfunc = len_usecase cr = compile_isolated(pyfunc, @@ -220,7 +215,6 @@ def test_len(self): [types.UniTuple(types.int64, 3)]) self.assertPreciseEqual(cr.entry_point((4, 5, 6)), 3) - @tag('important') def test_index(self): pyfunc = tuple_index cr = compile_isolated(pyfunc, @@ -313,7 +307,6 @@ def test_bool(self): [types.Tuple(())]) self.assertPreciseEqual(cr.entry_point(()), pyfunc(())) - @tag('important') def test_add(self): pyfunc = add_usecase samples = [(types.Tuple(()), ()), @@ -353,27 +346,21 @@ def eq(pyfunc, cfunc, args): ((4, 5), (4, 6, 7))]: eq(pyfunc, cfunc, args) - @tag('important') def test_eq(self): self._test_compare(eq_usecase) - @tag('important') def test_ne(self): self._test_compare(ne_usecase) - @tag('important') def test_gt(self): self._test_compare(gt_usecase) - @tag('important') def test_ge(self): self._test_compare(ge_usecase) - @tag('important') def test_lt(self): self._test_compare(lt_usecase) - @tag('important') def test_le(self): self._test_compare(le_usecase) @@ -448,11 +435,9 @@ def eq(pyfunc, cfunc, args): ((4, 5), (4, 6, 7))]: eq(pyfunc, cfunc, (Rect(*a), Point(*b))) - @tag('important') def test_eq(self): self._test_compare(eq_usecase) - @tag('important') def test_ne(self): self._test_compare(ne_usecase) @@ -468,7 +453,6 @@ def test_lt(self): def test_le(self): self._test_compare(le_usecase) - @tag('important') def test_getattr(self): pyfunc = getattr_usecase cfunc = jit(nopython=True)(pyfunc) @@ -477,7 +461,6 @@ def test_getattr(self): p = Point(*args) self.assertPreciseEqual(cfunc(p), pyfunc(p)) - @tag('important') def test_construct(self): def check(pyfunc): cfunc = jit(nopython=True)(pyfunc) diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index 96e6381e626..3b6ae2f0cc0 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -130,7 +130,6 @@ def assert_unify(self, aty, bty, expected): def assert_unify_failure(self, aty, bty): self.assert_unify(aty, bty, None) - @tag('important') def test_integer(self): ctx = typing.Context() for aty, bty in itertools.product(types.integer_domain, @@ -142,7 +141,6 @@ def test_integer(self): expected = self.int_unify[key[::-1]] self.assert_unify(aty, bty, getattr(types, expected)) - @tag('important') def test_bool(self): aty = types.boolean for bty in types.integer_domain: @@ -186,7 +184,6 @@ def test_none_to_optional(self): for res in results: self.assertEqual(res, expected) - @tag('important') def test_none(self): aty = types.none bty = types.none @@ -207,7 +204,6 @@ def test_optional(self): bty = types.Optional(types.slice3_type) self.assert_unify_failure(aty, bty) - @tag('important') def test_tuple(self): aty = types.UniTuple(i32, 3) bty = types.UniTuple(i64, 3) @@ -267,7 +263,6 @@ def test_optional_tuple(self): self.assert_unify(aty, bty, types.Tuple((types.Optional(i32), types.Optional(i64)))) - @tag('important') def test_arrays(self): aty = types.Array(i32, 3, "C") bty = types.Array(i32, 3, "A") @@ -290,7 +285,6 @@ def test_arrays(self): bty = types.Array(u32, 2, "C") self.assert_unify_failure(aty, bty) - @tag('important') def test_list(self): aty = types.List(types.undefined) bty = types.List(i32) @@ -323,7 +317,6 @@ def test_set(self): bty = types.Set(types.Tuple([i16])) self.assert_unify_failure(aty, bty) - @tag('important') def test_range(self): aty = types.range_state32_type bty = types.range_state64_type @@ -345,7 +338,6 @@ def assert_cannot_convert(self, aty, bty): got = ctx.can_convert(aty, bty) self.assertIsNone(got) - @tag('important') def test_convert_number_types(self): # Check that Context.can_convert() is compatible with the default # number conversion rules registered in the typeconv module @@ -353,7 +345,6 @@ def test_convert_number_types(self): ctx = typing.Context() self.check_number_compatibility(ctx.can_convert) - @tag('important') def test_tuple(self): # UniTuple -> UniTuple aty = types.UniTuple(i32, 3) @@ -387,7 +378,6 @@ def test_tuple(self): aty = types.UniTuple(i64, 2) bty = types.UniTuple(i64, 3) - @tag('important') def test_arrays(self): # Different layouts aty = types.Array(i32, 3, "C") @@ -512,7 +502,6 @@ def pyfunc(a): cres = compile_isolated(pyfunc, argtys) return (pyfunc, cres) - @tag('important') def test_complex_unify_issue599(self): pyfunc, cres = self._actually_test_complex_unify() arg = np.array([1.0j]) @@ -534,7 +523,6 @@ def test_complex_unify_issue599_multihash(self): subproc.wait() self.assertEqual(subproc.returncode, 0, 'Child process failed.') - @tag('important') def test_int_tuple_unify(self): """ Test issue #493 @@ -640,7 +628,6 @@ def issue_1394(a): class TestMiscIssues(TestCase): - @tag('important') def test_issue_797(self): """https://github.com/numba/numba/issues/797#issuecomment-58592401 @@ -650,7 +637,6 @@ def test_issue_797(self): g = np.zeros(shape=(10, 10), dtype=np.int32) foo(np.int32(0), np.int32(0), np.int32(1), np.int32(1), g) - @tag('important') def test_issue_1080(self): """https://github.com/numba/numba/issues/1080 @@ -659,7 +645,6 @@ def test_issue_1080(self): foo = jit(nopython=True)(issue_1080) foo(True, False) - @tag('important') def test_list_unify1(self): """ Exercise back-propagation of refined list type. @@ -670,7 +655,6 @@ def test_list_unify1(self): res = cfunc(n) self.assertPreciseEqual(res, pyfunc(n)) - @tag('important') def test_list_unify2(self): pyfunc = list_unify_usecase2 cfunc = jit(nopython=True)(pyfunc) @@ -679,7 +663,6 @@ def test_list_unify2(self): # converted values). self.assertEqual(res, pyfunc(3)) - @tag('important') def test_range_unify(self): pyfunc = range_unify_usecase cfunc = jit(nopython=True)(pyfunc) @@ -687,7 +670,6 @@ def test_range_unify(self): res = cfunc(v) self.assertPreciseEqual(res, pyfunc(v)) - @tag('important') def test_issue_1394(self): pyfunc = issue_1394 cfunc = jit(nopython=True)(pyfunc) diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 3010f9ea7e5..874788c6238 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -52,7 +52,6 @@ class TestTypeof(ValueTypingTestBase, TestCase): Test typeof() and, implicitly, typing.Context.get_argument_type(). """ - @tag('important') def test_number_values(self): """ Test special.typeof() with scalar number values. @@ -66,21 +65,18 @@ def test_number_values(self): self.assertEqual(typeof(2**63 - 1), types.int64) self.assertEqual(typeof(-2**63), types.int64) - @tag('important') def test_datetime_values(self): """ Test special.typeof() with np.timedelta64 values. """ self.check_datetime_values(typeof) - @tag('important') def test_timedelta_values(self): """ Test special.typeof() with np.timedelta64 values. """ self.check_timedelta_values(typeof) - @tag('important') def test_array_values(self): """ Test special.typeof() with ndarray values. @@ -112,7 +108,6 @@ def check(arr, ndim, layout, mutable, aligned): self.assertIn("Unsupported array dtype: %s" % (a5.dtype,), str(raises.exception)) - @tag('important') def test_structured_arrays(self): def check(arr, dtype, ndim, layout, aligned): ty = typeof(arr) @@ -156,12 +151,10 @@ def test_buffers(self): self.assertEqual(ty, types.ByteArray(types.uint8, 1, "C")) self.assertTrue(ty.mutable) - @tag('important') def test_none(self): ty = typeof(None) self.assertEqual(ty, types.none) - @tag('important') def test_ellipsis(self): ty = typeof(Ellipsis) self.assertEqual(ty, types.ellipsis) @@ -170,7 +163,6 @@ def test_str(self): ty = typeof("abc") self.assertEqual(ty, types.string) - @tag('important') def test_slices(self): for args in [(1,), (1, 2), (1, 2, 1), (1, 2, None)]: v = slice(*args) @@ -179,7 +171,6 @@ def test_slices(self): v = slice(*args) self.assertIs(typeof(v), types.slice3_type) - @tag('important') def test_tuples(self): v = (1, 2) self.assertEqual(typeof(v), types.UniTuple(types.intp, 2)) @@ -189,12 +180,10 @@ def test_tuples(self): types.Tuple((types.float64, types.intp)))) ) - @tag('important') def test_lists(self): v = [1.0] * 100 self.assertEqual(typeof(v), types.List(types.float64, reflected=True)) - @tag('important') def test_sets(self): v = set([1.0, 2.0, 3.0]) self.assertEqual(typeof(v), types.Set(types.float64, reflected=True)) @@ -202,7 +191,6 @@ def test_sets(self): with self.assertRaises(ValueError): typeof(v) - @tag('important') def test_namedtuple(self): v = Point(1, 2) tp_point = typeof(v) @@ -218,7 +206,6 @@ def test_namedtuple(self): self.assertNotEqual(tp_rect, tp_point) self.assertNotEqual(tp_rect, types.UniTuple(tp_rect.dtype, tp_rect.count)) - @tag('important') def test_enum(self): tp_red = typeof(Color.red) self.assertEqual(tp_red, types.EnumMember(Color, types.intp)) @@ -236,7 +223,6 @@ def test_enum(self): self.assertEqual(str(raises.exception), "Cannot type heterogeneous enum: got value types complex128, float64") - @tag('important') def test_enum_class(self): tp_color = typeof(Color) self.assertEqual(tp_color, types.EnumClass(Color, types.intp)) @@ -255,7 +241,6 @@ def test_enum_class(self): self.assertEqual(str(raises.exception), "Cannot type heterogeneous enum: got value types complex128, float64") - @tag('important') def test_dtype(self): dtype = np.dtype('int64') self.assertEqual(typeof(dtype), types.DType(types.int64)) @@ -264,14 +249,12 @@ def test_dtype(self): rec_ty = numpy_support.from_struct_dtype(dtype) self.assertEqual(typeof(dtype), types.DType(rec_ty)) - @tag('important') def test_dtype_values(self): self.assertEqual(typeof(np.int64), types.NumberClass(types.int64)) self.assertEqual(typeof(np.float64), types.NumberClass(types.float64)) self.assertEqual(typeof(np.int32), types.NumberClass(types.int32)) self.assertEqual(typeof(np.int8), types.NumberClass(types.int8)) - @tag('important') def test_ctypes(self): ty_cos = typeof(c_cos) ty_sin = typeof(c_sin) @@ -282,7 +265,6 @@ def test_ctypes(self): self.assertNotEqual(ty_cos.get_pointer(c_cos), ty_sin.get_pointer(c_sin)) - @tag('important') @unittest.skipUnless(cffi_support.SUPPORTED, "CFFI not supported") def test_cffi(self): from . import cffi_usecases as mod diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 2c713444dac..4dfdf6baff0 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -46,7 +46,6 @@ class Dummy(object): class TestTypes(TestCase): - @tag('important') def test_equality(self): self.assertEqual(types.int32, types.int32) self.assertEqual(types.uint32, types.uint32) @@ -138,7 +137,6 @@ def test_weaktype(self): self.assertTrue(b != c) self.assertTrue(a != z) - @tag('important') def test_interning(self): # Test interning and lifetime of dynamic types. a = types.Dummy('xyzzyx') @@ -174,7 +172,6 @@ def test_cache_trimming(self): gc.collect() self.assertEqual(len(cache), cache_len) - @tag('important') def test_array_notation(self): def check(arrty, scalar, ndim, layout): self.assertIs(arrty.dtype, scalar) @@ -200,7 +197,6 @@ def check(arrty, scalar, ndim, layout): check(dtyped[:, ::1], scalar, 2, 'C') check(dtyped[::1, :], scalar, 2, 'F') - @tag('important') def test_call_notation(self): # Function call signature i = types.int32 diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index daa5b665db4..c57107b06e3 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -316,19 +316,15 @@ def binary_int_ufunc_test(self, name=None, flags=no_pyobj_flags): ############################################################################ # Math operations - @tag('important') def test_add_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.add, flags=flags) - @tag('important') def test_subtract_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.subtract, flags=flags) - @tag('important') def test_multiply_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.multiply, flags=flags) - @tag('important') def test_divide_ufunc(self, flags=no_pyobj_flags): # Bear in mind that in python3 divide IS true_divide # so the out type for int types will be a double @@ -343,15 +339,12 @@ def test_logaddexp_ufunc(self): def test_logaddexp2_ufunc(self): self.binary_ufunc_test(np.logaddexp2, kinds='f') - @tag('important') def test_true_divide_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.true_divide, flags=flags, int_output_type=types.float64) - @tag('important') def test_floor_divide_ufunc(self): self.binary_ufunc_test(np.floor_divide) - @tag('important') def test_negative_ufunc(self, flags=no_pyobj_flags): # NumPy ufunc has bug with uint32 as input and int64 as output, # so skip uint32 input. @@ -359,7 +352,6 @@ def test_negative_ufunc(self, flags=no_pyobj_flags): skip_inputs=[types.Array(types.uint32, 1, 'C'), types.uint32], flags=flags) - @tag('important') def test_power_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.power, flags=flags, positive_only=True) @@ -370,22 +362,18 @@ def test_gcd_ufunc(self, flags=no_pyobj_flags): def test_lcm_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.lcm, flags=flags, kinds="iu") - @tag('important') def test_remainder_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.remainder, flags=flags) - @tag('important') def test_mod_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.mod, flags=flags, kinds='ifcu', additional_inputs = [ ((np.uint64(np.iinfo(np.uint64).max), np.uint64(16)), types.uint64) ]) - @tag('important') def test_fmod_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.fmod, flags=flags) - @tag('important') def test_abs_ufunc(self, flags=no_pyobj_flags, ufunc=np.abs): self.unary_ufunc_test(ufunc, flags=flags, additional_inputs = [ @@ -395,63 +383,48 @@ def test_abs_ufunc(self, flags=no_pyobj_flags, ufunc=np.abs): (np.float64(np.finfo(np.float64).min), types.float64) ]) - @tag('important') def test_absolute_ufunc(self, flags=no_pyobj_flags): self.test_abs_ufunc(flags=flags, ufunc=np.absolute) - @tag('important') def test_fabs_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.fabs, flags=flags, kinds='f') - @tag('important') def test_rint_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.rint, flags=flags, kinds='cf') - @tag('important') def test_sign_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.sign, flags=flags) - @tag('important') def test_conj_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.conj, flags=flags) - @tag('important') def test_exp_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.exp, flags=flags, kinds='cf') - @tag('important') def test_exp2_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.exp2, flags=flags, kinds='cf') - @tag('important') def test_log_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.log, flags=flags, kinds='cf') - @tag('important') def test_log2_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.log2, flags=flags, kinds='cf') - @tag('important') def test_log10_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.log10, flags=flags, kinds='cf') - @tag('important') def test_expm1_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.expm1, flags=flags, kinds='cf') - @tag('important') def test_log1p_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.log1p, flags=flags, kinds='cf') - @tag('important') def test_sqrt_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.sqrt, flags=flags, kinds='cf') - @tag('important') def test_square_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.square, flags=flags) - @tag('important') def test_reciprocal_ufunc(self, flags=no_pyobj_flags): # reciprocal for integers doesn't make much sense and is problematic # in the case of division by zero, as an inf will overflow float to @@ -462,7 +435,6 @@ def test_reciprocal_ufunc(self, flags=no_pyobj_flags): types.Array(types.int64, 1, 'C'), types.int64] self.unary_ufunc_test(np.reciprocal, skip_inputs=to_skip, flags=flags) - @tag('important') def test_conjugate_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.conjugate, flags=flags) @@ -470,15 +442,12 @@ def test_conjugate_ufunc(self, flags=no_pyobj_flags): ############################################################################ # Trigonometric Functions - @tag('important') def test_sin_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.sin, flags=flags, kinds='cf') - @tag('important') def test_cos_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.cos, flags=flags, kinds='cf') - @tag('important') def test_tan_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.tan, flags=flags, kinds='cf') @@ -497,15 +466,12 @@ def test_arctan2_ufunc(self, flags=no_pyobj_flags): def test_hypot_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.hypot, kinds='f') - @tag('important') def test_sinh_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.sinh, flags=flags, kinds='cf') - @tag('important') def test_cosh_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.cosh, flags=flags, kinds='cf') - @tag('important') def test_tanh_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.tanh, flags=flags, kinds='cf') @@ -574,27 +540,21 @@ def test_bitwise_not_ufunc(self, flags=no_pyobj_flags): ############################################################################ # Comparison functions - @tag('important') def test_greater_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.greater, flags=flags) - @tag('important') def test_greater_equal_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.greater_equal, flags=flags) - @tag('important') def test_less_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.less, flags=flags) - @tag('important') def test_less_equal_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.less_equal, flags=flags) - @tag('important') def test_not_equal_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.not_equal, flags=flags) - @tag('important') def test_equal_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.equal, flags=flags) @@ -610,11 +570,9 @@ def test_logical_xor_ufunc(self, flags=no_pyobj_flags): def test_logical_not_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.logical_not, flags=flags) - @tag('important') def test_maximum_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.maximum, flags=flags) - @tag('important') def test_minimum_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.minimum, flags=flags) @@ -634,32 +592,27 @@ def bool_additional_inputs(self): types.Array(types.bool_, 1, 'C')), ] - @tag('important') def test_isfinite_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test( np.isfinite, flags=flags, kinds='ifcb', additional_inputs=self.bool_additional_inputs(), ) - @tag('important') def test_isinf_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test( np.isinf, flags=flags, kinds='ifcb', additional_inputs=self.bool_additional_inputs(), ) - @tag('important') def test_isnan_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test( np.isnan, flags=flags, kinds='ifcb', additional_inputs=self.bool_additional_inputs(), ) - @tag('important') def test_signbit_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.signbit, flags=flags) - @tag('important') def test_copysign_ufunc(self, flags=no_pyobj_flags): self.binary_ufunc_test(np.copysign, flags=flags, kinds='f') @@ -678,15 +631,12 @@ def test_modf_ufunc(self, flags=no_pyobj_flags): def test_frexp_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.frexp, flags=flags, kinds='f') - @tag('important') def test_floor_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.floor, flags=flags, kinds='f') - @tag('important') def test_ceil_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.ceil, flags=flags, kinds='f') - @tag('important') def test_trunc_ufunc(self, flags=no_pyobj_flags): self.unary_ufunc_test(np.trunc, flags=flags, kinds='f') @@ -769,7 +719,6 @@ def binary_ufunc_mixed_types_test(self, ufunc, flags=no_pyobj_flags): else 'double') self.assertPreciseEqual(expected, result, prec=prec) - @tag('important') def test_broadcasting(self): # Test unary ufunc @@ -1090,7 +1039,6 @@ def inplace_bitwise_op_test(self, operator, lhs_values, rhs_values): def test_unary_positive_array_op(self): self.unary_op_test('+') - @tag('important') def test_unary_negative_array_op(self): self.unary_op_test('-') @@ -1104,17 +1052,14 @@ def test_unary_invert_array_op(self): # ____________________________________________________________ # Inplace operators - @tag('important') def test_inplace_add(self): self.inplace_float_op_test('+=', [-1, 1.5, 3], [-5, 0, 2.5]) self.inplace_float_op_test(operator.iadd, [-1, 1.5, 3], [-5, 0, 2.5]) - @tag('important') def test_inplace_sub(self): self.inplace_float_op_test('-=', [-1, 1.5, 3], [-5, 0, 2.5]) self.inplace_float_op_test(operator.isub, [-1, 1.5, 3], [-5, 0, 2.5]) - @tag('important') def test_inplace_mul(self): self.inplace_float_op_test('*=', [-1, 1.5, 3], [-5, 0, 2.5]) self.inplace_float_op_test(operator.imul, [-1, 1.5, 3], [-5, 0, 2.5]) @@ -1131,7 +1076,6 @@ def test_inplace_remainder(self): self.inplace_float_op_test('%=', [-1, 1.5, 3], [-5, 2, 2.5]) self.inplace_float_op_test(operator.imod, [-1, 1.5, 3], [-5, 2, 2.5]) - @tag('important') def test_inplace_pow(self): self.inplace_float_op_test('**=', [-1, 1.5, 3], [-5, 2, 2.5]) self.inplace_float_op_test(operator.ipow, [-1, 1.5, 3], [-5, 2, 2.5]) @@ -1148,7 +1092,6 @@ def test_inplace_xor(self): self.inplace_bitwise_op_test('^=', [0, 1, 2, 3, 51], [0, 13, 16, 42, 255]) self.inplace_bitwise_op_test(operator.ixor, [0, 1, 2, 3, 51], [0, 13, 16, 42, 255]) - @tag('important') def test_inplace_lshift(self): self.inplace_int_op_test('<<=', [0, 5, -10, -51], [0, 1, 4, 14]) self.inplace_int_op_test(operator.ilshift, [0, 5, -10, -51], [0, 1, 4, 14]) @@ -1182,25 +1125,20 @@ def f(a1): # ____________________________________________________________ # Binary operators - @tag('important') def test_add_array_op(self): self.binary_op_test('+') - @tag('important') def test_subtract_array_op(self): self.binary_op_test('-') - @tag('important') def test_multiply_array_op(self): self.binary_op_test('*') - @tag('important') def test_divide_array_op(self): int_out_type = None int_out_type = types.float64 self.binary_op_test('/', int_output_type=int_out_type) - @tag('important') def test_floor_divide_array_op(self): # Avoid floating-point zeros as x // 0.0 can have varying results # depending on the algorithm (which changed across Numpy versions) @@ -1227,55 +1165,42 @@ def test_floor_divide_array_op(self): ] self.binary_op_test('//') - @tag('important') def test_remainder_array_op(self): self.binary_op_test('%') - @tag('important') def test_power_array_op(self): self.binary_op_test('**', positive_rhs=True) - @tag('important') def test_left_shift_array_op(self): self.binary_int_op_test('<<', positive_rhs=True) - @tag('important') def test_right_shift_array_op(self): self.binary_int_op_test('>>', positive_rhs=True) - @tag('important') def test_bitwise_and_array_op(self): self.binary_bitwise_op_test('&') - @tag('important') def test_bitwise_or_array_op(self): self.binary_bitwise_op_test('|') - @tag('important') def test_bitwise_xor_array_op(self): self.binary_bitwise_op_test('^') - @tag('important') def test_equal_array_op(self): self.binary_op_test('==') - @tag('important') def test_greater_array_op(self): self.binary_op_test('>') - @tag('important') def test_greater_equal_array_op(self): self.binary_op_test('>=') - @tag('important') def test_less_array_op(self): self.binary_op_test('<') - @tag('important') def test_less_equal_array_op(self): self.binary_op_test('<=') - @tag('important') def test_not_equal_array_op(self): self.binary_op_test('!=') diff --git a/numba/tests/test_unpack_sequence.py b/numba/tests/test_unpack_sequence.py index dbe360213b8..d1a5bfcd2d8 100644 --- a/numba/tests/test_unpack_sequence.py +++ b/numba/tests/test_unpack_sequence.py @@ -121,21 +121,18 @@ def test_unpack_shape(self, flags=force_pyobj_flags): a = np.zeros(shape=(1, 2, 3)).astype(np.int32) self.assertPreciseEqual(cfunc(a), pyfunc(a)) - @tag('important') def test_unpack_shape_npm(self): self.test_unpack_shape(flags=no_pyobj_flags) def test_unpack_range(self, flags=force_pyobj_flags): self.run_nullary_func(unpack_range, flags) - @tag('important') def test_unpack_range_npm(self): self.test_unpack_range(flags=no_pyobj_flags) def test_unpack_tuple(self, flags=force_pyobj_flags): self.run_nullary_func(unpack_tuple, flags) - @tag('important') def test_unpack_tuple_npm(self): self.test_unpack_tuple(flags=no_pyobj_flags) @@ -148,7 +145,6 @@ def test_unpack_heterogeneous_tuple_npm(self): def test_unpack_nested_heterogeneous_tuple(self, flags=force_pyobj_flags): self.run_nullary_func(unpack_nested_heterogeneous_tuple, flags) - @tag('important') def test_unpack_nested_heterogeneous_tuple_npm(self): self.test_unpack_nested_heterogeneous_tuple(flags=no_pyobj_flags) @@ -211,7 +207,6 @@ def check_conditional_swap(self, flags=force_pyobj_flags): def test_conditional_swap(self): self.check_conditional_swap() - @tag('important') def test_conditional_swap_npm(self): self.check_conditional_swap(no_pyobj_flags) diff --git a/numba/tests/test_usecases.py b/numba/tests/test_usecases.py index 7217e543fa5..dcef9b11df5 100644 --- a/numba/tests/test_usecases.py +++ b/numba/tests/test_usecases.py @@ -16,7 +16,6 @@ class TestUsecases(TestCase): - @tag('important') def test_andor(self): pyfunc = usecases.andor cr = compile_isolated(pyfunc, (types.int32, types.int32)) @@ -29,7 +28,6 @@ def test_andor(self): for args in itertools.product(xs, ys): self.assertEqual(pyfunc(*args), cfunc(*args), "args %s" % (args,)) - @tag('important') def test_sum1d(self): pyfunc = usecases.sum1d cr = compile_isolated(pyfunc, (types.int32, types.int32)) @@ -64,7 +62,6 @@ def bm_numba(): print(utils.benchmark(bm_python, maxsec=.1)) print(utils.benchmark(bm_numba, maxsec=.1)) - @tag('important') def test_sum2d(self): pyfunc = usecases.sum2d cr = compile_isolated(pyfunc, (types.int32, types.int32)) @@ -76,7 +73,6 @@ def test_sum2d(self): for args in itertools.product(ss, es): self.assertEqual(pyfunc(*args), cfunc(*args), args) - @tag('important') def test_while_count(self): pyfunc = usecases.while_count cr = compile_isolated(pyfunc, (types.int32, types.int32)) @@ -104,7 +100,6 @@ def test_copy_arrays(self): cfunc(*args) self.assertPreciseEqual(a, b, msg=str(args)) - @tag('important') def test_copy_arrays2d(self): pyfunc = usecases.copy_arrays2d arraytype = types.Array(types.int32, 2, 'A') From efbe44770b2008ba6c1260beb8f30bcba881b56d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 15:19:37 +0000 Subject: [PATCH 263/595] Remove @tag('important') 2 --- numba/tests/npyufunc/test_ufunc.py | 2 +- numba/tests/test_api.py | 2 +- numba/tests/test_closure.py | 2 +- numba/tests/test_debuginfo.py | 2 +- numba/tests/test_dispatcher.py | 2 +- numba/tests/test_exceptions.py | 1 - numba/tests/test_flow_control.py | 2 +- numba/tests/test_generators.py | 2 +- numba/tests/test_jitclasses.py | 2 +- numba/tests/test_numpy_support.py | 2 +- numba/tests/test_record_dtype.py | 1 - numba/tests/test_recursion.py | 2 +- numba/tests/test_types.py | 2 +- 13 files changed, 11 insertions(+), 13 deletions(-) diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index d76c1962c45..b6d97747020 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -4,7 +4,7 @@ from numba import float32, jit from numba.npyufunc import Vectorize from numba.errors import TypingError -from ..support import tag, TestCase +from ..support import TestCase dtype = np.float32 diff --git a/numba/tests/test_api.py b/numba/tests/test_api.py index 52e413c0163..19fcd16d484 100644 --- a/numba/tests/test_api.py +++ b/numba/tests/test_api.py @@ -1,7 +1,7 @@ import numba from numba import unittest_support as unittest -from .support import TestCase, tag +from .support import TestCase class TestNumbaModule(TestCase): diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 4353d10e0d4..cc64157dfb9 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -5,7 +5,7 @@ import numba.unittest_support as unittest from numba import njit, jit, testing from numba.errors import TypingError, UnsupportedError -from .support import TestCase, tag +from .support import TestCase class TestClosure(TestCase): diff --git a/numba/tests/test_debuginfo.py b/numba/tests/test_debuginfo.py index cf891d9373d..5c3eed17774 100644 --- a/numba/tests/test_debuginfo.py +++ b/numba/tests/test_debuginfo.py @@ -1,6 +1,6 @@ import re -from .support import TestCase, override_config, tag +from .support import TestCase, override_config from numba import unittest_support as unittest from numba import jit, types diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 8d4b4ac5268..43fd9093693 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -30,7 +30,7 @@ from numba import _dispatcher from numba.compiler import compile_isolated from numba.errors import NumbaWarning -from .support import (TestCase, tag, temp_directory, import_dynamic, +from .support import (TestCase, temp_directory, import_dynamic, override_env_config, capture_cache_log, captured_stdout) from numba.numpy_support import as_dtype from numba.targets import codegen diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index fc4966b2e48..6e386dacbc1 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -5,7 +5,6 @@ from numba.compiler import compile_isolated, Flags from numba import jit, types, errors, njit from numba import unittest_support as unittest -from .support import TestCase, tag force_pyobj_flags = Flags() force_pyobj_flags.set("force_pyobject") diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index 19b9bfcaa00..e90c3003342 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -5,7 +5,7 @@ from numba.compiler import compile_isolated, Flags from numba import types from numba.bytecode import FunctionIdentity, ByteCode -from .support import TestCase, tag +from .support import TestCase enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index f3e2dc497c0..564199a6755 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -4,7 +4,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import jit, njit, types -from .support import TestCase, MemoryLeakMixin, tag +from .support import TestCase, MemoryLeakMixin from numba import testing from numba.datamodel.testing import test_factory diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index ca993d2a274..584ec654a6b 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -10,7 +10,7 @@ from numba import njit, typeof, types, errors from numba import unittest_support as unittest from numba import jitclass -from .support import TestCase, MemoryLeakMixin, tag +from .support import TestCase, MemoryLeakMixin from numba.jitclass import _box from numba.runtime.nrt import MemInfo from numba.errors import LoweringError diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index a4ac585f315..0150deb3680 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -10,7 +10,7 @@ import numba.unittest_support as unittest from numba import numpy_support, types -from .support import TestCase, tag +from .support import TestCase from .enum_usecases import Shake, RequestError diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 7e326838135..d628fd72e72 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -8,7 +8,6 @@ from numba.itanium_mangler import mangle_type from numba.config import IS_WIN32 from numba.numpy_support import numpy_version -from .support import tag def get_a(ary, i): diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index ac58d6d4263..ada4b913788 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -4,7 +4,7 @@ from numba import jit from numba import unittest_support as unittest from numba.errors import TypingError, NumbaWarning -from .support import TestCase, tag +from .support import TestCase class TestSelfRecursion(TestCase): diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 4dfdf6baff0..65fa9edc881 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -27,7 +27,7 @@ from numba import jit, njit, numpy_support, typeof from numba.extending import (overload, register_model, models, unbox, NativeValue, typeof_impl) -from .support import TestCase, tag, temp_directory +from .support import TestCase, temp_directory from .enum_usecases import Color, Shake, Shape From 901b5b59b77cdba8647669e7818f163b29754da0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 15:23:08 +0000 Subject: [PATCH 264/595] flake8 --- numba/targets/arraymath.py | 15 +++++++++------ numba/targets/arrayobj.py | 3 +++ numba/tests/test_exceptions.py | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 20236045910..7bcec33b689 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -770,6 +770,7 @@ def nanmean_impl(a): return nanmean_impl + @overload(np.nanvar) def np_nanvar(a): if not isinstance(a, types.Array): @@ -794,6 +795,7 @@ def nanvar_impl(a): return nanvar_impl + @overload(np.nanstd) def np_nanstd(a): if not isinstance(a, types.Array): @@ -873,6 +875,7 @@ def nancumprod_impl(a): return nancumprod_impl + @overload(np.nancumsum) def np_nancumsum(a): if not isinstance(a, types.Array): @@ -1631,7 +1634,7 @@ def np_ediff1d_impl(ary, to_end=None, to_begin=None): if len(mid) > 0: out = np.empty((len(start) + len(mid) + len(end) - 1), - dtype=out_dtype) + dtype=out_dtype) start_idx = len(start) mid_idx = len(start) + len(mid) - 1 out[:start_idx] = start @@ -2574,19 +2577,18 @@ def np_cov(m, y=None, rowvar=True, bias=False, ddof=None): def np_cov_impl(m, y=None, rowvar=True, bias=False, ddof=None): X = _prepare_cov_input(m, y, rowvar, dtype, ddof, _DDOF_HANDLER, - _M_DIM_HANDLER).astype(dtype) + _M_DIM_HANDLER).astype(dtype) if np.any(np.array(X.shape) == 0): - return np.full((X.shape[0], X.shape[0]), - fill_value=np.nan, - dtype=dtype) + return np.full((X.shape[0], X.shape[0]), fill_value=np.nan, + dtype=dtype) else: return np_cov_impl_inner(X, bias, ddof) def np_cov_impl_single_variable(m, y=None, rowvar=True, bias=False, ddof=None): X = _prepare_cov_input(m, y, rowvar, ddof, dtype, _DDOF_HANDLER, - _M_DIM_HANDLER).astype(dtype) + _M_DIM_HANDLER).astype(dtype) if np.any(np.array(X.shape) == 0): variance = np.nan @@ -2600,6 +2602,7 @@ def np_cov_impl_single_variable(m, y=None, rowvar=True, bias=False, else: return np_cov_impl + @overload(np.corrcoef) def np_corrcoef(x, y=None, rowvar=True): diff --git a/numba/targets/arrayobj.py b/numba/targets/arrayobj.py index 7213f936c04..c1dc5555732 100644 --- a/numba/targets/arrayobj.py +++ b/numba/targets/arrayobj.py @@ -3527,6 +3527,7 @@ def full(shape, value): res = context.compile_internal(builder, full, sig, args) return impl_ret_new_ref(context, builder, sig.return_type, res) + @lower_builtin(np.full, types.Any, types.Any, types.DTypeSpec) def numpy_full_dtype_nd(context, builder, sig, args): @@ -3539,6 +3540,7 @@ def full(shape, value, dtype): res = context.compile_internal(builder, full, sig, args) return impl_ret_new_ref(context, builder, sig.return_type, res) + @lower_builtin(np.full_like, types.Any, types.Any) def numpy_full_like_nd(context, builder, sig, args): @@ -3551,6 +3553,7 @@ def full_like(arr, value): res = context.compile_internal(builder, full_like, sig, args) return impl_ret_new_ref(context, builder, sig.return_type, res) + @lower_builtin(np.full_like, types.Any, types.Any, types.DTypeSpec) def numpy_full_like_nd_type_spec(context, builder, sig, args): diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index 6e386dacbc1..f8e80925ce6 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -5,6 +5,7 @@ from numba.compiler import compile_isolated, Flags from numba import jit, types, errors, njit from numba import unittest_support as unittest +from .support import TestCase force_pyobj_flags = Flags() force_pyobj_flags.set("force_pyobject") From 6b5ced5f3e1b0713fe08727719512f7aec870684 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 15:32:38 +0000 Subject: [PATCH 265/595] Remove dead functions --- numba/targets/npyfuncs.py | 281 -------------------------------------- 1 file changed, 281 deletions(-) diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index e84dab199c3..38d0de2baef 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -830,44 +830,6 @@ def np_real_tan_impl(context, builder, sig, args): return mathimpl.tan_impl(context, builder, sig, args) -def np_complex_tan_impl(context, builder, sig, args): - # npymath does not provide complex tan functions. The code - # in funcs.inc.src for tan is translated here... - _check_arity_and_homogeneity(sig, args, 1) - - ty = sig.args[0] - float_ty = ty.underlying_float - float_unary_sig = typing.signature(*[float_ty]*2) - ONE = context.get_constant(float_ty, 1.0) - x = context.make_complex(builder, ty, args[0]) - out = context.make_complex(builder, ty) - - xr = x.real - xi = x.imag - sr = np_real_sin_impl(context, builder, float_unary_sig, [xr]) - cr = np_real_cos_impl(context, builder, float_unary_sig, [xr]) - shi = np_real_sinh_impl(context, builder, float_unary_sig, [xi]) - chi = np_real_cosh_impl(context, builder, float_unary_sig, [xi]) - rs = builder.fmul(sr, chi) - is_ = builder.fmul(cr, shi) - rc = builder.fmul(cr, chi) - ic = builder.fmul(sr, shi) # note: opposite sign from code in funcs.inc.src - sqr_rc = builder.fmul(rc, rc) - sqr_ic = builder.fmul(ic, ic) - d = builder.fadd(sqr_rc, sqr_ic) - inv_d = builder.fdiv(ONE, d) - rs_rc = builder.fmul(rs, rc) - is_ic = builder.fmul(is_, ic) - is_rc = builder.fmul(is_, rc) - rs_ic = builder.fmul(rs, ic) - numr = builder.fsub(rs_rc, is_ic) - numi = builder.fadd(is_rc, rs_ic) - out.real = builder.fmul(numr, inv_d) - out.imag = builder.fmul(numi, inv_d) - - return out._getvalue() - - ######################################################################## # NumPy asin @@ -876,89 +838,6 @@ def np_real_asin_impl(context, builder, sig, args): return mathimpl.asin_impl(context, builder, sig, args) -def _complex_expand_series(context, builder, ty, initial, x, coefs): - """this is used to implement approximations using series that are - quite common in NumPy's source code to improve precision when the - magnitude of the arguments is small. In funcs.inc.src this is - implemented by repeated use of the macro "SERIES_HORNER_TERM - """ - assert ty in types.complex_domain - binary_sig = typing.signature(*[ty]*3) - accum = context.make_complex(builder, ty, value=initial) - ONE = context.get_constant(ty.underlying_float, 1.0) - for coef in reversed(coefs): - constant = context.get_constant(ty.underlying_float, coef) - value = numbers.complex_mul_impl(context, builder, binary_sig, - [x, accum._getvalue()]) - accum._setvalue(value) - accum.real = builder.fadd(ONE, builder.fmul(accum.real, constant)) - accum.imag = builder.fmul(accum.imag, constant) - - return accum._getvalue() - - -def np_complex_asin_impl(context, builder, sig, args): - # npymath does not provide a complex asin. The code in funcs.inc.src - # is translated here... - _check_arity_and_homogeneity(sig, args, 1) - - ty = sig.args[0] - float_ty = ty.underlying_float - epsilon = context.get_constant(float_ty, 1e-3) - - # if real or imag has magnitude over 1e-3... - x = context.make_complex(builder, ty, value=args[0]) - out = context.make_complex(builder, ty) - abs_r = _fabs(context, builder, x.real) - abs_i = _fabs(context, builder, x.imag) - abs_r_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_r, epsilon) - abs_i_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_i, epsilon) - any_gt_epsilon = builder.or_(abs_r_gt_epsilon, abs_i_gt_epsilon) - complex_binary_sig = typing.signature(*[ty]*3) - with builder.if_else(any_gt_epsilon) as (then, otherwise): - with then: - # ... then use formula: - # - j * log(j * x + sqrt(1 - sqr(x))) - I = context.get_constant_generic(builder, ty, 1.0j) - ONE = context.get_constant_generic(builder, ty, 1.0 + 0.0j) - ZERO = context.get_constant_generic(builder, ty, 0.0 + 0.0j) - xx = np_complex_square_impl(context, builder, sig, args) - one_minus_xx = numbers.complex_sub_impl(context, builder, - complex_binary_sig, - [ONE, xx]) - sqrt_one_minus_xx = np_complex_sqrt_impl(context, builder, sig, - [one_minus_xx]) - ix = numbers.complex_mul_impl(context, builder, - complex_binary_sig, - [I, args[0]]) - log_arg = numbers.complex_add_impl(context, builder, sig, - [ix, sqrt_one_minus_xx]) - log = np_complex_log_impl(context, builder, sig, [log_arg]) - ilog = numbers.complex_mul_impl(context, builder, - complex_binary_sig, - [I, log]) - out._setvalue(numbers.complex_sub_impl(context, builder, - complex_binary_sig, - [ZERO, ilog])) - with otherwise: - # ... else use series expansion (to avoid loss of precision) - coef_dict = { - types.complex64: [1.0/6.0, 9.0/20.0], - types.complex128: [1.0/6.0, 9.0/20.0, 25.0/42.0], - # types.complex256: [1.0/6.0, 9.0/20.0, 25.0/42.0, 49.0/72.0, 81.0/110.0] - } - - xx = np_complex_square_impl(context, builder, sig, args) - ONE = context.get_constant_generic(builder, ty, 1.0 + 0.0j) - tmp = _complex_expand_series(context, builder, ty, - ONE, xx, coef_dict[ty]) - out._setvalue(numbers.complex_mul_impl(context, builder, - complex_binary_sig, - [args[0], tmp])) - - return out._getvalue() - - ######################################################################## # NumPy acos @@ -975,60 +854,6 @@ def np_real_atan_impl(context, builder, sig, args): return mathimpl.atan_impl(context, builder, sig, args) -def np_complex_atan_impl(context, builder, sig, args): - # npymath does not provide a complex atan. The code in funcs.inc.src - # is translated here... - _check_arity_and_homogeneity(sig, args, 1) - - ty = sig.args[0] - float_ty = ty.underlying_float - epsilon = context.get_constant(float_ty, 1e-3) - - # if real or imag has magnitude over 1e-3... - x = context.make_complex(builder, ty, value=args[0]) - out = context.make_complex(builder, ty) - abs_r = _fabs(context, builder, x.real) - abs_i = _fabs(context, builder, x.imag) - abs_r_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_r, epsilon) - abs_i_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_i, epsilon) - any_gt_epsilon = builder.or_(abs_r_gt_epsilon, abs_i_gt_epsilon) - binary_sig = typing.signature(*[ty]*3) - with builder.if_else(any_gt_epsilon) as (then, otherwise): - with then: - # ... then use formula - # 0.5j * log((j + x)/(j - x)) - I = context.get_constant_generic(builder, ty, 0.0 + 1.0j) - I2 = context.get_constant_generic(builder, ty, 0.0 + 0.5j) - den = numbers.complex_sub_impl(context, builder, binary_sig, - [I, args[0]]) - num = numbers.complex_add_impl(context, builder, binary_sig, - [I, args[0]]) - div = np_complex_div_impl(context, builder, binary_sig, - [num, den]) - log = np_complex_log_impl(context, builder, sig, [div]) - res = numbers.complex_mul_impl(context, builder, binary_sig, - [I2, log]) - - out._setvalue(res) - with otherwise: - # else use series expansion (to avoid loss of precision) - coef_dict = { - types.complex64: [-1.0/3.0, -3.0/5.0], - types.complex128: [-1.0/3.0, -3.0/5.0, -5.0/7.0], - # types.complex256: [-1.0/3.0, -3.0/5.0, -5.0/7.0, -7.0/9.0, -9.0/11.0] - } - - xx = np_complex_square_impl(context, builder, sig, args) - ONE = context.get_constant_generic(builder, ty, 1.0 + 0.0j) - tmp = _complex_expand_series(context, builder, ty, - ONE, xx, coef_dict[ty]) - out._setvalue(numbers.complex_mul_impl(context, builder, - binary_sig, - [args[0], tmp])) - - return out._getvalue() - - ######################################################################## # NumPy atan2 @@ -1164,57 +989,6 @@ def np_real_asinh_impl(context, builder, sig, args): return mathimpl.asinh_impl(context, builder, sig, args) -def np_complex_asinh_impl(context, builder, sig, args): - # npymath does not provide a complex atan. The code in funcs.inc.src - # is translated here... - _check_arity_and_homogeneity(sig, args, 1) - - ty = sig.args[0] - float_ty = ty.underlying_float - epsilon = context.get_constant(float_ty, 1e-3) - - # if real or imag has magnitude over 1e-3... - x = context.make_complex(builder, ty, value=args[0]) - out = context.make_complex(builder, ty) - abs_r = _fabs(context, builder, x.real) - abs_i = _fabs(context, builder, x.imag) - abs_r_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_r, epsilon) - abs_i_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_i, epsilon) - any_gt_epsilon = builder.or_(abs_r_gt_epsilon, abs_i_gt_epsilon) - binary_sig = typing.signature(*[ty]*3) - with builder.if_else(any_gt_epsilon) as (then, otherwise): - with then: - # ... then use formula - # log(sqrt(1+sqr(x)) + x) - ONE = context.get_constant_generic(builder, ty, 1.0 + 0.0j) - xx = np_complex_square_impl(context, builder, sig, args) - one_plus_xx = numbers.complex_add_impl(context, builder, - binary_sig, [ONE, xx]) - sqrt_res = np_complex_sqrt_impl(context, builder, sig, - [one_plus_xx]) - log_arg = numbers.complex_add_impl(context, builder, - binary_sig, [sqrt_res, args[0]]) - res = np_complex_log_impl(context, builder, sig, [log_arg]) - out._setvalue(res) - with otherwise: - # else use series expansion (to avoid loss of precision) - coef_dict = { - types.complex64: [-1.0/6.0, -9.0/20.0], - types.complex128: [-1.0/6.0, -9.0/20.0, -25.0/42.0], - # types.complex256: [-1.0/6.0, -9.0/20.0, -25.0/42.0, -49.0/72.0, -81.0/110.0] - } - - xx = np_complex_square_impl(context, builder, sig, args) - ONE = context.get_constant_generic(builder, ty, 1.0 + 0.0j) - tmp = _complex_expand_series(context, builder, ty, - ONE, xx, coef_dict[ty]) - out._setvalue(numbers.complex_mul_impl(context, builder, - binary_sig, - [args[0], tmp])) - - return out._getvalue() - - ######################################################################## # NumPy acosh @@ -1258,61 +1032,6 @@ def np_real_atanh_impl(context, builder, sig, args): return mathimpl.atanh_impl(context, builder, sig, args) -def np_complex_atanh_impl(context, builder, sig, args): - # npymath does not provide a complex atanh. The code in funcs.inc.src - # is translated here... - _check_arity_and_homogeneity(sig, args, 1) - - ty = sig.args[0] - float_ty = ty.underlying_float - epsilon = context.get_constant(float_ty, 1e-3) - - # if real or imag has magnitude over 1e-3... - x = context.make_complex(builder, ty, value=args[0]) - out = context.make_complex(builder, ty) - abs_r = _fabs(context, builder, x.real) - abs_i = _fabs(context, builder, x.imag) - abs_r_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_r, epsilon) - abs_i_gt_epsilon = builder.fcmp(lc.FCMP_OGT, abs_i, epsilon) - any_gt_epsilon = builder.or_(abs_r_gt_epsilon, abs_i_gt_epsilon) - binary_sig = typing.signature(*[ty]*3) - with builder.if_else(any_gt_epsilon) as (then, otherwise): - with then: - # ... then use formula - # 0.5 * log((1 + x)/(1 - x)) - ONE = context.get_constant_generic(builder, ty, 1.0 + 0.0j) - HALF = context.get_constant_generic(builder, ty, 0.5 + 0.0j) - den = numbers.complex_sub_impl(context, builder, binary_sig, - [ONE, args[0]]) - num = numbers.complex_add_impl(context, builder, binary_sig, - [ONE, args[0]]) - div = np_complex_div_impl(context, builder, binary_sig, - [num, den]) - log = np_complex_log_impl(context, builder, sig, [div]) - res = numbers.complex_mul_impl(context, builder, binary_sig, - [HALF, log]) - - out._setvalue(res) - with otherwise: - # else use series expansion (to avoid loss of precision) - coef_dict = { - types.complex64: [1.0/3.0, 3.0/5.0], - types.complex128: [1.0/3.0, 3.0/5.0, 5.0/7.0], - # types.complex256: [1.0/3.0, 3.0/5.0, 5.0/7.0, 7.0/9.0, 9.0/11.0] - } - - xx = np_complex_square_impl(context, builder, sig, args) - ONE = context.get_constant_generic(builder, ty, 1.0 + 0.0j) - tmp = _complex_expand_series(context, builder, ty, - ONE, xx, coef_dict[ty]) - out._setvalue(numbers.complex_mul_impl(context, builder, - binary_sig, - [args[0], tmp])) - - return out._getvalue() - - - ######################################################################## # NumPy floor From a5d98b345494549697d6da4ee342a364aa2c0a2e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 16:26:41 +0000 Subject: [PATCH 266/595] Remove custom maths functions --- numba/_helperlib.c | 4 +- numba/_math_c99.c | 781 ------------------------------------ numba/_math_c99.h | 89 ---- numba/mathnames.h | 1 - numba/pycc/cc.py | 2 +- numba/targets/intrinsics.py | 1 - setup.py | 2 - 7 files changed, 2 insertions(+), 878 deletions(-) delete mode 100644 numba/_math_c99.c delete mode 100644 numba/_math_c99.h diff --git a/numba/_helperlib.c b/numba/_helperlib.c index ba00b705b44..ad698cdf5b2 100644 --- a/numba/_helperlib.c +++ b/numba/_helperlib.c @@ -8,7 +8,6 @@ #include #include #include -#include "_math_c99.h" #ifdef _MSC_VER #define int64_t signed __int64 #define uint64_t unsigned __int64 @@ -134,8 +133,7 @@ numba_cpowf(npy_cfloat *a, npy_cfloat *b, npy_cfloat *out) { *out = npy_cpackf((float) _out.real, (float) _out.imag); } -/* C99 math functions: redirect to system implementations - (but see _math_c99.h for Windows) */ +/* C99 math functions: redirect to system implementations */ NUMBA_EXPORT_FUNC(double) numba_gamma(double x) diff --git a/numba/_math_c99.c b/numba/_math_c99.c deleted file mode 100644 index 8988446ddaf..00000000000 --- a/numba/_math_c99.c +++ /dev/null @@ -1,781 +0,0 @@ -#include "Python.h" -#include -#include "_math_c99.h" - - -/* Copied from Python Module/_math.c with modification to symbol name */ - - -/* The following copyright notice applies to the original - implementations of acosh, asinh and atanh. */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -static const double ln2 = 6.93147180559945286227E-01; -static const double two_pow_m28 = 3.7252902984619141E-09; /* 2**-28 */ -static const double two_pow_p28 = 268435456.0; /* 2**28 */ -#ifndef Py_NAN -static const double zero = 0.0; // used only if no NaN is available -#endif - -/* acosh(x) - * Method : - * Based on - * acosh(x) = log [ x + sqrt(x*x-1) ] - * we have - * acosh(x) := log(x)+ln2, if x is large; else - * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else - * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1. - * - * Special cases: - * acosh(x) is NaN with signal if x<1. - * acosh(NaN) is NaN without signal. - */ - -double -m_acosh(double x) -{ - if (Py_IS_NAN(x)) { - return x+x; - } - if (x < 1.) { /* x < 1; return a signaling NaN */ - errno = EDOM; -#ifdef Py_NAN - return Py_NAN; -#else - return (x-x)/(x-x); -#endif - } - else if (x >= two_pow_p28) { /* x > 2**28 */ - if (Py_IS_INFINITY(x)) { - return x+x; - } - else { - return log(x)+ln2; /* acosh(huge)=log(2x) */ - } - } - else if (x == 1.) { - return 0.0; /* acosh(1) = 0 */ - } - else if (x > 2.) { /* 2 < x < 2**28 */ - double t = x*x; - return log(2.0*x - 1.0 / (x + sqrt(t - 1.0))); - } - else { /* 1 < x <= 2 */ - double t = x - 1.0; - return m_log1p(t + sqrt(2.0*t + t*t)); - } -} - - -/* asinh(x) - * Method : - * Based on - * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] - * we have - * asinh(x) := x if 1+x*x=1, - * := sign(x)*(log(x)+ln2)) for large |x|, else - * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else - * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) - */ - -double -m_asinh(double x) -{ - double w; - double absx = fabs(x); - - if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) { - return x+x; - } - if (absx < two_pow_m28) { /* |x| < 2**-28 */ - return x; /* return x inexact except 0 */ - } - if (absx > two_pow_p28) { /* |x| > 2**28 */ - w = log(absx)+ln2; - } - else if (absx > 2.0) { /* 2 < |x| < 2**28 */ - w = log(2.0*absx + 1.0 / (sqrt(x*x + 1.0) + absx)); - } - else { /* 2**-28 <= |x| < 2= */ - double t = x*x; - w = m_log1p(absx + t / (1.0 + sqrt(1.0 + t))); - } - return copysign(w, x); - -} - -/* atanh(x) - * Method : - * 1.Reduced x to positive by atanh(-x) = -atanh(x) - * 2.For x>=0.5 - * 1 2x x - * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * -------) - * 2 1 - x 1 - x - * - * For x<0.5 - * atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) - * - * Special cases: - * atanh(x) is NaN if |x| >= 1 with signal; - * atanh(NaN) is that NaN with no signal; - * - */ - -double -m_atanh(double x) -{ - double absx; - double t; - - if (Py_IS_NAN(x)) { - return x+x; - } - absx = fabs(x); - if (absx >= 1.) { /* |x| >= 1 */ - errno = EDOM; -#ifdef Py_NAN - return Py_NAN; -#else - return x/zero; -#endif - } - if (absx < two_pow_m28) { /* |x| < 2**-28 */ - return x; - } - if (absx < 0.5) { /* |x| < 0.5 */ - t = absx+absx; - t = 0.5 * m_log1p(t + t*absx / (1.0 - absx)); - } - else { /* 0.5 <= |x| <= 1.0 */ - t = 0.5 * m_log1p((absx + absx) / (1.0 - absx)); - } - return copysign(t, x); -} - -/* Mathematically, expm1(x) = exp(x) - 1. The expm1 function is designed - to avoid the significant loss of precision that arises from direct - evaluation of the expression exp(x) - 1, for x near 0. */ - -double -m_expm1(double x) -{ - /* For abs(x) >= log(2), it's safe to evaluate exp(x) - 1 directly; this - also works fine for infinities and nans. - - For smaller x, we can use a method due to Kahan that achieves close to - full accuracy. - */ - - if (fabs(x) < 0.7) { - double u; - u = exp(x); - if (u == 1.0) - return x; - else - return (u - 1.0) * x / log(u); - } - else - return exp(x) - 1.0; -} - -/* log1p(x) = log(1+x). The log1p function is designed to avoid the - significant loss of precision that arises from direct evaluation when x is - small. */ - -double -m_log1p(double x) -{ - /* For x small, we use the following approach. Let y be the nearest float - to 1+x, then - - 1+x = y * (1 - (y-1-x)/y) - - so log(1+x) = log(y) + log(1-(y-1-x)/y). Since (y-1-x)/y is tiny, the - second term is well approximated by (y-1-x)/y. If abs(x) >= - DBL_EPSILON/2 or the rounding-mode is some form of round-to-nearest - then y-1-x will be exactly representable, and is computed exactly by - (y-1)-x. - - If abs(x) < DBL_EPSILON/2 and the rounding mode is not known to be - round-to-nearest then this method is slightly dangerous: 1+x could be - rounded up to 1+DBL_EPSILON instead of down to 1, and in that case - y-1-x will not be exactly representable any more and the result can be - off by many ulps. But this is easily fixed: for a floating-point - number |x| < DBL_EPSILON/2., the closest floating-point number to - log(1+x) is exactly x. - */ - - double y; - if (fabs(x) < DBL_EPSILON/2.) { - return x; - } - else if (-0.5 <= x && x <= 1.) { - /* WARNING: it's possible than an overeager compiler - will incorrectly optimize the following two lines - to the equivalent of "return log(1.+x)". If this - happens, then results from log1p will be inaccurate - for small x. */ - y = 1.+x; - return log(y)-((y-1.)-x)/y; - } - else { - /* NaNs and infinities should end up here */ - return log(1.+x); - } -} - -/* Hand written */ -double m_trunc(double x) -{ - double integral; - (void)modf(x, &integral); - return integral; -} - - -/* Hand written */ -double m_round(double x) { - if (x < 0.0) { - return ceil(x - 0.5); - } else { - return floor(x + 0.5); - } -} - -/* Hand written */ -float m_roundf(float x) { - if (x < 0.0) { - return (float) ceilf(x - 0.5f); - } else { - return (float) floorf(x + 0.5f); - } -} - -/* - CPython implementation for atan2(): - - wrapper for atan2 that deals directly with special cases before - delegating to the platform libm for the remaining cases. This - is necessary to get consistent behaviour across platforms. - Windows, FreeBSD and alpha Tru64 are amongst platforms that don't - always follow C99. -*/ - -double m_atan2(double y, double x) -{ - if (Py_IS_NAN(x) || Py_IS_NAN(y)) - return Py_NAN; - if (Py_IS_INFINITY(y)) { - if (Py_IS_INFINITY(x)) { - if (copysign(1., x) == 1.) - /* atan2(+-inf, +inf) == +-pi/4 */ - return copysign(0.25*Py_MATH_PI, y); - else - /* atan2(+-inf, -inf) == +-pi*3/4 */ - return copysign(0.75*Py_MATH_PI, y); - } - /* atan2(+-inf, x) == +-pi/2 for finite x */ - return copysign(0.5*Py_MATH_PI, y); - } - if (Py_IS_INFINITY(x) || y == 0.) { - if (copysign(1., x) == 1.) - /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */ - return copysign(0., y); - else - /* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */ - return copysign(Py_MATH_PI, y); - } - return atan2(y, x); -} - -/* Map to double version directly */ -float m_atan2f(float y, float x) { - return (float) m_atan2(y, x); -} - - -/* provide gamma() and lgamma(); code borrowed from CPython */ - -/* - sin(pi*x), giving accurate results for all finite x (especially x - integral or close to an integer). This is here for use in the - reflection formula for the gamma function. It conforms to IEEE - 754-2008 for finite arguments, but not for infinities or nans. -*/ - -static const double pi = 3.141592653589793238462643383279502884197; -static const double sqrtpi = 1.772453850905516027298167483341145182798; -static const double logpi = 1.144729885849400174143427351353058711647; - -static double -sinpi(double x) -{ - double y, r; - int n; - /* this function should only ever be called for finite arguments */ - assert(Py_IS_FINITE(x)); - y = fmod(fabs(x), 2.0); - n = (int)round(2.0*y); - assert(0 <= n && n <= 4); - switch (n) { - case 0: - r = sin(pi*y); - break; - case 1: - r = cos(pi*(y-0.5)); - break; - case 2: - /* N.B. -sin(pi*(y-1.0)) is *not* equivalent: it would give - -0.0 instead of 0.0 when y == 1.0. */ - r = sin(pi*(1.0-y)); - break; - case 3: - r = -cos(pi*(y-1.5)); - break; - case 4: - r = sin(pi*(y-2.0)); - break; - default: - assert(0); /* should never get here */ - r = -1.23e200; /* silence gcc warning */ - } - return copysign(1.0, x)*r; -} - -/* Implementation of the real gamma function. In extensive but non-exhaustive - random tests, this function proved accurate to within <= 10 ulps across the - entire float domain. Note that accuracy may depend on the quality of the - system math functions, the pow function in particular. Special cases - follow C99 annex F. The parameters and method are tailored to platforms - whose double format is the IEEE 754 binary64 format. - - Method: for x > 0.0 we use the Lanczos approximation with parameters N=13 - and g=6.024680040776729583740234375; these parameters are amongst those - used by the Boost library. Following Boost (again), we re-express the - Lanczos sum as a rational function, and compute it that way. The - coefficients below were computed independently using MPFR, and have been - double-checked against the coefficients in the Boost source code. - - For x < 0.0 we use the reflection formula. - - There's one minor tweak that deserves explanation: Lanczos' formula for - Gamma(x) involves computing pow(x+g-0.5, x-0.5) / exp(x+g-0.5). For many x - values, x+g-0.5 can be represented exactly. However, in cases where it - can't be represented exactly the small error in x+g-0.5 can be magnified - significantly by the pow and exp calls, especially for large x. A cheap - correction is to multiply by (1 + e*g/(x+g-0.5)), where e is the error - involved in the computation of x+g-0.5 (that is, e = computed value of - x+g-0.5 - exact value of x+g-0.5). Here's the proof: - - Correction factor - ----------------- - Write x+g-0.5 = y-e, where y is exactly representable as an IEEE 754 - double, and e is tiny. Then: - - pow(x+g-0.5,x-0.5)/exp(x+g-0.5) = pow(y-e, x-0.5)/exp(y-e) - = pow(y, x-0.5)/exp(y) * C, - - where the correction_factor C is given by - - C = pow(1-e/y, x-0.5) * exp(e) - - Since e is tiny, pow(1-e/y, x-0.5) ~ 1-(x-0.5)*e/y, and exp(x) ~ 1+e, so: - - C ~ (1-(x-0.5)*e/y) * (1+e) ~ 1 + e*(y-(x-0.5))/y - - But y-(x-0.5) = g+e, and g+e ~ g. So we get C ~ 1 + e*g/y, and - - pow(x+g-0.5,x-0.5)/exp(x+g-0.5) ~ pow(y, x-0.5)/exp(y) * (1 + e*g/y), - - Note that for accuracy, when computing r*C it's better to do - - r + e*g/y*r; - - than - - r * (1 + e*g/y); - - since the addition in the latter throws away most of the bits of - information in e*g/y. -*/ - -#define LANCZOS_N 13 -static const double lanczos_g = 6.024680040776729583740234375; -static const double lanczos_g_minus_half = 5.524680040776729583740234375; -static const double lanczos_num_coeffs[LANCZOS_N] = { - 23531376880.410759688572007674451636754734846804940, - 42919803642.649098768957899047001988850926355848959, - 35711959237.355668049440185451547166705960488635843, - 17921034426.037209699919755754458931112671403265390, - 6039542586.3520280050642916443072979210699388420708, - 1439720407.3117216736632230727949123939715485786772, - 248874557.86205415651146038641322942321632125127801, - 31426415.585400194380614231628318205362874684987640, - 2876370.6289353724412254090516208496135991145378768, - 186056.26539522349504029498971604569928220784236328, - 8071.6720023658162106380029022722506138218516325024, - 210.82427775157934587250973392071336271166969580291, - 2.5066282746310002701649081771338373386264310793408 -}; - -/* denominator is x*(x+1)*...*(x+LANCZOS_N-2) */ -static const double lanczos_den_coeffs[LANCZOS_N] = { - 0.0, 39916800.0, 120543840.0, 150917976.0, 105258076.0, 45995730.0, - 13339535.0, 2637558.0, 357423.0, 32670.0, 1925.0, 66.0, 1.0}; - -/* gamma values for small positive integers, 1 though NGAMMA_INTEGRAL */ -#define NGAMMA_INTEGRAL 23 -static const double gamma_integral[NGAMMA_INTEGRAL] = { - 1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0, 362880.0, - 3628800.0, 39916800.0, 479001600.0, 6227020800.0, 87178291200.0, - 1307674368000.0, 20922789888000.0, 355687428096000.0, - 6402373705728000.0, 121645100408832000.0, 2432902008176640000.0, - 51090942171709440000.0, 1124000727777607680000.0, -}; - -/* Lanczos' sum L_g(x), for positive x */ - -static double -lanczos_sum(double x) -{ - double num = 0.0, den = 0.0; - int i; - assert(x > 0.0); - /* evaluate the rational function lanczos_sum(x). For large - x, the obvious algorithm risks overflow, so we instead - rescale the denominator and numerator of the rational - function by x**(1-LANCZOS_N) and treat this as a - rational function in 1/x. This also reduces the error for - larger x values. The choice of cutoff point (5.0 below) is - somewhat arbitrary; in tests, smaller cutoff values than - this resulted in lower accuracy. */ - if (x < 5.0) { - for (i = LANCZOS_N; --i >= 0; ) { - num = num * x + lanczos_num_coeffs[i]; - den = den * x + lanczos_den_coeffs[i]; - } - } - else { - for (i = 0; i < LANCZOS_N; i++) { - num = num / x + lanczos_num_coeffs[i]; - den = den / x + lanczos_den_coeffs[i]; - } - } - return num/den; -} - -double -m_gamma(double x) -{ - double absx, r, y, z, sqrtpow; - - /* special cases */ - if (!Py_IS_FINITE(x)) { - if (Py_IS_NAN(x) || x > 0.0) - return x; /* tgamma(nan) = nan, tgamma(inf) = inf */ - else { - /*errno = EDOM;*/ - return Py_NAN; /* tgamma(-inf) = nan, invalid */ - } - } - if (x == 0.0) { - /*errno = EDOM;*/ - /* tgamma(+-0.0) = +-inf, divide-by-zero */ - return copysign(Py_HUGE_VAL, x); - } - - /* integer arguments */ - if (x == floor(x)) { - if (x < 0.0) { - /*errno = EDOM;*/ /* tgamma(n) = nan, invalid for */ - return Py_NAN; /* negative integers n */ - } - if (x <= NGAMMA_INTEGRAL) - return gamma_integral[(int)x - 1]; - } - absx = fabs(x); - - /* tiny arguments: tgamma(x) ~ 1/x for x near 0 */ - if (absx < 1e-20) { - r = 1.0/x; - /*if (Py_IS_INFINITY(r)) - errno = ERANGE;*/ - return r; - } - - /* large arguments: assuming IEEE 754 doubles, tgamma(x) overflows for - x > 200, and underflows to +-0.0 for x < -200, not a negative - integer. */ - if (absx > 200.0) { - if (x < 0.0) { - return 0.0/sinpi(x); - } - else { - /*errno = ERANGE;*/ - return Py_HUGE_VAL; - } - } - - y = absx + lanczos_g_minus_half; - /* compute error in sum */ - if (absx > lanczos_g_minus_half) { - /* note: the correction can be foiled by an optimizing - compiler that (incorrectly) thinks that an expression like - a + b - a - b can be optimized to 0.0. This shouldn't - happen in a standards-conforming compiler. */ - double q = y - absx; - z = q - lanczos_g_minus_half; - } - else { - double q = y - lanczos_g_minus_half; - z = q - absx; - } - z = z * lanczos_g / y; - if (x < 0.0) { - r = -pi / sinpi(absx) / absx * exp(y) / lanczos_sum(absx); - r -= z * r; - if (absx < 140.0) { - r /= pow(y, absx - 0.5); - } - else { - sqrtpow = pow(y, absx / 2.0 - 0.25); - r /= sqrtpow; - r /= sqrtpow; - } - } - else { - r = lanczos_sum(absx) / exp(y); - r += z * r; - if (absx < 140.0) { - r *= pow(y, absx - 0.5); - } - else { - sqrtpow = pow(y, absx / 2.0 - 0.25); - r *= sqrtpow; - r *= sqrtpow; - } - } - /*if (Py_IS_INFINITY(r)) - errno = ERANGE;*/ - return r; -} - -/* - lgamma: natural log of the absolute value of the Gamma function. - For large arguments, Lanczos' formula works extremely well here. -*/ - -double -m_lgamma(double x) -{ - double r, absx; - - /* special cases */ - if (!Py_IS_FINITE(x)) { - if (Py_IS_NAN(x)) - return x; /* lgamma(nan) = nan */ - else - return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */ - } - - /* integer arguments */ - if (x == floor(x) && x <= 2.0) { - if (x <= 0.0) { - /*errno = EDOM;*/ /* lgamma(n) = inf, divide-by-zero for */ - return Py_HUGE_VAL; /* integers n <= 0 */ - } - else { - return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */ - } - } - - absx = fabs(x); - /* tiny arguments: lgamma(x) ~ -log(fabs(x)) for small x */ - if (absx < 1e-20) - return -log(absx); - - /* Lanczos' formula. We could save a fraction of a ulp in accuracy by - having a second set of numerator coefficients for lanczos_sum that - absorbed the exp(-lanczos_g) term, and throwing out the lanczos_g - subtraction below; it's probably not worth it. */ - r = log(lanczos_sum(absx)) - lanczos_g; - r += (absx - 0.5) * (log(absx + lanczos_g - 0.5) - 1); - if (x < 0.0) - /* Use reflection formula to get value for negative x. */ - r = logpi - log(fabs(sinpi(absx))) - log(absx) - r; - /*if (Py_IS_INFINITY(r)) - errno = ERANGE;*/ - return r; -} - -/* provide erf() and erfc(); code borrowed from CPython */ - -/* - Implementations of the error function erf(x) and the complementary error - function erfc(x). - - Method: following 'Numerical Recipes' by Flannery, Press et. al. (2nd ed., - Cambridge University Press), we use a series approximation for erf for - small x, and a continued fraction approximation for erfc(x) for larger x; - combined with the relations erf(-x) = -erf(x) and erfc(x) = 1.0 - erf(x), - this gives us erf(x) and erfc(x) for all x. - - The series expansion used is: - - erf(x) = x*exp(-x*x)/sqrt(pi) * [ - 2/1 + 4/3 x**2 + 8/15 x**4 + 16/105 x**6 + ...] - - The coefficient of x**(2k-2) here is 4**k*factorial(k)/factorial(2*k). - This series converges well for smallish x, but slowly for larger x. - - The continued fraction expansion used is: - - erfc(x) = x*exp(-x*x)/sqrt(pi) * [1/(0.5 + x**2 -) 0.5/(2.5 + x**2 - ) - 3.0/(4.5 + x**2 - ) 7.5/(6.5 + x**2 - ) ...] - - after the first term, the general term has the form: - - k*(k-0.5)/(2*k+0.5 + x**2 - ...). - - This expansion converges fast for larger x, but convergence becomes - infinitely slow as x approaches 0.0. The (somewhat naive) continued - fraction evaluation algorithm used below also risks overflow for large x; - but for large x, erfc(x) == 0.0 to within machine precision. (For - example, erfc(30.0) is approximately 2.56e-393). - - Parameters: use series expansion for abs(x) < ERF_SERIES_CUTOFF and - continued fraction expansion for ERF_SERIES_CUTOFF <= abs(x) < - ERFC_CONTFRAC_CUTOFF. ERFC_SERIES_TERMS and ERFC_CONTFRAC_TERMS are the - numbers of terms to use for the relevant expansions. */ - -#define ERF_SERIES_CUTOFF 1.5 -#define ERF_SERIES_TERMS 25 -#define ERFC_CONTFRAC_CUTOFF 30.0 -#define ERFC_CONTFRAC_TERMS 50 - -/* - Error function, via power series. - - Given a finite float x, return an approximation to erf(x). - Converges reasonably fast for small x. -*/ - -static double -m_erf_series(double x) -{ - double x2, acc, fk, result; - int i, saved_errno; - - x2 = x * x; - acc = 0.0; - fk = (double)ERF_SERIES_TERMS + 0.5; - for (i = 0; i < ERF_SERIES_TERMS; i++) { - acc = 2.0 + x2 * acc / fk; - fk -= 1.0; - } - /* Make sure the exp call doesn't affect errno; - see m_erfc_contfrac for more. */ - saved_errno = errno; - result = acc * x * exp(-x2) / sqrtpi; - errno = saved_errno; - return result; -} - -/* - Complementary error function, via continued fraction expansion. - - Given a positive float x, return an approximation to erfc(x). Converges - reasonably fast for x large (say, x > 2.0), and should be safe from - overflow if x and nterms are not too large. On an IEEE 754 machine, with x - <= 30.0, we're safe up to nterms = 100. For x >= 30.0, erfc(x) is smaller - than the smallest representable nonzero float. */ - -static double -m_erfc_contfrac(double x) -{ - double x2, a, da, p, p_last, q, q_last, b, result; - int i, saved_errno; - - if (x >= ERFC_CONTFRAC_CUTOFF) - return 0.0; - - x2 = x*x; - a = 0.0; - da = 0.5; - p = 1.0; p_last = 0.0; - q = da + x2; q_last = 1.0; - for (i = 0; i < ERFC_CONTFRAC_TERMS; i++) { - double temp; - a += da; - da += 2.0; - b = da + x2; - temp = p; p = b*p - a*p_last; p_last = temp; - temp = q; q = b*q - a*q_last; q_last = temp; - } - /* Issue #8986: On some platforms, exp sets errno on underflow to zero; - save the current errno value so that we can restore it later. */ - saved_errno = errno; - result = p / q * x * exp(-x2) / sqrtpi; - errno = saved_errno; - return result; -} - -/* Error function erf(x), for general x */ - -double -m_erf(double x) -{ - double absx, cf; - - if (Py_IS_NAN(x)) - return x; - absx = fabs(x); - if (absx < ERF_SERIES_CUTOFF) - return m_erf_series(x); - else { - cf = m_erfc_contfrac(absx); - return x > 0.0 ? 1.0 - cf : cf - 1.0; - } -} - -/* Complementary error function erfc(x), for general x. */ - -double -m_erfc(double x) -{ - double absx, cf; - - if (Py_IS_NAN(x)) - return x; - absx = fabs(x); - if (absx < ERF_SERIES_CUTOFF) - return 1.0 - m_erf_series(x); - else { - cf = m_erfc_contfrac(absx); - return x > 0.0 ? cf : 2.0 - cf; - } -} - -#define FLOATVER(Fn) float Fn##f(float x) { return (float)Fn(x); } - -FLOATVER(m_acosh); -FLOATVER(m_asinh); -FLOATVER(m_atanh); -FLOATVER(m_erf); -FLOATVER(m_erfc); -FLOATVER(m_expm1); -FLOATVER(m_gamma); -FLOATVER(m_lgamma); -FLOATVER(m_log1p); -FLOATVER(m_trunc); - diff --git a/numba/_math_c99.h b/numba/_math_c99.h deleted file mode 100644 index 9ea7dd9b001..00000000000 --- a/numba/_math_c99.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef NUMBA_MATH_C99_H_ -#define NUMBA_MATH_C99_H_ - -#include "_numba_common.h" - -/* We require C99 on POSIX */ - -#if !defined(_MSC_VER) || _MSC_VER >= 1800 /* Visual Studio 2013 */ -#define HAVE_C99_MATH 1 -#else -#define HAVE_C99_MATH 0 -#endif - - -VISIBILITY_HIDDEN double m_acosh(double x); -VISIBILITY_HIDDEN float m_acoshf(float x); - -VISIBILITY_HIDDEN double m_asinh(double x); -VISIBILITY_HIDDEN float m_asinhf(float x); - -VISIBILITY_HIDDEN double m_atanh(double x); -VISIBILITY_HIDDEN float m_atanhf(float x); - -VISIBILITY_HIDDEN double m_erf(double x); -VISIBILITY_HIDDEN float m_erff(float x); - -VISIBILITY_HIDDEN double m_erfc(double x); -VISIBILITY_HIDDEN float m_erfcf(float x); - -VISIBILITY_HIDDEN double m_expm1(double x); -VISIBILITY_HIDDEN float m_expm1f(float x); - -VISIBILITY_HIDDEN double m_gamma(double x); -VISIBILITY_HIDDEN float m_gammaf(float x); - -VISIBILITY_HIDDEN double m_lgamma(double x); -VISIBILITY_HIDDEN float m_lgammaf(float x); - -VISIBILITY_HIDDEN double m_log1p(double x); -VISIBILITY_HIDDEN float m_log1pf(float x); - -VISIBILITY_HIDDEN double m_round(double x); -VISIBILITY_HIDDEN float m_roundf(float x); - -VISIBILITY_HIDDEN double m_trunc(double x); -VISIBILITY_HIDDEN float m_truncf(float x); - -VISIBILITY_HIDDEN double m_atan2(double y, double x); -VISIBILITY_HIDDEN float m_atan2f(float y, float x); - - -#if !HAVE_C99_MATH - -/* Define missing math functions */ - -#define asinh(x) m_asinh(x) -#define asinhf(x) m_asinhf(x) -#define acosh(x) m_acosh(x) -#define acoshf(x) m_acoshf(x) -#define atanh(x) m_atanh(x) -#define atanhf(x) m_atanhf(x) - -#define erf(x) m_erf(x) -#define erfc(x) m_erfc(x) -#define erfcf(x) m_erfcf(x) -#define erff(x) m_erff(x) - -#define expm1(x) m_expm1(x) -#define expm1f(x) m_expm1f(x) -#define log1p(x) m_log1p(x) -#define log1pf(x) m_log1pf(x) - -#define lgamma(x) m_lgamma(x) -#define lgammaf(x) m_lgammaf(x) -#define tgamma(x) m_gamma(x) -#define tgammaf(x) m_gammaf(x) - -#define round(x) m_round(x) -#define roundf(x) m_roundf(x) -#define trunc(x) m_trunc(x) -#define truncf(x) m_truncf(x) - -#define atan2f(x, y) m_atan2f(x, y) - -#endif /* !HAVE_C99_MATH */ - -#define atan2_fixed(x, y) m_atan2(x, y) - -#endif /* NUMBA_MATH_C99_H_ */ diff --git a/numba/mathnames.h b/numba/mathnames.h index b06f7013b1c..73d45b18d12 100644 --- a/numba/mathnames.h +++ b/numba/mathnames.h @@ -73,6 +73,5 @@ MATH_BINARY(powf, float, float, float) MATH_BINARY(fmod, double, double, double) MATH_BINARY(fmodf, float, float, float) -MATH_BINARY(atan2_fixed, double, double, double) MATH_BINARY(atan2, double, double, double) MATH_BINARY(atan2f, float, float, float) diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index 064f6bdd790..74e672316b9 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -25,7 +25,7 @@ class CC(object): # NOTE: using ccache can speed up repetitive builds # (especially for the mixin modules) - _mixin_sources = ['modulemixin.c', '../_math_c99.c'] + extension_libs + _mixin_sources = ['modulemixin.c',] + extension_libs # -flto strips all unused helper functions, which 1) makes the # produced output much smaller and 2) can make the linking step faster. diff --git a/numba/targets/intrinsics.py b/numba/targets/intrinsics.py index c87e4c9b1df..8e85bb35400 100644 --- a/numba/targets/intrinsics.py +++ b/numba/targets/intrinsics.py @@ -80,7 +80,6 @@ def fix_divmod(mod): atanf atan2 atan2f -atan2_fixed asinh asinhf acosh diff --git a/setup.py b/setup.py index 4f3b46f00e3..4f325bddb7c 100644 --- a/setup.py +++ b/setup.py @@ -121,7 +121,6 @@ def get_ext_modules(): ext_helperlib = Extension(name="numba._helperlib", sources=["numba/_helpermod.c", - "numba/_math_c99.c", "numba/cext/utils.c", "numba/cext/dictobject.c", "numba/cext/listobject.c", @@ -129,7 +128,6 @@ def get_ext_modules(): extra_compile_args=CFLAGS, extra_link_args=install_name_tool_fixer, depends=["numba/_pymodule.h", - "numba/_math_c99.h", "numba/_helperlib.c", "numba/_lapack.c", "numba/_npymath_exports.c", From 0a0552319d36dc24af983e3dda50abc978879f9a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 16:28:59 +0000 Subject: [PATCH 267/595] Fix has_blas import errr --- numba/tests/compile_with_pycc.py | 2 +- numba/tests/test_pycc.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/numba/tests/compile_with_pycc.py b/numba/tests/compile_with_pycc.py index 56f0c928918..f47e14fa3ca 100644 --- a/numba/tests/compile_with_pycc.py +++ b/numba/tests/compile_with_pycc.py @@ -4,7 +4,7 @@ from numba import float32 from numba.pycc import CC, exportmany, export -from numba.tests.matmul_usecase import has_blas +from numba.tests.support import has_blas from numba import typed diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index c15c3755daf..f41afb5d7aa 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -31,8 +31,7 @@ _windows_only = unittest.skipIf(not sys.platform.startswith('win'), _skip_reason) -from .matmul_usecase import has_blas -from .support import TestCase, tag, import_dynamic, temp_directory +from .support import TestCase, tag, import_dynamic, temp_directory, has_blas base_path = os.path.dirname(os.path.abspath(__file__)) From eef5bffd4aaa842bf2918b847d0353e647e29c25 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 16:32:38 +0000 Subject: [PATCH 268/595] Fix up docs --- docs/source/developer/repomap.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/developer/repomap.rst b/docs/source/developer/repomap.rst index f3b683b8c49..126b25cb4e5 100644 --- a/docs/source/developer/repomap.rst +++ b/docs/source/developer/repomap.rst @@ -216,8 +216,6 @@ with CPython APIs. - :ghfile:`numba/mathnames.h` - Macros for defining names of math functions - :ghfile:`numba/_pymodule.h` - C macros for Python 2/3 portable naming of C API functions -- :ghfile:`numba/_math_c99.{h,c}` - C99 math compatibility (needed Python - 2.7 on Windows, compiled with VS2008) - :ghfile:`numba/mviewbuf.c` - Handles Python memoryviews - :ghfile:`numba/_typeof.{h,c}` - C implementation of type fingerprinting, used by dispatcher From 61f40a49751ec6123adf5486b4a3c2d2e6fcabc4 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 24 Jan 2020 11:27:33 -0600 Subject: [PATCH 269/595] Apply suggestions to threading docs from @gmarkall code review Co-Authored-By: Graham Markall <535640+gmarkall@users.noreply.github.com> --- docs/source/developer/threading_implementation.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index f269f3fec03..b2610118ab2 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -50,7 +50,7 @@ scope and also simple. The number of threads in use is specified by calling ``get_num_threads``.These two functions are synonymous with their OpenMP counterparts (with the above restriction that the mask must be less than or equal to the number of launched threads). The execution semantics are also -similar to OpenmP in that once a parallel region is launched, altering the +similar to OpenMP in that once a parallel region is launched, altering the thread mask has no impact on the currently executing region, but will have an impact on parallel regions executed subsequently. @@ -137,11 +137,11 @@ Thread ID A private ``get_thread_id()`` function was added to each threading backend, which returns a unique ID for each thread. This can be accessed from Python by -``numba.npyufunc.parallel._get_thread_id()`` (it can also be used inside of +``numba.npyufunc.parallel._get_thread_id()`` (it can also be used inside a JIT compiled function). The thread ID function is useful for testing that the thread masking behavior is correct, but it should not be used outside of the tests. For example, one can call ``set_num_threads(4)`` and then collect all -unique ``_get_thread_id()``\ 's in a parallel region to verify that only 4 +unique ``_get_thread_id()``\ s in a parallel region to verify that only 4 threads are run. Caveats From 43ca3fa15922ce72e6f6799afd03199b38c93d4a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 24 Jan 2020 10:39:19 -0700 Subject: [PATCH 270/595] Use the same tbb version format as conda This makes the error message a little easier to read. --- numba/npyufunc/parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index d5ad4bcf89a..e9fad3ac256 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -350,7 +350,7 @@ def _check_tbb_version_compatible(): tbb_iface_ver = version_func() if tbb_iface_ver < 11005: # magic number from TBB msg = ("The TBB threading layer requires TBB " - "version 2019 update 5 or later i.e. " + "version 2019.5 or later i.e., " "TBB_INTERFACE_VERSION >= 11005. Found " "TBB_INTERFACE_VERSION = %s. The TBB " "threading layer is disabled.") From a0356a0ec12a4a3c47f5e5f340833a9ec0fcbd2f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 24 Jan 2020 20:03:41 +0000 Subject: [PATCH 271/595] remove removed symbol --- numba/targets/mathimpl.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/numba/targets/mathimpl.py b/numba/targets/mathimpl.py index b466c399f7d..2aacf37a8b6 100644 --- a/numba/targets/mathimpl.py +++ b/numba/targets/mathimpl.py @@ -317,8 +317,7 @@ def atan2_float_impl(context, builder, sig, args): lty = context.get_value_type(ty) func_name = { types.float32: "atan2f", - # Workaround atan2() issues under Windows - types.float64: "atan2_fixed" if sys.platform == "win32" else "atan2" + types.float64: "atan2" }[ty] fnty = Type.function(lty, (lty, lty)) fn = cgutils.insert_pure_function(builder.module, fnty, name=func_name) From 90d1b8d4b446dd4a68161465bbca73a9a43086c8 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 27 Jan 2020 09:01:50 -0600 Subject: [PATCH 272/595] Merge pull request #5146 from sklam/misc/update0.48_iss5087 Update 0.48 branch --- CHANGE_LOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGE_LOG b/CHANGE_LOG index 8f1166364a5..80192590903 100644 --- a/CHANGE_LOG +++ b/CHANGE_LOG @@ -4,7 +4,7 @@ Version 0.49.0dev In development -Version 0.48.0 (Jan 16, 2020) +Version 0.48.0 (Jan 27, 2020) ----------------------------- This release is particularly small as it was present to catch anything that @@ -81,6 +81,7 @@ Fixes: multiple consistent defines. * PR #5058: Permit mixed int types in wrap_index * PR #5078: Catch the use of global typed-list in JITed functions +* PR #5092: Fix #5087, bug in bytecode analysis. CUDA Enhancements/Fixes: From f1e80c76d83753122bf27041ff5736ac51d1282c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 27 Jan 2020 15:56:34 -0700 Subject: [PATCH 273/595] Note the relevant files in the threading implementation documentation --- .../developer/threading_implementation.rst | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/source/developer/threading_implementation.rst b/docs/source/developer/threading_implementation.rst index f269f3fec03..0866d55bd64 100644 --- a/docs/source/developer/threading_implementation.rst +++ b/docs/source/developer/threading_implementation.rst @@ -16,6 +16,33 @@ function in the threading library that performs the parallel execution is the ``parallel_for`` function. The job of this function is to both orchestrate and execute the parallel tasks. +The relevant source files referenced in this document are + +- ``numba/npyufunc/tbbpool.cpp`` +- ``numba/npyufunc/omppool.cpp`` +- ``numba/npyufunc/workqueue.c`` + + These files contain the TBB, OpenMP, and workqueue threadpool + implementations, respectively. Each includes the functions + ``set_num_threads()``, ``get_num_threads()``, and ``get_thread_id()``, as + well as the relevant logic for thread masking in their respective + schedulers. Note that the basic thread local variable logic is duplicated in + each of these files, and not shared between them. + +- ``numba/npyufunc/parallel.py`` + + This file contains the Python and JIT compatible wrappers for + ``set_num_threads()``, ``get_num_threads()``, and ``get_thread_id()``, as + well as the code that loads the above libraries into Python and launches the + threadpool. + +- ``numba/npyufunc/parfor.py`` + + This file contains the main logic for generating code for the parallel + backend. The thread mask is accessed in this file in the code that generates + scheduler code, and passed to the relevant backend scheduler function (see + below). + Thread masking -------------- From 99cba4a15a50335cd2248932c28399eb988e3ce3 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 27 Jan 2020 20:28:00 +0100 Subject: [PATCH 274/595] implement None-typed typed-list This is the code for the None-typed typed-list as extracted from: https://github.com/numba/numba/pull/4883/files The support is very limited and was designed only for a single, very limited use-case: populating a typed-list with a list comprehension. Let's imagine you want to do the following: ```python from numba import njit, typed @njit def foo(): l = typed.List() [l.append(i) for i in range(10)] ``` While it is true, that this is fairly uncommon way to initialize a list, it was and is used to populate a typed-list since that doesn't (at the time of writing this) have a way to be initialised from an iterable or similar. And so the list comprehension approach is one line shorter than a for-loop construct. As a by product of this idiom, is that a None-typed list is generated and discarded as a result. If the list comprehension is to generate a Numba typed-list, rather than a reflected list, in future, then it must support a None-typed variant A mentioned, the implementation here is as minimal as it can be and doesn't have an optimizations. Most of the method are not supported and will be guarded against. An optimized variant may not need to allocate any memory at all, for example, since a None value will always be returned when accessing it and we only need a count of the number of Nones stored --- numba/listobject.py | 141 ++++++++++++++++++++++++++-------- numba/tests/test_typedlist.py | 136 ++++++++++++++++++++++++++++++++ numba/types/containers.py | 2 +- 3 files changed, 247 insertions(+), 32 deletions(-) diff --git a/numba/listobject.py b/numba/listobject.py index 4af7b30d678..cb75e87c347 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -26,6 +26,7 @@ ListTypeIterableType, ListTypeIteratorType, Type, + NoneType, ) from numba.targets.imputils import impl_ret_borrowed, RefType from numba.errors import TypingError @@ -94,6 +95,12 @@ def _raise_if_error(context, builder, status, msg): context.call_conv.return_user_exc(builder, RuntimeError, (msg,)) +def _check_for_none_typed(lst, method): + if isinstance(lst.dtype, NoneType): + raise TypingError("method support for List[None] is limited, " + "not supported: '{}'.".format(method)) + + @intrinsic def _as_meminfo(typingctx, lstobj): """Returns the MemInfoPointer of a list. @@ -560,14 +567,18 @@ def _list_pop(typingctx, l, index): def _list_getitem_pop_helper(typingctx, l, index, op): """Wrap numba_list_getitem and numba_list_pop - Returns 2-tuple of (intp, ?item_type) + Returns 2-tuple of (int32, ?item_type) This is a helper that is parametrized on the type of operation, which can be either 'pop' or 'getitem'. This is because, signature wise, getitem and pop and are the same. """ assert(op in ("pop", "getitem")) - resty = types.Tuple([types.int32, types.Optional(l.item_type)]) + IS_NOT_NONE = not isinstance(l.item_type, types.NoneType) + resty = types.Tuple([types.int32, + types.Optional(l.item_type + if IS_NOT_NONE + else types.int64)]) sig = resty(l, index) def codegen(context, builder, sig, args): @@ -596,15 +607,19 @@ def codegen(context, builder, sig, args): # Load item if output is available found = builder.icmp_signed('>=', status, status.type(int(ListStatus.LIST_OK))) - - out = context.make_optional_none(builder, tl.item_type) + out = context.make_optional_none(builder, + tl.item_type + if IS_NOT_NONE + else types.int64) pout = cgutils.alloca_once_value(builder, out) with builder.if_then(found): - item = dm_item.load_from_data_pointer(builder, ptr_item) - context.nrt.incref(builder, tl.item_type, item) - loaded = context.make_optional_value(builder, tl.item_type, item) - builder.store(loaded, pout) + if IS_NOT_NONE: + item = dm_item.load_from_data_pointer(builder, ptr_item) + context.nrt.incref(builder, tl.item_type, item) + loaded = context.make_optional_value( + builder, tl.item_type, item) + builder.store(loaded, pout) out = builder.load(pout) return context.make_tuple(builder, resty, [status, out]) @@ -619,18 +634,24 @@ def impl_getitem(l, index): indexty = INDEXTY itemty = l.item_type + IS_NOT_NONE = not isinstance(l.item_type, types.NoneType) if index in index_types: - def integer_impl(l, index): - index = handle_index(l, index) - castedindex = _cast(index, indexty) - status, item = _list_getitem(l, castedindex) - if status == ListStatus.LIST_OK: - return _nonoptional(item) - else: - raise AssertionError("internal list error during getitem") - - return integer_impl + if IS_NOT_NONE: + def integer_non_none_impl(l, index): + index = handle_index(l, index) + castedindex = _cast(index, indexty) + status, item = _list_getitem(l, castedindex) + if status == ListStatus.LIST_OK: + return _nonoptional(item) + else: + raise AssertionError("internal list error during getitem") + return integer_non_none_impl + else: + def integer_none_impl(l, index): + index = handle_index(l, index) + return None + return integer_none_impl elif isinstance(index, types.SliceType): def slice_impl(l, index): @@ -759,6 +780,8 @@ def impl_pop(l, index=-1): if not isinstance(l, types.ListType): return + _check_for_none_typed(l, 'pop') + indexty = INDEXTY # FIXME: this type check works, but it isn't clear why and if it optimal @@ -843,6 +866,7 @@ def impl_contains(l, item): return itemty = l.item_type + _check_for_none_typed(l, "__contains__") def impl(l, item): casteditem = _cast(item, itemty) @@ -859,6 +883,8 @@ def impl_count(l, item): if not isinstance(l, types.ListType): return + _check_for_none_typed(l, 'count') + itemty = l.item_type def impl(l, item): @@ -922,6 +948,11 @@ def impl_insert(l, index, item): if not isinstance(l, types.ListType): return + _check_for_none_typed(l, 'insert') + # insert can refine + if isinstance(item, NoneType): + raise TypingError("method support for List[None] is limited") + if index in index_types: def impl(l, index, item): # If the index is larger than the size of the list or if the list is @@ -964,6 +995,8 @@ def impl_remove(l, item): if not isinstance(l, types.ListType): return + _check_for_none_typed(l, 'remove') + itemty = l.item_type def impl(l, item): @@ -995,6 +1028,8 @@ def impl_reverse(l): if not isinstance(l, types.ListType): return + _check_for_none_typed(l, 'reverse') + def impl(l): front = 0 back = len(l) - 1 @@ -1008,7 +1043,11 @@ def impl(l): @overload_method(types.ListType, 'copy') def impl_copy(l): + + _check_for_none_typed(l, 'copy') + itemty = l.item_type + if isinstance(l, types.ListType): def impl(l): newl = new_list(itemty, len(l)) @@ -1023,6 +1062,9 @@ def impl(l): def impl_index(l, item, start=None, end=None): if not isinstance(l, types.ListType): return + + _check_for_none_typed(l, 'index') + itemty = l.item_type def check_arg(arg, name): @@ -1091,17 +1133,29 @@ def _equals_helper(this, other, OP): if not isinstance(other, types.ListType): return lambda this, other: False - def impl(this, other): - def equals(this, other): - if len(this) != len(other): - return False - for i in range(len(this)): - if this[i] != other[i]: + this_is_none = isinstance(this.dtype, types.NoneType) + other_is_none = isinstance(other.dtype, types.NoneType) + + if this_is_none or other_is_none: + def impl_some_none(this, other): + def equals(this, other): + # Equal if both none-typed and have equal length + return bool(this_is_none == other_is_none + and len(this) == len(other)) + return OP(equals(this, other)) + return impl_some_none + else: + def impl_not_none(this, other): + def equals(this, other): + if len(this) != len(other): return False - else: - return True - return OP(equals(this, other)) - return impl + for i in range(len(this)): + if this[i] != other[i]: + return False + else: + return True + return OP(equals(this, other)) + return impl_not_none @overload(operator.eq) @@ -1115,7 +1169,7 @@ def impl_not_equals(this, other): @register_jitable -def compare(this, other): +def compare_not_none(this, other): """Oldschool (python 2.x) cmp. if this < other return -1 @@ -1132,14 +1186,39 @@ def compare(this, other): return 0 +@register_jitable +def compare_some_none(this, other, this_is_none, other_is_none): + """Oldschool (python 2.x) cmp for None typed lists. + + if this < other return -1 + if this = other return 0 + if this > other return 1 + """ + if len(this) != len(other): + return -1 if len(this) < len(other) else 1 + if this_is_none and other_is_none: # both none + return 0 + # to get here there is precisely one none, and if the first is none, by + # induction, the second cannot be + return -1 if this_is_none else 1 + + def compare_helper(this, other, accepted): if not isinstance(this, types.ListType): return if not isinstance(other, types.ListType): return lambda this, other: False - def impl(this, other): - return compare(this, other) in accepted + this_is_none = isinstance(this.dtype, types.NoneType) + other_is_none = isinstance(other.dtype, types.NoneType) + + if this_is_none or other_is_none: + def impl(this, other): + return compare_some_none( + this, other, this_is_none, other_is_none) in accepted + else: + def impl(this, other): + return compare_not_none(this, other) in accepted return impl diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 42a9623de95..be41e166538 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -1,4 +1,5 @@ from itertools import product +from textwrap import dedent import numpy as np @@ -7,6 +8,7 @@ from numba import jitclass, typeof from numba.typed import List, Dict from numba.errors import TypingError +from numba.utils import exec_ from .support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen, skip_parfors_unsupported) @@ -479,6 +481,140 @@ def foo(): ) +class TestNoneType(MemoryLeakMixin, TestCase): + + def test_append_none(self): + @njit + def impl(): + l = List() + l.append(None) + return l + + self.assertEqual(impl.py_func(), impl()) + + def test_len_none(self): + @njit + def impl(): + l = List() + l.append(None) + return len(l) + + self.assertEqual(impl.py_func(), impl()) + + def test_getitem_none(self): + @njit + def impl(): + l = List() + l.append(None) + return l[0] + + self.assertEqual(impl.py_func(), impl()) + + def test_setitem_none(self): + @njit + def impl(): + l = List() + l.append(None) + l[0] = None + return l + + self.assertEqual(impl.py_func(), impl()) + + def test_equals_none(self): + @njit + def impl(): + l = List() + l.append(None) + m = List() + m.append(None) + return l == m, l != m, l < m, l <= m, l > m, l >= m + + self.assertEqual(impl.py_func(), impl()) + + def test_not_equals_none(self): + @njit + def impl(): + l = List() + l.append(None) + m = List() + m.append(1) + return l == m, l != m, l < m, l <= m, l > m, l >= m + + self.assertEqual(impl.py_func(), impl()) + + def test_iter_none(self): + @njit + def impl(): + l = List() + l.append(None) + l.append(None) + l.append(None) + count = 0 + for i in l: + count += 1 + return count + + self.assertEqual(impl.py_func(), impl()) + + def test_square_bracket_builtin_with_None(self): + @njit(_disable_reflected_list=True) + def foo(): + l = [None, None, None] + return l + expected = List() + expected.append(None) + expected.append(None) + expected.append(None) + received = foo() + self.assertEqual(expected, received) + + def test_list_comprehension_with_none(self): + @njit(_disable_reflected_list=True) + def foo(): + l = List() + # the following construct results in a List[None] that is discarded + [l.append(i) for i in (1, 3, 3)] + return l + expected = List() + [expected.append(i) for i in (1, 3, 3)] + received = foo() + self.assertEqual(expected, received) + + def test_none_typed_method_fails(self): + """ Test that unsupported operations on List[None] raise. """ + def generate_function(line1, line2): + context = {} + exec_(dedent(""" + from numba.typed import List + def bar(): + lst = List() + {} + {} + """.format(line1, line2)), context) + return njit(context["bar"], _disable_reflected_list=True) + for line1, line2 in ( + ("lst.append(None)", "lst.pop()"), + ("lst.append(None)", "lst.count(None)"), + ("lst.append(None)", "lst.index(None)"), + ("lst.append(None)", "lst.insert(0, None)"), + ("" , "lst.insert(0, None)"), + ("lst.append(None)", "lst.clear()"), + ("lst.append(None)", "lst.copy()"), + ("lst.append(None)", "lst.extend([None])"), + ("", "lst.extend([None])"), + ("lst.append(None)", "lst.remove(None)"), + ("lst.append(None)", "lst.reverse()"), + ("lst.append(None)", "None in lst"), + ): + with self.assertRaises(TypingError) as raises: + foo = generate_function(line1, line2) + foo() + self.assertIn( + "method support for List[None] is limited", + str(raises.exception), + ) + + class TestAllocation(MemoryLeakMixin, TestCase): def test_allocation(self): diff --git a/numba/types/containers.py b/numba/types/containers.py index 76f2800d23f..b98660ccf8d 100644 --- a/numba/types/containers.py +++ b/numba/types/containers.py @@ -497,7 +497,7 @@ class ListType(IterableType): def __init__(self, itemty): assert not isinstance(itemty, TypeRef) itemty = unliteral(itemty) - if isinstance(itemty, (Optional, NoneType)): + if isinstance(itemty, Optional): fmt = 'List.item_type cannot be of type {}' raise TypingError(fmt.format(itemty)) # FIXME: _sentry_forbidden_types(itemty) From 176dfc69d5725f6b93257fbdf0d53018e7c2e91f Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 27 Jan 2020 21:43:29 +0100 Subject: [PATCH 275/595] add missing dtype interface --- numba/types/containers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/types/containers.py b/numba/types/containers.py index b98660ccf8d..e9cc0ed2f1f 100644 --- a/numba/types/containers.py +++ b/numba/types/containers.py @@ -502,6 +502,7 @@ def __init__(self, itemty): raise TypingError(fmt.format(itemty)) # FIXME: _sentry_forbidden_types(itemty) self.item_type = itemty + self.dtype = itemty name = '{}[{}]'.format( self.__class__.__name__, itemty, From e244eac726c02c03a180af47917984d70c0687e9 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 27 Jan 2020 22:44:32 +0100 Subject: [PATCH 276/595] disable extend We disable lst.extend(ARG) too, since it most likely won't be needed. --- numba/listobject.py | 2 ++ numba/tests/test_typedlist.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/numba/listobject.py b/numba/listobject.py index cb75e87c347..8933a722689 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -905,6 +905,8 @@ def impl_extend(l, iterable): if not isinstance(iterable, types.IterableType): raise TypingError("extend argument must be iterable") + _check_for_none_typed(l, 'insert') + def select_impl(): if isinstance(iterable, types.ListType): def impl(l, iterable): diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index be41e166538..cecf7a20f0b 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -591,7 +591,9 @@ def bar(): {} {} """.format(line1, line2)), context) - return njit(context["bar"], _disable_reflected_list=True) + # FIXME: when _disable_reflected_list becomes available + # return njit(context["bar"], _disable_reflected_list=True) + return njit(context["bar"]) for line1, line2 in ( ("lst.append(None)", "lst.pop()"), ("lst.append(None)", "lst.count(None)"), From 331fad56d7db409d309bd13f556a10d1f4636cce Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 27 Jan 2020 22:45:25 +0100 Subject: [PATCH 277/595] disable tests from future These tests depend on `_disable_reflected_list` being available. --- numba/tests/test_typedlist.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index cecf7a20f0b..df9855e57eb 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -556,6 +556,7 @@ def impl(): self.assertEqual(impl.py_func(), impl()) + @unittest.skip("Works only with _disable_reflected_list") def test_square_bracket_builtin_with_None(self): @njit(_disable_reflected_list=True) def foo(): @@ -568,6 +569,7 @@ def foo(): received = foo() self.assertEqual(expected, received) + @unittest.skip("Works only with _disable_reflected_list") def test_list_comprehension_with_none(self): @njit(_disable_reflected_list=True) def foo(): From 009910751a88c6ab924c9490af8bde81102882c9 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Tue, 28 Jan 2020 10:15:47 +0100 Subject: [PATCH 278/595] fix failed rebase With the removal of legacy Python https://github.com/numba/numba/pull/5122 a few changes had to be made. --- numba/tests/test_typedlist.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index df9855e57eb..0582d4dd82c 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -8,8 +8,7 @@ from numba import jitclass, typeof from numba.typed import List, Dict from numba.errors import TypingError -from numba.utils import exec_ -from .support import (TestCase, MemoryLeakMixin, override_config, +from .support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen, skip_parfors_unsupported) from numba.unsafe.refcount import get_refcount @@ -586,7 +585,7 @@ def test_none_typed_method_fails(self): """ Test that unsupported operations on List[None] raise. """ def generate_function(line1, line2): context = {} - exec_(dedent(""" + exec(dedent(""" from numba.typed import List def bar(): lst = List() From 4f94813e07ab984179d1b08a14181377c3ffc8ba Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 28 Jan 2020 13:50:35 -0600 Subject: [PATCH 279/595] Add tests for call_jit_code --- numba/tests/test_extending.py | 178 +++++++++++++++++++++++++++++++--- 1 file changed, 166 insertions(+), 12 deletions(-) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 0e822fb9a86..219b5033b10 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -33,6 +33,7 @@ ) from numba.typing.templates import ( ConcreteTemplate, signature, infer, infer_global, AbstractTemplate) +from numba import cgutils _IS_PY3 = sys.version_info >= (3,) @@ -88,24 +89,25 @@ def unbox_index(typ, obj, c): # ----------------------------------------------------------------------- # Define a second custom type but w/o implicit cast to Number -class MyDummy2(object): - pass +def base_dummy_type_factory(name): + class DynType(object): + pass -class MyDummyType2(types.Opaque): - pass + class DynTypeType(types.Opaque): + pass -mydummy_type_2 = MyDummyType2('mydummy_2') -mydummy_2 = MyDummy2() + dyn_type_type = DynTypeType(name) -@typeof_impl.register(MyDummy2) -def typeof_mydummy(val, c): - return mydummy_type_2 + @typeof_impl.register(DynType) + def typeof_mydummy(val, c): + return dyn_type_type + + register_model(DynTypeType)(models.OpaqueModel) + return DynTypeType, DynType, dyn_type_type -def get_dummy_2(): - return mydummy_2 +MyDummyType2, MyDummy2, mydummy_type_2 = base_dummy_type_factory('mydummy2') -register_model(MyDummyType2)(models.OpaqueModel) @unbox(MyDummyType2) def unbox_index(typ, obj, c): @@ -1444,5 +1446,157 @@ def udt(x): self.check_error_no_nrt(udt, mydummy) +class TestUnboxer(TestCase): + def setUp(self): + super().setUp() + many = base_dummy_type_factory('mydummy2') + self.DynTypeType, self.DynType, self.dyn_type_type = many + self.dyn_type = self.DynType() + + def test_unboxer_basic(self): + # Implements an unboxer on DynType that calls an intrinsic into the + # unboxer code. + magic_token = 0xbeefcafe + magic_offset = 123 + + @intrinsic + def my_intrinsic(typingctx, val): + # An intrinsic that returns `val + magic_offset` + def impl(context, builder, sig, args): + [val] = args + return builder.add(val, val.type(magic_offset)) + sig = signature(val, val) + return sig, impl + + + @unbox(self.DynTypeType) + def unboxer(typ, obj, c): + # The unboxer that calls some jitcode + def bridge(x): + # proof that this is a jit'ed context by calling jit only + # intrinsic + return my_intrinsic(x) + + args = [c.context.get_constant(types.intp, magic_token)] + sig = signature(types.voidptr, types.intp) + is_error, res = c.pyapi.call_jit_code(bridge, sig, args) + return NativeValue(res, is_error=is_error) + + @box(self.DynTypeType) + def boxer(typ, val, c): + # The boxer that returns an integer representation + res = c.builder.ptrtoint(val, cgutils.intp_t) + return c.pyapi.long_from_ulonglong(res) + + @njit + def passthru(x): + return x + + out = passthru(self.dyn_type) + self.assertEqual(out, magic_token + magic_offset) + + def test_unboxer_raise(self): + # Testing exception raising in jitcode called from unboxing. + @unbox(self.DynTypeType) + def unboxer(typ, obj, c): + # The unboxer that calls some jitcode + def bridge(x): + if x > 0: + raise ValueError('cannot be x > 0') + return x + + args = [c.context.get_constant(types.intp, 1)] + sig = signature(types.voidptr, types.intp) + is_error, res = c.pyapi.call_jit_code(bridge, sig, args) + return NativeValue(res, is_error=is_error) + + @box(self.DynTypeType) + def boxer(typ, val, c): + # The boxer that returns an integer representation + res = c.builder.ptrtoint(val, cgutils.intp_t) + return c.pyapi.long_from_ulonglong(res) + + @njit + def passthru(x): + return x + + with self.assertRaises(ValueError) as raises: + out = passthru(self.dyn_type) + self.assertIn( + "cannot be x > 0", + str(raises.exception), + ) + + def test_boxer(self): + # Call jitcode inside the boxer + magic_token = 0xcafe + magic_offset = 312 + + @intrinsic + def my_intrinsic(typingctx, val): + # An intrinsic that returns `val + magic_offset` + def impl(context, builder, sig, args): + [val] = args + return builder.add(val, val.type(magic_offset)) + sig = signature(val, val) + return sig, impl + + @unbox(self.DynTypeType) + def unboxer(typ, obj, c): + return NativeValue(c.context.get_dummy_value()) + + @box(self.DynTypeType) + def boxer(typ, val, c): + # Note: this doesn't do proper error handling + def bridge(x): + return my_intrinsic(x) + + args = [c.context.get_constant(types.intp, magic_token)] + sig = signature(types.intp, types.intp) + is_error, res = c.pyapi.call_jit_code(bridge, sig, args) + return c.pyapi.long_from_ulonglong(res) + + @njit + def passthru(x): + return x + + r = passthru(self.dyn_type) + self.assertEqual(r, magic_token + magic_offset) + + def test_boxer_raise(self): + # Call jitcode inside the boxer + @unbox(self.DynTypeType) + def unboxer(typ, obj, c): + return NativeValue(c.context.get_dummy_value()) + + @box(self.DynTypeType) + def boxer(typ, val, c): + def bridge(x): + if x > 0: + raise ValueError("cannot do x > 0") + return x + + args = [c.context.get_constant(types.intp, 1)] + sig = signature(types.intp, types.intp) + is_error, res = c.pyapi.call_jit_code(bridge, sig, args) + # The error handling + retval = cgutils.alloca_once(c.builder, c.pyapi.pyobj, zfill=True) + with c.builder.if_then(c.builder.not_(is_error)): + obj = c.pyapi.long_from_ulonglong(res) + c.builder.store(obj, retval) + return c.builder.load(retval) + + @njit + def passthru(x): + return x + + with self.assertRaises(ValueError) as raises: + passthru(self.dyn_type) + self.assertIn( + "cannot do x > 0", + str(raises.exception), + ) + + if __name__ == '__main__': unittest.main() From fb2a1eb1caf23b4e7eb8979be959048c73f27e63 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 28 Jan 2020 14:51:50 -0600 Subject: [PATCH 280/595] Fix test on 32-bit --- numba/tests/test_extending.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 219b5033b10..4c9355ba3a3 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -1486,7 +1486,7 @@ def bridge(x): def boxer(typ, val, c): # The boxer that returns an integer representation res = c.builder.ptrtoint(val, cgutils.intp_t) - return c.pyapi.long_from_ulonglong(res) + return c.pyapi.long_from_ssize_t(res) @njit def passthru(x): @@ -1514,7 +1514,7 @@ def bridge(x): def boxer(typ, val, c): # The boxer that returns an integer representation res = c.builder.ptrtoint(val, cgutils.intp_t) - return c.pyapi.long_from_ulonglong(res) + return c.pyapi.long_from_ssize_t(res) @njit def passthru(x): @@ -1554,7 +1554,7 @@ def bridge(x): args = [c.context.get_constant(types.intp, magic_token)] sig = signature(types.intp, types.intp) is_error, res = c.pyapi.call_jit_code(bridge, sig, args) - return c.pyapi.long_from_ulonglong(res) + return c.pyapi.long_from_ssize_t(res) @njit def passthru(x): @@ -1582,7 +1582,7 @@ def bridge(x): # The error handling retval = cgutils.alloca_once(c.builder, c.pyapi.pyobj, zfill=True) with c.builder.if_then(c.builder.not_(is_error)): - obj = c.pyapi.long_from_ulonglong(res) + obj = c.pyapi.long_from_ssize_t(res) c.builder.store(obj, retval) return c.builder.load(retval) From bee8ecd7be64aec353542486e3c1b568044192f7 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Wed, 29 Jan 2020 11:13:00 +0100 Subject: [PATCH 281/595] explain what inlining at Numba IR level will do As the issue https://github.com/numba/numba/issues/5142 caused some confusion over the purpose and effect of inlining at the Numba IR level add an additional explanation and a worked example. --- docs/source/developer/inlining.rst | 44 +++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/docs/source/developer/inlining.rst b/docs/source/developer/inlining.rst index 6ac3dc60c6c..6739471021d 100644 --- a/docs/source/developer/inlining.rst +++ b/docs/source/developer/inlining.rst @@ -3,10 +3,46 @@ Notes on Inlining ================= -There are occasions where it is useful to be able to inline a function -at its call site, at the Numba IR level of representation. The decorators -:func:`numba.jit` and :func:`numba.extending.overload` both -support the keyword argument ``inline``, to facilitate this behaviour. +There are occasions where it is useful to be able to inline a function at its +call site, at the Numba IR level of representation. The decorators such as +:func:`numba.jit`, :func:`numba.extending.overload` and +:func:`register_jitable` support the keyword argument ``inline``, to facilitate +this behaviour. + +When attempting to inline at this level, it is important to understand what +purpose this serves and what effect this will have. In contrast to the inlining +performed by LLVM, which is aimed at improving performance, the main reason to +inline at the Numba IR level is to allow type inference to cross function +boundaries. + +As an example, consider the following snippet: + +.. code:: python + + from numba import njit + + + @njit + def bar(a): + a.append(10) + + + @njit + def foo(): + z = [] + bar(z) + + + foo() + +This will fail to compile and run, because the type of ``z`` can not be inferred +as it will only be refined within ``bar``. If we now add ``inline=True`` to the +decorator for ``bar`` the snippet will compile and run. This i because inlining +the call to ``a.append(10)`` will mean that ``z`` will be refined to hold integers +and so type inference will succeed. + +So, to recap, inlining at the Numba IR level is unlikely to have a performance +benefit. Whereas inlining at the LLVM level stands a better chance. The ``inline`` keyword argument can be one of three values: From 6926ead019e6163cc9815d3e365d9175446ed44e Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Wed, 29 Jan 2020 15:10:06 +0100 Subject: [PATCH 282/595] remove tests that depend on _disable_reflected_list --- numba/tests/test_typedlist.py | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 0582d4dd82c..c343dded931 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -8,7 +8,7 @@ from numba import jitclass, typeof from numba.typed import List, Dict from numba.errors import TypingError -from .support import (TestCase, MemoryLeakMixin, unittest, override_config, +from .support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen, skip_parfors_unsupported) from numba.unsafe.refcount import get_refcount @@ -555,32 +555,6 @@ def impl(): self.assertEqual(impl.py_func(), impl()) - @unittest.skip("Works only with _disable_reflected_list") - def test_square_bracket_builtin_with_None(self): - @njit(_disable_reflected_list=True) - def foo(): - l = [None, None, None] - return l - expected = List() - expected.append(None) - expected.append(None) - expected.append(None) - received = foo() - self.assertEqual(expected, received) - - @unittest.skip("Works only with _disable_reflected_list") - def test_list_comprehension_with_none(self): - @njit(_disable_reflected_list=True) - def foo(): - l = List() - # the following construct results in a List[None] that is discarded - [l.append(i) for i in (1, 3, 3)] - return l - expected = List() - [expected.append(i) for i in (1, 3, 3)] - received = foo() - self.assertEqual(expected, received) - def test_none_typed_method_fails(self): """ Test that unsupported operations on List[None] raise. """ def generate_function(line1, line2): From 92540ea585e1cd6da28ab7c8b709e29b22e005cb Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Wed, 29 Jan 2020 15:16:03 +0100 Subject: [PATCH 283/595] remove reminder comment Since we don't know if _disable_reflected_list will manifest itself this way, remove the comment that references it. --- numba/tests/test_typedlist.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index c343dded931..4ea6c917d91 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -566,8 +566,6 @@ def bar(): {} {} """.format(line1, line2)), context) - # FIXME: when _disable_reflected_list becomes available - # return njit(context["bar"], _disable_reflected_list=True) return njit(context["bar"]) for line1, line2 in ( ("lst.append(None)", "lst.pop()"), From baee51e73bd243803e91bf79dbc5eb828c9429a3 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 29 Jan 2020 09:46:55 -0600 Subject: [PATCH 284/595] Fix README formatting --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 6d5da15ea4f..ee3d5e140e5 100644 --- a/README.rst +++ b/README.rst @@ -32,6 +32,7 @@ Supported Platforms - macOS: x86_64 * (Optional) Accelerators and GPUs: + * NVIDIA GPUs (Kepler architecture or later) via CUDA driver on Linux, Windows, macOS (< 10.14) * AMD GPUs via ROCm driver on Linux From 1d31bd6f1cb112fdb1fb367430e686090b03e670 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 29 Jan 2020 09:47:07 -0600 Subject: [PATCH 285/595] Add CI check of README.rst --- buildscripts/incremental/setup_conda_environment.sh | 2 +- buildscripts/incremental/test.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/buildscripts/incremental/setup_conda_environment.sh b/buildscripts/incremental/setup_conda_environment.sh index 12b85291b12..9fe9d605c32 100755 --- a/buildscripts/incremental/setup_conda_environment.sh +++ b/buildscripts/incremental/setup_conda_environment.sh @@ -84,7 +84,7 @@ if [ $PYTHON \< "3.4" ]; then $PIP_INSTALL singledispatch; fi if [ $PYTHON \< "3.3" ]; then $CONDA_INSTALL -c numba funcsigs; fi # Install dependencies for building the documentation if [ "$BUILD_DOC" == "yes" ]; then $CONDA_INSTALL sphinx pygments numpydoc; fi -if [ "$BUILD_DOC" == "yes" ]; then $PIP_INSTALL sphinx_bootstrap_theme; fi +if [ "$BUILD_DOC" == "yes" ]; then $PIP_INSTALL sphinx_bootstrap_theme rstcheck; fi # Install dependencies for code coverage (codecov.io) if [ "$RUN_COVERAGE" == "yes" ]; then $PIP_INSTALL codecov; fi # Install SVML diff --git a/buildscripts/incremental/test.sh b/buildscripts/incremental/test.sh index e955c54f8d3..f5c00f52cfc 100755 --- a/buildscripts/incremental/test.sh +++ b/buildscripts/incremental/test.sh @@ -5,6 +5,8 @@ source activate $CONDA_ENV # Make sure any error below is reported as such set -v -e +# Ensure the README is correctly formatted +if [ "$BUILD_DOC" == "yes" ]; then rstcheck README.rst; fi # Ensure that the documentation builds without warnings pushd docs if [ "$BUILD_DOC" == "yes" ]; then make SPHINXOPTS=-W clean html; fi From a73046e00115d876b0e8f2243696fba0030b5812 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 29 Jan 2020 16:04:50 -0600 Subject: [PATCH 286/595] Fix test on 32-bit avoid using high-bit --- numba/tests/test_extending.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 4c9355ba3a3..446be53f0cc 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -1456,7 +1456,7 @@ def setUp(self): def test_unboxer_basic(self): # Implements an unboxer on DynType that calls an intrinsic into the # unboxer code. - magic_token = 0xbeefcafe + magic_token = 0xcafe magic_offset = 123 @intrinsic From d4a859f8adabf38183046d68654f96573bd67ad6 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 29 Jan 2020 16:05:58 -0600 Subject: [PATCH 287/595] Better test name --- numba/tests/test_extending.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 446be53f0cc..9ea1e755228 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -1446,7 +1446,7 @@ def udt(x): self.check_error_no_nrt(udt, mydummy) -class TestUnboxer(TestCase): +class TestBoxingCallingJIT(TestCase): def setUp(self): super().setUp() many = base_dummy_type_factory('mydummy2') From ac4275847d737f7f246bb8b6301e23ee20f12fb3 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 29 Jan 2020 16:23:42 -0600 Subject: [PATCH 288/595] Adapt set hasher to use pyapi.call_jit_code --- numba/targets/setobj.py | 48 ++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/numba/targets/setobj.py b/numba/targets/setobj.py index 7d135d34478..389af693c6a 100644 --- a/numba/targets/setobj.py +++ b/numba/targets/setobj.py @@ -15,6 +15,7 @@ iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, for_iter, call_len, RefType) +from numba.extending import intrinsic from numba.utils import cached_property from . import quicksort, slicing @@ -68,6 +69,16 @@ def get_hash_value(context, builder, typ, value): fallback = ir.Constant(h.type, FALLBACK) return builder.select(is_ok, h, fallback) + +@intrinsic +def _get_hash_value_intrinsic(typingctx, value): + def impl(context, builder, typ, args): + return get_hash_value(context, builder, value, args[0]) + fnty = typingctx.resolve_value_type(hash) + sig = fnty.get_call_type(typingctx, (value,), {}) + return sig, impl + + def is_hash_empty(context, builder, h): """ Whether the hash value denotes an empty entry. @@ -490,39 +501,18 @@ def add_pyapi(self, pyapi, item, do_resize=True): def _pyapi_get_hash_value(self, pyapi, context, builder, item): """Python API compatible version of `get_hash_value()`. """ - def emit_wrapper(resty, argtypes): - # Because `get_hash_value()` could raise a nopython exception, - # we need to wrap it in a function that has nopython - # calling convention. - - fnty = context.call_conv.get_function_type(resty, argtypes) - mod = builder.module - fn = ir.Function( - mod, fnty, name=mod.get_unique_name('.set_hash_item'), - ) - fn.linkage = 'internal' - inner_builder = ir.IRBuilder(fn.append_basic_block()) - [inner_item] = context.call_conv.decode_arguments( - inner_builder, argtypes, fn, - ) - # Call get_hash_value() - h = get_hash_value( - context, inner_builder, self._ty.dtype, inner_item, - ) - context.call_conv.return_value(inner_builder, h) - return fn - argtypes = [self._ty.dtype] resty = types.intp - fn = emit_wrapper(resty, argtypes) - # Call wrapper function - status, retval = context.call_conv.call_function( - builder, fn, resty, argtypes, [item], - ) + + def wrapper(val): + return _get_hash_value_intrinsic(val) + + args = [item] + sig = typing.signature(resty, *argtypes) + is_error, retval = pyapi.call_jit_code(wrapper, sig, args) # Handle return status - with builder.if_then(builder.not_(status.is_ok), likely=False): + with builder.if_then(is_error, likely=False): # Raise nopython exception as a Python exception - context.call_conv.raise_error(builder, pyapi, status) builder.ret(pyapi.get_null_object()) return retval From 20bae75b2bdab2352cec975fd896c6dc5f274816 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 29 Jan 2020 16:51:37 -0600 Subject: [PATCH 289/595] Add doc string --- numba/pythonapi.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/numba/pythonapi.py b/numba/pythonapi.py index 43674349f34..421c8859ec9 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -1586,6 +1586,15 @@ def string_from_constant_string(self, string): def call_jit_code(self, func, sig, args): """Calls into Numba jitted code and propagate error using the Python calling convention. + + Parameters + ---------- + func : function + The Python function to be compiled. + sig : numba.typing.Signature + The function signature for *func*. + args : Sequence[llvmlite.binding.Value] + LLVM values to use as arguments. """ builder = self.builder cres = self.context.compile_subroutine(builder, func, sig) From 65e40b720a189d5da3013b52d077d0bd9e324b84 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 29 Jan 2020 16:54:04 -0600 Subject: [PATCH 290/595] More docstrings --- numba/pythonapi.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/numba/pythonapi.py b/numba/pythonapi.py index 421c8859ec9..c87c1dcea31 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -1595,6 +1595,12 @@ def call_jit_code(self, func, sig, args): The function signature for *func*. args : Sequence[llvmlite.binding.Value] LLVM values to use as arguments. + + Returns + ------- + (is_error, res) : 2-tuple of llvmlite.binding.Value. + is_error : true iff *func* raised a nopython exception. + res : Returned value from *func* if *is_error* is false. """ builder = self.builder cres = self.context.compile_subroutine(builder, func, sig) From 5adb06554bb3a9e6f1c99201c2f9289db5449ea3 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 30 Jan 2020 07:50:55 -0600 Subject: [PATCH 291/595] More docs/comments --- numba/pythonapi.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/numba/pythonapi.py b/numba/pythonapi.py index c87c1dcea31..b722e5d63cb 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -1590,7 +1590,8 @@ def call_jit_code(self, func, sig, args): Parameters ---------- func : function - The Python function to be compiled. + The Python function to be compiled. This function is compiled + in nopython-mode. sig : numba.typing.Signature The function signature for *func*. args : Sequence[llvmlite.binding.Value] @@ -1599,9 +1600,14 @@ def call_jit_code(self, func, sig, args): Returns ------- (is_error, res) : 2-tuple of llvmlite.binding.Value. - is_error : true iff *func* raised a nopython exception. - res : Returned value from *func* if *is_error* is false. + is_error : true iff *func* raised an exception. + res : Returned value from *func* iff *is_error* is false. + + If *is_error* is true, this method will adapt the nopython exception + into a Python exception. Caller should return NULL to Python to + indicate an error. """ + # Compile *func* builder = self.builder cres = self.context.compile_subroutine(builder, func, sig) got_retty = cres.signature.return_type @@ -1612,18 +1618,23 @@ def call_jit_code(self, func, sig, args): raise errors.LoweringError( f'mismatching signature {got_retty} != {retty}.\n' ) + # Call into *func* status, res = self.context.call_internal_no_propagate( builder, cres.fndesc, sig, args, ) + # Post-call handling for *func* is_error_ptr = cgutils.alloca_once(builder, cgutils.bool_t, zfill=True) res_type = self.context.get_value_type(sig.return_type) res_ptr = cgutils.alloca_once(builder, res_type, zfill=True) + # Handle error and adapt the nopython exception into cpython exception with builder.if_else(status.is_error) as (has_err, no_err): with has_err: builder.store(status.is_error, is_error_ptr) + # Set error state in the Python interpreter self.context.call_conv.raise_error(builder, self, status) with no_err: + # Handle returned value res = imputils.fix_returning_optional( self.context, builder, sig, status, res, ) From 5acc6ba267cccfcbc2152357eb4c7fc9dedc24c3 Mon Sep 17 00:00:00 2001 From: Marcin Tolysz Date: Fri, 31 Jan 2020 16:33:56 +0000 Subject: [PATCH 292/595] patch for https://github.com/numba/numba/issues/4739 Nothing fancy, do not allow dots. --- numba/pycc/cc.py | 4 +- .../nested/source_module.py | 18 +++++++++ .../setup_distutils_nested.py | 15 +++++++ .../setup_setuptools_nested.py | 15 +++++++ numba/tests/test_pycc.py | 39 +++++++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 numba/tests/pycc_distutils_usecase/nested/source_module.py create mode 100644 numba/tests/pycc_distutils_usecase/setup_distutils_nested.py create mode 100644 numba/tests/pycc_distutils_usecase/setup_setuptools_nested.py diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index 74e672316b9..e7bc31d1904 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -246,7 +246,7 @@ def distutils_extension(self, **kwargs): library_dirs = (kwargs.pop('library_dirs', []) + self._toolchain.get_python_library_dirs()) - ext = _CCExtension(name=self._basename, + ext = _CCExtension(name=self._source_module[:self._source_module.rfind('.')+1] + self._basename, sources=self._get_mixin_sources(), depends=depends, define_macros=macros, @@ -272,7 +272,7 @@ class _CCExtension(Extension): def _prepare_object_files(self, build_ext): cc = self._cc - dir_util.mkpath(build_ext.build_temp) + dir_util.mkpath(os.path.join(build_ext.build_temp, *self.name.split('.')[:-1])) objects, _ = cc._compile_object_files(build_ext.build_temp) # Add generated object files for linking self.extra_objects = objects diff --git a/numba/tests/pycc_distutils_usecase/nested/source_module.py b/numba/tests/pycc_distutils_usecase/nested/source_module.py new file mode 100644 index 00000000000..e5e6ea82f3b --- /dev/null +++ b/numba/tests/pycc_distutils_usecase/nested/source_module.py @@ -0,0 +1,18 @@ +import numpy as np + +from numba.pycc import CC + + +cc = CC('pycc_compiled_module') + +_const = 42 + +# This ones references a global variable at compile time +@cc.export('get_const', 'i8()') +def get_const(): + return _const + +# This one needs NRT and an environment +@cc.export('ones', 'f8[:](i4)') +def ones(n): + return np.ones(n) diff --git a/numba/tests/pycc_distutils_usecase/setup_distutils_nested.py b/numba/tests/pycc_distutils_usecase/setup_distutils_nested.py new file mode 100644 index 00000000000..a64de8bbc32 --- /dev/null +++ b/numba/tests/pycc_distutils_usecase/setup_distutils_nested.py @@ -0,0 +1,15 @@ +from distutils.core import setup + +from nested.source_module import cc + +from numba.pycc.platform import _patch_exec_command + + +def run_setup(): + # Avoid sporadic crashes on Windows due to MSVCRT spawnve() + _patch_exec_command() + setup(ext_modules=[cc.distutils_extension()]) + + +if __name__ == '__main__': + run_setup() diff --git a/numba/tests/pycc_distutils_usecase/setup_setuptools_nested.py b/numba/tests/pycc_distutils_usecase/setup_setuptools_nested.py new file mode 100644 index 00000000000..3ba6434fc61 --- /dev/null +++ b/numba/tests/pycc_distutils_usecase/setup_setuptools_nested.py @@ -0,0 +1,15 @@ +from setuptools import setup + +from nested.source_module import cc + +from numba.pycc.platform import _patch_exec_command + + +def run_setup(): + # Avoid sporadic crashes on Windows due to MSVCRT spawnve() + _patch_exec_command() + setup(ext_modules=[cc.distutils_extension()]) + + +if __name__ == '__main__': + run_setup() diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index f41afb5d7aa..293bbd52cc2 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -353,13 +353,52 @@ def run_python(args): """ run_python(["-c", code]) + def check_setup_nested_py(self, setup_py_file): + # Compute PYTHONPATH to ensure the child processes see this Numba + import numba + numba_path = os.path.abspath(os.path.dirname( + os.path.dirname(numba.__file__))) + env = dict(os.environ) + if env.get('PYTHONPATH', ''): + env['PYTHONPATH'] = numba_path + os.pathsep + env['PYTHONPATH'] + else: + env['PYTHONPATH'] = numba_path + + def run_python(args): + p = subprocess.Popen([sys.executable] + args, + cwd=self.usecase_dir, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + env=env) + out, _ = p.communicate() + rc = p.wait() + if rc != 0: + self.fail("python failed with the following output:\n%s" + % out.decode('utf-8', 'ignore')) + + run_python([setup_py_file, "build_ext", "--inplace"]) + code = """if 1: + import nested.pycc_compiled_module as lib + assert lib.get_const() == 42 + res = lib.ones(3) + assert list(res) == [1.0, 1.0, 1.0] + """ + run_python(["-c", code]) + def test_setup_py_distutils(self): self.check_setup_py("setup_distutils.py") + def test_setup_py_distutils_nested(self): + self.check_setup_nested_py("setup_distutils_nested.py") + @unittest.skipIf(setuptools is None, "test needs setuptools") def test_setup_py_setuptools(self): self.check_setup_py("setup_setuptools.py") + @unittest.skipIf(setuptools is None, "test needs setuptools") + def test_setup_py_setuptools_nested(self): + self.check_setup_nested_py("setup_setuptools_nested.py") + if __name__ == "__main__": unittest.main() From 52bdcd8412c66f79e5615144793b0776db77783d Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 31 Jan 2020 11:24:48 -0600 Subject: [PATCH 293/595] Normalize kws going into fold_arguments. CallConstrain may be passing list of 2-tuple for the dictionary --- numba/typing/templates.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/numba/typing/templates.py b/numba/typing/templates.py index f09dba50261..03893ded1eb 100644 --- a/numba/typing/templates.py +++ b/numba/typing/templates.py @@ -7,6 +7,7 @@ import inspect import os.path from collections import namedtuple +from collections.abc import Sequence from types import MethodType, FunctionType import numba @@ -147,6 +148,9 @@ def fold_arguments(pysig, args, kws, normal_handler, default_handler, - default_handler(index, param, default) is called for omitted arguments - stararg_handler(index, param, values) is called for a "*args" argument """ + if isinstance(kws, Sequence): + # Normalize dict kws + kws = dict(kws) # deal with kwonly args params = pysig.parameters From 60305ce6f1f012d7236cfcdbac33bae7b8c1442f Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 31 Jan 2020 13:34:45 -0600 Subject: [PATCH 294/595] Add unittest for fold_arguments --- numba/tests/test_typeinfer.py | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index 3b6ae2f0cc0..38e20e871e5 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -6,6 +6,7 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated from numba import types, typeinfer, typing, jit, errors +from numba import utils from numba.typeconv import Conversion from .support import TestCase, tag @@ -678,5 +679,60 @@ def test_issue_1394(self): self.assertEqual(res, pyfunc(v)) +class TestFoldArguments(unittest.TestCase): + def check_fold_arguments_list_inputs(self, func, args, kws): + def make_tuple(*args): + return args + + unused_handler = None + + pysig = utils.pysignature(func) + names = list(pysig.parameters) + + with self.subTest(kind='dict'): + folded_dict = typing.fold_arguments( + pysig, args, kws, make_tuple, unused_handler, unused_handler, + ) + # correct ordering + for i, (j, k) in enumerate(zip(folded_dict, names)): + (got_index, got_param, got_name) = j + self.assertEqual(got_index, i) + self.assertEqual(got_name, f'arg.{k}') + + kws = list(kws.items()) + with self.subTest(kind='list'): + folded_list = typing.fold_arguments( + pysig, args, kws, make_tuple, unused_handler, unused_handler, + ) + self.assertEqual(folded_list, folded_dict) + + def test_fold_arguments_list_inputs(self): + cases = [ + dict( + func=lambda a, b, c, d: None, + args=['arg.a', 'arg.b'], + kws=dict(c='arg.c', d='arg.d') + ), + dict( + func=lambda: None, + args=[], + kws=dict(), + ), + dict( + func=lambda a: None, + args=['arg.a'], + kws={}, + ), + dict( + func=lambda a: None, + args=[], + kws=dict(a='arg.a'), + ), + ] + for case in cases: + with self.subTest(**case): + self.check_fold_arguments_list_inputs(**case) + + if __name__ == '__main__': unittest.main() From e29fbcb37ec2254c28cf6f2f2e2ef4a3c7a4fe44 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Sat, 1 Feb 2020 02:19:26 -0500 Subject: [PATCH 295/595] Add JAX --- docs/source/cuda/cuda_array_interface.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/cuda/cuda_array_interface.rst b/docs/source/cuda/cuda_array_interface.rst index f505b232e6a..dfa345a8966 100644 --- a/docs/source/cuda/cuda_array_interface.rst +++ b/docs/source/cuda/cuda_array_interface.rst @@ -113,6 +113,7 @@ The following Python libraries have adopted the CUDA Array Interface: - `PyArrow `_ - `mpi4py `_ - `ArrayViews `_ +- `JAX `_ - The RAPIDS stack: - `cuDF `_ - `cuML `_ From 1d4369b479606f849e21d77758c21cdd63ca8621 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Sun, 2 Feb 2020 20:52:50 +0100 Subject: [PATCH 296/595] added after-inference rewrite and typing of getitem --- numba/rewrites/static_getitem.py | 45 +++++++++++++++++++++++++++++++- numba/targets/arrayobj.py | 9 +++++++ numba/typing/arraydecl.py | 11 ++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/numba/rewrites/static_getitem.py b/numba/rewrites/static_getitem.py index 6a8eefc6938..169d9779ba8 100644 --- a/numba/rewrites/static_getitem.py +++ b/numba/rewrites/static_getitem.py @@ -1,4 +1,4 @@ -from numba import ir, errors +from numba import ir, errors, types from . import register_rewrite, Rewrite @@ -46,6 +46,49 @@ def apply(self): return new_block +@register_rewrite('after-inference') +class RewriteConstGetitemsAfterInf(Rewrite): + """ + Rewrite IR expressions of the kind `getitem(value=arr, index=$constXX)` + where `$constXX` is a known constant as + `static_getitem(value=arr, index=)`. + """ + + def match(self, func_ir, block, typemap, calltypes): + self.getitems = getitems = {} + self.block = block + # Detect all getitem expressions and find which ones can be + # rewritten + for expr in block.find_exprs(op='getitem'): + if expr.op == 'getitem': + if isinstance(typemap[expr.index.name], + types.StringLiteral): + getitems[expr] = (expr.index, + typemap[expr.index.name].literal_value) + + return len(getitems) > 0 + + def apply(self): + """ + Rewrite all matching getitems as static_getitems. + """ + new_block = self.block.copy() + new_block.clear() + for inst in self.block.body: + if isinstance(inst, ir.Assign): + expr = inst.value + if expr in self.getitems: + const, lit_val = self.getitems[expr] + new_expr = ir.Expr.static_getitem(value=expr.value, + index=lit_val, + index_var=expr.index, + loc=expr.loc) + inst = ir.Assign(value=new_expr, target=inst.target, + loc=inst.loc) + new_block.append(inst) + return new_block + + @register_rewrite('before-inference') class RewriteConstSetitems(Rewrite): """ diff --git a/numba/targets/arrayobj.py b/numba/targets/arrayobj.py index c1dc5555732..da056009e6e 100644 --- a/numba/targets/arrayobj.py +++ b/numba/targets/arrayobj.py @@ -2409,6 +2409,15 @@ def record_getitem(context, builder, sig, args): return impl(context, builder, sig.args[0], args[0], args[1]) +# @lower_builtin(operator.getitem, types.Record, types.StringLiteral) +# def record_getitem(context, builder, sig, args): +# """ +# Record.__getitem__ redirects to getattr() +# """ +# impl = context.get_getattr(sig.args[0], args[1]) +# return impl(context, builder, sig.args[0], args[0], args[1]) + + @lower_builtin('static_setitem', types.Record, types.StringLiteral, types.Any) def record_setitem(context, builder, sig, args): """ diff --git a/numba/typing/arraydecl.py b/numba/typing/arraydecl.py index e43548c4b4f..646532c287c 100644 --- a/numba/typing/arraydecl.py +++ b/numba/typing/arraydecl.py @@ -544,6 +544,17 @@ def generic(self, args, kws): assert ret return signature(ret, *args) + +@infer_global(operator.getitem) +class GetItemRecord(AbstractTemplate): + def generic(self, args, kws): + # Resolution of members for records + record, idx = args + if isinstance(record, types.Record) and isinstance(idx, types.StringLiteral): + ret = record.typeof(idx.literal_value) + assert ret + return signature(ret, *args) + @infer class StaticSetItemRecord(AbstractTemplate): key = "static_setitem" From e27edf409ab727f2603acd59127a01eff09c408a Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Sun, 2 Feb 2020 21:10:16 +0100 Subject: [PATCH 297/595] updates docstring --- numba/rewrites/static_getitem.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/numba/rewrites/static_getitem.py b/numba/rewrites/static_getitem.py index 169d9779ba8..857a3b47db1 100644 --- a/numba/rewrites/static_getitem.py +++ b/numba/rewrites/static_getitem.py @@ -47,11 +47,11 @@ def apply(self): @register_rewrite('after-inference') -class RewriteConstGetitemsAfterInf(Rewrite): +class RewriteLiteralGetitems(Rewrite): """ - Rewrite IR expressions of the kind `getitem(value=arr, index=$constXX)` - where `$constXX` is a known constant as - `static_getitem(value=arr, index=)`. + Rewrite IR expressions of the kind `getitem(value=arr, index=$XX)` + where `$XX` is a Literal value as + `static_getitem(value=arr, index=)`. """ def match(self, func_ir, block, typemap, calltypes): @@ -61,10 +61,9 @@ def match(self, func_ir, block, typemap, calltypes): # rewritten for expr in block.find_exprs(op='getitem'): if expr.op == 'getitem': - if isinstance(typemap[expr.index.name], - types.StringLiteral): - getitems[expr] = (expr.index, - typemap[expr.index.name].literal_value) + if isinstance(typemap[expr.index.name], types.StringLiteral): + literal_value = typemap[expr.index.name].literal_value + getitems[expr] = (expr.index, literal_value) return len(getitems) > 0 From 30ff74c190cc5dd3b9204ccda23bcbd350673531 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Sun, 2 Feb 2020 22:47:33 +0100 Subject: [PATCH 298/595] added tests --- numba/tests/test_record_dtype.py | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index d628fd72e72..50181ee56e1 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -2,7 +2,7 @@ import numpy as np import ctypes -from numba import jit, numpy_support, types +from numba import jit, numpy_support, types, literal_unroll, njit from numba import unittest_support as unittest from numba.compiler import compile_isolated from numba.itanium_mangler import mangle_type @@ -249,6 +249,20 @@ def get_charseq_tuple(ary, i): return ary[i].m, ary[i].n +def get_field1(rec): + fs = ('e', 'f') + f = fs[1] + return rec[f] + + +def get_field2(rec): + fs = ('e', 'f') + out = 0 + for f in literal_unroll(fs): + out += rec[f] + return out + + recordtype = np.dtype([('a', np.float64), ('b', np.int16), ('c', np.complex64), @@ -978,5 +992,22 @@ def test_return_charseq_tuple(self): self.assertEqual(expected, got) +class TestRecordArrayGetItem(unittest.TestCase): + """ + Test getitem when index is Literal[str] + """ + def test_literal_variable(self): + arr = np.array([1, 2], dtype=recordtype2) + pyfunc = get_field1 + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) + + def test_literal_unroll(self): + arr = np.array([1, 2], dtype=recordtype2) + pyfunc = get_field2 + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) + + if __name__ == '__main__': unittest.main() From 89ac6220d870ed06ceb708cadcafbe756e101fd6 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 3 Feb 2020 10:06:56 +0100 Subject: [PATCH 299/595] pass 'inline' explicitly to overload Since `@register_jitable` doesn't have 'inline' as an explicit keyword, but `@overload` does, we need to pop the keword argument from `kwargs` and hand it over explicity. --- numba/extending.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numba/extending.py b/numba/extending.py index 5a33ba322a1..bbaffef34d3 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -137,7 +137,8 @@ def foo(x, y): """ def wrap(fn): # It is just a wrapper for @overload - @overload(fn, jit_options=kwargs, strict=False) + inline = kwargs.pop('inline', 'never') + @overload(fn, jit_options=kwargs, inline=inline, strict=False) def ov_wrap(*args, **kwargs): return fn return fn From 2adc1dc5137d35fbd692a5327193bdad8162ced4 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Tue, 28 Jan 2020 11:28:37 +0100 Subject: [PATCH 300/595] extract code-gen utilities from closures This is just a refactoring of codegen utilities for the typed list. Some of these codegen functions will be used later on when unboxing into a typed-list. No functional changes were made, so no tests needed updating. --- numba/listobject.py | 182 +++++++++++++++++++++++++------------------- 1 file changed, 104 insertions(+), 78 deletions(-) diff --git a/numba/listobject.py b/numba/listobject.py index 8933a722689..10ff4a7742a 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -86,13 +86,23 @@ class ListStatus(IntEnum): LIST_ERR_ITER_EXHAUSTED = -4 -def _raise_if_error(context, builder, status, msg): - """Raise an internal error depending on the value of *status* +class ErrorHandler(object): + """ErrorHandler for calling codegen functions from this file. + + Stores the state needed to raise an exception from nopython mode. """ - ok_status = status.type(int(ListStatus.LIST_OK)) - with builder.if_then(builder.icmp_signed('!=', status, ok_status), - likely=True): - context.call_conv.return_user_exc(builder, RuntimeError, (msg,)) + + def __init__(self, context): + self.context = context + + def __call__(self, builder, status, msg): + ok_status = status.type(int(ListStatus.LIST_OK)) + with builder.if_then(builder.icmp_signed('!=', status, ok_status), + likely=True): + self.context.call_conv.return_user_exc( + builder, RuntimeError, (msg,)) + + def _check_for_none_typed(lst, method): @@ -157,6 +167,42 @@ def codegen(context, builder, sig, args): return sig, codegen +def _list_codegen_set_method_table(context, builder, lp, itemty): + vtablety = ir.LiteralStructType([ + ll_voidptr_type, # item incref + ll_voidptr_type, # item decref + ]) + setmethod_fnty = ir.FunctionType( + ir.VoidType(), + [ll_list_type, vtablety.as_pointer()] + ) + + setmethod_fn = builder.module.get_or_insert_function( + setmethod_fnty, + name='numba_list_set_method_table') + vtable = cgutils.alloca_once(builder, vtablety, zfill=True) + + # install item incref/decref + item_incref_ptr = cgutils.gep_inbounds(builder, vtable, 0, 0) + item_decref_ptr = cgutils.gep_inbounds(builder, vtable, 0, 1) + + dm_item = context.data_model_manager[itemty] + if dm_item.contains_nrt_meminfo(): + item_incref, item_decref = _get_incref_decref( + context, builder.module, dm_item, "list" + ) + builder.store( + builder.bitcast(item_incref, item_incref_ptr.type.pointee), + item_incref_ptr, + ) + builder.store( + builder.bitcast(item_decref, item_decref_ptr.type.pointee), + item_decref_ptr, + ) + + builder.call(setmethod_fn, [lp, vtable]) + + @intrinsic def _list_set_method_table(typingctx, lp, itemty): """Wrap numba_list_set_method_table @@ -165,41 +211,8 @@ def _list_set_method_table(typingctx, lp, itemty): sig = resty(lp, itemty) def codegen(context, builder, sig, args): - vtablety = ir.LiteralStructType([ - ll_voidptr_type, # item incref - ll_voidptr_type, # item decref - ]) - setmethod_fnty = ir.FunctionType( - ir.VoidType(), - [ll_list_type, vtablety.as_pointer()] - ) - setmethod_fn = ir.Function( - builder.module, - setmethod_fnty, - name='numba_list_set_method_table', - ) - dp = args[0] - vtable = cgutils.alloca_once(builder, vtablety, zfill=True) - - # install item incref/decref - item_incref_ptr = cgutils.gep_inbounds(builder, vtable, 0, 0) - item_decref_ptr = cgutils.gep_inbounds(builder, vtable, 0, 1) - - dm_item = context.data_model_manager[itemty.instance_type] - if dm_item.contains_nrt_meminfo(): - item_incref, item_decref = _get_incref_decref( - context, builder.module, dm_item, "list" - ) - builder.store( - builder.bitcast(item_incref, item_incref_ptr.type.pointee), - item_incref_ptr, - ) - builder.store( - builder.bitcast(item_decref, item_decref_ptr.type.pointee), - item_decref_ptr, - ) - - builder.call(setmethod_fn, [dp, vtable]) + _list_codegen_set_method_table( + context, builder, args[0], itemty.instance_type) return sig, codegen @@ -265,6 +278,23 @@ def new_list(item, allocated=0): return list() +def _add_meminfo(context, builder, lstruct): + alloc_size = context.get_abi_sizeof( + context.get_value_type(types.voidptr), + ) + dtor = _imp_dtor(context, builder.module) + meminfo = context.nrt.meminfo_alloc_dtor( + builder, + context.get_constant(types.uintp, alloc_size), + dtor, + ) + + data_pointer = context.nrt.meminfo_data(builder, meminfo) + data_pointer = builder.bitcast(data_pointer, ll_list_type.as_pointer()) + builder.store(lstruct.data, data_pointer) + lstruct.meminfo = meminfo + + @intrinsic def _make_list(typingctx, itemty, ptr): """Make a list struct with the given *ptr* @@ -279,33 +309,41 @@ def _make_list(typingctx, itemty, ptr): list_ty = types.ListType(itemty.instance_type) def codegen(context, builder, signature, args): - [_, ptr] = args + ptr = args[1] ctor = cgutils.create_struct_proxy(list_ty) lstruct = ctor(context, builder) lstruct.data = ptr - - alloc_size = context.get_abi_sizeof( - context.get_value_type(types.voidptr), - ) - dtor = _imp_dtor(context, builder.module) - meminfo = context.nrt.meminfo_alloc_dtor( - builder, - context.get_constant(types.uintp, alloc_size), - dtor, - ) - - data_pointer = context.nrt.meminfo_data(builder, meminfo) - data_pointer = builder.bitcast(data_pointer, ll_list_type.as_pointer()) - builder.store(ptr, data_pointer) - - lstruct.meminfo = meminfo - + _add_meminfo(context, builder, lstruct) return lstruct._getvalue() sig = list_ty(itemty, ptr) return sig, codegen +def _list_new_codegen(context, builder, itemty, new_size, error_handler): + fnty = ir.FunctionType( + ll_status, + [ll_list_type.as_pointer(), ll_ssize_t, ll_ssize_t], + ) + fn = builder.module.get_or_insert_function(fnty, name='numba_list_new') + # Determine sizeof item types + ll_item = context.get_data_type(itemty) + sz_item = context.get_abi_sizeof(ll_item) + reflp = cgutils.alloca_once(builder, ll_list_type, zfill=True) + status = builder.call( + fn, + [reflp, ll_ssize_t(sz_item), new_size], + ) + msg = "Failed to allocate list" + error_handler( + builder, + status, + msg, + ) + lp = builder.load(reflp) + return lp + + @intrinsic def _list_new(typingctx, itemty, allocated): """Wrap numba_list_new. @@ -324,25 +362,13 @@ def _list_new(typingctx, itemty, allocated): sig = resty(itemty, allocated) def codegen(context, builder, sig, args): - fnty = ir.FunctionType( - ll_status, - [ll_list_type.as_pointer(), ll_ssize_t, ll_ssize_t], - ) - fn = builder.module.get_or_insert_function(fnty, name='numba_list_new') - # Determine sizeof item types - ll_item = context.get_data_type(itemty.instance_type) - sz_item = context.get_abi_sizeof(ll_item) - reflp = cgutils.alloca_once(builder, ll_list_type, zfill=True) - status = builder.call( - fn, - [reflp, ll_ssize_t(sz_item), args[1]], - ) - _raise_if_error( - context, builder, status, - msg="Failed to allocate list", - ) - lp = builder.load(reflp) - return lp + error_handler = ErrorHandler(context) + return _list_new_codegen(context, + builder, + itemty.instance_type, + args[1], + error_handler, + ) return sig, codegen From 400b58e321816f46076f65b82ab312e78c62b118 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 3 Feb 2020 11:58:16 +0100 Subject: [PATCH 301/595] flake8: too many blank lines --- numba/listobject.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/numba/listobject.py b/numba/listobject.py index 10ff4a7742a..96fb2f141c5 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -103,8 +103,6 @@ def __call__(self, builder, status, msg): builder, RuntimeError, (msg,)) - - def _check_for_none_typed(lst, method): if isinstance(lst.dtype, NoneType): raise TypingError("method support for List[None] is limited, " From f380fe44cfbda612e8637456886bb44c9536421c Mon Sep 17 00:00:00 2001 From: Marcin Tolysz Date: Mon, 3 Feb 2020 11:13:53 +0000 Subject: [PATCH 302/595] improving readability --- numba/pycc/cc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index e7bc31d1904..b24d9fafe56 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -245,8 +245,9 @@ def distutils_extension(self, **kwargs): + self._toolchain.get_python_libraries()) library_dirs = (kwargs.pop('library_dirs', []) + self._toolchain.get_python_library_dirs()) + python_package_path = self._source_module[:self._source_module.rfind('.')+1] - ext = _CCExtension(name=self._source_module[:self._source_module.rfind('.')+1] + self._basename, + ext = _CCExtension(name=python_package_path + self._basename, sources=self._get_mixin_sources(), depends=depends, define_macros=macros, From 61eecf7855be4a8e171c54bb11a5d46b11ba4552 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 3 Feb 2020 21:42:25 +0800 Subject: [PATCH 303/595] Apply suggestions from code review Co-Authored-By: Valentin Haenel --- docs/source/cuda/cuda_array_interface.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/source/cuda/cuda_array_interface.rst b/docs/source/cuda/cuda_array_interface.rst index dfa345a8966..703e6c418f7 100644 --- a/docs/source/cuda/cuda_array_interface.rst +++ b/docs/source/cuda/cuda_array_interface.rst @@ -25,19 +25,19 @@ that must contain the following entries: - **shape**: ``(integer, ...)`` - A tuple of `int` (or `long`) representing the size of each dimension. + A tuple of ``int`` (or ``long``) representing the size of each dimension. -- **typestr**: `str` +- **typestr**: ``str`` - The type string. This has the same definition as *typestr* in the + The type string. This has the same definition as ``typestr`` in the `numpy array interface`_. -- **data**: `(integer, boolean)` +- **data**: ``(integer, boolean)`` The **data** is a 2-tuple. The first element is the data pointer - as a Python `int` (or `long`). The data must be device-accessible. - For zero-size arrays, use `0` here. - The second element is the read-only flag as a Python `bool`. + as a Python ``int`` (or ``long``). The data must be device-accessible. + For zero-size arrays, use ``0`` here. + The second element is the read-only flag as a Python ``bool``. Because the user of the interface may or may not be in the same context, the most common case is to use ``cuPointerGetAttribute`` with @@ -45,7 +45,7 @@ that must contain the following entries: equivalent CUDA Runtime API) to retrieve a device pointer that is usable in the currently active context. -- **version**: `integer` +- **version**: ``integer`` An integer for the version of the interface being exported. The current version is *2*. @@ -56,7 +56,7 @@ The following are optional entries: - **strides**: ``None`` or ``(integer, ...)`` If **strides** is not given, or it is ``None``, the array is in - C-contiguous layout. Otherwise, a tuple of `int` (or `long`) is explicitly + C-contiguous layout. Otherwise, a tuple of ``int`` (or ``long``) is explicitly given for representing the number of bytes to skip to access the next element at each dimension. @@ -69,11 +69,11 @@ The following are optional entries: If ``None`` then all values in **data** are valid. All elements of the mask array should be interpreted only as true or not true indicating which - elements of this array are valid. This has the same definition as *mask* + elements of this array are valid. This has the same definition as ``mask`` in the `numpy array interface`_. .. note:: Numba does not currently support working with masked CUDA arrays - and will raise a `NotImplementedError` exception if one is passed + and will raise a ``NotImplementedError`` exception if one is passed to a GPU function. Additional information about the data pointer can be retrieved using From 062421dae7fa276e2aead36070780227f6424c18 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 3 Feb 2020 14:50:21 +0100 Subject: [PATCH 304/595] remove duplicate 'test' in comment As title. --- numba/tests/test_ir_inlining.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index fe70d4658ee..a0633c7e994 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -44,7 +44,7 @@ def define_pipelines(self): return [pipeline] -# this global has the same name as the the global in inlining_usecases.py, it +# this global has the same name as the global in inlining_usecases.py, it # is here to check that inlined functions bind to their own globals _GLOBAL1 = -50 From 807301364b2def8393330f2b548857bf1f06cd00 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 3 Feb 2020 15:31:45 +0100 Subject: [PATCH 305/595] adding test As title. --- numba/tests/test_ir_inlining.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index a0633c7e994..c12fd8997ed 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -16,6 +16,7 @@ typeof_impl, unbox, NativeValue, + register_jitable, ) from numba.datamodel.models import OpaqueModel from numba.targets.cpu import InlineOptions @@ -456,6 +457,20 @@ def bar(x): 'fortran': True}, block_count=37) +class TestRegisterJitableInlining(InliningBase): + + def test_register_jitable_inlines(self): + + @register_jitable(inline='always') + def foo(): + return 1 + + def impl(): + foo() + + self.check(impl, inline_expect={'foo': True}) + + class TestOverloadInlining(InliningBase): def test_basic_inline_never(self): From 704c5402b7bff014c92f5cccecb1ab2d5f7659ec Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 3 Feb 2020 18:57:24 -0600 Subject: [PATCH 306/595] Fix CI failure due to missing files when installed --- numba/tests/pycc_distutils_usecase/__init__.py | 0 numba/tests/pycc_distutils_usecase/nested/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/tests/pycc_distutils_usecase/__init__.py create mode 100644 numba/tests/pycc_distutils_usecase/nested/__init__.py diff --git a/numba/tests/pycc_distutils_usecase/__init__.py b/numba/tests/pycc_distutils_usecase/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/numba/tests/pycc_distutils_usecase/nested/__init__.py b/numba/tests/pycc_distutils_usecase/nested/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From b0c408c6bbae36aa5692b1daf23e9d78162cd01e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 28 Jan 2020 15:02:00 +0000 Subject: [PATCH 307/595] Moved linalg, created np and misc --- numba/ir_utils.py | 2 +- numba/misc/__init__.py | 0 numba/{targets => misc}/mergesort.py | 0 numba/{targets => misc}/quicksort.py | 0 numba/np/__init__.py | 0 numba/{targets => np}/arrayobj.py | 3 ++- numba/{targets => np}/linalg.py | 0 numba/{targets => np}/slicing.py | 6 +++--- numba/targets/arraymath.py | 4 ++-- numba/targets/base.py | 9 ++++++--- numba/targets/cffiimpl.py | 2 +- numba/targets/listobj.py | 3 ++- numba/targets/npyimpl.py | 3 ++- numba/targets/rangeobj.py | 2 +- numba/targets/setobj.py | 3 ++- numba/unicode.py | 2 +- 16 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 numba/misc/__init__.py rename numba/{targets => misc}/mergesort.py (100%) rename numba/{targets => misc}/quicksort.py (100%) create mode 100644 numba/np/__init__.py rename numba/{targets => np}/arrayobj.py (99%) rename numba/{targets => np}/linalg.py (100%) rename numba/{targets => np}/slicing.py (97%) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 612a985975b..199f822ae68 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -665,7 +665,7 @@ def has_no_side_effect(rhs, lives, call_table): call_list[0]._name == 'unsafe_empty_inferred')): return True from numba.targets.registry import CPUDispatcher - from numba.targets.linalg import dot_3_mv_check_args + from numba.np.linalg import dot_3_mv_check_args if isinstance(call_list[0], CPUDispatcher): py_func = call_list[0].py_func if py_func == dot_3_mv_check_args: diff --git a/numba/misc/__init__.py b/numba/misc/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/numba/targets/mergesort.py b/numba/misc/mergesort.py similarity index 100% rename from numba/targets/mergesort.py rename to numba/misc/mergesort.py diff --git a/numba/targets/quicksort.py b/numba/misc/quicksort.py similarity index 100% rename from numba/targets/quicksort.py rename to numba/misc/quicksort.py diff --git a/numba/np/__init__.py b/numba/np/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/numba/targets/arrayobj.py b/numba/np/arrayobj.py similarity index 99% rename from numba/targets/arrayobj.py rename to numba/np/arrayobj.py index c1dc5555732..f8a3557a762 100644 --- a/numba/targets/arrayobj.py +++ b/numba/np/arrayobj.py @@ -27,7 +27,8 @@ RefType) from numba.typing import signature from numba.extending import register_jitable, overload, overload_method -from . import quicksort, mergesort, slicing +from numba.misc import quicksort, mergesort +from numba.np import slicing def set_range_metadata(builder, load, lower_bound, upper_bound): diff --git a/numba/targets/linalg.py b/numba/np/linalg.py similarity index 100% rename from numba/targets/linalg.py rename to numba/np/linalg.py diff --git a/numba/targets/slicing.py b/numba/np/slicing.py similarity index 97% rename from numba/targets/slicing.py rename to numba/np/slicing.py index 26f2edb8e7f..12372687f7a 100644 --- a/numba/targets/slicing.py +++ b/numba/np/slicing.py @@ -7,9 +7,9 @@ from llvmlite import ir from numba import cgutils, types, typing, utils -from .imputils import (lower_builtin, lower_getattr, - iternext_impl, impl_ret_borrowed, - impl_ret_new_ref, impl_ret_untracked) +from numba.targets.imputils import (lower_builtin, lower_getattr, + iternext_impl, impl_ret_borrowed, + impl_ret_new_ref, impl_ret_untracked) def fix_index(builder, idx, size): diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 7bcec33b689..46391486dd0 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -20,8 +20,8 @@ from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) from numba.typing import signature -from .arrayobj import make_array, load_item, store_item, _empty_nd_impl -from .linalg import ensure_blas +from numba.np.arrayobj import make_array, load_item, store_item, _empty_nd_impl +from numba.np.linalg import ensure_blas from numba.extending import intrinsic from numba.errors import RequireLiteralValue, TypingError diff --git a/numba/targets/base.py b/numba/targets/base.py index bb1a25e110c..7a4202cad4b 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -16,7 +16,8 @@ from numba import _dynfunc, _helperlib from numba.compiler_lock import global_compiler_lock from numba.pythonapi import PythonAPI -from . import arrayobj, builtins, imputils +from numba.np import arrayobj +from . import builtins, imputils from .imputils import (user_function, user_generator, builtin_registry, impl_ret_borrowed, RegistryLoader) @@ -268,9 +269,11 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from . import (arraymath, enumimpl, iterators, linalg, numbers, - optional, polynomial, rangeobj, slicing, tupleobj, + from . import (arraymath, enumimpl, iterators, numbers, + optional, polynomial, rangeobj, tupleobj, gdb_hook, hashing, heapq, literal) + from numba.np import slicing, linalg + try: from . import npdatetime except NotImplementedError: diff --git a/numba/targets/cffiimpl.py b/numba/targets/cffiimpl.py index 48cc8155f5d..8277b9b85e7 100644 --- a/numba/targets/cffiimpl.py +++ b/numba/targets/cffiimpl.py @@ -5,7 +5,7 @@ from numba.targets.imputils import Registry from numba import types -from . import arrayobj +from numba.np import arrayobj registry = Registry() diff --git a/numba/targets/listobj.py b/numba/targets/listobj.py index 98a5c2debcc..57f66102deb 100644 --- a/numba/targets/listobj.py +++ b/numba/targets/listobj.py @@ -14,7 +14,8 @@ RefType) from numba.extending import overload_method, overload from numba.utils import cached_property -from . import quicksort, slicing +from numba.misc import quicksort +from numba.np import slicing def get_list_payload(context, builder, list_type, value): diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index f70312c9886..b1630900c23 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -13,7 +13,8 @@ import numpy as np import operator -from . import builtins, callconv, ufunc_db, arrayobj +from . import builtins, callconv, ufunc_db +from numba.np import arrayobj from .imputils import Registry, impl_ret_new_ref, force_error_model from .. import typing, types, cgutils, numpy_support, utils from ..numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype diff --git a/numba/targets/rangeobj.py b/numba/targets/rangeobj.py index 5af4575f39f..8b2a9f7dd03 100644 --- a/numba/targets/rangeobj.py +++ b/numba/targets/rangeobj.py @@ -8,7 +8,7 @@ from numba import types, cgutils, prange from .listobj import ListIterInstance -from .arrayobj import make_array +from numba.np.arrayobj import make_array from .imputils import (lower_builtin, lower_cast, iterator_impl, impl_ret_untracked) from numba.typing import signature diff --git a/numba/targets/setobj.py b/numba/targets/setobj.py index 2a2b6729f72..788bc6ddeb0 100644 --- a/numba/targets/setobj.py +++ b/numba/targets/setobj.py @@ -15,7 +15,8 @@ impl_ret_new_ref, impl_ret_untracked, for_iter, call_len, RefType) from numba.utils import cached_property -from . import quicksort, slicing +from numba.misc import quicksort +from numba.np import slicing def get_payload_struct(context, builder, set_type, ptr): diff --git a/numba/unicode.py b/numba/unicode.py index 9ad867c1c68..b0d50abf3b2 100644 --- a/numba/unicode.py +++ b/numba/unicode.py @@ -26,7 +26,7 @@ PY_UNICODE_4BYTE_KIND, PY_UNICODE_WCHAR_KIND, ) -from numba.targets import slicing +from numba.np import slicing from numba._helperlib import c_helpers from numba.targets.hashing import _Py_hash_t from numba.unsafe.bytes import memcpy_region From 37671fd3b6bb665ffc61a4c1eb64580bf7abd159 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 28 Jan 2020 17:46:24 +0000 Subject: [PATCH 308/595] massive churn, some stuff working --- numba/__init__.py | 11 ++--- numba/array_analysis.py | 5 ++- numba/bytecode.py | 2 +- numba/byteflow.py | 4 +- numba/caching.py | 8 ++-- numba/cgutils.py | 3 +- numba/compiler.py | 8 ++-- numba/compiler_machinery.py | 8 ++-- numba/consts.py | 4 +- numba/controlflow.py | 4 +- numba/{ => core}/errors.py | 2 +- numba/{np => core}/slicing.py | 3 +- numba/{ => core}/typeconv/__init__.py | 0 numba/{ => core}/typeconv/_typeconv.cpp | 0 numba/{ => core}/typeconv/castgraph.py | 0 numba/{ => core}/typeconv/rules.py | 0 numba/{ => core}/typeconv/test.cpp | 0 numba/{ => core}/typeconv/typeconv.cpp | 0 numba/{ => core}/typeconv/typeconv.hpp | 0 numba/{ => core}/typeconv/typeconv.py | 0 numba/{ => core}/types/__init__.py | 2 +- numba/{ => core}/types/abstract.py | 3 +- numba/{ => core}/types/common.py | 0 numba/{ => core}/types/containers.py | 0 numba/{ => core}/types/functions.py | 2 +- numba/{ => core}/types/iterators.py | 0 numba/{ => core}/types/misc.py | 0 numba/{ => core}/types/npytypes.py | 0 numba/{ => core}/types/scalars.py | 5 ++- numba/{ => core}/typing/__init__.py | 0 numba/{ => core}/typing/arraydecl.py | 12 +++--- numba/{ => core}/typing/bufproto.py | 0 numba/{ => core}/typing/builtins.py | 13 +++--- numba/{ => core}/typing/cffi_utils.py | 6 +-- numba/{ => core}/typing/cmathdecl.py | 4 +- numba/{ => core}/typing/collections.py | 0 numba/{ => core}/typing/context.py | 6 +-- numba/{ => core}/typing/ctypes_utils.py | 0 numba/{ => core}/typing/dictdecl.py | 0 numba/{ => core}/typing/enumdecl.py | 6 +-- numba/{ => core}/typing/listdecl.py | 0 numba/{ => core}/typing/mathdecl.py | 6 +-- numba/{ => core}/typing/npdatetime.py | 9 +++-- numba/{ => core}/typing/npydecl.py | 11 ++--- numba/{ => core}/typing/randomdecl.py | 4 +- numba/{ => core}/typing/setdecl.py | 0 numba/{ => core}/typing/templates.py | 6 +-- numba/{ => core}/typing/typeof.py | 4 +- numba/{ => core}/utils.py | 0 numba/cuda/args.py | 4 +- numba/cuda/codegen.py | 2 +- numba/cuda/compiler.py | 5 ++- numba/cuda/cudadrv/driver.py | 5 ++- numba/cuda/simulator/kernel.py | 2 +- numba/cuda/stubs.py | 3 +- numba/cuda/target.py | 7 ++-- numba/dataflow.py | 6 +-- numba/debuginfo.py | 2 +- numba/decorators.py | 8 ++-- numba/dictobject.py | 6 +-- numba/dispatcher.py | 15 +++---- numba/extending.py | 37 +++++++++-------- numba/funcdesc.py | 5 ++- numba/inline_closurecall.py | 4 +- numba/interpreter.py | 7 ++-- numba/ir.py | 7 ++-- numba/ir_utils.py | 12 +++--- numba/itanium_mangler.py | 2 +- numba/jitclass/base.py | 8 ++-- numba/listobject.py | 6 +-- numba/lowering.py | 7 ++-- numba/np/arrayobj.py | 6 +-- numba/np/linalg.py | 6 +-- numba/npyufunc/array_exprs.py | 7 ++-- numba/npyufunc/dufunc.py | 13 +++--- numba/npyufunc/parfor.py | 7 ++-- numba/npyufunc/sigparse.py | 2 +- numba/npyufunc/ufuncbuilder.py | 9 +++-- numba/numpy_support.py | 2 +- numba/object_mode_passes.py | 5 ++- numba/parfor.py | 11 ++--- numba/postproc.py | 3 +- numba/pylowering.py | 9 +++-- numba/pythonapi.py | 4 +- numba/roc/compiler.py | 7 ++-- numba/roc/hlc/common.py | 2 +- numba/roc/hlc/hlc.py | 2 +- numba/roc/hsadrv/driver.py | 4 +- numba/roc/hsadrv/drvapi.py | 2 +- numba/roc/stubs.py | 4 +- numba/runtime/nrt.py | 8 ++-- numba/sigutils.py | 2 +- numba/special.py | 2 +- numba/stencil.py | 8 ++-- numba/stencilparfor.py | 9 +++-- numba/targets/arraymath.py | 7 ++-- numba/targets/base.py | 3 +- numba/targets/builtins.py | 11 ++--- numba/targets/cmathimpl.py | 5 ++- numba/targets/codegen.py | 3 +- numba/targets/cpu.py | 14 ++++--- numba/targets/externals.py | 4 +- numba/targets/gdb_hook.py | 3 +- numba/targets/hashing.py | 3 +- numba/targets/imputils.py | 5 ++- numba/targets/listobj.py | 6 +-- numba/targets/mathimpl.py | 5 ++- numba/targets/numbers.py | 16 ++++---- numba/targets/optional.py | 8 ++-- numba/targets/rangeobj.py | 8 ++-- numba/targets/registry.py | 7 ++-- numba/targets/setobj.py | 7 ++-- numba/targets/tupleobj.py | 13 +++--- numba/tests/support.py | 3 +- numba/typed/typeddict.py | 5 ++- numba/typed/typedlist.py | 5 ++- numba/typed_passes.py | 24 +++++------ numba/typedobjectutils.py | 6 +-- numba/typeinfer.py | 10 +++-- numba/unicode.py | 54 ++++++++++++++++--------- numba/unicode_support.py | 5 ++- numba/unsafe/ndarray.py | 5 +-- numba/withcontexts.py | 7 ++-- 123 files changed, 389 insertions(+), 318 deletions(-) rename numba/{ => core}/errors.py (99%) rename numba/{np => core}/slicing.py (99%) rename numba/{ => core}/typeconv/__init__.py (100%) rename numba/{ => core}/typeconv/_typeconv.cpp (100%) rename numba/{ => core}/typeconv/castgraph.py (100%) rename numba/{ => core}/typeconv/rules.py (100%) rename numba/{ => core}/typeconv/test.cpp (100%) rename numba/{ => core}/typeconv/typeconv.cpp (100%) rename numba/{ => core}/typeconv/typeconv.hpp (100%) rename numba/{ => core}/typeconv/typeconv.py (100%) rename numba/{ => core}/types/__init__.py (99%) rename numba/{ => core}/types/abstract.py (99%) rename numba/{ => core}/types/common.py (100%) rename numba/{ => core}/types/containers.py (100%) rename numba/{ => core}/types/functions.py (99%) rename numba/{ => core}/types/iterators.py (100%) rename numba/{ => core}/types/misc.py (100%) rename numba/{ => core}/types/npytypes.py (100%) rename numba/{ => core}/types/scalars.py (98%) rename numba/{ => core}/typing/__init__.py (100%) rename numba/{ => core}/typing/arraydecl.py (98%) rename numba/{ => core}/typing/bufproto.py (100%) rename numba/{ => core}/typing/builtins.py (98%) rename numba/{ => core}/typing/cffi_utils.py (98%) rename numba/{ => core}/typing/cmathdecl.py (94%) rename numba/{ => core}/typing/collections.py (100%) rename numba/{ => core}/typing/context.py (99%) rename numba/{ => core}/typing/ctypes_utils.py (100%) rename numba/{ => core}/typing/dictdecl.py (100%) rename numba/{ => core}/typing/enumdecl.py (88%) rename numba/{ => core}/typing/listdecl.py (100%) rename numba/{ => core}/typing/mathdecl.py (95%) rename numba/{ => core}/typing/npdatetime.py (96%) rename numba/{ => core}/typing/npydecl.py (99%) rename numba/{ => core}/typing/randomdecl.py (99%) rename numba/{ => core}/typing/setdecl.py (100%) rename numba/{ => core}/typing/templates.py (99%) rename numba/{ => core}/typing/typeof.py (98%) rename numba/{ => core}/utils.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index e642b78a0e5..db6affd580e 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -11,7 +11,8 @@ __version__ = get_versions()['version'] del get_versions -from . import config, errors, _runtests as runtests, types +from . import config, _runtests as runtests +from numba.core import types, errors # Re-export typeof from .special import ( @@ -20,10 +21,10 @@ ) # Re-export error classes -from .errors import * +from numba.core.errors import * # Re-export all type names -from .types import * +from numba.core.types import * # Re-export decorators from .decorators import (cfunc, generated_jit, jit, njit, stencil, jit_module) @@ -110,8 +111,8 @@ def _ensure_critical_deps(): """ Make sure Python, NumPy and SciPy have supported versions. """ - from .numpy_support import numpy_version - from .utils import PYVERSION + from numba.numpy_support import numpy_version + from numba.core.utils import PYVERSION if PYVERSION < (3, 6): raise ImportError("Numba needs Python 3.6 or greater") diff --git a/numba/array_analysis.py b/numba/array_analysis.py index 2437085d749..a9dd69e4a61 100644 --- a/numba/array_analysis.py +++ b/numba/array_analysis.py @@ -6,7 +6,8 @@ import types as pytypes # avoid confusion with numba.types import numpy import operator -from numba import ir, analysis, types, config, cgutils, typing +from numba import ir, analysis, config, cgutils +from numba.core import types, typing from numba.ir_utils import ( mk_unique_var, replace_vars_inner, @@ -22,7 +23,7 @@ is_namedtuple_class, build_definitions) from numba.analysis import (compute_cfg_from_blocks) -from numba.typing import npydecl, signature +from numba.core.typing import npydecl, signature import collections import copy from numba.extending import intrinsic diff --git a/numba/bytecode.py b/numba/bytecode.py index df4d15f1eda..138a70576ec 100644 --- a/numba/bytecode.py +++ b/numba/bytecode.py @@ -9,7 +9,7 @@ import itertools from types import CodeType, ModuleType -from numba import errors, utils +from numba.core import errors, utils opcode_info = namedtuple('opcode_info', ['argsize']) diff --git a/numba/byteflow.py b/numba/byteflow.py index 81436b12fa8..23107102b56 100644 --- a/numba/byteflow.py +++ b/numba/byteflow.py @@ -7,10 +7,10 @@ from collections import namedtuple, defaultdict, deque from functools import total_ordering -from numba.utils import UniqueDict, PYVERSION +from numba.core.utils import UniqueDict, PYVERSION from numba.controlflow import NEW_BLOCKERS, CFGraph from numba.ir import Loc -from numba.errors import UnsupportedError +from numba.core.errors import UnsupportedError _logger = logging.getLogger(__name__) diff --git a/numba/caching.py b/numba/caching.py index 0247cd95f98..5a9fd0a06aa 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -15,12 +15,12 @@ import tempfile import warnings -from .appdirs import AppDirs -from numba.utils import add_metaclass, file_replace +from numba.appdirs import AppDirs +from numba.core.utils import add_metaclass, file_replace import numba -from . import compiler, config -from .errors import NumbaWarning +from numba import compiler, config +from numba.core.errors import NumbaWarning from numba.targets.base import BaseContext from numba.targets.codegen import CodeLibrary from numba.compiler import CompileResult diff --git a/numba/cgutils.py b/numba/cgutils.py index 5fc42209a34..db2021d1b0d 100644 --- a/numba/cgutils.py +++ b/numba/cgutils.py @@ -9,7 +9,8 @@ from llvmlite import ir -from . import utils, config, types +from numba.core import utils, types +from numba import config bool_t = ir.IntType(1) diff --git a/numba/compiler.py b/numba/compiler.py index 623b056352d..e08801c751b 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -1,14 +1,14 @@ from collections import namedtuple import copy import warnings -from .tracing import event +from numba.tracing import event -from numba import (bytecode, interpreter, postproc, typing, utils, config, - errors,) +from numba import (bytecode, interpreter, postproc, config,) +from numba.core import utils, errors, typing from numba.targets import cpu, callconv from numba.parfor import ParforDiagnostics from numba.inline_closurecall import InlineClosureCallPass -from numba.errors import CompilerError +from numba.core.errors import CompilerError from .compiler_machinery import PassManager diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index 64b9c8c9ed1..9023b283578 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -4,10 +4,10 @@ import inspect from numba.compiler_lock import global_compiler_lock from numba import errors -from . import config, transforms -from numba.utils import add_metaclass -from .tracing import event -from .postproc import PostProcessor +from numba import config, transforms +from numba.core.utils import add_metaclass +from numba.tracing import event +from numba.postproc import PostProcessor # terminal color markup _termcolor = errors.termcolor() diff --git a/numba/consts.py b/numba/consts.py index 9910795637a..abcd833756b 100644 --- a/numba/consts.py +++ b/numba/consts.py @@ -2,8 +2,8 @@ import weakref -from . import ir -from .errors import ConstantInferenceError, NumbaError +from numba import ir +from numba.core.errors import ConstantInferenceError, NumbaError class ConstantInference(object): diff --git a/numba/controlflow.py b/numba/controlflow.py index 1931d50b27f..6893c9657a6 100644 --- a/numba/controlflow.py +++ b/numba/controlflow.py @@ -2,9 +2,9 @@ import functools import sys -from numba import utils +from numba.core import utils from numba.ir import Loc -from numba.errors import UnsupportedError +from numba.core.errors import UnsupportedError # List of bytecodes creating a new block in the control flow graph # (in addition to explicit jump labels). diff --git a/numba/errors.py b/numba/core/errors.py similarity index 99% rename from numba/errors.py rename to numba/core/errors.py index 6a80cc3c83b..8104d035d3b 100644 --- a/numba/errors.py +++ b/numba/core/errors.py @@ -11,7 +11,7 @@ import numba import numpy as np from collections import defaultdict -from numba.utils import add_metaclass, reraise +from numba.core.utils import add_metaclass, reraise from functools import wraps from abc import abstractmethod diff --git a/numba/np/slicing.py b/numba/core/slicing.py similarity index 99% rename from numba/np/slicing.py rename to numba/core/slicing.py index 12372687f7a..e073e2d51ff 100644 --- a/numba/np/slicing.py +++ b/numba/core/slicing.py @@ -6,7 +6,8 @@ from llvmlite import ir -from numba import cgutils, types, typing, utils +from numba import cgutils +from numba.core import types, typing, utils from numba.targets.imputils import (lower_builtin, lower_getattr, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) diff --git a/numba/typeconv/__init__.py b/numba/core/typeconv/__init__.py similarity index 100% rename from numba/typeconv/__init__.py rename to numba/core/typeconv/__init__.py diff --git a/numba/typeconv/_typeconv.cpp b/numba/core/typeconv/_typeconv.cpp similarity index 100% rename from numba/typeconv/_typeconv.cpp rename to numba/core/typeconv/_typeconv.cpp diff --git a/numba/typeconv/castgraph.py b/numba/core/typeconv/castgraph.py similarity index 100% rename from numba/typeconv/castgraph.py rename to numba/core/typeconv/castgraph.py diff --git a/numba/typeconv/rules.py b/numba/core/typeconv/rules.py similarity index 100% rename from numba/typeconv/rules.py rename to numba/core/typeconv/rules.py diff --git a/numba/typeconv/test.cpp b/numba/core/typeconv/test.cpp similarity index 100% rename from numba/typeconv/test.cpp rename to numba/core/typeconv/test.cpp diff --git a/numba/typeconv/typeconv.cpp b/numba/core/typeconv/typeconv.cpp similarity index 100% rename from numba/typeconv/typeconv.cpp rename to numba/core/typeconv/typeconv.cpp diff --git a/numba/typeconv/typeconv.hpp b/numba/core/typeconv/typeconv.hpp similarity index 100% rename from numba/typeconv/typeconv.hpp rename to numba/core/typeconv/typeconv.hpp diff --git a/numba/typeconv/typeconv.py b/numba/core/typeconv/typeconv.py similarity index 100% rename from numba/typeconv/typeconv.py rename to numba/core/typeconv/typeconv.py diff --git a/numba/types/__init__.py b/numba/core/types/__init__.py similarity index 99% rename from numba/types/__init__.py rename to numba/core/types/__init__.py index f970a89ae42..98915c8435a 100644 --- a/numba/types/__init__.py +++ b/numba/core/types/__init__.py @@ -1,7 +1,7 @@ import struct import numpy as np -from numba import utils +from numba.core import utils from .abstract import * from .containers import * diff --git a/numba/types/abstract.py b/numba/core/types/abstract.py similarity index 99% rename from numba/types/abstract.py rename to numba/core/types/abstract.py index 1353b46c69a..0f7a8272f61 100644 --- a/numba/types/abstract.py +++ b/numba/core/types/abstract.py @@ -4,8 +4,7 @@ import numpy as np -from numba.utils import add_metaclass -from ..utils import cached_property +from numba.core.utils import cached_property, add_metaclass # Types are added to a global registry (_typecache) in order to assign diff --git a/numba/types/common.py b/numba/core/types/common.py similarity index 100% rename from numba/types/common.py rename to numba/core/types/common.py diff --git a/numba/types/containers.py b/numba/core/types/containers.py similarity index 100% rename from numba/types/containers.py rename to numba/core/types/containers.py diff --git a/numba/types/functions.py b/numba/core/types/functions.py similarity index 99% rename from numba/types/functions.py rename to numba/core/types/functions.py index e0c5553f163..35e67964a04 100644 --- a/numba/types/functions.py +++ b/numba/core/types/functions.py @@ -3,7 +3,7 @@ from .abstract import Callable, DTypeSpec, Dummy, Literal, Type, weakref from .common import Opaque from .misc import unliteral -from numba import errors +from numba.core import errors # terminal color markup _termcolor = errors.termcolor() diff --git a/numba/types/iterators.py b/numba/core/types/iterators.py similarity index 100% rename from numba/types/iterators.py rename to numba/core/types/iterators.py diff --git a/numba/types/misc.py b/numba/core/types/misc.py similarity index 100% rename from numba/types/misc.py rename to numba/core/types/misc.py diff --git a/numba/types/npytypes.py b/numba/core/types/npytypes.py similarity index 100% rename from numba/types/npytypes.py rename to numba/core/types/npytypes.py diff --git a/numba/types/scalars.py b/numba/core/types/scalars.py similarity index 98% rename from numba/types/scalars.py rename to numba/core/types/scalars.py index 4aaf1074691..892d8adce68 100644 --- a/numba/types/scalars.py +++ b/numba/core/types/scalars.py @@ -4,8 +4,9 @@ from .abstract import Dummy, Hashable, Literal, Number, Type from functools import total_ordering -from .. import npdatetime, utils -from ..typeconv import Conversion +from numba import npdatetime +from numba.core import utils +from numba.core.typeconv import Conversion class Boolean(Hashable): diff --git a/numba/typing/__init__.py b/numba/core/typing/__init__.py similarity index 100% rename from numba/typing/__init__.py rename to numba/core/typing/__init__.py diff --git a/numba/typing/arraydecl.py b/numba/core/typing/arraydecl.py similarity index 98% rename from numba/typing/arraydecl.py rename to numba/core/typing/arraydecl.py index e43548c4b4f..fc23129a2bb 100644 --- a/numba/typing/arraydecl.py +++ b/numba/core/typing/arraydecl.py @@ -2,14 +2,14 @@ import operator from collections import namedtuple -from numba import types, utils -from numba.typing.templates import (AttributeTemplate, AbstractTemplate, infer, - infer_global, infer_getattr, signature, - bound_function) +from numba.core import types, utils +from numba.core.typing.templates import (AttributeTemplate, AbstractTemplate, + infer, infer_global, infer_getattr, + signature, bound_function) # import time side effect: array operations requires typing support of sequence # defined in collections: e.g. array.shape[i] -from numba.typing import collections -from numba.errors import TypingError +from numba.core.typing import collections +from numba.core.errors import TypingError Indexing = namedtuple("Indexing", ("index", "result", "advanced")) diff --git a/numba/typing/bufproto.py b/numba/core/typing/bufproto.py similarity index 100% rename from numba/typing/bufproto.py rename to numba/core/typing/bufproto.py diff --git a/numba/typing/builtins.py b/numba/core/typing/builtins.py similarity index 98% rename from numba/typing/builtins.py rename to numba/core/typing/builtins.py index 1300837c002..97aafc56a68 100644 --- a/numba/typing/builtins.py +++ b/numba/core/typing/builtins.py @@ -3,14 +3,15 @@ import numpy as np import operator -from numba import types, prange, errors +from numba.core import types, errors +from numba import prange from numba.parfor import internal_prange -from numba.utils import RANGE_ITER_OBJECTS -from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, - AbstractTemplate, infer_global, infer, - infer_getattr, signature, bound_function, - make_callable_template) +from numba.core.utils import RANGE_ITER_OBJECTS +from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, + AbstractTemplate, infer_global, infer, + infer_getattr, signature, + bound_function, make_callable_template) @infer_global(print) diff --git a/numba/typing/cffi_utils.py b/numba/core/typing/cffi_utils.py similarity index 98% rename from numba/typing/cffi_utils.py rename to numba/core/typing/cffi_utils.py index b388bddf80f..58a6d3f1494 100644 --- a/numba/typing/cffi_utils.py +++ b/numba/core/typing/cffi_utils.py @@ -9,10 +9,10 @@ from functools import partial import numpy as np -from numba import types +from numba.core import types from numba import numpy_support -from numba.errors import TypingError -from . import templates +from numba.core.errors import TypingError +from numba.core.typing import templates try: import cffi diff --git a/numba/typing/cmathdecl.py b/numba/core/typing/cmathdecl.py similarity index 94% rename from numba/typing/cmathdecl.py rename to numba/core/typing/cmathdecl.py index 575245e4d50..010d2328aec 100644 --- a/numba/typing/cmathdecl.py +++ b/numba/core/typing/cmathdecl.py @@ -1,7 +1,7 @@ import cmath -from numba import types, utils -from numba.typing.templates import (AbstractTemplate, ConcreteTemplate, +from numba.core import types, utils +from numba.core.typing.templates import (AbstractTemplate, ConcreteTemplate, signature, Registry) registry = Registry() diff --git a/numba/typing/collections.py b/numba/core/typing/collections.py similarity index 100% rename from numba/typing/collections.py rename to numba/core/typing/collections.py diff --git a/numba/typing/context.py b/numba/core/typing/context.py similarity index 99% rename from numba/typing/context.py rename to numba/core/typing/context.py index 171171d87ef..98f06bbd817 100644 --- a/numba/typing/context.py +++ b/numba/core/typing/context.py @@ -7,12 +7,12 @@ import operator import numba -from numba import types, errors -from numba.typeconv import Conversion, rules +from numba.core import types, errors +from numba.core.typeconv import Conversion, rules from . import templates from .typeof import typeof, Purpose -from numba import utils +from numba.core import utils class Rating(object): diff --git a/numba/typing/ctypes_utils.py b/numba/core/typing/ctypes_utils.py similarity index 100% rename from numba/typing/ctypes_utils.py rename to numba/core/typing/ctypes_utils.py diff --git a/numba/typing/dictdecl.py b/numba/core/typing/dictdecl.py similarity index 100% rename from numba/typing/dictdecl.py rename to numba/core/typing/dictdecl.py diff --git a/numba/typing/enumdecl.py b/numba/core/typing/enumdecl.py similarity index 88% rename from numba/typing/enumdecl.py rename to numba/core/typing/enumdecl.py index ebac8e3f075..ce3c4d6c94b 100644 --- a/numba/typing/enumdecl.py +++ b/numba/core/typing/enumdecl.py @@ -2,9 +2,9 @@ Typing for enums. """ import operator -from numba import types -from numba.typing.templates import (AbstractTemplate, AttributeTemplate, - signature, Registry) +from numba.core import types +from numba.core.typing.templates import (AbstractTemplate, AttributeTemplate, + signature, Registry) registry = Registry() infer = registry.register diff --git a/numba/typing/listdecl.py b/numba/core/typing/listdecl.py similarity index 100% rename from numba/typing/listdecl.py rename to numba/core/typing/listdecl.py diff --git a/numba/typing/mathdecl.py b/numba/core/typing/mathdecl.py similarity index 95% rename from numba/typing/mathdecl.py rename to numba/core/typing/mathdecl.py index 052e23dee2a..c788d6d9902 100644 --- a/numba/typing/mathdecl.py +++ b/numba/core/typing/mathdecl.py @@ -1,7 +1,7 @@ import math -from numba import types, utils -from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, - signature, Registry) +from numba.core import types, utils +from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, + signature, Registry) registry = Registry() infer_global = registry.register_global diff --git a/numba/typing/npdatetime.py b/numba/core/typing/npdatetime.py similarity index 96% rename from numba/typing/npdatetime.py rename to numba/core/typing/npdatetime.py index 16624bae470..f0369ce98f5 100644 --- a/numba/typing/npdatetime.py +++ b/numba/core/typing/npdatetime.py @@ -6,10 +6,11 @@ from itertools import product import operator -from numba import npdatetime, types -from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, - AbstractTemplate, infer_global, infer, - infer_getattr, signature) +from numba import npdatetime +from numba.core import types +from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, + AbstractTemplate, infer_global, infer, + infer_getattr, signature) # timedelta64-only operations diff --git a/numba/typing/npydecl.py b/numba/core/typing/npydecl.py similarity index 99% rename from numba/typing/npydecl.py rename to numba/core/typing/npydecl.py index 6ad8e1489ad..139bbc25b2c 100644 --- a/numba/typing/npydecl.py +++ b/numba/core/typing/npydecl.py @@ -3,15 +3,16 @@ import numpy as np import operator -from .. import types, utils, config -from .templates import (AttributeTemplate, AbstractTemplate, CallableTemplate, - Registry, signature) +from numba.core import types, utils +from numba import config +from numba.core.typing.templates import (AttributeTemplate, AbstractTemplate, + CallableTemplate, Registry, signature) -from ..numpy_support import (ufunc_find_matching_loop, +from numba.numpy_support import (ufunc_find_matching_loop, supported_ufunc_loop, as_dtype, from_dtype, as_dtype, resolve_output_type, carray, farray) -from ..errors import TypingError, NumbaPerformanceWarning +from numba.core.errors import TypingError, NumbaPerformanceWarning from numba import pndindex registry = Registry() diff --git a/numba/typing/randomdecl.py b/numba/core/typing/randomdecl.py similarity index 99% rename from numba/typing/randomdecl.py rename to numba/core/typing/randomdecl.py index bdda70966fc..996d1acf34a 100644 --- a/numba/typing/randomdecl.py +++ b/numba/core/typing/randomdecl.py @@ -2,10 +2,10 @@ import numpy as np -from .. import types +from numba.core import types from .templates import (ConcreteTemplate, AbstractTemplate, AttributeTemplate, CallableTemplate, Registry, signature) -from ..numpy_support import numpy_version +from numba.numpy_support import numpy_version registry = Registry() diff --git a/numba/typing/setdecl.py b/numba/core/typing/setdecl.py similarity index 100% rename from numba/typing/setdecl.py rename to numba/core/typing/setdecl.py diff --git a/numba/typing/templates.py b/numba/core/typing/templates.py similarity index 99% rename from numba/typing/templates.py rename to numba/core/typing/templates.py index 03893ded1eb..c62845fbb90 100644 --- a/numba/typing/templates.py +++ b/numba/core/typing/templates.py @@ -11,9 +11,9 @@ from types import MethodType, FunctionType import numba -from .. import types, utils -from ..errors import TypingError, InternalError -from ..targets.cpu_options import InlineOptions +from numba.core import types, utils +from numba.core.errors import TypingError, InternalError +from numba.targets.cpu_options import InlineOptions # info store for inliner callback functions e.g. cost model _inline_info = namedtuple('inline_info', diff --git a/numba/typing/typeof.py b/numba/core/typing/typeof.py similarity index 98% rename from numba/typing/typeof.py rename to numba/core/typing/typeof.py index 4a30c8aabef..575f3962076 100644 --- a/numba/typing/typeof.py +++ b/numba/core/typing/typeof.py @@ -5,8 +5,8 @@ import numpy as np -from numba import numpy_support, types, utils -from numba import errors +from numba import numpy_support +from numba.core import types, utils, errors # terminal color markup _termcolor = errors.termcolor() diff --git a/numba/utils.py b/numba/core/utils.py similarity index 100% rename from numba/utils.py rename to numba/core/utils.py diff --git a/numba/cuda/args.py b/numba/cuda/args.py index f07b19da07a..15f7247153c 100644 --- a/numba/cuda/args.py +++ b/numba/cuda/args.py @@ -4,9 +4,9 @@ """ import abc -from numba.utils import add_metaclass +from numba.core.utils import add_metaclass -from numba.typing.typeof import typeof, Purpose +from numba.core.typing.typeof import typeof, Purpose @add_metaclass(abc.ABCMeta) diff --git a/numba/cuda/codegen.py b/numba/cuda/codegen.py index e2e6797e807..5f40a92ee24 100644 --- a/numba/cuda/codegen.py +++ b/numba/cuda/codegen.py @@ -2,7 +2,7 @@ from llvmlite.llvmpy import core as lc from numba.targets.codegen import BaseCPUCodegen, CodeLibrary -from numba import utils +from numba.core import utils from .cudadrv import nvvm diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index 9bcf1c89b19..8eb77843fa2 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -9,8 +9,9 @@ import numpy as np from numba import config, compiler, types, sigutils -from numba.typing.templates import AbstractTemplate, ConcreteTemplate -from numba import funcdesc, typing, utils, serialize +from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate +from numba import funcdesc, serialize +from numba.core import typing, utils from numba.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index e932985f983..9add85a48a5 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -27,13 +27,14 @@ import numpy as np from collections import namedtuple, deque -from numba import utils, mviewbuf +from numba import mviewbuf +from numba.core import utils from .error import CudaSupportError, CudaDriverError from .drvapi import API_PROTOTYPES from .drvapi import cu_occupancy_b2d_size from . import enums, drvapi, _extras from numba import config, serialize, errors -from numba.utils import longint as long +from numba.core.utils import longint as long from numba.cuda.envvars import get_numba_envvar diff --git a/numba/cuda/simulator/kernel.py b/numba/cuda/simulator/kernel.py index 5fa674e2af4..562f9b3a4e7 100644 --- a/numba/cuda/simulator/kernel.py +++ b/numba/cuda/simulator/kernel.py @@ -5,7 +5,7 @@ import numpy as np -from numba.utils import reraise +from numba.core.utils import reraise from .cudadrv.devicearray import to_device, auto_device from .kernelapi import Dim3, FakeCUDAModule, swapped_cuda_module from ..errors import normalize_kernel_dimensions diff --git a/numba/cuda/stubs.py b/numba/cuda/stubs.py index 2a4188f75a5..1828bfa8a59 100644 --- a/numba/cuda/stubs.py +++ b/numba/cuda/stubs.py @@ -4,7 +4,8 @@ import operator import numpy import llvmlite.llvmpy.core as lc -from numba import types, ir, typing, macro +from numba import ir, macro +from numba.core import types, typing from .cudadrv import nvvm diff --git a/numba/cuda/target.py b/numba/cuda/target.py index d6a90759479..a54e47d32ee 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -4,12 +4,13 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba import typing, types, cgutils, debuginfo, dispatcher -from numba.utils import cached_property +from numba.core import typing, types +from numba import cgutils, debuginfo, dispatcher +from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv from numba.targets import cmathimpl -from numba.typing import cmathdecl +from numba.core.typing import cmathdecl from numba import itanium_mangler from .cudadrv import nvvm diff --git a/numba/dataflow.py b/numba/dataflow.py index 398911b8f67..c4386d87124 100644 --- a/numba/dataflow.py +++ b/numba/dataflow.py @@ -3,9 +3,9 @@ import sys import warnings -from numba import utils -from .errors import UnsupportedError -from .ir import Loc +from numba.core import utils +from numba.core.errors import UnsupportedError +from numba.ir import Loc class DataFlowAnalysis(object): diff --git a/numba/debuginfo.py b/numba/debuginfo.py index 6f12373e32c..23f49d2b655 100644 --- a/numba/debuginfo.py +++ b/numba/debuginfo.py @@ -8,7 +8,7 @@ from llvmlite import ir -from numba.utils import add_metaclass +from numba.core.utils import add_metaclass @add_metaclass(abc.ABCMeta) diff --git a/numba/decorators.py b/numba/decorators.py index acfb2cbcd7c..7553432f955 100644 --- a/numba/decorators.py +++ b/numba/decorators.py @@ -8,10 +8,10 @@ import inspect import logging -from . import config, sigutils -from .errors import DeprecationError, NumbaDeprecationWarning -from .targets import registry -from .stencil import stencil +from numba import config, sigutils +from numba.core.errors import DeprecationError, NumbaDeprecationWarning +from numba.targets import registry +from numba.stencil import stencil _logger = logging.getLogger(__name__) diff --git a/numba/dictobject.py b/numba/dictobject.py index 27a3a997674..10890c25684 100644 --- a/numba/dictobject.py +++ b/numba/dictobject.py @@ -20,7 +20,7 @@ ) from numba.targets.imputils import iternext_impl from numba import types -from numba.types import ( +from numba.core.types import ( DictType, DictItemsIterableType, DictKeysIterableType, @@ -29,8 +29,8 @@ Type, ) from numba.targets.imputils import impl_ret_borrowed, RefType -from numba.errors import TypingError -from numba import typing +from numba.core.errors import TypingError +from numba.core import typing from numba.typedobjectutils import (_as_bytes, _cast, _nonoptional, diff --git a/numba/dispatcher.py b/numba/dispatcher.py index 82ac2aaaf54..c35e4c14ccd 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -11,15 +11,16 @@ import weakref from copy import deepcopy -from numba import _dispatcher, compiler, utils, types, config, errors +from numba import _dispatcher, compiler, config +from numba.core import utils, types, errors, typing from numba.compiler_lock import global_compiler_lock -from numba.typeconv.rules import default_type_manager -from numba import sigutils, serialize, typing -from numba.typing.templates import fold_arguments -from numba.typing.typeof import Purpose, typeof +from numba.core.typeconv.rules import default_type_manager +from numba import sigutils, serialize +from numba.core.typing.templates import fold_arguments +from numba.core.typing.typeof import Purpose, typeof from numba.bytecode import get_code_object -from numba.utils import reraise -from .caching import NullCache, FunctionCache +from numba.core.utils import reraise +from numba.caching import NullCache, FunctionCache class OmittedArg(object): diff --git a/numba/extending.py b/numba/extending.py index bbaffef34d3..064f2194244 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -5,17 +5,18 @@ import collections import numba -from numba import types, config, errors, utils +from numba.core import types, errors, utils +from numba import config # Exported symbols -from .typing.typeof import typeof_impl -from .typing.templates import infer, infer_getattr -from .targets.imputils import ( +from numba.core.typing.typeof import typeof_impl +from numba.core.typing.templates import infer, infer_getattr +from numba.targets.imputils import ( lower_builtin, lower_getattr, lower_getattr_generic, lower_setattr, lower_setattr_generic, lower_cast) -from .datamodel import models, register_default as register_model -from .pythonapi import box, unbox, reflect, NativeValue -from ._helperlib import _import_cython_function +from numba.datamodel import models, register_default as register_model +from numba.pythonapi import box, unbox, reflect, NativeValue +from numba._helperlib import _import_cython_function def type_callable(func): @@ -24,7 +25,8 @@ def type_callable(func): *func* can be a callable object (probably a global) or a string denoting a built-in operation (such 'getitem' or '__array_wrap__') """ - from .typing.templates import CallableTemplate, infer, infer_global + from numba.core.typing.templates import (CallableTemplate, infer, + infer_global) if not callable(func) and not isinstance(func, str): raise TypeError("`func` should be a function or string") try: @@ -100,7 +102,7 @@ def len_impl(seq): to determine whether to inline, this essentially permitting custom inlining rules (typical use might be cost models). """ - from .typing.templates import make_overload_template, infer_global + from numba.core.typing.templates import make_overload_template, infer_global # set default options opts = _overload_default_jit_options.copy() @@ -165,7 +167,7 @@ def get(arr): return get """ # TODO implement setters - from .typing.templates import make_overload_attribute_template + from numba.core.typing.templates import make_overload_attribute_template def decorate(overload_func): template = make_overload_attribute_template( @@ -199,7 +201,7 @@ def take_impl(arr, indices): return res return take_impl """ - from .typing.templates import make_overload_method_template + from numba.core.typing.templates import make_overload_method_template def decorate(overload_func): template = make_overload_method_template( @@ -219,11 +221,11 @@ def make_attribute_wrapper(typeclass, struct_attr, python_attr): as a read-only attribute named *python_attr*. The given *typeclass*'s model must be a StructModel subclass. """ - from .typing.templates import AttributeTemplate - from .datamodel import default_manager - from .datamodel.models import StructModel - from .targets.imputils import impl_ret_borrowed - from . import cgutils + from numba.core.typing.templates import AttributeTemplate + from numba.datamodel import default_manager + from numba.datamodel.models import StructModel + from numba.targets.imputils import impl_ret_borrowed + from numba import cgutils if not isinstance(typeclass, type) or not issubclass(typeclass, types.Type): raise TypeError("typeclass should be a Type subclass, got %s" @@ -291,7 +293,8 @@ def _set_uuid(self, u): self._recent.append(self) def _register(self): - from .typing.templates import make_intrinsic_template, infer_global + from numba.core.typing.templates import (make_intrinsic_template, + infer_global) template = make_intrinsic_template(self, self._defn, self._name) infer(template) diff --git a/numba/funcdesc.py b/numba/funcdesc.py index 24a3f3e6e66..6030759c288 100644 --- a/numba/funcdesc.py +++ b/numba/funcdesc.py @@ -5,8 +5,9 @@ from collections import defaultdict import sys -from . import types, itanium_mangler -from .utils import _dynamic_modname, _dynamic_module +from numba import itanium_mangler +from numba.core import types +from numba.core.utils import _dynamic_modname, _dynamic_module def default_mangler(name, argtypes): diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 3b35923c97e..978d6a430a1 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -1,8 +1,8 @@ import types as pytypes # avoid confusion with numba.types import ctypes import numba -from numba import (config, ir, ir_utils, utils, prange, rewrites, types, typing, - errors) +from numba.core import utils, types, typing, errors +from numba import (config, ir, ir_utils, prange, rewrites,) from numba.parfor import internal_prange from numba.ir_utils import ( mk_unique_var, diff --git a/numba/interpreter.py b/numba/interpreter.py index e07d4b11f56..b3e3917d704 100644 --- a/numba/interpreter.py +++ b/numba/interpreter.py @@ -4,9 +4,10 @@ import operator import logging -from . import config, ir, controlflow, dataflow, errors -from .errors import NotDefinedError -from .utils import ( +from numba.core import errors +from numba import config, ir, controlflow, dataflow +from numba.core.errors import NotDefinedError +from numba.core.utils import ( PYVERSION, BINOPS_TO_OPERATORS, INPLACE_BINOPS_TO_OPERATORS, diff --git a/numba/ir.py b/numba/ir.py index 2c3ce17853f..88b4aeddf1f 100644 --- a/numba/ir.py +++ b/numba/ir.py @@ -11,9 +11,10 @@ from functools import total_ordering from numba import config, errors -from .utils import BINOPS_TO_OPERATORS, INPLACE_BINOPS_TO_OPERATORS, UNARY_BUITINS_TO_OPERATORS, OPERATORS_TO_BUILTINS -from .errors import (NotDefinedError, RedefinedError, VerificationError, - ConstantInferenceError) +from numba.core.utils import (BINOPS_TO_OPERATORS, INPLACE_BINOPS_TO_OPERATORS, + UNARY_BUITINS_TO_OPERATORS, OPERATORS_TO_BUILTINS) +from numba.core.errors import (NotDefinedError, RedefinedError, + VerificationError, ConstantInferenceError) from io import StringIO # terminal color markup diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 199f822ae68..31c1d1a77a6 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -13,14 +13,16 @@ from llvmlite import ir as lir import numba -from numba import ir, types, typing, config, analysis, utils, cgutils, rewrites -from numba.typing.templates import signature, infer_global, AbstractTemplate +from numba.core import types, utils, typing +from numba import ir, config, analysis, cgutils, rewrites +from numba.core.typing.templates import (signature, infer_global, + AbstractTemplate) from numba.targets.imputils import impl_ret_untracked from numba.analysis import (compute_live_map, compute_use_defs, compute_cfg_from_blocks) -from numba.errors import (TypingError, UnsupportedError, - NumbaPendingDeprecationWarning, NumbaWarning, - feedback_details) +from numba.core.errors import (TypingError, UnsupportedError, + NumbaPendingDeprecationWarning, NumbaWarning, + feedback_details) import copy diff --git a/numba/itanium_mangler.py b/numba/itanium_mangler.py index ccbf95b50eb..85dfe9da66c 100644 --- a/numba/itanium_mangler.py +++ b/numba/itanium_mangler.py @@ -31,7 +31,7 @@ import re -from numba import types, utils +from numba.core import types, utils # According the scheme, valid characters for mangled names are [a-zA-Z0-9_$]. diff --git a/numba/jitclass/base.py b/numba/jitclass/base.py index fbc69a902b1..28778e85498 100644 --- a/numba/jitclass/base.py +++ b/numba/jitclass/base.py @@ -6,14 +6,14 @@ from llvmlite import ir as llvmir -from numba import types +from numba.core import types, utils, errors from numba.targets.registry import cpu_target from numba import njit -from numba.typing import templates +from numba.core.typing import templates from numba.datamodel import default_manager, models from numba.targets import imputils -from numba import cgutils, utils, errors -from . import _box +from numba import cgutils +from numba.jitclass import _box ############################################################################## diff --git a/numba/listobject.py b/numba/listobject.py index 96fb2f141c5..d9794cacfc2 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -21,7 +21,7 @@ ) from numba.targets.imputils import iternext_impl from numba import types -from numba.types import ( +from numba.core.types import ( ListType, ListTypeIterableType, ListTypeIteratorType, @@ -29,8 +29,8 @@ NoneType, ) from numba.targets.imputils import impl_ret_borrowed, RefType -from numba.errors import TypingError -from numba import typing +from numba.core.errors import TypingError +from numba.core import typing from numba.typedobjectutils import (_as_bytes, _cast, _nonoptional, diff --git a/numba/lowering.py b/numba/lowering.py index ee2146be9ce..fd59a963772 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -5,9 +5,10 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from . import (_dynfunc, cgutils, config, funcdesc, generators, ir, types, - typing, utils, ir_utils) -from .errors import (LoweringError, new_error_context, TypingError, +from numba import (_dynfunc, cgutils, config, funcdesc, generators, ir, + ir_utils) +from numba.core import typing, utils, types +from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) from .targets import removerefctpass from .funcdesc import default_mangler diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index f8a3557a762..6256b48476c 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -14,7 +14,8 @@ import numpy as np -from numba import types, cgutils, typing, utils, extending, pndindex, errors +from numba import cgutils, extending, pndindex +from numba.core import types, utils, typing, errors, slicing from numba.numpy_support import (as_dtype, carray, farray, is_contiguous, is_fortran) from numba.numpy_support import type_can_asarray, is_nonelike @@ -25,10 +26,9 @@ iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, RefType) -from numba.typing import signature +from numba.core.typing import signature from numba.extending import register_jitable, overload, overload_method from numba.misc import quicksort, mergesort -from numba.np import slicing def set_range_metadata(builder, load, lower_bound, upper_bound): diff --git a/numba/np/linalg.py b/numba/np/linalg.py index dfe4c2a227c..eca64d10237 100644 --- a/numba/np/linalg.py +++ b/numba/np/linalg.py @@ -14,12 +14,12 @@ from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) -from numba.typing import signature +from numba.core.typing import signature from numba.extending import overload, register_jitable -from numba import types +from numba.core import types +from numba.core.errors import TypingError from numba import numpy_support as np_support from .arrayobj import make_array, _empty_nd_impl, array_copy -from ..errors import TypingError ll_char = ir.IntType(8) ll_char_p = ll_char.as_pointer() diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index 582388f3d82..c731d828579 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -6,9 +6,10 @@ import numpy as np import operator -from .. import compiler, ir, types, rewrites, utils -from ..typing import npydecl -from .dufunc import DUFunc +from numba import compiler, ir, rewrites +from numba.core import types, utils +from numba.core.typing import npydecl +from numba.npyufunc.dufunc import DUFunc def _is_ufunc(func): diff --git a/numba/npyufunc/dufunc.py b/numba/npyufunc/dufunc.py index b51e3e0baa1..066fba029b2 100644 --- a/numba/npyufunc/dufunc.py +++ b/numba/npyufunc/dufunc.py @@ -1,11 +1,12 @@ from numba import serialize -from .. import jit, typeof, utils, types, numpy_support, sigutils -from ..typing import npydecl -from ..typing.templates import AbstractTemplate, signature -from . import _internal, ufuncbuilder -from ..dispatcher import Dispatcher -from .. import array_analysis +from numba import jit, typeof, numpy_support, sigutils +from numba.core import types, utils +from numba.core.typing import npydecl +from numba.core.typing.templates import AbstractTemplate, signature +from numba.npyufunc import _internal, ufuncbuilder +from numba.dispatcher import Dispatcher +from numba import array_analysis def make_dufunc_kernel(_dufunc): diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index cc2cf61c070..21b467569fa 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -10,7 +10,8 @@ import llvmlite.ir.values as liv import numba -from .. import compiler, ir, types, cgutils, sigutils, lowering, parfor +from numba import compiler, ir, cgutils, sigutils, lowering, parfor +from numba.core import types from numba.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, @@ -20,15 +21,15 @@ is_const_call) from numba.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) -from ..typing import signature +from numba.core.typing import signature from numba import config from numba.targets.cpu import ParallelOptions from numba.parfor import print_wrapped, ensure_parallel_support +from numba.core.errors import NumbaParallelSafetyWarning import types as pytypes import operator import warnings -from ..errors import NumbaParallelSafetyWarning def _lower_parfor_parallel(lowerer, parfor): diff --git a/numba/npyufunc/sigparse.py b/numba/npyufunc/sigparse.py index bd9ec871cb0..0d18d1349a3 100644 --- a/numba/npyufunc/sigparse.py +++ b/numba/npyufunc/sigparse.py @@ -1,6 +1,6 @@ import tokenize import string -from numba import utils +from numba.core import utils def parse_signature(sig): diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index cf074e8ac2d..d756bd7dea5 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -9,11 +9,12 @@ from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target from numba.targets.cpu import FastMathOptions -from numba import utils, compiler, types, sigutils +from numba import compiler, types, sigutils +from numba.core import utils from numba.numpy_support import as_dtype -from . import _internal -from .sigparse import parse_signature -from .wrappers import build_ufunc_wrapper, build_gufunc_wrapper +from numba.npyufunc import _internal +from numba.npyufunc.sigparse import parse_signature +from numba.npyufunc.wrappers import build_ufunc_wrapper, build_gufunc_wrapper from numba.caching import FunctionCache, NullCache from numba.compiler_lock import global_compiler_lock diff --git a/numba/numpy_support.py b/numba/numpy_support.py index 57b220103e8..2563a89ab65 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -4,7 +4,7 @@ import numpy as np -from . import errors, types, utils +from numba.core import errors, types, utils # re-export from numba.cgutils import is_nonelike # noqa: F401 diff --git a/numba/object_mode_passes.py b/numba/object_mode_passes.py index 9ae9c0363f8..0947a7216cd 100644 --- a/numba/object_mode_passes.py +++ b/numba/object_mode_passes.py @@ -1,7 +1,8 @@ from contextlib import contextmanager import warnings -from . import (config, errors, types, funcdesc, typing, pylowering, transforms) -from .compiler_machinery import FunctionPass, LoweringPass, register_pass +from numba import (config, funcdesc, pylowering, transforms) +from numba.core import errors, types, typing +from numba.compiler_machinery import FunctionPass, LoweringPass, register_pass from collections import defaultdict diff --git a/numba/parfor.py b/numba/parfor.py index ad3cd67a4a7..c7f92c52170 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -25,10 +25,11 @@ import operator import numba -from numba import ir, ir_utils, types, typing, rewrites, config, analysis, prange, pndindex -from numba import array_analysis, postproc, typeinfer, utils, errors +from numba.core import types, typing, utils, errors +from numba import ir, ir_utils, rewrites, config, analysis, prange, pndindex +from numba import array_analysis, postproc, typeinfer from numba.numpy_support import as_dtype -from numba.typing.templates import infer_global, AbstractTemplate +from numba.core.typing.templates import infer_global, AbstractTemplate from numba import stencilparfor from numba.stencilparfor import StencilPass from numba.extending import register_jitable @@ -82,8 +83,8 @@ from numba.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) from numba.controlflow import CFGraph -from numba.typing import npydecl, signature -from numba.types.functions import Function +from numba.core.typing import npydecl, signature +from numba.core.types.functions import Function from numba.array_analysis import (random_int_args, random_1arg_size, random_2arg_sizelast, random_3arg_sizelast, random_calls, assert_equiv) diff --git a/numba/postproc.py b/numba/postproc.py index cc5e617075f..98f08190e94 100644 --- a/numba/postproc.py +++ b/numba/postproc.py @@ -1,4 +1,5 @@ -from . import analysis, ir, transforms, utils +from numba import analysis, ir, transforms +from numba.core import utils class YieldPoint(object): diff --git a/numba/pylowering.py b/numba/pylowering.py index ba3ff312c48..7301dcdc6b7 100644 --- a/numba/pylowering.py +++ b/numba/pylowering.py @@ -9,9 +9,10 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from . import cgutils, generators, ir, types, utils -from .errors import ForbiddenConstruct -from .lowering import BaseLower +from numba import cgutils, generators, ir +from numba.core import types, utils +from numba.core.errors import ForbiddenConstruct +from numba.lowering import BaseLower # Issue #475: locals() is unsupported as calling it naively would give @@ -76,7 +77,7 @@ def pre_lower(self): super(PyLower, self).pre_lower() self.init_pyapi() # Pre-computed for later use - from .dispatcher import OmittedArg + from numba.dispatcher import OmittedArg self.omitted_typobj = self.pyapi.unserialize( self.pyapi.serialize_object(OmittedArg)) diff --git a/numba/pythonapi.py b/numba/pythonapi.py index 69084b9e7f5..dc2f9bc1d19 100644 --- a/numba/pythonapi.py +++ b/numba/pythonapi.py @@ -7,8 +7,8 @@ import llvmlite.llvmpy.core as lc import ctypes -from numba import config -from numba import types, utils, cgutils, lowering, _helperlib +from numba import config, cgutils, lowering, _helperlib +from numba.core import types, utils PY_UNICODE_1BYTE_KIND = _helperlib.py_unicode_1byte_kind diff --git a/numba/roc/compiler.py b/numba/roc/compiler.py index f1bf0d63608..02d1491b521 100644 --- a/numba/roc/compiler.py +++ b/numba/roc/compiler.py @@ -5,15 +5,16 @@ import numpy as np -from numba.typing.templates import ConcreteTemplate -from numba import types, compiler +from numba.core.typing.templates import ConcreteTemplate +from numba import compiler +from numba.core import types from .hlc import hlc from .hsadrv import devices, driver, enums, drvapi from .hsadrv.error import HsaKernelLaunchError from . import gcn_occupancy from numba.roc.hsadrv.driver import hsa, dgpu_present from .hsadrv import devicearray -from numba.typing.templates import AbstractTemplate +from numba.core.typing.templates import AbstractTemplate from numba import config from numba.compiler_lock import global_compiler_lock diff --git a/numba/roc/hlc/common.py b/numba/roc/hlc/common.py index 7fd82c6362f..c64c580a9cd 100644 --- a/numba/roc/hlc/common.py +++ b/numba/roc/hlc/common.py @@ -4,7 +4,7 @@ from abc import abstractmethod, ABCMeta -from numba.utils import add_metaclass +from numba.core.utils import add_metaclass import re # These are for parsing labels and metadata diff --git a/numba/roc/hlc/hlc.py b/numba/roc/hlc/hlc.py index 7336207702f..cc2b67b0622 100644 --- a/numba/roc/hlc/hlc.py +++ b/numba/roc/hlc/hlc.py @@ -14,7 +14,7 @@ from . import TRIPLE from datetime import datetime from contextlib import contextmanager -from numba import utils +from numba.core import utils from numba.roc.hsadrv.error import HsaSupportError _real_check_call = check_call diff --git a/numba/roc/hsadrv/driver.py b/numba/roc/hsadrv/driver.py index d6919cbb9ef..340bda40231 100644 --- a/numba/roc/hsadrv/driver.py +++ b/numba/roc/hsadrv/driver.py @@ -17,11 +17,11 @@ from collections import defaultdict, deque from functools import total_ordering from numba import mviewbuf -from numba import utils +from numba.core import utils from numba import config from .error import HsaSupportError, HsaDriverError, HsaApiError from . import enums, enums_ext, drvapi -from numba.utils import longint as long +from numba.core.utils import longint as long import numpy as np diff --git a/numba/roc/hsadrv/drvapi.py b/numba/roc/hsadrv/drvapi.py index 1761d341743..d112ddd2c00 100644 --- a/numba/roc/hsadrv/drvapi.py +++ b/numba/roc/hsadrv/drvapi.py @@ -1,7 +1,7 @@ import ctypes import warnings -from ... import utils +from numba.core import utils from . import enums from .error import HsaApiError, HsaWarning diff --git a/numba/roc/stubs.py b/numba/roc/stubs.py index d32059a122e..180ecf409c2 100644 --- a/numba/roc/stubs.py +++ b/numba/roc/stubs.py @@ -1,5 +1,5 @@ -from numba import types, ir, typing, macro - +from numba import ir, macro +from numba.core import types, typing _stub_error = NotImplementedError("This is a stub.") diff --git a/numba/runtime/nrt.py b/numba/runtime/nrt.py index 6f51e3c8b35..72638f5589b 100644 --- a/numba/runtime/nrt.py +++ b/numba/runtime/nrt.py @@ -1,13 +1,13 @@ from collections import namedtuple from weakref import finalize as _finalize -from . import nrtdynmod +from numba.runtime import nrtdynmod from llvmlite import binding as ll from numba.compiler_lock import global_compiler_lock -from numba.typing.typeof import typeof_impl -from numba import types -from . import _nrt_python as _nrt +from numba.core.typing.typeof import typeof_impl +from numba.core import types +from numba.runtime import _nrt_python as _nrt _nrt_mstats = namedtuple("nrt_mstats", ["alloc", "free", "mi_alloc", "mi_free"]) diff --git a/numba/sigutils.py b/numba/sigutils.py index 6348a9e1fdc..cad5202ac54 100644 --- a/numba/sigutils.py +++ b/numba/sigutils.py @@ -1,4 +1,4 @@ -from numba import types, typing +from numba.core import types, typing def is_signature(sig): diff --git a/numba/special.py b/numba/special.py index 65416445e64..8fc2ee9d305 100644 --- a/numba/special.py +++ b/numba/special.py @@ -1,6 +1,6 @@ import numpy as np -from .typing.typeof import typeof +from numba.core.typing.typeof import typeof def pndindex(*args): diff --git a/numba/stencil.py b/numba/stencil.py index ca075b455fa..2107eb16049 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -8,11 +8,11 @@ import numpy as np from llvmlite import ir as lir -from numba import (compiler, types, ir_utils, ir, typing, numpy_support, utils, - typed_passes) +from numba import (compiler, ir_utils, ir, numpy_support, typed_passes) +from numba.core import types, typing, utils from numba import config -from numba.typing.templates import (CallableTemplate, signature, infer_global, - AbstractTemplate) +from numba.core.typing.templates import (CallableTemplate, signature, + infer_global, AbstractTemplate) from numba.targets import registry from numba.targets.imputils import lower_builtin from numba.extending import register_jitable diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 8e9944d29c7..b36d880d5e4 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -13,13 +13,14 @@ import numba from numba import types -from numba.typing.templates import infer_global, AbstractTemplate -from numba.typing import signature -from numba import ir_utils, ir, utils, config, typing +from numba.core.typing.templates import infer_global, AbstractTemplate +from numba.core.typing import signature +from numba.core import utils, typing +from numba import ir_utils, ir, config from numba.ir_utils import (get_call_table, mk_unique_var, compile_to_numba_ir, replace_arg_nodes, guard, find_callname, require, find_const, GuardException) -from numba.utils import OPERATORS_TO_BUILTINS +from numba.core.utils import OPERATORS_TO_BUILTINS def _compute_last_ind(dim_size, index_const): diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 46391486dd0..06ef64a2737 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -12,19 +12,20 @@ import llvmlite.llvmpy.core as lc -from numba import types, cgutils, generated_jit +from numba import cgutils, generated_jit +from numba.core import types from numba.extending import overload, overload_method, register_jitable from numba.numpy_support import as_dtype, type_can_asarray from numba.numpy_support import numpy_version from numba.numpy_support import is_nonelike from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) -from numba.typing import signature +from numba.core.typing import signature from numba.np.arrayobj import make_array, load_item, store_item, _empty_nd_impl from numba.np.linalg import ensure_blas from numba.extending import intrinsic -from numba.errors import RequireLiteralValue, TypingError +from numba.core.errors import RequireLiteralValue, TypingError def _check_blas(): diff --git a/numba/targets/base.py b/numba/targets/base.py index 7a4202cad4b..dfa8fa95a54 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -12,7 +12,8 @@ from llvmlite.llvmpy.core import Type, Constant, LLVMException import llvmlite.binding as ll -from numba import types, utils, cgutils, typing, funcdesc, debuginfo, config +from numba.core import types, utils, typing +from numba import cgutils, funcdesc, debuginfo, config from numba import _dynfunc, _helperlib from numba.compiler_lock import global_compiler_lock from numba.pythonapi import PythonAPI diff --git a/numba/targets/builtins.py b/numba/targets/builtins.py index e0f501710d5..fa1c0496e51 100644 --- a/numba/targets/builtins.py +++ b/numba/targets/builtins.py @@ -13,10 +13,11 @@ call_getiter, call_iternext, impl_ret_borrowed, impl_ret_untracked, numba_typeref_ctor) -from .. import typing, types, cgutils, utils -from ..extending import overload, intrinsic -from numba.typeconv import Conversion -from numba.errors import TypingError +from numba.core import typing, types, utils +from numba import cgutils +from numba.extending import overload, intrinsic +from numba.core.typeconv import Conversion +from numba.core.errors import TypingError @overload(operator.truth) @@ -481,7 +482,7 @@ def lower_get_type_max_value(context, builder, sig, args): # ----------------------------------------------------------------------------- -from numba.typing.builtins import IndexValue, IndexValueType +from numba.core.typing.builtins import IndexValue, IndexValueType from numba.extending import overload, register_jitable @lower_builtin(IndexValue, types.intp, types.Type) diff --git a/numba/targets/cmathimpl.py b/numba/targets/cmathimpl.py index 005081ca50e..eb984ea5d0c 100644 --- a/numba/targets/cmathimpl.py +++ b/numba/targets/cmathimpl.py @@ -10,8 +10,9 @@ from llvmlite.llvmpy.core import Type from numba.targets.imputils import Registry, impl_ret_untracked -from numba import types, cgutils -from numba.typing import signature +from numba import cgutils +from numba.core import types +from numba.core.typing import signature from . import builtins, mathimpl registry = Registry() diff --git a/numba/targets/codegen.py b/numba/targets/codegen.py index 6c03052ae9e..e0e95d351ff 100644 --- a/numba/targets/codegen.py +++ b/numba/targets/codegen.py @@ -9,7 +9,8 @@ import llvmlite.binding as ll import llvmlite.ir as llvmir -from numba import config, utils, cgutils +from numba.core import utils +from numba import config, cgutils from numba.runtime.nrtopt import remove_redundant_nrt_refct from numba.runtime import rtsys from numba.compiler_lock import require_global_compiler_lock diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index dc247ce05a0..f29b4805092 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -6,18 +6,20 @@ from numba import _dynfunc, config from numba.callwrapper import PyCallWrapper -from .base import BaseContext, PYOBJECT -from numba import utils, cgutils, types -from numba.utils import cached_property +from numba.targets.base import BaseContext, PYOBJECT +from numba.core import utils, types +from numba import cgutils +from numba.core.utils import cached_property from numba.targets import ( callconv, codegen, externals, intrinsics, listobj, setobj, dictimpl, ) -from .options import TargetOptions +from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.compiler_lock import global_compiler_lock import numba.entrypoints -from . import fastmathpass -from .cpu_options import ParallelOptions, FastMathOptions, InlineOptions +from numba.targets import fastmathpass +from numba.targets.cpu_options import (ParallelOptions, FastMathOptions, + InlineOptions) # Keep those structures in sync with _dynfunc.c. diff --git a/numba/targets/externals.py b/numba/targets/externals.py index 522854d9b52..e0f77f0abfe 100644 --- a/numba/targets/externals.py +++ b/numba/targets/externals.py @@ -7,9 +7,9 @@ from llvmlite import ir import llvmlite.binding as ll -from numba import utils +from numba.core import utils from numba import _helperlib -from . import intrinsics +from numba.targets import intrinsics def _add_missing_symbol(symbol, addr): diff --git a/numba/targets/gdb_hook.py b/numba/targets/gdb_hook.py index b0ee6322ba3..5eb1b64c34d 100644 --- a/numba/targets/gdb_hook.py +++ b/numba/targets/gdb_hook.py @@ -3,7 +3,8 @@ from llvmlite import ir -from numba import gdb, gdb_init, gdb_breakpoint, types, utils, cgutils, config +from numba.core import types, utils +from numba import gdb, gdb_init, gdb_breakpoint, cgutils, config from numba.extending import overload, intrinsic _path = os.path.dirname(__file__) diff --git a/numba/targets/hashing.py b/numba/targets/hashing.py index 20793d44909..c1601cf86b4 100644 --- a/numba/targets/hashing.py +++ b/numba/targets/hashing.py @@ -14,7 +14,8 @@ from numba.extending import ( overload, overload_method, intrinsic, register_jitable) -from numba import types, errors, utils +from numba import errors +from numba.core import types, utils from numba.unsafe.bytes import grab_byte, grab_uint64_t _py38_or_later = utils.PYVERSION >= (3, 8) diff --git a/numba/targets/imputils.py b/numba/targets/imputils.py index 4865b15e720..6bbd3574728 100644 --- a/numba/targets/imputils.py +++ b/numba/targets/imputils.py @@ -9,8 +9,9 @@ import functools from enum import Enum -from .. import typing, cgutils, types, utils -from .. typing.templates import BaseRegistryLoader +from numba.core import typing, types, utils +from numba import cgutils +from numba.core.typing.templates import BaseRegistryLoader class Registry(object): diff --git a/numba/targets/listobj.py b/numba/targets/listobj.py index 57f66102deb..727fe3d5010 100644 --- a/numba/targets/listobj.py +++ b/numba/targets/listobj.py @@ -7,15 +7,15 @@ import operator from llvmlite import ir -from numba import types, cgutils, typing, errors +from numba import cgutils +from numba.core import types, typing, errors, slicing from numba.targets.imputils import (lower_builtin, lower_cast, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, RefType) from numba.extending import overload_method, overload -from numba.utils import cached_property +from numba.core.utils import cached_property from numba.misc import quicksort -from numba.np import slicing def get_list_payload(context, builder, list_type, value): diff --git a/numba/targets/mathimpl.py b/numba/targets/mathimpl.py index 2aacf37a8b6..813b79418af 100644 --- a/numba/targets/mathimpl.py +++ b/numba/targets/mathimpl.py @@ -11,9 +11,10 @@ from llvmlite.llvmpy.core import Type from numba.targets.imputils import Registry, impl_ret_untracked -from numba import types, typeof, cgutils, utils, config +from numba import typeof, cgutils, config +from numba.core import types, utils from numba.extending import overload -from numba.typing import signature +from numba.core.typing import signature from numba.unsafe.numbers import trailing_zeros diff --git a/numba/targets/numbers.py b/numba/targets/numbers.py index c3235a05d08..ec396ecb8a9 100644 --- a/numba/targets/numbers.py +++ b/numba/targets/numbers.py @@ -8,13 +8,15 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from .imputils import (lower_builtin, lower_getattr, lower_getattr_generic, - lower_cast, lower_constant, - impl_ret_borrowed, impl_ret_untracked) -from . import optional -from .. import typing, types, cgutils, utils, errors -from ..extending import intrinsic, overload_method -from ..unsafe.numbers import viewer +from numba.targets.imputils import (lower_builtin, lower_getattr, + lower_getattr_generic, lower_cast, + lower_constant, impl_ret_borrowed, + impl_ret_untracked) +from numba.targets import optional +from numba.core import typing, types, utils, errors +from numba import cgutils +from numba.extending import intrinsic, overload_method +from numba.unsafe.numbers import viewer def _int_arith_flags(rettype): diff --git a/numba/targets/optional.py b/numba/targets/optional.py index ce718e72278..15b8ed8b905 100644 --- a/numba/targets/optional.py +++ b/numba/targets/optional.py @@ -1,9 +1,11 @@ import operator -from numba import types, cgutils, typing +from numba.core import types, typing +from numba import cgutils -from .imputils import (lower_cast, lower_builtin, lower_getattr_generic, - impl_ret_untracked, lower_setattr_generic) +from numba.targets.imputils import (lower_cast, lower_builtin, + lower_getattr_generic, impl_ret_untracked, + lower_setattr_generic) def always_return_true_impl(context, builder, sig, args): diff --git a/numba/targets/rangeobj.py b/numba/targets/rangeobj.py index 8b2a9f7dd03..53f078a1b67 100644 --- a/numba/targets/rangeobj.py +++ b/numba/targets/rangeobj.py @@ -7,11 +7,11 @@ import llvmlite.llvmpy.core as lc from numba import types, cgutils, prange -from .listobj import ListIterInstance +from numba.targets.listobj import ListIterInstance from numba.np.arrayobj import make_array -from .imputils import (lower_builtin, lower_cast, - iterator_impl, impl_ret_untracked) -from numba.typing import signature +from numba.targets.imputils import (lower_builtin, lower_cast, + iterator_impl, impl_ret_untracked) +from numba.core.typing import signature from numba.extending import intrinsic, overload, overload_attribute, register_jitable from numba.parfor import internal_prange diff --git a/numba/targets/registry.py b/numba/targets/registry.py index 106a0603174..3930682463d 100644 --- a/numba/targets/registry.py +++ b/numba/targets/registry.py @@ -1,8 +1,9 @@ import contextlib -from . import cpu -from .descriptors import TargetDescriptor -from .. import dispatcher, utils, typing +from numba.targets import cpu +from numba.targets.descriptors import TargetDescriptor +from numba import dispatcher +from numba.core import utils, typing # ----------------------------------------------------------------------------- # Default CPU target descriptors diff --git a/numba/targets/setobj.py b/numba/targets/setobj.py index 788bc6ddeb0..b0bcdfc69b6 100644 --- a/numba/targets/setobj.py +++ b/numba/targets/setobj.py @@ -9,14 +9,15 @@ import operator from llvmlite import ir -from numba import types, cgutils, typing +from numba.core import types, typing +from numba import cgutils from numba.targets.imputils import (lower_builtin, lower_cast, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, for_iter, call_len, RefType) -from numba.utils import cached_property +from numba.core.utils import cached_property from numba.misc import quicksort -from numba.np import slicing +from numba.core import slicing def get_payload_struct(context, builder, set_type, ptr): diff --git a/numba/targets/tupleobj.py b/numba/targets/tupleobj.py index f82c1188336..32681f4d76e 100644 --- a/numba/targets/tupleobj.py +++ b/numba/targets/tupleobj.py @@ -6,12 +6,13 @@ import llvmlite.llvmpy.core as lc import operator -from .imputils import (lower_builtin, lower_getattr_generic, lower_cast, - lower_constant, - iternext_impl, impl_ret_borrowed, impl_ret_untracked, - RefType) -from .. import typing, types, cgutils -from ..extending import overload_method, overload, intrinsic +from numba.targets.imputils import (lower_builtin, lower_getattr_generic, + lower_cast, lower_constant, iternext_impl, + impl_ret_borrowed, impl_ret_untracked, + RefType) +from numba.core import typing, types +from numba import cgutils +from numba.extending import overload_method, overload, intrinsic @lower_builtin(types.NamedTupleClass, types.VarArg(types.Any)) diff --git a/numba/tests/support.py b/numba/tests/support.py index bb23789d98f..dd95e1d81fd 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -27,7 +27,8 @@ except ImportError: scipy = None -from numba import config, errors, typing, utils, numpy_support, testing +from numba import config, numpy_support, testing +from numba.core import errors, typing, utils from numba.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS from numba.targets import cpu import numba.unittest_support as unittest diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index c976c2c61d6..0b5636f5963 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -4,9 +4,10 @@ from collections.abc import MutableMapping from numba import config -from numba.types import DictType, TypeRef +from numba.core.types import DictType, TypeRef from numba.targets.imputils import numba_typeref_ctor -from numba import njit, dictobject, types, cgutils, errors, typeof +from numba import njit, dictobject, cgutils, typeof +from numba.core import types, errors from numba.extending import ( overload_method, overload, diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index 4d6346d81f4..e0a950cf685 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -10,12 +10,13 @@ """ from collections.abc import MutableSequence -from numba.types import ListType, TypeRef +from numba.core.types import ListType, TypeRef from numba.targets.imputils import numba_typeref_ctor from numba import listobject from numba.dispatcher import Dispatcher from numba import config -from numba import njit, types, cgutils, errors, typeof +from numba.core import types, errors +from numba import njit, cgutils, typeof from numba.extending import ( overload_method, overload, diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 05217f9463c..67b0a644266 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -1,18 +1,18 @@ from contextlib import contextmanager import warnings -from . import (config, errors, types, rewrites, typeinfer, funcdesc, lowering, - typing, ir) - -from .parfor import PreParforPass as _parfor_PreParforPass -from .parfor import ParforPass as _parfor_ParforPass -from .parfor import Parfor - -from .compiler_machinery import FunctionPass, LoweringPass, register_pass -from .annotations import type_annotations -from .ir_utils import (raise_on_unsupported_feature, warn_deprecated, - check_and_legalize_ir, guard, dead_code_elimination, - simplify_CFG, get_definition) +from numba import (config, rewrites, typeinfer, funcdesc, lowering, ir) +from numba.core import errors, types, typing + +from numba.parfor import PreParforPass as _parfor_PreParforPass +from numba.parfor import ParforPass as _parfor_ParforPass +from numba.parfor import Parfor + +from numba.compiler_machinery import FunctionPass, LoweringPass, register_pass +from numba.annotations import type_annotations +from numba.ir_utils import (raise_on_unsupported_feature, warn_deprecated, + check_and_legalize_ir, guard, dead_code_elimination, + simplify_CFG, get_definition) @contextmanager diff --git a/numba/typedobjectutils.py b/numba/typedobjectutils.py index 9ae34788b8a..ba345fa32da 100644 --- a/numba/typedobjectutils.py +++ b/numba/typedobjectutils.py @@ -8,11 +8,11 @@ from numba import cgutils from numba import types -from numba import typing +from numba.core import typing from numba.targets.registry import cpu_target -from numba.typeconv import Conversion +from numba.core.typeconv import Conversion from numba.extending import intrinsic -from numba.errors import TypingError, NumbaTypeSafetyWarning +from numba.core.errors import TypingError, NumbaTypeSafetyWarning def _as_bytes(builder, ptr): diff --git a/numba/typeinfer.py b/numba/typeinfer.py index 789c8ae6f9a..8faa1e3bd55 100644 --- a/numba/typeinfer.py +++ b/numba/typeinfer.py @@ -21,10 +21,12 @@ from collections import OrderedDict, defaultdict from functools import reduce -from numba import ir, types, utils, config, typing -from .errors import (TypingError, UntypedAttributeError, new_error_context, - termcolor, UnsupportedError, ForceLiteralArg) -from .funcdesc import qualifying_prefix +from numba import ir, config +from numba.core import types, utils, typing +from numba.core.errors import (TypingError, UntypedAttributeError, + new_error_context, termcolor, UnsupportedError, + ForceLiteralArg) +from numba.funcdesc import qualifying_prefix _logger = logging.getLogger(__name__) diff --git a/numba/unicode.py b/numba/unicode.py index b0d50abf3b2..7b361549108 100644 --- a/numba/unicode.py +++ b/numba/unicode.py @@ -19,34 +19,50 @@ from numba.targets.imputils import (lower_constant, lower_cast, lower_builtin, iternext_impl, impl_ret_new_ref, RefType) from numba.datamodel import register_default, StructModel -from numba import cgutils, utils, types +from numba import cgutils +from numba.core import utils, types from numba.pythonapi import ( PY_UNICODE_1BYTE_KIND, PY_UNICODE_2BYTE_KIND, PY_UNICODE_4BYTE_KIND, PY_UNICODE_WCHAR_KIND, ) -from numba.np import slicing +from numba.core import slicing from numba._helperlib import c_helpers from numba.targets.hashing import _Py_hash_t from numba.unsafe.bytes import memcpy_region -from numba.errors import TypingError -from .unicode_support import (_Py_TOUPPER, _Py_TOLOWER, _Py_UCS4, _Py_ISALNUM, - _PyUnicode_ToUpperFull, _PyUnicode_ToLowerFull, - _PyUnicode_ToFoldedFull, - _PyUnicode_ToTitleFull, _PyUnicode_IsPrintable, - _PyUnicode_IsSpace, _Py_ISSPACE, - _PyUnicode_IsXidStart, _PyUnicode_IsXidContinue, - _PyUnicode_IsCased, _PyUnicode_IsCaseIgnorable, - _PyUnicode_IsUppercase, _PyUnicode_IsLowercase, - _PyUnicode_IsLineBreak, _Py_ISLINEBREAK, - _Py_ISLINEFEED, _Py_ISCARRIAGERETURN, - _PyUnicode_IsTitlecase, _Py_ISLOWER, _Py_ISUPPER, - _Py_TAB, _Py_LINEFEED, - _Py_CARRIAGE_RETURN, _Py_SPACE, - _PyUnicode_IsAlpha, _PyUnicode_IsNumeric, - _Py_ISALPHA, _PyUnicode_IsDigit, - _PyUnicode_IsDecimalDigit) +from numba.core.errors import TypingError +from numba.unicode_support import (_Py_TOUPPER, _Py_TOLOWER, _Py_UCS4, + _Py_ISALNUM, + _PyUnicode_ToUpperFull, + _PyUnicode_ToLowerFull, + _PyUnicode_ToFoldedFull, + _PyUnicode_ToTitleFull, + _PyUnicode_IsPrintable, + _PyUnicode_IsSpace, + _Py_ISSPACE, + _PyUnicode_IsXidStart, + _PyUnicode_IsXidContinue, + _PyUnicode_IsCased, + _PyUnicode_IsCaseIgnorable, + _PyUnicode_IsUppercase, + _PyUnicode_IsLowercase, + _PyUnicode_IsLineBreak, + _Py_ISLINEBREAK, + _Py_ISLINEFEED, + _Py_ISCARRIAGERETURN, + _PyUnicode_IsTitlecase, + _Py_ISLOWER, + _Py_ISUPPER, + _Py_TAB, + _Py_LINEFEED, + _Py_CARRIAGE_RETURN, + _Py_SPACE, + _PyUnicode_IsAlpha, + _PyUnicode_IsNumeric, + _Py_ISALPHA, + _PyUnicode_IsDigit, + _PyUnicode_IsDecimalDigit) _py38_or_later = utils.PYVERSION >= (3, 8) diff --git a/numba/unicode_support.py b/numba/unicode_support.py index d170102e0cf..e4ed4defb33 100644 --- a/numba/unicode_support.py +++ b/numba/unicode_support.py @@ -9,11 +9,12 @@ import numpy as np import llvmlite.llvmpy.core as lc -from numba import types, cgutils +from numba.core import types +from numba import cgutils from numba.targets.imputils import (impl_ret_untracked) from numba.extending import overload, intrinsic, register_jitable -from .errors import TypingError +from numba.core.errors import TypingError # This is equivalent to the struct `_PyUnicode_TypeRecord defined in CPython's # Objects/unicodectype.c diff --git a/numba/unsafe/ndarray.py b/numba/unsafe/ndarray.py index d585eb63a0b..81801863e81 100644 --- a/numba/unsafe/ndarray.py +++ b/numba/unsafe/ndarray.py @@ -2,12 +2,11 @@ This file provides internal compiler utilities that support certain special operations with numpy. """ -from numba import types -from numba import typing +from numba.core import types, typing from numba.cgutils import unpack_tuple from numba.extending import intrinsic from numba.targets.imputils import impl_ret_new_ref -from numba.errors import RequireLiteralValue, TypingError +from numba.core.errors import RequireLiteralValue, TypingError from .tuple import tuple_setitem diff --git a/numba/withcontexts.py b/numba/withcontexts.py index 92fefb68ce2..3de88dca01e 100644 --- a/numba/withcontexts.py +++ b/numba/withcontexts.py @@ -1,6 +1,7 @@ -from numba import ir, ir_utils, types, errors, sigutils -from numba.typing.typeof import typeof_impl -from .transforms import find_region_inout_vars +from numba import ir, ir_utils, sigutils +from numba.core import types, errors +from numba.core.typing.typeof import typeof_impl +from numba.transforms import find_region_inout_vars class WithContext(object): From 374eaa11dc8438b3df2c820446636748e56ca94e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 28 Jan 2020 17:48:02 +0000 Subject: [PATCH 309/595] fix errors imports --- docs/source/extending/mynorm.py | 2 +- numba/cuda/tests/cudapy/test_device_func.py | 2 +- numba/cuda/tests/cudapy/test_macro.py | 2 +- numba/cuda/tests/nocuda/test_library_lookup.py | 2 +- numba/roc/tests/hsapy/test_intrinsics.py | 2 +- numba/targets/heapq.py | 2 +- numba/targets/literal.py | 2 +- numba/tests/npyufunc/test_ufunc.py | 2 +- numba/tests/test_array_attr.py | 2 +- numba/tests/test_array_constants.py | 2 +- numba/tests/test_array_manipulation.py | 2 +- numba/tests/test_array_methods.py | 2 +- numba/tests/test_closure.py | 2 +- numba/tests/test_comprehension.py | 2 +- numba/tests/test_debug.py | 2 +- numba/tests/test_deprecations.py | 2 +- numba/tests/test_dictobject.py | 2 +- numba/tests/test_dicts.py | 2 +- numba/tests/test_dispatcher.py | 2 +- numba/tests/test_dyn_array.py | 2 +- numba/tests/test_extending.py | 2 +- numba/tests/test_extending_types.py | 2 +- numba/tests/test_fancy_indexing.py | 2 +- numba/tests/test_jitclasses.py | 2 +- numba/tests/test_listobject.py | 2 +- numba/tests/test_np_functions.py | 2 +- numba/tests/test_npdatetime.py | 2 +- numba/tests/test_numbers.py | 2 +- numba/tests/test_recursion.py | 2 +- numba/tests/test_return_values.py | 2 +- numba/tests/test_serialize.py | 2 +- numba/tests/test_stencils.py | 2 +- numba/tests/test_try_except.py | 2 +- numba/tests/test_typedlist.py | 2 +- numba/tests/test_typingerror.py | 2 +- numba/tests/test_ufuncs.py | 2 +- numba/tests/test_unicode.py | 2 +- numba/tests/test_unsafe_intrinsics.py | 2 +- numba/tests/test_warnings.py | 2 +- 39 files changed, 39 insertions(+), 39 deletions(-) diff --git a/docs/source/extending/mynorm.py b/docs/source/extending/mynorm.py index 66a3f9c0c90..884634ea31c 100644 --- a/docs/source/extending/mynorm.py +++ b/docs/source/extending/mynorm.py @@ -1,7 +1,7 @@ import numpy as np from numba import njit, types from numba.extending import overload, register_jitable -from numba.errors import TypingError +from numba.core.errors import TypingError import scipy.linalg diff --git a/numba/cuda/tests/cudapy/test_device_func.py b/numba/cuda/tests/cudapy/test_device_func.py index 39b95ef65e3..796810528f5 100644 --- a/numba/cuda/tests/cudapy/test_device_func.py +++ b/numba/cuda/tests/cudapy/test_device_func.py @@ -5,7 +5,7 @@ from numba.cuda.testing import unittest, skip_on_cudasim, SerialMixin from numba import cuda, jit, int32 -from numba.errors import TypingError +from numba.core.errors import TypingError class TestDeviceFunc(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_macro.py b/numba/cuda/tests/cudapy/test_macro.py index 84538c014ba..ffc0631e403 100644 --- a/numba/cuda/tests/cudapy/test_macro.py +++ b/numba/cuda/tests/cudapy/test_macro.py @@ -1,6 +1,6 @@ import numpy as np from numba import cuda, float32 -from numba.errors import MacroError +from numba.core.errors import MacroError from numba.cuda.testing import unittest, SerialMixin from numba.cuda.testing import skip_on_cudasim diff --git a/numba/cuda/tests/nocuda/test_library_lookup.py b/numba/cuda/tests/nocuda/test_library_lookup.py index f104331f723..9d2dda414ca 100644 --- a/numba/cuda/tests/nocuda/test_library_lookup.py +++ b/numba/cuda/tests/nocuda/test_library_lookup.py @@ -4,7 +4,7 @@ import warnings from numba.config import IS_WIN32, IS_OSX -from numba.errors import NumbaWarning +from numba.core.errors import NumbaWarning from numba.cuda.cudadrv import nvvm from numba.cuda.testing import ( unittest, diff --git a/numba/roc/tests/hsapy/test_intrinsics.py b/numba/roc/tests/hsapy/test_intrinsics.py index dfc47e06eec..793e4263d5c 100644 --- a/numba/roc/tests/hsapy/test_intrinsics.py +++ b/numba/roc/tests/hsapy/test_intrinsics.py @@ -2,7 +2,7 @@ from numba import unittest_support as unittest from numba import roc -from numba.errors import TypingError +from numba.core.errors import TypingError import operator as oper _WAVESIZE = roc.get_context().agent.wavefront_size diff --git a/numba/targets/heapq.py b/numba/targets/heapq.py index e86ab12fdff..88356ffba63 100644 --- a/numba/targets/heapq.py +++ b/numba/targets/heapq.py @@ -4,7 +4,7 @@ import heapq as hq from numba import types -from numba.errors import TypingError +from numba.core.errors import TypingError from numba.extending import overload, register_jitable diff --git a/numba/targets/literal.py b/numba/targets/literal.py index ffcfcddd935..bafbbfe100d 100644 --- a/numba/targets/literal.py +++ b/numba/targets/literal.py @@ -1,7 +1,7 @@ from numba.extending import overload from numba import types from numba.special import literally, literal_unroll -from numba.errors import TypingError +from numba.core.errors import TypingError @overload(literally) diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index b6d97747020..1b9d9bb3378 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -3,7 +3,7 @@ from numba import unittest_support as unittest from numba import float32, jit from numba.npyufunc import Vectorize -from numba.errors import TypingError +from numba.core.errors import TypingError from ..support import TestCase diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index b4fdb5fbd37..d1bfbb830a3 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -7,7 +7,7 @@ from numba import types, njit, typeof from .support import (TestCase, CompilationCache, MemoryLeakMixin, tag, skip_parfors_unsupported) -from numba.errors import TypingError +from numba.core.errors import TypingError def array_dtype(a): diff --git a/numba/tests/test_array_constants.py b/numba/tests/test_array_constants.py index 2391b7e3fdd..df534f8d648 100644 --- a/numba/tests/test_array_constants.py +++ b/numba/tests/test_array_constants.py @@ -2,7 +2,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated -from numba.errors import TypingError +from numba.core.errors import TypingError from numba import jit, types, typeof diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 22182682efc..ae8e6d3b27b 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -6,7 +6,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import jit, njit, types, from_dtype, errors, typeof -from numba.errors import TypingError +from numba.core.errors import TypingError from .support import TestCase, MemoryLeakMixin, CompilationCache, tag enable_pyobj_flags = Flags() diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index 542080cdcd0..c8b12ffeac4 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -7,7 +7,7 @@ from numba import unittest_support as unittest from numba import jit, typeof, types from numba.compiler import compile_isolated -from numba.errors import TypingError, LoweringError +from numba.core.errors import TypingError, LoweringError from numba.numpy_support import as_dtype from .support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, tag, needs_blas) diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index cc64157dfb9..62ec28923cf 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -4,7 +4,7 @@ import numba.unittest_support as unittest from numba import njit, jit, testing -from numba.errors import TypingError, UnsupportedError +from numba.core.errors import TypingError, UnsupportedError from .support import TestCase diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index 69db5c2c5e8..f107d80c9ed 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -10,7 +10,7 @@ from numba.compiler import compile_isolated from numba import types, utils, jit, types -from numba.errors import TypingError, LoweringError +from numba.core.errors import TypingError, LoweringError from .support import tag, _32bit from numba.tests.support import captured_stdout diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 3ddd7259d12..1bb00612456 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -13,7 +13,7 @@ from numba import jit, jitclass, types from numba.compiler import compile_isolated, Flags from numba.targets.cpu import ParallelOptions -from numba.errors import NumbaPerformanceWarning +from numba.core.errors import NumbaPerformanceWarning from numba import compiler, prange diff --git a/numba/tests/test_deprecations.py b/numba/tests/test_deprecations.py index d367dda0e25..a1d48e41899 100644 --- a/numba/tests/test_deprecations.py +++ b/numba/tests/test_deprecations.py @@ -1,6 +1,6 @@ import warnings from numba import jit -from numba.errors import (NumbaDeprecationWarning, +from numba.core.errors import (NumbaDeprecationWarning, NumbaPendingDeprecationWarning, NumbaWarning) import numba.unittest_support as unittest diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 7fed08c58ed..350487c5331 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -16,7 +16,7 @@ from numba import dictobject, typeof from numba.typed import Dict from numba.typedobjectutils import _sentry_safe_cast -from numba.errors import TypingError +from numba.core.errors import TypingError from .support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) diff --git a/numba/tests/test_dicts.py b/numba/tests/test_dicts.py index ed85cf08eb6..9e862cd338b 100644 --- a/numba/tests/test_dicts.py +++ b/numba/tests/test_dicts.py @@ -1,5 +1,5 @@ from numba import njit -from numba.errors import TypingError +from numba.core.errors import TypingError import numba.unittest_support as unittest from .support import TestCase, force_pyobj_flags diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 43fd9093693..cac1b8a9a85 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -29,7 +29,7 @@ from numba import jit, generated_jit, types, typeof, errors from numba import _dispatcher from numba.compiler import compile_isolated -from numba.errors import NumbaWarning +from numba.core.errors import NumbaWarning from .support import (TestCase, temp_directory, import_dynamic, override_env_config, capture_cache_log, captured_stdout) from numba.numpy_support import as_dtype diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 8f0f86e2a6e..400ef64cf4a 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -6,7 +6,7 @@ import gc from numba import unittest_support as unittest -from numba.errors import TypingError +from numba.core.errors import TypingError from numba import config from numba import njit from numba import types diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 3f32a992a6c..bac2c8e37ff 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -16,7 +16,7 @@ from numba.compiler import compile_isolated from .support import (TestCase, captured_stdout, tag, temp_directory, override_config) -from numba.errors import LoweringError +from numba.core.errors import LoweringError from numba.extending import (typeof_impl, type_callable, lower_builtin, lower_cast, diff --git a/numba/tests/test_extending_types.py b/numba/tests/test_extending_types.py index f2ac7cfa468..c1874d61dd2 100644 --- a/numba/tests/test_extending_types.py +++ b/numba/tests/test_extending_types.py @@ -5,7 +5,7 @@ from numba import njit from numba import types from numba import cgutils -from numba.errors import TypingError +from numba.core.errors import TypingError from numba.extending import lower_builtin from numba.extending import models, register_model from numba.extending import make_attribute_wrapper diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index 34f98250234..957fc83b249 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -4,7 +4,7 @@ import numba.unittest_support as unittest from numba import types, jit, typeof -from numba.errors import TypingError +from numba.core.errors import TypingError from .support import MemoryLeakMixin, TestCase, tag diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index 584ec654a6b..80c0bde8099 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -13,7 +13,7 @@ from .support import TestCase, MemoryLeakMixin from numba.jitclass import _box from numba.runtime.nrt import MemInfo -from numba.errors import LoweringError +from numba.core.errors import LoweringError class TestClass1(object): diff --git a/numba/tests/test_listobject.py b/numba/tests/test_listobject.py index be37aa7773d..04970d5fbb0 100644 --- a/numba/tests/test_listobject.py +++ b/numba/tests/test_listobject.py @@ -13,7 +13,7 @@ from numba import njit from numba import int32, types -from numba.errors import TypingError +from numba.core.errors import TypingError from numba import listobject from .support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen) diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index f5cfc843df1..37ec503c987 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -11,7 +11,7 @@ from numba.compiler import Flags from numba import jit, njit, typeof, types from numba.numpy_support import numpy_version -from numba.errors import TypingError +from numba.core.errors import TypingError from numba.config import IS_WIN32, IS_32BITS from numba.utils import pysignature from numba.targets.arraymath import cross2d diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 0c75e3f4ef2..682b2bd5957 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -14,7 +14,7 @@ import numba.unittest_support as unittest from numba import config, jit, npdatetime, types, vectorize, numpy_support from numba.numpy_support import numpy_version -from numba.errors import TypingError +from numba.core.errors import TypingError from .support import TestCase, tag diff --git a/numba/tests/test_numbers.py b/numba/tests/test_numbers.py index dcf465bd82e..a3b30db2fe6 100644 --- a/numba/tests/test_numbers.py +++ b/numba/tests/test_numbers.py @@ -3,7 +3,7 @@ import numpy as np from numba import njit, types -from numba.errors import TypingError +from numba.core.errors import TypingError from .support import TestCase diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index ada4b913788..35251fa9d1a 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -3,7 +3,7 @@ from numba import jit from numba import unittest_support as unittest -from numba.errors import TypingError, NumbaWarning +from numba.core.errors import TypingError, NumbaWarning from .support import TestCase diff --git a/numba/tests/test_return_values.py b/numba/tests/test_return_values.py index 3d35fea83c0..ef281693348 100644 --- a/numba/tests/test_return_values.py +++ b/numba/tests/test_return_values.py @@ -8,7 +8,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import types -from numba.errors import TypingError +from numba.core.errors import TypingError enable_pyobj_flags = Flags() diff --git a/numba/tests/test_serialize.py b/numba/tests/test_serialize.py index 01bf7207e0f..00c7aaa8be6 100644 --- a/numba/tests/test_serialize.py +++ b/numba/tests/test_serialize.py @@ -5,7 +5,7 @@ import sys from numba import unittest_support as unittest -from numba.errors import TypingError +from numba.core.errors import TypingError from numba.targets import registry from .support import TestCase, tag from .serialize_usecases import * diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index 0b702c8145b..7431c9cd408 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -20,7 +20,7 @@ from numba.targets import registry from numba.targets.cpu import ParallelOptions from .support import tag, skip_parfors_unsupported, _32bit -from numba.errors import LoweringError, TypingError +from numba.core.errors import LoweringError, TypingError skip_unsupported = skip_parfors_unsupported diff --git a/numba/tests/test_try_except.py b/numba/tests/test_try_except.py index 3d19e930c83..1e8d184b4cc 100644 --- a/numba/tests/test_try_except.py +++ b/numba/tests/test_try_except.py @@ -4,7 +4,7 @@ import numpy as np from numba import njit, typed, objmode, prange -from numba.errors import ( +from numba.core.errors import ( UnsupportedError, CompilerError, NumbaPerformanceWarning, TypingError, ) from .support import ( diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 4ea6c917d91..e75cf1604cb 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -7,7 +7,7 @@ from numba import int32, float32, types, prange from numba import jitclass, typeof from numba.typed import List, Dict -from numba.errors import TypingError +from numba.core.errors import TypingError from .support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen, skip_parfors_unsupported) diff --git a/numba/tests/test_typingerror.py b/numba/tests/test_typingerror.py index 6575c7a7286..c6e5a664ac1 100644 --- a/numba/tests/test_typingerror.py +++ b/numba/tests/test_typingerror.py @@ -8,7 +8,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated from numba import jit, types -from numba.errors import TypingError +from numba.core.errors import TypingError from .support import TestCase diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index c57107b06e3..ba098263713 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -13,7 +13,7 @@ from numba.compiler import compile_isolated, Flags, DEFAULT_FLAGS from numba.numpy_support import from_dtype from numba import jit, vectorize -from numba.errors import LoweringError, TypingError +from numba.core.errors import LoweringError, TypingError from .support import TestCase, CompilationCache, MemoryLeakMixin, tag from numba.typing.npydecl import supported_ufuncs, all_ufuncs diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 356e18a2e47..885bf9ecd25 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -5,7 +5,7 @@ from numba import njit, types, utils import numba.unittest_support as unittest from .support import (TestCase, no_pyobj_flags, MemoryLeakMixin) -from numba.errors import TypingError +from numba.core.errors import TypingError _py37_or_later = utils.PYVERSION >= (3, 7) diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index 13c77001614..47b9c6a5f4c 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -8,7 +8,7 @@ from numba.unsafe.bytes import memcpy_region from numba.unsafe.refcount import dump_refcount from numba.unsafe.numbers import trailing_zeros, leading_zeros -from numba.errors import TypingError +from numba.core.errors import TypingError class TestTupleIntrinsic(TestCase): diff --git a/numba/tests/test_warnings.py b/numba/tests/test_warnings.py index 1dbdf5bc097..91f677476cd 100644 --- a/numba/tests/test_warnings.py +++ b/numba/tests/test_warnings.py @@ -6,7 +6,7 @@ import numba.unittest_support as unittest from numba import jit -from numba.errors import NumbaWarning, deprecated, NumbaDeprecationWarning +from numba.core.errors import NumbaWarning, deprecated, NumbaDeprecationWarning from numba import errors From ad0275446757279f4599ea103042a59c6c72792a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 10:45:19 +0000 Subject: [PATCH 310/595] tmp --- numba/targets/base.py | 3 ++- numba/targets/npyimpl.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/numba/targets/base.py b/numba/targets/base.py index dfa8fa95a54..251ac2655fc 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -273,7 +273,8 @@ def refresh(self): from . import (arraymath, enumimpl, iterators, numbers, optional, polynomial, rangeobj, tupleobj, gdb_hook, hashing, heapq, literal) - from numba.np import slicing, linalg + from numba.core import slicing + from numba.np import linalg try: from . import npdatetime diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index b1630900c23..18ac79b0485 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -13,15 +13,16 @@ import numpy as np import operator -from . import builtins, callconv, ufunc_db +from numba.targets import builtins, callconv, ufunc_db from numba.np import arrayobj -from .imputils import Registry, impl_ret_new_ref, force_error_model -from .. import typing, types, cgutils, numpy_support, utils -from ..numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype -from ..typing import npydecl -from ..extending import overload, intrinsic - -from .. import errors +from numba.targets.imputils import Registry, impl_ret_new_ref, force_error_model +from numba import cgutils, numpy_support +from numba.core import typing, types, utils +from numba.numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype +from numba.core.typing import npydecl +from numba.extending import overload, intrinsic + +from numba.core import errors registry = Registry() lower = registry.lower From 5805ba4ce351fda2a20c3cd9fc973322a39d95b3 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 12:35:57 +0000 Subject: [PATCH 311/595] Fix c++ --- numba/_dispatcherimpl.cpp | 2 +- numba/core/typeconv/_typeconv.cpp | 4 ++-- numba/tests/test_datamodel.py | 2 +- setup.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/numba/_dispatcherimpl.cpp b/numba/_dispatcherimpl.cpp index b28c9094a5f..67ea1351116 100644 --- a/numba/_dispatcherimpl.cpp +++ b/numba/_dispatcherimpl.cpp @@ -1,4 +1,4 @@ -#include "typeconv/typeconv.hpp" +#include "core/typeconv/typeconv.hpp" #include #include diff --git a/numba/core/typeconv/_typeconv.cpp b/numba/core/typeconv/_typeconv.cpp index 0db3f89169c..305e651dc39 100644 --- a/numba/core/typeconv/_typeconv.cpp +++ b/numba/core/typeconv/_typeconv.cpp @@ -1,5 +1,5 @@ -#include "../_pymodule.h" -#include "../capsulethunk.h" +#include "../../_pymodule.h" +#include "../../capsulethunk.h" #include "typeconv.hpp" extern "C" { diff --git a/numba/tests/test_datamodel.py b/numba/tests/test_datamodel.py index 2d113baf126..bc9515cef04 100644 --- a/numba/tests/test_datamodel.py +++ b/numba/tests/test_datamodel.py @@ -1,6 +1,6 @@ from llvmlite import ir, binding as ll -from numba import types +from numba.core import types from numba import unittest_support as unittest from numba import datamodel from numba.datamodel.testing import test_factory diff --git a/setup.py b/setup.py index 4f325bddb7c..c2f7bb11ab8 100644 --- a/setup.py +++ b/setup.py @@ -112,7 +112,7 @@ def get_ext_modules(): 'numba/_typeof.c', 'numba/_hashtable.c', 'numba/_dispatcherimpl.cpp', - 'numba/typeconv/typeconv.cpp'], + 'numba/core/typeconv/typeconv.cpp'], depends=["numba/_pymodule.h", "numba/_dispatcher.h", "numba/_typeof.h", @@ -136,9 +136,9 @@ def get_ext_modules(): ], **np_compile_args) - ext_typeconv = Extension(name="numba.typeconv._typeconv", - sources=["numba/typeconv/typeconv.cpp", - "numba/typeconv/_typeconv.cpp"], + ext_typeconv = Extension(name="numba.core.typeconv._typeconv", + sources=["numba/core/typeconv/typeconv.cpp", + "numba/core/typeconv/_typeconv.cpp"], depends=["numba/_pymodule.h"], ) From 6b4800703b8ec35feb72273b96880dd0a01bd768 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 13:16:59 +0000 Subject: [PATCH 312/595] fix a load more tests --- numba/cffi_support.py | 4 ++-- numba/core/types/abstract.py | 6 +++--- numba/core/types/misc.py | 13 +++++++------ numba/inline_closurecall.py | 2 +- numba/targets/randomimpl.py | 5 +++-- numba/tests/cache_usecases.py | 3 ++- numba/tests/serialize_usecases.py | 3 ++- numba/tests/test_array_analysis.py | 5 +++-- numba/tests/test_array_exprs.py | 5 +++-- numba/tests/test_debug.py | 3 ++- numba/tests/test_dictobject.py | 3 ++- numba/tests/test_extending.py | 3 ++- numba/tests/test_extending_types.py | 2 +- numba/tests/test_flow_control.py | 4 ++-- numba/tests/test_func_lifetime.py | 5 +++-- numba/tests/test_generators.py | 5 +++-- numba/tests/test_inlining.py | 3 ++- numba/tests/test_ir_inlining.py | 3 ++- numba/tests/test_ir_utils.py | 5 +++-- numba/tests/test_itanium_mangler.py | 2 +- numba/tests/test_iteration.py | 5 +++-- numba/tests/test_mathlib.py | 7 ++++--- numba/tests/test_numconv.py | 2 +- numba/tests/test_python_int.py | 2 +- numba/tests/test_record_dtype.py | 3 ++- numba/tests/test_stencils.py | 5 +++-- numba/tests/test_target_overloadselector.py | 2 +- numba/tests/test_typeof.py | 11 ++++++----- numba/tests/test_unpack_sequence.py | 5 +++-- numba/tests/test_unsafe_intrinsics.py | 5 +++-- numba/tests/test_warnings.py | 2 +- numba/unsafe/ndarray.py | 2 +- 32 files changed, 78 insertions(+), 57 deletions(-) diff --git a/numba/cffi_support.py b/numba/cffi_support.py index 56ae9b609b3..f78cff04e2a 100644 --- a/numba/cffi_support.py +++ b/numba/cffi_support.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- """ -Alias to numba.typing.cffi_utils for backward compatibility +Alias to numba.core.typing.cffi_utils for backward compatibility """ -from numba.typing.cffi_utils import * +from numba.core.typing.cffi_utils import * diff --git a/numba/core/types/abstract.py b/numba/core/types/abstract.py index 0f7a8272f61..3c19d908e71 100644 --- a/numba/core/types/abstract.py +++ b/numba/core/types/abstract.py @@ -172,7 +172,7 @@ def augment(self, other): # usable as a function signature). def __call__(self, *args): - from ..typing import signature + from numba.core.typing import signature if len(args) == 1 and not isinstance(args[0], Type): return self.cast_python_value(args[0]) return signature(self, # return_type @@ -245,7 +245,7 @@ def unify(self, typingctx, other): """ Unify the two number types using Numpy's rules. """ - from .. import numpy_support + from numba import numpy_support if isinstance(other, Number): # XXX: this can produce unsafe conversions, # e.g. would unify {int64, uint64} to float64 @@ -433,7 +433,7 @@ def literal_value(self): @property def literal_type(self): if self._literal_type_cache is None: - from numba import typing + from numba.core import typing ctx = typing.Context() res = ctx.resolve_value_type(self.literal_value) self._literal_type_cache = res diff --git a/numba/core/types/misc.py b/numba/core/types/misc.py index 05de8ce764b..e4c5792020f 100644 --- a/numba/core/types/misc.py +++ b/numba/core/types/misc.py @@ -1,7 +1,8 @@ -from .abstract import Callable, Literal, Type -from .common import Dummy, IterableType, Opaque, SimpleIteratorType -from ..typeconv import Conversion -from ..errors import TypingError, LiteralTypingError +from numba.core.types.abstract import Callable, Literal, Type +from numba.core.types.common import (Dummy, IterableType, Opaque, + SimpleIteratorType) +from numba.core.typeconv import Conversion +from numba.core.errors import TypingError, LiteralTypingError @@ -285,7 +286,7 @@ def get_call_type(self, context, args, kws): return self.get_call_signatures()[0][0] def get_call_signatures(self): - from .. import typing + from numba.core import typing return_type = ExceptionInstance(self.exc_class) return [typing.signature(return_type)], False @@ -480,7 +481,7 @@ def get_call_signatures(self): return (), False def get_call_type(self, context, args, kws): - from numba import typing + from numba.core import typing if not self.cm.is_callable: msg = "contextmanager {} is not callable".format(self.cm) diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 978d6a430a1..426f11ebbdc 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -423,7 +423,7 @@ def _get_callee_args(call_expr, callee, loc, func_ir): # handle defaults and kw arguments using pysignature if callee is function if isinstance(callee, pytypes.FunctionType): - pysig = numba.utils.pysignature(callee) + pysig = numba.core.utils.pysignature(callee) normal_handler = lambda index, param, default: default default_handler = lambda index, param, default: ir.Const(default, loc) # Throw error for stararg diff --git a/numba/targets/randomimpl.py b/numba/targets/randomimpl.py index 6ea9892555a..c46a6100cdc 100644 --- a/numba/targets/randomimpl.py +++ b/numba/targets/randomimpl.py @@ -14,8 +14,9 @@ from numba.extending import overload, register_jitable from numba.targets.imputils import (Registry, impl_ret_untracked, impl_ret_new_ref) -from numba.typing import signature -from numba import _helperlib, cgutils, types, utils +from numba.core.typing import signature +from numba import _helperlib, cgutils +from numba.core import types, utils POST_PY38 = utils.PYVERSION >= (3, 8) diff --git a/numba/tests/cache_usecases.py b/numba/tests/cache_usecases.py index 7dfef49b380..a54a708731e 100644 --- a/numba/tests/cache_usecases.py +++ b/numba/tests/cache_usecases.py @@ -9,7 +9,8 @@ import numpy as np -from numba import jit, generated_jit, types, prange +from numba import jit, generated_jit, prange +from numba.core import types from numba.tests.ctypes_usecases import c_sin from numba.tests.support import TestCase, captured_stderr diff --git a/numba/tests/serialize_usecases.py b/numba/tests/serialize_usecases.py index ade941daac1..f5a342e9b45 100644 --- a/numba/tests/serialize_usecases.py +++ b/numba/tests/serialize_usecases.py @@ -5,7 +5,8 @@ import math -from numba import jit, generated_jit, types +from numba import jit, generated_jit +from numba.core import types @jit((types.int32, types.int32)) diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 5921eed1725..a6296b28705 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -6,9 +6,10 @@ from io import StringIO from numba import unittest_support as unittest -from numba import (njit, typeof, types, typing, typeof, ir, bytecode, jitclass, +from numba import (njit, typeof, typing, typeof, ir, bytecode, jitclass, prange, postproc) -from .support import TestCase, tag, skip_parfors_unsupported +from numba.core import types +from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager from numba.targets import cpu, registry diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index 1ab36395c1d..e454f913da0 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -5,10 +5,11 @@ from numba import njit, vectorize from numba import unittest_support as unittest -from numba import compiler, typing, typeof, ir, utils, types +from numba import compiler, typeof, ir +from numba.core import utils, types, typing from numba.compiler import Compiler, Flags from numba.targets import cpu -from .support import MemoryLeakMixin, TestCase +from numba.tests.support import MemoryLeakMixin, TestCase class Namespace(dict): diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 1bb00612456..2bfe792f8f3 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -10,7 +10,8 @@ captured_stdout, forbid_codegen, skip_parfors_unsupported, needs_blas) from numba import unittest_support as unittest -from numba import jit, jitclass, types +from numba import jit, jitclass +from numba.core import types from numba.compiler import compile_isolated, Flags from numba.targets.cpu import ParallelOptions from numba.core.errors import NumbaPerformanceWarning diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 350487c5331..2a66ff5082c 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -12,11 +12,12 @@ import numpy as np from numba import njit, jitclass -from numba import int32, int64, float32, float64, types +from numba import int32, int64, float32, float64 from numba import dictobject, typeof from numba.typed import Dict from numba.typedobjectutils import _sentry_safe_cast from numba.core.errors import TypingError +from numba.core import types from .support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index bac2c8e37ff..29b2d7e00c2 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -10,7 +10,8 @@ import numpy as np from numba import unittest_support as unittest -from numba import njit, jit, types, errors, typing, compiler +from numba import njit, jit, compiler +from numba.core import types, errors, typing from numba.typed_passes import type_inference_stage from numba.targets.registry import cpu_target from numba.compiler import compile_isolated diff --git a/numba/tests/test_extending_types.py b/numba/tests/test_extending_types.py index c1874d61dd2..156da1edf4f 100644 --- a/numba/tests/test_extending_types.py +++ b/numba/tests/test_extending_types.py @@ -3,7 +3,7 @@ """ from numba import njit -from numba import types +from numba.core import types from numba import cgutils from numba.core.errors import TypingError from numba.extending import lower_builtin diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index e90c3003342..d38c7988d71 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -3,9 +3,9 @@ import numba.unittest_support as unittest from numba.controlflow import CFGraph, ControlFlowAnalysis from numba.compiler import compile_isolated, Flags -from numba import types +from numba.core import types from numba.bytecode import FunctionIdentity, ByteCode -from .support import TestCase +from numba.tests.support import TestCase enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_func_lifetime.py b/numba/tests/test_func_lifetime.py index cbdadde007f..3960044037b 100644 --- a/numba/tests/test_func_lifetime.py +++ b/numba/tests/test_func_lifetime.py @@ -2,8 +2,9 @@ import weakref from numba import unittest_support as unittest -from numba import jit, types -from .support import TestCase +from numba import jit +from numba.core import types +from numba.tests.support import TestCase class Dummy(object): diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index 564199a6755..c73f721478d 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -3,8 +3,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import jit, njit, types -from .support import TestCase, MemoryLeakMixin +from numba import jit, njit +from numba.core import types +from numba.tests.support import TestCase, MemoryLeakMixin from numba import testing from numba.datamodel.testing import test_factory diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 6851e1683ac..50d999acfdc 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -5,7 +5,8 @@ skip_parfors_unsupported) import numba from numba import unittest_support as unittest -from numba import jit, njit, types, ir, compiler +from numba import jit, njit, ir, compiler +from numba.core import types from numba.ir_utils import guard, find_callname, find_const, get_definition from numba.targets.registry import CPUDispatcher from numba.inline_closurecall import inline_closure_call diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index c12fd8997ed..dbb1acab6f5 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -7,7 +7,8 @@ import numpy as np import numba -from numba import njit, ir, types +from numba import njit, ir +from numba.core import types from numba.extending import ( overload, overload_method, diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index c00c0a81225..ea29605edb1 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -5,7 +5,8 @@ from numba.compiler import CompilerBase, Flags from numba.compiler_machinery import PassManager from numba.targets import registry -from numba import types, ir_utils, bytecode +from numba import ir_utils, bytecode +from numba.core import types from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) @@ -16,7 +17,7 @@ GLOBAL_B = 11 -@jitclass([('val', numba.types.List(numba.intp))]) +@jitclass([('val', numba.core.types.List(numba.intp))]) class Dummy(object): def __init__(self, val): self.val = val diff --git a/numba/tests/test_itanium_mangler.py b/numba/tests/test_itanium_mangler.py index 5b727fb5c43..981e56fcb92 100644 --- a/numba/tests/test_itanium_mangler.py +++ b/numba/tests/test_itanium_mangler.py @@ -5,7 +5,7 @@ from numba import unittest_support as unittest from numba import itanium_mangler from numba import int32, int64, uint32, uint64, float32, float64 -from numba.types import range_iter32_type +from numba.core.types import range_iter32_type class TestItaniumManager(unittest.TestCase): diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index 6a77e6ba502..8061ce8a57f 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -3,8 +3,9 @@ from numba import njit import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import numpy_support, types, errors -from .support import TestCase, MemoryLeakMixin, tag +from numba import numpy_support +from numba.core import types, errors +from numba.tests.support import TestCase, MemoryLeakMixin, tag enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index 1e2128be310..d11046538e4 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -6,10 +6,11 @@ import numpy as np from numba import unittest_support as unittest -from numba.compiler import compile_isolated, Flags, utils -from numba import types, numpy_support +from numba.compiler import compile_isolated, Flags +from numba import numpy_support +from numba.core import utils, types from numba.config import IS_WIN32, IS_32BITS -from .support import TestCase, CompilationCache, tag +from numba.tests.support import TestCase, CompilationCache, tag enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_numconv.py b/numba/tests/test_numconv.py index f1a5f6d371d..e83df2528cc 100644 --- a/numba/tests/test_numconv.py +++ b/numba/tests/test_numconv.py @@ -1,7 +1,7 @@ import itertools import numba.unittest_support as unittest from numba.compiler import compile_isolated -from numba import types +from numba.core import types def template(fromty, toty): diff --git a/numba/tests/test_python_int.py b/numba/tests/test_python_int.py index d8e63681cba..b5b6e13cc77 100644 --- a/numba/tests/test_python_int.py +++ b/numba/tests/test_python_int.py @@ -1,6 +1,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types +from numba.core import types force_pyobj_flags = Flags() diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index d628fd72e72..076c55b0e61 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -2,7 +2,8 @@ import numpy as np import ctypes -from numba import jit, numpy_support, types +from numba import jit, numpy_support +from numba.core import types from numba import unittest_support as unittest from numba.compiler import compile_isolated from numba.itanium_mangler import mangle_type diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index 7431c9cd408..e71813a7a50 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -15,11 +15,12 @@ import numba from numba import unittest_support as unittest -from numba import njit, stencil, types +from numba import njit, stencil +from numba.core import types from numba.compiler import compile_extra, Flags from numba.targets import registry from numba.targets.cpu import ParallelOptions -from .support import tag, skip_parfors_unsupported, _32bit +from numba.tests.support import tag, skip_parfors_unsupported, _32bit from numba.core.errors import LoweringError, TypingError diff --git a/numba/tests/test_target_overloadselector.py b/numba/tests/test_target_overloadselector.py index 8cf208388df..44ff57b6f0b 100644 --- a/numba/tests/test_target_overloadselector.py +++ b/numba/tests/test_target_overloadselector.py @@ -5,7 +5,7 @@ from numba.targets.base import OverloadSelector from numba.targets.registry import cpu_target from numba.targets.imputils import builtin_registry, RegistryLoader -from numba import types +from numba.core import types class TestOverloadSelector(unittest.TestCase): diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 874788c6238..1d212c1c0f8 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -9,15 +9,16 @@ import numpy as np import numba.unittest_support as unittest -from numba import cffi_support, numpy_support, types +from numba import cffi_support, numpy_support +from numba.core import types from numba.special import typeof from numba.dispatcher import OmittedArg from numba._dispatcher import compute_fingerprint -from .support import TestCase, tag -from .test_numpy_support import ValueTypingTestBase -from .ctypes_usecases import * -from .enum_usecases import * +from numba.tests.support import TestCase, tag +from numba.tests.test_numpy_support import ValueTypingTestBase +from numba.tests.ctypes_usecases import * +from numba.tests.enum_usecases import * recordtype = np.dtype([('a', np.float64), diff --git a/numba/tests/test_unpack_sequence.py b/numba/tests/test_unpack_sequence.py index d1a5bfcd2d8..e2b7bf615da 100644 --- a/numba/tests/test_unpack_sequence.py +++ b/numba/tests/test_unpack_sequence.py @@ -2,8 +2,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import errors, types, typeof -from .support import TestCase, MemoryLeakMixin, tag +from numba.core import errors, types +from numba import typeof +from numba.testes.support import TestCase, MemoryLeakMixin, tag enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index 47b9c6a5f4c..38e9e460203 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -1,8 +1,9 @@ import random import numpy as np -from .support import TestCase, captured_stdout -from numba import njit, types +from numba.tests.support import TestCase, captured_stdout +from numba import njit +from numba.core import types from numba.unsafe.tuple import tuple_setitem from numba.unsafe.ndarray import to_fixed_tuple, empty_inferred from numba.unsafe.bytes import memcpy_region diff --git a/numba/tests/test_warnings.py b/numba/tests/test_warnings.py index 91f677476cd..c0131c01942 100644 --- a/numba/tests/test_warnings.py +++ b/numba/tests/test_warnings.py @@ -7,7 +7,7 @@ import numba.unittest_support as unittest from numba import jit from numba.core.errors import NumbaWarning, deprecated, NumbaDeprecationWarning -from numba import errors +from numba.core import errors class TestBuiltins(unittest.TestCase): diff --git a/numba/unsafe/ndarray.py b/numba/unsafe/ndarray.py index 81801863e81..cc756e13cb9 100644 --- a/numba/unsafe/ndarray.py +++ b/numba/unsafe/ndarray.py @@ -20,7 +20,7 @@ def empty_inferred(typingctx, shape): There is special logic in the type-inferencer to handle the "refine"-ing of undefined dtype. """ - from numba.targets.arrayobj import _empty_nd_impl + from numba.np.arrayobj import _empty_nd_impl def codegen(context, builder, signature, args): # check that the return type is now defined From c32cf6bd87178e35f85fd6edc1e9403e4a69ad9e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 13:18:33 +0000 Subject: [PATCH 313/595] fix with sed 1 --- docs/source/proposals/np-where-override.py | 2 +- examples/dict_usage.py | 4 ++-- numba/core/typeconv/rules.py | 2 +- numba/core/typing/bufproto.py | 2 +- numba/core/typing/ctypes_utils.py | 2 +- numba/cuda/cudadecl.py | 2 +- numba/cuda/cudaimpl.py | 2 +- numba/datamodel/manager.py | 2 +- numba/dictobject.py | 2 +- numba/listobject.py | 2 +- numba/misc/quicksort.py | 2 +- numba/roc/hsadecl.py | 2 +- numba/roc/hsaimpl.py | 2 +- numba/roc/mathimpl.py | 2 +- numba/roc/tests/hsapy/test_compiler.py | 2 +- numba/stencilparfor.py | 2 +- numba/targets/cffiimpl.py | 2 +- numba/targets/heapq.py | 2 +- numba/targets/literal.py | 2 +- numba/targets/removerefctpass.py | 2 +- numba/tests/test_annotations.py | 2 +- numba/tests/test_complex.py | 2 +- numba/tests/test_copy_propagate.py | 2 +- numba/tests/test_dyn_array.py | 2 +- numba/tests/test_help.py | 2 +- numba/tests/test_looplifting.py | 2 +- numba/tests/test_maxmin.py | 2 +- numba/tests/test_nan.py | 2 +- numba/tests/test_obj_lifetime.py | 2 +- numba/tests/test_objects.py | 2 +- numba/tests/test_parfors.py | 2 +- numba/tests/test_remove_dead.py | 2 +- numba/tests/test_return_values.py | 2 +- numba/tests/test_typeconv.py | 2 +- numba/tests/test_typedobjectutils.py | 2 +- numba/tests/test_typenames.py | 2 +- numba/tests/test_types.py | 2 +- numba/tests/timsort.py | 2 +- numba/typedobjectutils.py | 2 +- numba/unsafe/nrt.py | 2 +- numba/unsafe/refcount.py | 2 +- 41 files changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/source/proposals/np-where-override.py b/docs/source/proposals/np-where-override.py index 7f7e7956e97..109ba6a4365 100644 --- a/docs/source/proposals/np-where-override.py +++ b/docs/source/proposals/np-where-override.py @@ -1,6 +1,6 @@ import numpy as np -from numba import types +from numba.core import types from numba.extending import overload @overload(np.where) diff --git a/examples/dict_usage.py b/examples/dict_usage.py index 80619ad4062..8a8b892b706 100644 --- a/examples/dict_usage.py +++ b/examples/dict_usage.py @@ -6,7 +6,7 @@ def ex_typed_dict_from_cpython(): # magictoken.ex_typed_dict_from_cpython.begin import numpy as np from numba import njit - from numba import types + from numba.core import types from numba.typed import Dict # The Dict.empty() constructs a typed dictionary. @@ -48,7 +48,7 @@ def ex_typed_dict_njit(): # magictoken.ex_typed_dict_njit.begin import numpy as np from numba import njit - from numba import types + from numba.core import types from numba.typed import Dict # Make array type. Type-expression is not supported in jit functions. diff --git a/numba/core/typeconv/rules.py b/numba/core/typeconv/rules.py index 00f8fcba78b..a769c60bffd 100644 --- a/numba/core/typeconv/rules.py +++ b/numba/core/typeconv/rules.py @@ -1,6 +1,6 @@ import itertools from .typeconv import TypeManager, TypeCastingRules -from numba import types +from numba.core import types default_type_manager = TypeManager() diff --git a/numba/core/typing/bufproto.py b/numba/core/typing/bufproto.py index fbfde99f8b9..b5ec67aad82 100644 --- a/numba/core/typing/bufproto.py +++ b/numba/core/typing/bufproto.py @@ -4,7 +4,7 @@ import array -from numba import types +from numba.core import types _pep3118_int_types = set('bBhHiIlLqQnN') diff --git a/numba/core/typing/ctypes_utils.py b/numba/core/typing/ctypes_utils.py index ea093c1b375..4622e02622e 100644 --- a/numba/core/typing/ctypes_utils.py +++ b/numba/core/typing/ctypes_utils.py @@ -6,7 +6,7 @@ import ctypes import sys -from numba import types +from numba.core import types from . import templates from .typeof import typeof_impl diff --git a/numba/cuda/cudadecl.py b/numba/cuda/cudadecl.py index 1a85470f544..1664da77c9a 100644 --- a/numba/cuda/cudadecl.py +++ b/numba/cuda/cudadecl.py @@ -1,4 +1,4 @@ -from numba import types +from numba.core import types from numba.typing.npydecl import register_number_classes from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, MacroTemplate, diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index 4dfc202e1d7..32e973aaf3d 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -8,7 +8,7 @@ from numba.targets.imputils import Registry from numba import cgutils -from numba import types +from numba.core import types from .cudadrv import nvvm from . import nvvmutils, stubs diff --git a/numba/datamodel/manager.py b/numba/datamodel/manager.py index 0096d9206ef..819f33511c1 100644 --- a/numba/datamodel/manager.py +++ b/numba/datamodel/manager.py @@ -1,6 +1,6 @@ import weakref -from numba import types +from numba.core import types class DataModelManager(object): diff --git a/numba/dictobject.py b/numba/dictobject.py index 10890c25684..09fbd90b160 100644 --- a/numba/dictobject.py +++ b/numba/dictobject.py @@ -19,7 +19,7 @@ lower_builtin, ) from numba.targets.imputils import iternext_impl -from numba import types +from numba.core import types from numba.core.types import ( DictType, DictItemsIterableType, diff --git a/numba/listobject.py b/numba/listobject.py index d9794cacfc2..458f3c1d79f 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -20,7 +20,7 @@ lower_builtin, ) from numba.targets.imputils import iternext_impl -from numba import types +from numba.core import types from numba.core.types import ( ListType, ListTypeIterableType, diff --git a/numba/misc/quicksort.py b/numba/misc/quicksort.py index dc87572d2c0..9b4c986220c 100644 --- a/numba/misc/quicksort.py +++ b/numba/misc/quicksort.py @@ -2,7 +2,7 @@ import numpy as np -from numba import types +from numba.core import types QuicksortImplementation = collections.namedtuple( diff --git a/numba/roc/hsadecl.py b/numba/roc/hsadecl.py index 9de693cd0b1..a51f56537ff 100644 --- a/numba/roc/hsadecl.py +++ b/numba/roc/hsadecl.py @@ -1,4 +1,4 @@ -from numba import types +from numba.core import types from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, MacroTemplate, signature, Registry) diff --git a/numba/roc/hsaimpl.py b/numba/roc/hsaimpl.py index a5ae907cf30..a0e5d45ac35 100644 --- a/numba/roc/hsaimpl.py +++ b/numba/roc/hsaimpl.py @@ -8,7 +8,7 @@ from numba.targets.imputils import Registry from numba import cgutils -from numba import types +from numba.core import types from numba.itanium_mangler import mangle_c, mangle, mangle_type from . import target from . import stubs diff --git a/numba/roc/mathimpl.py b/numba/roc/mathimpl.py index 47140796e42..624c8cb4fc6 100644 --- a/numba/roc/mathimpl.py +++ b/numba/roc/mathimpl.py @@ -2,7 +2,7 @@ import warnings from numba.targets.imputils import Registry -from numba import types +from numba.core import types from numba.itanium_mangler import mangle from .hsaimpl import _declare_function diff --git a/numba/roc/tests/hsapy/test_compiler.py b/numba/roc/tests/hsapy/test_compiler.py index b606f46cb8f..1ad80190cca 100644 --- a/numba/roc/tests/hsapy/test_compiler.py +++ b/numba/roc/tests/hsapy/test_compiler.py @@ -4,7 +4,7 @@ import numba.unittest_support as unittest from numba import roc -from numba import types +from numba.core import types from numba.roc import compiler from numba.roc.hsadrv.driver import hsa as hsart from numba.roc.hsadrv.driver import BrigModule, Executable, Program diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index b36d880d5e4..27f6f8d2cee 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -12,7 +12,7 @@ import numpy as np import numba -from numba import types +from numba.core import types from numba.core.typing.templates import infer_global, AbstractTemplate from numba.core.typing import signature from numba.core import utils, typing diff --git a/numba/targets/cffiimpl.py b/numba/targets/cffiimpl.py index 8277b9b85e7..9548c84a2ab 100644 --- a/numba/targets/cffiimpl.py +++ b/numba/targets/cffiimpl.py @@ -4,7 +4,7 @@ from numba.targets.imputils import Registry -from numba import types +from numba.core import types from numba.np import arrayobj registry = Registry() diff --git a/numba/targets/heapq.py b/numba/targets/heapq.py index 88356ffba63..0ce2a3280f3 100644 --- a/numba/targets/heapq.py +++ b/numba/targets/heapq.py @@ -3,7 +3,7 @@ import heapq as hq -from numba import types +from numba.core import types from numba.core.errors import TypingError from numba.extending import overload, register_jitable diff --git a/numba/targets/literal.py b/numba/targets/literal.py index bafbbfe100d..5b33472b179 100644 --- a/numba/targets/literal.py +++ b/numba/targets/literal.py @@ -1,5 +1,5 @@ from numba.extending import overload -from numba import types +from numba.core import types from numba.special import literally, literal_unroll from numba.core.errors import TypingError diff --git a/numba/targets/removerefctpass.py b/numba/targets/removerefctpass.py index 2403f746fa7..160e8946277 100644 --- a/numba/targets/removerefctpass.py +++ b/numba/targets/removerefctpass.py @@ -5,7 +5,7 @@ from llvmlite.ir.transforms import CallVisitor -from numba import types +from numba.core import types class _MarkNrtCallVisitor(CallVisitor): diff --git a/numba/tests/test_annotations.py b/numba/tests/test_annotations.py index 0bb31205615..2bf3e520b80 100644 --- a/numba/tests/test_annotations.py +++ b/numba/tests/test_annotations.py @@ -4,7 +4,7 @@ import numba from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types +from numba.core import types try: import jinja2 diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index 54950f3d031..46fee534995 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -5,7 +5,7 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags, utils -from numba import types +from numba.core import types from .support import TestCase, tag from .complex_usecases import * diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 10a85aea369..5037326fb65 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -5,7 +5,7 @@ from numba import compiler, typing from numba.targets import cpu -from numba import types +from numba.core import types from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 400ef64cf4a..60ce38f35e5 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -9,7 +9,7 @@ from numba.core.errors import TypingError from numba import config from numba import njit -from numba import types +from numba.core import types from numba import utils from .support import MemoryLeakMixin, TestCase, tag diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index 64bdd36f149..5a74e7081cc 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -6,7 +6,7 @@ import numpy as np import builtins -from numba import types +from numba.core import types from .support import TestCase, temp_directory from numba.help.inspector import inspect_function, inspect_module diff --git a/numba/tests/test_looplifting.py b/numba/tests/test_looplifting.py index ac97a73f113..01f99aea04c 100644 --- a/numba/tests/test_looplifting.py +++ b/numba/tests/test_looplifting.py @@ -1,7 +1,7 @@ from io import StringIO import numpy as np -from numba import types +from numba.core import types from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags from .support import TestCase, tag, MemoryLeakMixin diff --git a/numba/tests/test_maxmin.py b/numba/tests/test_maxmin.py index ab1e8821b87..b83ca1f1c18 100644 --- a/numba/tests/test_maxmin.py +++ b/numba/tests/test_maxmin.py @@ -1,6 +1,6 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated -from numba import types +from numba.core import types def domax3(a, b, c): diff --git a/numba/tests/test_nan.py b/numba/tests/test_nan.py index 3a791914538..82112ebfc4e 100644 --- a/numba/tests/test_nan.py +++ b/numba/tests/test_nan.py @@ -1,6 +1,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types +from numba.core import types enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_obj_lifetime.py b/numba/tests/test_obj_lifetime.py index 0f845569e1f..4ef851d92c3 100644 --- a/numba/tests/test_obj_lifetime.py +++ b/numba/tests/test_obj_lifetime.py @@ -6,7 +6,7 @@ import numba.unittest_support as unittest from numba.controlflow import CFGraph, Loop from numba.compiler import compile_extra, compile_isolated, Flags -from numba import types +from numba.core import types from .support import TestCase enable_pyobj_flags = Flags() diff --git a/numba/tests/test_objects.py b/numba/tests/test_objects.py index 90ba1e68a36..7f31341d4e4 100644 --- a/numba/tests/test_objects.py +++ b/numba/tests/test_objects.py @@ -5,7 +5,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types +from numba.core import types from .support import TestCase diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 90b8674252e..e42afeb926e 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -23,7 +23,7 @@ from numba import njit, prange, stencil, inline_closurecall, utils from numba import compiler, typing, errors, typed_passes from numba.targets import cpu -from numba import types +from numba.core import types from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 6fd359e907c..e59e14e7610 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -7,7 +7,7 @@ from numba import compiler, typing from numba.compiler import compile_isolated, Flags from numba.targets import cpu -from numba import types +from numba.core import types from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations diff --git a/numba/tests/test_return_values.py b/numba/tests/test_return_values.py index ef281693348..6ec8de0d68c 100644 --- a/numba/tests/test_return_values.py +++ b/numba/tests/test_return_values.py @@ -7,7 +7,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types +from numba.core import types from numba.core.errors import TypingError diff --git a/numba/tests/test_typeconv.py b/numba/tests/test_typeconv.py index cd0c22f92af..96bd4960922 100644 --- a/numba/tests/test_typeconv.py +++ b/numba/tests/test_typeconv.py @@ -1,7 +1,7 @@ import itertools from numba import unittest_support as unittest -from numba import types +from numba.core import types from numba.typeconv.typeconv import TypeManager, TypeCastingRules from numba.typeconv import rules from numba.typeconv import castgraph, Conversion diff --git a/numba/tests/test_typedobjectutils.py b/numba/tests/test_typedobjectutils.py index cef073845b2..e504e207be9 100644 --- a/numba/tests/test_typedobjectutils.py +++ b/numba/tests/test_typedobjectutils.py @@ -5,7 +5,7 @@ import warnings -from numba import types +from numba.core import types from .support import TestCase from numba.typedobjectutils import _sentry_safe_cast diff --git a/numba/tests/test_typenames.py b/numba/tests/test_typenames.py index 7cb5ed77a1b..4258df81b36 100644 --- a/numba/tests/test_typenames.py +++ b/numba/tests/test_typenames.py @@ -1,6 +1,6 @@ import numpy as np -from numba import types +from numba.core import types from numba import unittest_support as unittest diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 65fa9edc881..0699c7b5088 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -615,7 +615,7 @@ class TestIsInternalTypeMarker(TestCase): the `is_internal` attr of a concrete Type class """ source_lines = """ -from numba import types +from numba.core import types class FooType(types.Type): def __init__(self): diff --git a/numba/tests/timsort.py b/numba/tests/timsort.py index 419eb528414..ba1560e399e 100644 --- a/numba/tests/timsort.py +++ b/numba/tests/timsort.py @@ -7,7 +7,7 @@ import collections -from numba import types +from numba.core import types TimsortImplementation = collections.namedtuple( diff --git a/numba/typedobjectutils.py b/numba/typedobjectutils.py index ba345fa32da..2ce5cfdbe02 100644 --- a/numba/typedobjectutils.py +++ b/numba/typedobjectutils.py @@ -7,7 +7,7 @@ from llvmlite.llvmpy.core import Builder from numba import cgutils -from numba import types +from numba.core import types from numba.core import typing from numba.targets.registry import cpu_target from numba.core.typeconv import Conversion diff --git a/numba/unsafe/nrt.py b/numba/unsafe/nrt.py index ba7aed3f47d..1dc2a72cd63 100644 --- a/numba/unsafe/nrt.py +++ b/numba/unsafe/nrt.py @@ -2,7 +2,7 @@ Contains unsafe intrinsic that calls NRT C API """ -from numba import types +from numba.core import types from numba.typing import signature from numba.extending import intrinsic diff --git a/numba/unsafe/refcount.py b/numba/unsafe/refcount.py index 38c7ed5f971..b9925948367 100644 --- a/numba/unsafe/refcount.py +++ b/numba/unsafe/refcount.py @@ -3,7 +3,7 @@ """ from llvmlite import ir -from numba import types +from numba.core import types from numba import cgutils from numba.extending import intrinsic From 37399df6402b712ce48b16647e9a234aeab35c10 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 13:19:09 +0000 Subject: [PATCH 314/595] fix with sed 2 --- numba/compiler_machinery.py | 2 +- numba/cuda/envvars.py | 2 +- numba/help/inspector.py | 2 +- numba/targets/hashing.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index 9023b283578..063406d5b07 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -3,7 +3,7 @@ from collections import namedtuple, OrderedDict import inspect from numba.compiler_lock import global_compiler_lock -from numba import errors +from numba.core import errors from numba import config, transforms from numba.core.utils import add_metaclass from numba.tracing import event diff --git a/numba/cuda/envvars.py b/numba/cuda/envvars.py index 79ac4eac53c..c79edae38da 100644 --- a/numba/cuda/envvars.py +++ b/numba/cuda/envvars.py @@ -1,7 +1,7 @@ import os import warnings -from numba import errors +from numba.core import errors def get_numbapro_envvar(envvar, default=None): diff --git a/numba/help/inspector.py b/numba/help/inspector.py index 1121d18d051..1acb930562a 100644 --- a/numba/help/inspector.py +++ b/numba/help/inspector.py @@ -10,7 +10,7 @@ import warnings import types as pytypes -from numba import errors +from numba.core import errors from numba._version import get_versions from numba.targets.registry import cpu_target from numba.tests.support import captured_stdout diff --git a/numba/targets/hashing.py b/numba/targets/hashing.py index c1601cf86b4..e447482e18e 100644 --- a/numba/targets/hashing.py +++ b/numba/targets/hashing.py @@ -14,7 +14,7 @@ from numba.extending import ( overload, overload_method, intrinsic, register_jitable) -from numba import errors +from numba.core import errors from numba.core import types, utils from numba.unsafe.bytes import grab_byte, grab_uint64_t From 1e4caee39a80a2c62d90c6653801b066d2ac0a89 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 13:37:13 +0000 Subject: [PATCH 315/595] 2% working --- numba/inline_closurecall.py | 2 +- numba/npyufunc/parfor.py | 3 +-- numba/parfor.py | 2 +- numba/stencilparfor.py | 2 +- numba/tests/cffi_usecases.py | 2 +- numba/tests/test_boundscheck.py | 4 ++-- numba/tests/test_indexing.py | 3 ++- numba/tests/test_ir_inlining.py | 2 +- numba/tests/test_literal_dispatch.py | 5 +++-- numba/tests/test_types.py | 6 +++--- numba/typed/typeddict.py | 2 +- numba/typed/typedlist.py | 2 +- numba/typed_passes.py | 2 +- 13 files changed, 19 insertions(+), 18 deletions(-) diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 426f11ebbdc..776ed76b180 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -436,7 +436,7 @@ def stararg_handler(index, param, default): kws = dict(call_expr.kws) else: kws = {} - return numba.typing.fold_arguments( + return numba.core.typing.fold_arguments( pysig, args, kws, normal_handler, default_handler, stararg_handler) else: diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 21b467569fa..ca7a2a3549d 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -1030,8 +1030,7 @@ def _create_gufunc_for_parfor_body( print("gufunc_ir dump after renaming ") gufunc_ir.dump() - gufunc_param_types = [ - numba.types.npytypes.Array( + gufunc_param_types = [types.npytypes.Array( index_var_typ, 1, "C")] + param_types if config.DEBUG_ARRAY_OPT: print( diff --git a/numba/parfor.py b/numba/parfor.py index c7f92c52170..7fdf20c84cc 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -1439,7 +1439,7 @@ def replace_func(): # Get the dtype function from the numpy module. dtype_attr_var = ir.Var(scope, mk_unique_var("$dtype_attr_var"), loc) temp = find_template(numpy.dtype) - tfunc = numba.types.Function(temp) + tfunc = numba.core.types.Function(temp) tfunc.get_call_type(self.typingctx, (self.typemap[typ_var.name],), {}) self.typemap[dtype_attr_var.name] = types.functions.Function(temp) dtype_attr_getattr = ir.Expr.getattr(g_np_var, 'dtype', loc) diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 27f6f8d2cee..2ad4fcd82c2 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -245,7 +245,7 @@ def _mk_stencil_parfor(self, label, in_args, out_arr, stencil_ir, so_name = ir_utils.mk_unique_var("stencil_output") out_arr = ir.Var(scope, so_name, loc) - self.typemap[out_arr.name] = numba.types.npytypes.Array( + self.typemap[out_arr.name] = numba.core.types.npytypes.Array( return_type.dtype, in_arr_typ.ndim, in_arr_typ.layout) diff --git a/numba/tests/cffi_usecases.py b/numba/tests/cffi_usecases.py index f0e708bf71c..fc5a8685f7e 100644 --- a/numba/tests/cffi_usecases.py +++ b/numba/tests/cffi_usecases.py @@ -4,7 +4,7 @@ from numba import cffi_support from numba.tests.support import import_dynamic, temp_directory -from numba.types import complex128 +from numba.core.types import complex128 def load_inline_module(): diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index d103cea365e..b5df1766946 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -3,9 +3,9 @@ from numba.compiler import compile_isolated, DEFAULT_FLAGS from numba.cuda.testing import SerialMixin from numba import typeof, config, cuda, njit -from numba.types import float64 +from numba.core.types import float64 from numba import unittest_support as unittest -from .support import MemoryLeakMixin, override_env_config +from numba.tests.support import MemoryLeakMixin, override_env_config BOUNDSCHECK_FLAGS = DEFAULT_FLAGS.copy() BOUNDSCHECK_FLAGS.set('boundscheck', True) diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index ed1f0a16804..d6b6af75e35 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -5,7 +5,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, utils, njit, errors, typeof +from numba import utils, njit, typeof +from numba.core import types, errors from .support import TestCase, tag diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index dbb1acab6f5..3ae914a0b6d 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -25,7 +25,7 @@ from numba.typed_passes import DeadCodeElimination, IRLegalization from numba.untyped_passes import PreserveIR from itertools import product -from .support import TestCase, unittest, skip_py38_or_later +from numba.tests.support import TestCase, unittest, skip_py38_or_later class InlineTestPipeline(numba.compiler.CompilerBase): diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index 9d065cf47cf..e788f1afea0 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -3,7 +3,8 @@ import numba import numba.unittest_support as unittest from numba.tests.support import TestCase -from numba import njit, types, errors, cgutils +from numba import njit, cgutils +from numba.core import types, errors from numba.typing import signature from numba.datamodel import models from numba.extending import ( @@ -334,7 +335,7 @@ class Dummy(object): def lit(self, a): return a - class DummyType(numba.types.Type): + class DummyType(types.Type): def __init__(self): super(DummyType, self).__init__(name="dummy") diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 0699c7b5088..44e096dd54c 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -22,13 +22,13 @@ from numba import unittest_support as unittest from numba import sigutils, types, typing, errors -from numba.types.abstract import _typecache +from numba.core.types.abstract import _typecache from numba.typing.templates import make_overload_template from numba import jit, njit, numpy_support, typeof from numba.extending import (overload, register_model, models, unbox, NativeValue, typeof_impl) -from .support import TestCase, temp_directory -from .enum_usecases import Color, Shake, Shape +from numba.tests.support import TestCase, temp_directory +from numba.tests.enum_usecases import Color, Shake, Shape Point = namedtuple('Point', ('x', 'y')) diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index 0b5636f5963..faa2a03453f 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -107,7 +107,7 @@ def __init__(self, **kwargs): Parameters ---------- - dcttype : numba.types.DictType; keyword-only + dcttype : numba.core.types.DictType; keyword-only Used internally for the dictionary type. meminfo : MemInfo; keyword-only Used internally to pass the MemInfo object when boxing. diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index e0a950cf685..d61eac2d241 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -187,7 +187,7 @@ def __init__(self, **kwargs): Parameters ---------- - lsttype : numba.types.ListType; keyword-only + lsttype : numba.core.types.ListType; keyword-only Used internally for the list type. meminfo : MemInfo; keyword-only Used internally to pass the MemInfo object when boxing. diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 67b0a644266..fe4309b5714 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -602,7 +602,7 @@ def _run_inliner( do_inline = True if not inline_type.is_always_inline: - from numba.typing.templates import _inline_info + from numba.core.typing.templates import _inline_info caller_inline_info = _inline_info(state.func_ir, state.type_annotation.typemap, state.type_annotation.calltypes, From 99cf865ea7c439770a5faabed303c2ad9de8ea2b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 13:55:21 +0000 Subject: [PATCH 316/595] 6% working --- numba/cuda/simulator/api.py | 2 +- numba/targets/randomimpl.py | 3 +-- numba/tests/test_cgutils.py | 5 +++-- numba/tests/test_intwidth.py | 5 +++-- numba/typeinfer.py | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/numba/cuda/simulator/api.py b/numba/cuda/simulator/api.py index da9e403eb03..118f6f8e464 100644 --- a/numba/cuda/simulator/api.py +++ b/numba/cuda/simulator/api.py @@ -5,7 +5,7 @@ from contextlib import contextmanager from .cudadrv.devices import require_context, reset, gpus from .kernel import FakeCUDAKernel -from numba.typing import Signature +from numba.core.typing import Signature from warnings import warn from ..args import In, Out, InOut diff --git a/numba/targets/randomimpl.py b/numba/targets/randomimpl.py index c46a6100cdc..641c8d12e06 100644 --- a/numba/targets/randomimpl.py +++ b/numba/targets/randomimpl.py @@ -17,7 +17,7 @@ from numba.core.typing import signature from numba import _helperlib, cgutils from numba.core import types, utils - +from numba.np import arrayobj POST_PY38 = utils.PYVERSION >= (3, 8) @@ -1288,7 +1288,6 @@ def permutation_impl(x): @lower(typing_key, *(types.Any,) * arity) def random_arr(context, builder, sig, args, typing_key=typing_key): - from . import arrayobj arrty = sig.return_type dtype = arrty.dtype diff --git a/numba/tests/test_cgutils.py b/numba/tests/test_cgutils.py index 7fd06573e5e..868a2d17dc7 100644 --- a/numba/tests/test_cgutils.py +++ b/numba/tests/test_cgutils.py @@ -7,10 +7,11 @@ import numpy as np import numba.unittest_support as unittest -from numba import cgutils, types, typing +from numba import cgutils +from numba.core import types, typing from numba.compiler_lock import global_compiler_lock from numba.targets import cpu -from .support import TestCase +from numba.tests.support import TestCase machine_int = lc.Type.int(types.intp.bitwidth) diff --git a/numba/tests/test_intwidth.py b/numba/tests/test_intwidth.py index 9a4bf067312..2ce4cfc517f 100644 --- a/numba/tests/test_intwidth.py +++ b/numba/tests/test_intwidth.py @@ -3,8 +3,9 @@ import math import sys -from numba import jit, utils -from .support import TestCase, tag +from numba import jit +from numba.core import utils +from numba.tests.support import TestCase, tag max_uint64 = 18446744073709551615 diff --git a/numba/typeinfer.py b/numba/typeinfer.py index 8faa1e3bd55..5787106a552 100644 --- a/numba/typeinfer.py +++ b/numba/typeinfer.py @@ -23,6 +23,7 @@ from numba import ir, config from numba.core import types, utils, typing +from numba.core.typing.templates import Signature from numba.core.errors import (TypingError, UntypedAttributeError, new_error_context, termcolor, UnsupportedError, ForceLiteralArg) @@ -406,7 +407,6 @@ def __call__(self, typeinfer): typevars = typeinfer.typevars idx_ty = typevars[self.index.name].get() ty = typevars[self.value.name].get() - from numba.typing.templates import Signature self.signature = Signature(self.dtype, ty + idx_ty, None) typeinfer.add_type(self.target, self.dtype, loc=self.loc) From 4eebc9b1425bbc8923747c5ebd7346544125412e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 16:11:33 +0000 Subject: [PATCH 317/595] Fix up loads more imports --- numba/analysis.py | 3 ++- numba/callwrapper.py | 3 ++- numba/ccallback.py | 15 ++++++++------- numba/charseq.py | 3 ++- numba/cuda/compiler.py | 4 ++-- numba/cuda/cudadrv/devicearray.py | 3 ++- numba/cuda/cudamath.py | 4 ++-- numba/cuda/decorators.py | 3 ++- numba/cuda/libdevice.py | 3 ++- numba/cuda/printimpl.py | 3 ++- numba/cuda/simulator/cudadrv/devicearray.py | 3 ++- numba/cuda/tests/cudapy/test_casting.py | 8 +++++--- numba/cuda/tests/cudapy/test_complex.py | 3 ++- numba/cuda/tests/cudapy/test_debuginfo.py | 3 ++- numba/cuda/tests/cudapy/test_deprecation.py | 3 ++- numba/cuda/tests/cudapy/test_record_dtype.py | 3 ++- numba/cuda/tests/cudapy/test_serialize.py | 3 ++- numba/cuda/tests/nocuda/test_nvvm.py | 2 +- numba/datamodel/models.py | 5 +++-- numba/datamodel/packer.py | 3 ++- numba/jitclass/boxing.py | 3 ++- numba/jitclass/decorators.py | 3 ++- numba/np/linalg.py | 2 +- numba/npyufunc/deviceufunc.py | 5 +++-- numba/npyufunc/parallel.py | 3 ++- numba/npyufunc/ufuncbuilder.py | 4 ++-- numba/npyufunc/wrappers.py | 3 ++- numba/roc/decorators.py | 3 ++- numba/roc/hsadrv/devicearray.py | 3 ++- numba/roc/mathdecl.py | 2 +- numba/roc/target.py | 5 +++-- numba/runtime/context.py | 3 ++- numba/runtime/nrtdynmod.py | 3 ++- numba/targets/boxing.py | 2 +- numba/targets/callconv.py | 5 +++-- numba/targets/iterators.py | 3 ++- numba/targets/npdatetime.py | 6 ++++-- numba/targets/npyfuncs.py | 7 ++++--- numba/targets/polynomial.py | 3 ++- numba/targets/printimpl.py | 3 ++- numba/targets/rangeobj.py | 3 ++- numba/tests/pdlike_usecase.py | 3 ++- numba/tests/test_analysis.py | 5 +++-- numba/tests/test_array_attr.py | 7 ++++--- numba/tests/test_array_constants.py | 3 ++- numba/tests/test_array_iterators.py | 5 +++-- numba/tests/test_array_manipulation.py | 6 ++++-- numba/tests/test_array_methods.py | 7 ++++--- numba/tests/test_blackscholes.py | 4 ++-- numba/tests/test_builtins.py | 5 +++-- numba/tests/test_casting.py | 3 ++- numba/tests/test_cffi.py | 3 ++- numba/tests/test_cfunc.py | 7 ++++--- numba/tests/test_compile_cache.py | 2 +- numba/tests/test_comprehension.py | 8 ++++---- numba/tests/test_conversion.py | 5 +++-- numba/tests/test_ctypes.py | 7 ++++--- numba/tests/test_dataflow.py | 5 +++-- numba/tests/test_debuginfo.py | 5 +++-- numba/tests/test_dispatcher.py | 10 ++++++---- numba/tests/test_dyn_array.py | 5 ++--- numba/tests/test_exceptions.py | 5 +++-- numba/tests/test_fancy_indexing.py | 5 +++-- numba/tests/test_hashing.py | 5 +++-- numba/tests/test_import.py | 5 +++-- numba/tests/test_jitclasses.py | 5 +++-- numba/tests/test_jitmethod.py | 3 ++- numba/tests/test_listobject.py | 7 ++++--- numba/tests/test_lists.py | 7 ++++--- numba/tests/test_mandelbrot.py | 2 +- numba/tests/test_mangling.py | 4 ++-- numba/tests/test_mixed_tuple_unroller.py | 3 ++- numba/tests/test_multi3.py | 3 ++- numba/tests/test_nested_calls.py | 5 +++-- numba/tests/test_np_functions.py | 6 ++++-- numba/tests/test_npdatetime.py | 3 ++- numba/tests/test_nrt.py | 3 ++- numba/tests/test_numberctor.py | 5 +++-- numba/tests/test_numbers.py | 5 +++-- numba/tests/test_numpy_support.py | 7 ++++--- numba/tests/test_object_mode.py | 5 +++-- numba/tests/test_operators.py | 8 +++++--- numba/tests/test_optional.py | 6 +++--- numba/tests/test_overlap.py | 5 +++-- numba/tests/test_pipeline.py | 5 +++-- numba/tests/test_practical_lowering_issues.py | 3 ++- numba/tests/test_print.py | 5 +++-- numba/tests/test_random.py | 5 +++-- numba/tests/test_range.py | 5 +++-- numba/tests/test_recarray_usecases.py | 5 +++-- numba/tests/test_sets.py | 7 ++++--- numba/tests/test_slices.py | 5 +++-- numba/tests/test_sort.py | 7 ++++--- numba/tests/test_storeslice.py | 4 ++-- numba/tests/test_tuples.py | 5 +++-- numba/tests/test_typeconv.py | 6 +++--- numba/tests/test_typedlist.py | 3 ++- numba/tests/test_typeinfer.py | 10 +++++----- numba/tests/test_types.py | 3 ++- numba/tests/test_typingerror.py | 5 +++-- numba/tests/test_ufuncs.py | 5 +++-- numba/tests/test_unicode.py | 5 +++-- numba/tests/test_unicode_array.py | 3 ++- numba/tests/test_usecases.py | 4 ++-- numba/tests/test_withlifting.py | 5 +++-- numba/tests/test_wrapper.py | 3 ++- numba/unsafe/bytes.py | 3 ++- numba/unsafe/eh.py | 3 ++- 108 files changed, 290 insertions(+), 195 deletions(-) diff --git a/numba/analysis.py b/numba/analysis.py index 15cc1f5eba7..d51de11c7fd 100644 --- a/numba/analysis.py +++ b/numba/analysis.py @@ -7,7 +7,8 @@ from numba import ir, errors from numba.controlflow import CFGraph -from numba import types, consts, special +from numba import consts, special +from numba.core import types # # Analysis related to variable lifetime diff --git a/numba/callwrapper.py b/numba/callwrapper.py index 9cb41039d86..9845e739525 100644 --- a/numba/callwrapper.py +++ b/numba/callwrapper.py @@ -1,7 +1,8 @@ from llvmlite.llvmpy.core import Type, Builder, Constant import llvmlite.llvmpy.core as lc -from numba import types, cgutils, config +from numba.core import types +from numba import cgutils, config class _ArgManager(object): diff --git a/numba/ccallback.py b/numba/ccallback.py index ec82857f6ea..cf6b32a0469 100644 --- a/numba/ccallback.py +++ b/numba/ccallback.py @@ -7,13 +7,14 @@ from llvmlite import ir -from . import utils, compiler -from .caching import NullCache, FunctionCache -from .dispatcher import _FunctionCompiler -from .targets import registry -from .typing import signature -from .typing.ctypes_utils import to_ctypes -from .compiler_lock import global_compiler_lock +from numba.core import utils +from numba import compiler +from numba.caching import NullCache, FunctionCache +from numba.dispatcher import _FunctionCompiler +from numba.targets import registry +from numba.core.typing import signature +from numba.core.typing.ctypes_utils import to_ctypes +from numba.compiler_lock import global_compiler_lock class _CFuncCompiler(_FunctionCompiler): diff --git a/numba/charseq.py b/numba/charseq.py index baa87588a13..74f3229fcf3 100644 --- a/numba/charseq.py +++ b/numba/charseq.py @@ -3,7 +3,8 @@ import numpy as np from llvmlite import ir -from numba import types, cgutils, unicode +from numba.core import types +from numba import cgutils, unicode from numba.extending import (overload, intrinsic, overload_method, lower_cast, register_jitable) from numba.cgutils import is_nonelike diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index 8eb77843fa2..e313aed60c3 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -8,10 +8,10 @@ import numpy as np -from numba import config, compiler, types, sigutils +from numba import config, compiler, sigutils from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate from numba import funcdesc, serialize -from numba.core import typing, utils +from numba.core import types, typing, utils from numba.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 0c2d5ed9c2e..d0639f30aae 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -16,7 +16,8 @@ import numba from . import driver as _driver from . import devices -from numba import dummyarray, types, numpy_support +from numba import dummyarray, numpy_support +from numba.core import types from numba.unsafe.ndarray import to_fixed_tuple try: diff --git a/numba/cuda/cudamath.py b/numba/cuda/cudamath.py index ece0551e9ae..f375733fdb8 100644 --- a/numba/cuda/cudamath.py +++ b/numba/cuda/cudamath.py @@ -1,6 +1,6 @@ import math -from numba import types, utils -from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, +from numba.core import types, utils +from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, signature, Registry) registry = Registry() diff --git a/numba/cuda/decorators.py b/numba/cuda/decorators.py index aadbbda28df..bc252c4fe38 100644 --- a/numba/cuda/decorators.py +++ b/numba/cuda/decorators.py @@ -1,5 +1,6 @@ -from numba import config, sigutils, types from warnings import warn +from numba import config, sigutils +from numba.core import types from .compiler import (compile_kernel, compile_device, declare_device_function, AutoJitCUDAKernel, compile_device_template) from .simulator.kernel import FakeCUDAKernel diff --git a/numba/cuda/libdevice.py b/numba/cuda/libdevice.py index 56e247e2c88..e283941e76a 100644 --- a/numba/cuda/libdevice.py +++ b/numba/cuda/libdevice.py @@ -1,7 +1,8 @@ import sys import math from llvmlite.llvmpy.core import Type -from numba import cgutils, types +from numba import cgutils +from numba.core import types from numba.targets.imputils import Registry registry = Registry() diff --git a/numba/cuda/printimpl.py b/numba/cuda/printimpl.py index 78fbf47ee32..f64c6335cd8 100644 --- a/numba/cuda/printimpl.py +++ b/numba/cuda/printimpl.py @@ -2,7 +2,8 @@ from llvmlite.llvmpy.core import Type, Constant -from numba import types, typing, cgutils +from numba import cgutils +from numba.core import types, typing from numba.targets.imputils import Registry from . import nvvmutils diff --git a/numba/cuda/simulator/cudadrv/devicearray.py b/numba/cuda/simulator/cudadrv/devicearray.py index c36890b30c2..1b4c1556e66 100644 --- a/numba/cuda/simulator/cudadrv/devicearray.py +++ b/numba/cuda/simulator/cudadrv/devicearray.py @@ -7,7 +7,8 @@ import numpy as np -from numba import types, numpy_support +from numba import numpy_support +from numba.core import types DeviceRecord = None from_record_like = None diff --git a/numba/cuda/tests/cudapy/test_casting.py b/numba/cuda/tests/cudapy/test_casting.py index 33e63966f27..b6f5e0e51f2 100644 --- a/numba/cuda/tests/cudapy/test_casting.py +++ b/numba/cuda/tests/cudapy/test_casting.py @@ -1,7 +1,9 @@ -from numba import unittest_support as unittest -import numpy as np -from numba import cuda, types import struct +import numpy as np + +from numba import unittest_support as unittest +from numba import cuda +from numba.core import types from numba.cuda.testing import SerialMixin diff --git a/numba/cuda/tests/cudapy/test_complex.py b/numba/cuda/tests/cudapy/test_complex.py index 73a300679e1..b1e35c7b645 100644 --- a/numba/cuda/tests/cudapy/test_complex.py +++ b/numba/cuda/tests/cudapy/test_complex.py @@ -8,7 +8,8 @@ import numpy as np from numba.cuda.testing import unittest, SerialMixin -from numba import cuda, types, utils, numpy_support +from numba.core import types, utils +from numba import cuda, numpy_support from numba.tests.support import TestCase, compile_function from numba.tests.complex_usecases import * diff --git a/numba/cuda/tests/cudapy/test_debuginfo.py b/numba/cuda/tests/cudapy/test_debuginfo.py index f4494aa09c5..4b09bc5edf5 100644 --- a/numba/cuda/tests/cudapy/test_debuginfo.py +++ b/numba/cuda/tests/cudapy/test_debuginfo.py @@ -1,7 +1,8 @@ from numba.tests.support import override_config, TestCase from numba.cuda.testing import skip_on_cudasim from numba import unittest_support as unittest -from numba import cuda, types +from numba import cuda +from numba.core import types from numba.cuda.testing import SerialMixin diff --git a/numba/cuda/tests/cudapy/test_deprecation.py b/numba/cuda/tests/cudapy/test_deprecation.py index d1504dd0a46..9eff8ce608b 100644 --- a/numba/cuda/tests/cudapy/test_deprecation.py +++ b/numba/cuda/tests/cudapy/test_deprecation.py @@ -4,7 +4,8 @@ from numba.tests.support import override_config, TestCase from numba.cuda.testing import skip_on_cudasim from numba import unittest_support as unittest -from numba import cuda, types +from numba import cuda +from numba.core import types from numba.cuda.testing import SerialMixin diff --git a/numba/cuda/tests/cudapy/test_record_dtype.py b/numba/cuda/tests/cudapy/test_record_dtype.py index 5729985c9ef..3471b7f4786 100644 --- a/numba/cuda/tests/cudapy/test_record_dtype.py +++ b/numba/cuda/tests/cudapy/test_record_dtype.py @@ -1,7 +1,8 @@ import sys import numpy as np -from numba import cuda, numpy_support, types +from numba import cuda, numpy_support +from numba.core import types from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin diff --git a/numba/cuda/tests/cudapy/test_serialize.py b/numba/cuda/tests/cudapy/test_serialize.py index 9d3bdc03336..69b7c57ac7a 100644 --- a/numba/cuda/tests/cudapy/test_serialize.py +++ b/numba/cuda/tests/cudapy/test_serialize.py @@ -1,6 +1,7 @@ import pickle import numpy as np -from numba import cuda, vectorize, numpy_support, types +from numba import cuda, vectorize, numpy_support +from numba.core import types from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin diff --git a/numba/cuda/tests/nocuda/test_nvvm.py b/numba/cuda/tests/nocuda/test_nvvm.py index 7ee8e9d2da8..e2991204185 100644 --- a/numba/cuda/tests/nocuda/test_nvvm.py +++ b/numba/cuda/tests/nocuda/test_nvvm.py @@ -2,7 +2,7 @@ from numba.cuda.cudadrv import nvvm from numba.cuda.testing import skip_on_cudasim, SerialMixin from numba import unittest_support as unittest -from numba import types, utils +from numba.core import types, utils @skip_on_cudasim('libNVVM not supported in simulator') diff --git a/numba/datamodel/models.py b/numba/datamodel/models.py index 81db633db9e..ec01008d1e6 100644 --- a/numba/datamodel/models.py +++ b/numba/datamodel/models.py @@ -2,8 +2,9 @@ from llvmlite import ir -from numba import cgutils, types, numpy_support -from .registry import register_default +from numba import cgutils, numpy_support +from numba.datamodel.registry import register_default +from numba.core import types class DataModel(object): diff --git a/numba/datamodel/packer.py b/numba/datamodel/packer.py index 261123d4df2..2d959a9f2c2 100644 --- a/numba/datamodel/packer.py +++ b/numba/datamodel/packer.py @@ -1,6 +1,7 @@ from collections import deque -from numba import cgutils, types +from numba import cgutils +from numba.core import types diff --git a/numba/jitclass/boxing.py b/numba/jitclass/boxing.py index b108bd3767f..6d3116fbde4 100644 --- a/numba/jitclass/boxing.py +++ b/numba/jitclass/boxing.py @@ -7,7 +7,8 @@ from llvmlite import ir -from numba import types, cgutils +from numba import cgutils +from numba.core import types from numba.pythonapi import box, unbox, NativeValue from numba import njit from . import _box diff --git a/numba/jitclass/decorators.py b/numba/jitclass/decorators.py index a5e21391080..d11c4e0b761 100644 --- a/numba/jitclass/decorators.py +++ b/numba/jitclass/decorators.py @@ -1,4 +1,5 @@ -from numba import config, types +from numba import config +from numba.core import types from .base import register_class_type, ClassBuilder diff --git a/numba/np/linalg.py b/numba/np/linalg.py index eca64d10237..3006dd60094 100644 --- a/numba/np/linalg.py +++ b/numba/np/linalg.py @@ -10,7 +10,7 @@ import numpy as np import operator -from numba import types, cgutils +from numba import cgutils from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) diff --git a/numba/npyufunc/deviceufunc.py b/numba/npyufunc/deviceufunc.py index 7f7d10388a6..ebead63bf23 100644 --- a/numba/npyufunc/deviceufunc.py +++ b/numba/npyufunc/deviceufunc.py @@ -11,8 +11,9 @@ from numba.utils import longint from numba.npyufunc.ufuncbuilder import _BaseUFuncBuilder, parse_identity -from numba import sigutils, types -from numba.typing import signature +from numba import sigutils +from numba.core import types +from numba.core.typing import signature from numba.npyufunc.sigparse import parse_signature diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 225f4d041d7..6d61034b955 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -24,7 +24,8 @@ from numba.npyufunc import ufuncbuilder from numba.numpy_support import as_dtype -from numba import types, config +from numba import config +from numba.core import types from numba.npyufunc.wrappers import _wrapper_info diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index d756bd7dea5..ea86529aa7e 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -9,8 +9,8 @@ from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target from numba.targets.cpu import FastMathOptions -from numba import compiler, types, sigutils -from numba.core import utils +from numba import compiler, sigutils +from numba.core import utils, types from numba.numpy_support import as_dtype from numba.npyufunc import _internal from numba.npyufunc.sigparse import parse_signature diff --git a/numba/npyufunc/wrappers.py b/numba/npyufunc/wrappers.py index 6e8972fa8fd..0c9ae3ad18f 100644 --- a/numba/npyufunc/wrappers.py +++ b/numba/npyufunc/wrappers.py @@ -4,7 +4,8 @@ from llvmlite.llvmpy.core import Type, Builder, ICMP_EQ, Constant -from numba import types, cgutils +from numba import cgutils +from numba.core import types from numba.compiler_lock import global_compiler_lock from ..caching import make_library_cache, NullCache diff --git a/numba/roc/decorators.py b/numba/roc/decorators.py index 51920051eab..78a8132042c 100644 --- a/numba/roc/decorators.py +++ b/numba/roc/decorators.py @@ -1,4 +1,5 @@ -from numba import sigutils, types +from numba import sigutils +from numba.core import types from .compiler import (compile_kernel, compile_device, AutoJitHSAKernel, compile_device_template) diff --git a/numba/roc/hsadrv/devicearray.py b/numba/roc/hsadrv/devicearray.py index 3f388470a0d..a219a81a447 100644 --- a/numba/roc/hsadrv/devicearray.py +++ b/numba/roc/hsadrv/devicearray.py @@ -11,7 +11,8 @@ import numpy as np from numba.roc.hsadrv import driver as _driver from . import devices -from numba import dummyarray, types, numpy_support +from numba import dummyarray, numpy_support +from numba.core import types from .error import HsaContextMismatchError try: diff --git a/numba/roc/mathdecl.py b/numba/roc/mathdecl.py index c663f705439..6b541b04edc 100644 --- a/numba/roc/mathdecl.py +++ b/numba/roc/mathdecl.py @@ -1,5 +1,5 @@ import math -from numba import types, utils +from numba.core import types, utils from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, signature, Registry) diff --git a/numba/roc/target.py b/numba/roc/target.py index 201fb7b9b27..000c55b0141 100644 --- a/numba/roc/target.py +++ b/numba/roc/target.py @@ -4,8 +4,9 @@ from llvmlite import ir as llvmir from llvmlite import binding as ll -from numba import typing, types, utils, cgutils -from numba.utils import cached_property +from numba import cgutils +from numba.core import typing, types, utils +from numba.core.utils import cached_property from numba import datamodel from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv diff --git a/numba/runtime/context.py b/numba/runtime/context.py index e62bd1b06e1..5093e5c7a10 100644 --- a/numba/runtime/context.py +++ b/numba/runtime/context.py @@ -1,6 +1,7 @@ from llvmlite import ir -from numba import cgutils, types +from numba import cgutils +from numba.core import types class NRTContext(object): diff --git a/numba/runtime/nrtdynmod.py b/numba/runtime/nrtdynmod.py index c859b0d2b68..5da6b5ebd33 100644 --- a/numba/runtime/nrtdynmod.py +++ b/numba/runtime/nrtdynmod.py @@ -4,7 +4,8 @@ from numba.config import MACHINE_BITS -from numba import cgutils, types +from numba import cgutils +from numba.core import types from llvmlite import ir, binding # Flag to enable debug print in NRT_incref and NRT_decref diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 5ab80a71a62..01613dceaf9 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -367,7 +367,7 @@ def unbox_slice(typ, obj, c): """ Convert object *obj* to a native slice structure. """ - from . import slicing + from numba.core import slicing ok, start, stop, step = c.pyapi.slice_as_ints(obj) sli = c.context.make_helper(c.builder, typ) sli.start = start diff --git a/numba/targets/callconv.py b/numba/targets/callconv.py index 4cb13382d11..ab553010ca1 100644 --- a/numba/targets/callconv.py +++ b/numba/targets/callconv.py @@ -7,8 +7,9 @@ from llvmlite import ir as ir -from numba import cgutils, types -from .base import PYOBJECT, GENERIC_POINTER +from numba import cgutils +from numba.core import types +from numba.targets.base import PYOBJECT, GENERIC_POINTER TryStatus = namedtuple('TryStatus', ['in_try', 'excinfo']) diff --git a/numba/targets/iterators.py b/numba/targets/iterators.py index 57b1a1431a7..74f8d67ba8e 100644 --- a/numba/targets/iterators.py +++ b/numba/targets/iterators.py @@ -2,7 +2,8 @@ Implementation of various iterable and iterator types. """ -from numba import types, cgutils +from numba.core import types +from numba import cgutils from numba.targets.imputils import ( lower_builtin, iternext_impl, call_iternext, call_getiter, impl_ret_borrowed, impl_ret_new_ref, RefType) diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index d70f14c4d4c..e8448610e87 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -8,8 +8,10 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba import npdatetime, types, cgutils, numpy_support -from .imputils import lower_builtin, lower_constant, impl_ret_untracked +from numba import npdatetime, cgutils, numpy_support +from numba.core import types +from numba.targets.imputils import (lower_builtin, lower_constant, + impl_ret_untracked) # datetime64 and timedelta64 use the same internal representation DATETIME64 = TIMEDELTA64 = Type.int(64) diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index 38d0de2baef..b796cdc3e58 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -9,9 +9,10 @@ from llvmlite.llvmpy import core as lc -from .imputils import impl_ret_untracked -from .. import cgutils, typing, types, lowering, errors -from . import cmathimpl, mathimpl, numbers, npdatetime +from numba.targets.imputils import impl_ret_untracked +from numba import cgutils, lowering +from numba.core import typing, types, errors +from numba.targets import cmathimpl, mathimpl, numbers, npdatetime # some NumPy constants. Note that we could generate some of them using # the math library, but having the values copied from npy_math seems to diff --git a/numba/targets/polynomial.py b/numba/targets/polynomial.py index 785fe6f1f37..2f5d7714fb0 100644 --- a/numba/targets/polynomial.py +++ b/numba/targets/polynomial.py @@ -5,7 +5,8 @@ import numpy as np -from numba import types, jit +from numba import jit +from numba.core import types from numba.extending import overload from numba import numpy_support as np_support diff --git a/numba/targets/printimpl.py b/numba/targets/printimpl.py index b95c04a2a42..8f2558cfc9f 100644 --- a/numba/targets/printimpl.py +++ b/numba/targets/printimpl.py @@ -2,7 +2,8 @@ This file implements print functionality for the CPU. """ from llvmlite.llvmpy.core import Type -from numba import types, typing, cgutils +from numba.core import types, typing +from numba import cgutils from numba.targets.imputils import Registry, impl_ret_untracked registry = Registry() diff --git a/numba/targets/rangeobj.py b/numba/targets/rangeobj.py index 53f078a1b67..43ad6efaa8f 100644 --- a/numba/targets/rangeobj.py +++ b/numba/targets/rangeobj.py @@ -6,7 +6,8 @@ import llvmlite.llvmpy.core as lc -from numba import types, cgutils, prange +from numba import cgutils, prange +from numba.core import types from numba.targets.listobj import ListIterInstance from numba.np.arrayobj import make_array from numba.targets.imputils import (lower_builtin, lower_cast, diff --git a/numba/tests/pdlike_usecase.py b/numba/tests/pdlike_usecase.py index 8142e0983cc..76abb1d0248 100644 --- a/numba/tests/pdlike_usecase.py +++ b/numba/tests/pdlike_usecase.py @@ -4,7 +4,8 @@ import numpy as np -from numba import types, cgutils +from numba.core import types +from numba import cgutils from numba.datamodel import models from numba.extending import ( typeof_impl, type_callable, register_model, diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index acdc833709f..399d73583f7 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -3,8 +3,9 @@ import numpy as np from numba.compiler import compile_isolated, run_frontend, Flags, StateDict -from numba import types, rewrites, ir, jit, ir_utils, errors, njit -from .support import TestCase, MemoryLeakMixin, SerialMixin +from numba import rewrites, ir, jit, ir_utils, njit +from numba.core import types, errors +from numba.tests.support import TestCase, MemoryLeakMixin, SerialMixin from numba.analysis import dead_branch_prune, rewrite_semantic_constants diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index d1bfbb830a3..c5330231b07 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -4,9 +4,10 @@ from numba import jitclass from numba.compiler import compile_isolated from numba.numpy_support import from_dtype -from numba import types, njit, typeof -from .support import (TestCase, CompilationCache, MemoryLeakMixin, tag, - skip_parfors_unsupported) +from numba import njit, typeof +from numba.core import types +from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, + tag, skip_parfors_unsupported) from numba.core.errors import TypingError diff --git a/numba/tests/test_array_constants.py b/numba/tests/test_array_constants.py index df534f8d648..849bf02a06c 100644 --- a/numba/tests/test_array_constants.py +++ b/numba/tests/test_array_constants.py @@ -3,7 +3,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated from numba.core.errors import TypingError -from numba import jit, types, typeof +from numba import jit, typeof +from numba.core import types a0 = np.array(42) diff --git a/numba/tests/test_array_iterators.py b/numba/tests/test_array_iterators.py index eae161e4e0a..d9fc1d3490d 100644 --- a/numba/tests/test_array_iterators.py +++ b/numba/tests/test_array_iterators.py @@ -3,9 +3,10 @@ import numpy as np from numba import unittest_support as unittest -from numba import jit, typeof, types +from numba import jit, typeof +from numba.core import types from numba.compiler import compile_isolated -from .support import TestCase, CompilationCache, MemoryLeakMixin, tag +from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin, tag def array_iter(arr): diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index ae8e6d3b27b..7cfd78402b8 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -5,9 +5,11 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import jit, njit, types, from_dtype, errors, typeof +from numba import jit, njit, from_dtype, typeof from numba.core.errors import TypingError -from .support import TestCase, MemoryLeakMixin, CompilationCache, tag +from numba.core import types, errors +from numba.tests.support import (TestCase, MemoryLeakMixin, CompilationCache, + tag) enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index c8b12ffeac4..6056e2ce2db 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -5,12 +5,13 @@ import numpy as np from numba import unittest_support as unittest -from numba import jit, typeof, types +from numba import jit, typeof +from numba.core import types from numba.compiler import compile_isolated from numba.core.errors import TypingError, LoweringError from numba.numpy_support import as_dtype -from .support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, - tag, needs_blas) +from numba.tests.support import (TestCase, CompilationCache, MemoryLeak, + MemoryLeakMixin, tag, needs_blas) def np_around_array(arr, decimals, out): diff --git a/numba/tests/test_blackscholes.py b/numba/tests/test_blackscholes.py index 4e024cf1444..d6df9f02b92 100644 --- a/numba/tests/test_blackscholes.py +++ b/numba/tests/test_blackscholes.py @@ -4,8 +4,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, compile_extra, Flags -from numba import types, typing -from .support import TestCase +from numba.core import types, typing +from numb.support import TestCase RISKFREE = 0.02 diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index cfb52f65fa9..dd92edf62c1 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -7,8 +7,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import jit, typeof, errors, types, utils, config, njit -from .support import TestCase, tag +from numba import jit, typeof, config, njit +from numba.core import errors, types, utils +from numba.tests.support import TestCase, tag enable_pyobj_flags = Flags() diff --git a/numba/tests/test_casting.py b/numba/tests/test_casting.py index 4fd5ce821d3..fae93701a4c 100644 --- a/numba/tests/test_casting.py +++ b/numba/tests/test_casting.py @@ -1,7 +1,8 @@ from numba import unittest_support as unittest import numpy as np from numba.compiler import compile_isolated -from numba import types, njit +from numba import njit +from numba.core import types import struct diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index f8476d2ecdc..0e1d147f5ea 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -2,7 +2,8 @@ import numpy as np from numba import unittest_support as unittest -from numba import jit, cffi_support, types, errors +from numba import jit, cffi_support +from numba.core import types, errors from numba.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index f7f3ff3c806..e2fd49a9134 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -12,10 +12,11 @@ import numpy as np from numba import unittest_support as unittest -from numba import cfunc, carray, farray, types, typing, utils, njit +from numba import cfunc, carray, farray, njit +from numba.core import types, typing, utils from numba import cffi_support, numpy_support -from .support import TestCase, tag, captured_stderr -from .test_dispatcher import BaseCacheTest +from numba.tests.support import TestCase, tag, captured_stderr +from numba.tests.test_dispatcher import BaseCacheTest skip_cffi_unsupported = unittest.skipUnless( cffi_support.SUPPORTED, diff --git a/numba/tests/test_compile_cache.py b/numba/tests/test_compile_cache.py index 1a87265f887..a002b838241 100644 --- a/numba/tests/test_compile_cache.py +++ b/numba/tests/test_compile_cache.py @@ -3,7 +3,7 @@ import llvmlite.llvmpy.core as lc -from numba import types, typing +from numba.core import types, typing from numba.targets import callconv, cpu diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index f107d80c9ed..e66ec44cacd 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -1,5 +1,5 @@ import numba.unittest_support as unittest -from .support import TestCase +from numba.tests.support import TestCase import sys import operator @@ -9,10 +9,10 @@ import numpy from numba.compiler import compile_isolated -from numba import types, utils, jit, types +from numba import jit +from numba.core import types, utils from numba.core.errors import TypingError, LoweringError -from .support import tag, _32bit -from numba.tests.support import captured_stdout +from numba.tests.support import tag, _32bit, captured_stdout PARALLEL_SUPPORTED = not _32bit diff --git a/numba/tests/test_conversion.py b/numba/tests/test_conversion.py index 467601ce928..34b2d95f2c8 100644 --- a/numba/tests/test_conversion.py +++ b/numba/tests/test_conversion.py @@ -7,8 +7,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, jit, numpy_support -from .support import TestCase +from numba import jit, numpy_support +from numba.core import types +from numba.tests.support import TestCase def identity(x): diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index fb042e8347e..f3964bc2e11 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -7,10 +7,11 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated -from numba import jit, types, errors +from numba import jit +from numba.core import types, errors from numba.typing import ctypes_utils -from .support import MemoryLeakMixin, tag, TestCase -from .ctypes_usecases import * +from numba.tests.support import MemoryLeakMixin, tag, TestCase +from numba.tests.ctypes_usecases import * class TestCTypesTypes(TestCase): diff --git a/numba/tests/test_dataflow.py b/numba/tests/test_dataflow.py index 919eeff1ef2..54f79bdaa0f 100644 --- a/numba/tests/test_dataflow.py +++ b/numba/tests/test_dataflow.py @@ -2,8 +2,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, errors -from .support import TestCase, CompilationCache, skip_tryexcept_supported +from numba.core import types, errors +from numba.tests.support import (TestCase, CompilationCache, + skip_tryexcept_supported) enable_pyobj_flags = Flags() diff --git a/numba/tests/test_debuginfo.py b/numba/tests/test_debuginfo.py index 5c3eed17774..0a408fca340 100644 --- a/numba/tests/test_debuginfo.py +++ b/numba/tests/test_debuginfo.py @@ -1,8 +1,9 @@ import re -from .support import TestCase, override_config +from numba.tests.support import TestCase, override_config from numba import unittest_support as unittest -from numba import jit, types +from numba import jit +from numba.core import types class TestDebugInfo(TestCase): diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index cac1b8a9a85..28592970e15 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -26,18 +26,20 @@ import numpy as np from numba import unittest_support as unittest -from numba import jit, generated_jit, types, typeof, errors +from numba import jit, generated_jit, typeof +from numba.core import types, errors from numba import _dispatcher from numba.compiler import compile_isolated from numba.core.errors import NumbaWarning -from .support import (TestCase, temp_directory, import_dynamic, - override_env_config, capture_cache_log, captured_stdout) +from numba.tests.support import (TestCase, temp_directory, import_dynamic, + override_env_config, capture_cache_log, + captured_stdout) from numba.numpy_support import as_dtype from numba.targets import codegen from numba.caching import _UserWideCacheLocator from numba.dispatcher import Dispatcher from numba import parfor -from .support import skip_parfors_unsupported, needs_lapack +from numba.tests.support import skip_parfors_unsupported, needs_lapack import llvmlite.binding as ll diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 60ce38f35e5..3bc50dd4bbe 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -9,9 +9,8 @@ from numba.core.errors import TypingError from numba import config from numba import njit -from numba.core import types -from numba import utils -from .support import MemoryLeakMixin, TestCase, tag +from numba.core import types, utils +from numba.tests.support import MemoryLeakMixin, TestCase, tag nrtjit = njit(_nrt=True, nogil=True) diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index f8e80925ce6..e9838d911a7 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -3,9 +3,10 @@ import traceback from numba.compiler import compile_isolated, Flags -from numba import jit, types, errors, njit +from numba import jit, njit +from numba.core import types, errors from numba import unittest_support as unittest -from .support import TestCase +from numba.tests.support import TestCase force_pyobj_flags = Flags() force_pyobj_flags.set("force_pyobject") diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index 957fc83b249..23a70a37e64 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -3,9 +3,10 @@ import numpy as np import numba.unittest_support as unittest -from numba import types, jit, typeof +from numba import jit, typeof +from numba.core import types from numba.core.errors import TypingError -from .support import MemoryLeakMixin, TestCase, tag +from numba.tests.support import MemoryLeakMixin, TestCase, tag def getitem_usecase(a, b): diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index f5b6158e30b..773a9d139b7 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -10,9 +10,10 @@ import numpy as np -from numba import jit, types, utils +from numba import jit +from numba.core import types, utils import numba.unittest_support as unittest -from .support import TestCase, tag, CompilationCache +from numba.tests.support import TestCase, tag, CompilationCache from numba.targets import hashing from numba.unicode import compile_time_get_string_data diff --git a/numba/tests/test_import.py b/numba/tests/test_import.py index 44b2389807c..c59e84171b4 100644 --- a/numba/tests/test_import.py +++ b/numba/tests/test_import.py @@ -2,7 +2,7 @@ import sys from numba import unittest_support as unittest -from .support import TestCase +from numba.tests.support import TestCase class TestNumbaImport(TestCase): @@ -33,7 +33,8 @@ def test_laziness(self): __import__(mod) code = """if 1: - from numba import jit, types, vectorize + from numba import jit, vectorize + from numba.core import types import sys print(list(sys.modules)) """ diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index 80c0bde8099..bbe3ad0e492 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -7,10 +7,11 @@ from numba import (float32, float64, int16, int32, boolean, deferred_type, optional) -from numba import njit, typeof, types, errors +from numba import njit, typeof +from numba.core import types, errors from numba import unittest_support as unittest from numba import jitclass -from .support import TestCase, MemoryLeakMixin +from numba.tests.support import TestCase, MemoryLeakMixin from numba.jitclass import _box from numba.runtime.nrt import MemInfo from numba.core.errors import LoweringError diff --git a/numba/tests/test_jitmethod.py b/numba/tests/test_jitmethod.py index 5d9bc740442..8bd35ee4a7f 100644 --- a/numba/tests/test_jitmethod.py +++ b/numba/tests/test_jitmethod.py @@ -2,7 +2,8 @@ import numpy as np -from numba import config, jit, types +from numba import config, jit +from numba.core import types from numba.compiler import compile_isolated from numba.tests.support import override_config diff --git a/numba/tests/test_listobject.py b/numba/tests/test_listobject.py index 04970d5fbb0..f77c8f71846 100644 --- a/numba/tests/test_listobject.py +++ b/numba/tests/test_listobject.py @@ -12,11 +12,12 @@ """ from numba import njit -from numba import int32, types +from numba import int32 +from numba.core import types from numba.core.errors import TypingError from numba import listobject -from .support import (TestCase, MemoryLeakMixin, override_config, - forbid_codegen) +from numba.tests.support import (TestCase, MemoryLeakMixin, override_config, + forbid_codegen) class TestCreateAppendLength(MemoryLeakMixin, TestCase): diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 0bca472d87f..0b0ac9a0f26 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -7,10 +7,11 @@ import numpy as np from numba.compiler import compile_isolated, Flags -from numba import jit, types, utils, typeof, jitclass +from numba import jit, typeof, jitclass import numba.unittest_support as unittest -from numba import testing, errors -from .support import TestCase, MemoryLeakMixin, tag +from numba import testing +from numba.core import types, utils, errors +from numba.tests.support import TestCase, MemoryLeakMixin, tag enable_pyobj_flags = Flags() diff --git a/numba/tests/test_mandelbrot.py b/numba/tests/test_mandelbrot.py index aac984bdb71..ac605259ba3 100644 --- a/numba/tests/test_mandelbrot.py +++ b/numba/tests/test_mandelbrot.py @@ -1,6 +1,6 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, utils +from numba.core import types, utils enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_mangling.py b/numba/tests/test_mangling.py index 9ce3bdaf3c4..e648478edc6 100644 --- a/numba/tests/test_mangling.py +++ b/numba/tests/test_mangling.py @@ -4,9 +4,9 @@ The mangling affects the ABI of numba compiled binaries. """ -from numba import types, utils +from numba.core import types, utils from numba.funcdesc import default_mangler -from .support import unittest, TestCase +from numba.tests.support import unittest, TestCase class TestMangling(TestCase): diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index c6bd299b8a7..3f03bbea933 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -2,7 +2,8 @@ from numba.tests.support import (TestCase, MemoryLeakMixin, skip_parfors_unsupported) -from numba import njit, types, typed, ir, errors, literal_unroll, prange +from numba import njit, typed, ir, literal_unroll, prange +from numba.core import types, errors from numba.testing import unittest from numba.extending import overload from numba.compiler_machinery import PassManager, register_pass, FunctionPass diff --git a/numba/tests/test_multi3.py b/numba/tests/test_multi3.py index 32c81ad4881..b6cd87835e9 100644 --- a/numba/tests/test_multi3.py +++ b/numba/tests/test_multi3.py @@ -2,7 +2,8 @@ import numpy as np -from numba import njit, types +from numba import njit +from numba.core import types from numba import unittest_support as unittest class TestMulti3(unittest.TestCase): diff --git a/numba/tests/test_nested_calls.py b/numba/tests/test_nested_calls.py index 677519d8255..6a5dd5df4ba 100644 --- a/numba/tests/test_nested_calls.py +++ b/numba/tests/test_nested_calls.py @@ -5,9 +5,10 @@ from numba import int32, int64 -from numba import jit, generated_jit, types +from numba import jit, generated_jit +from numba.core import types from numba import unittest_support as unittest -from .support import TestCase, tag +from numba.tests.support import TestCase, tag @jit(nopython=True) diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 37ec503c987..1fb93e469f9 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -9,13 +9,15 @@ from numba import unittest_support as unittest from numba.compiler import Flags -from numba import jit, njit, typeof, types +from numba import jit, njit, typeof +from numba.core import types from numba.numpy_support import numpy_version from numba.core.errors import TypingError from numba.config import IS_WIN32, IS_32BITS from numba.utils import pysignature from numba.targets.arraymath import cross2d -from .support import TestCase, CompilationCache, MemoryLeakMixin, needs_blas +from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, + needs_blas) no_pyobj_flags = Flags() diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 682b2bd5957..ff91ee8c7c0 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -12,8 +12,9 @@ import numpy as np import numba.unittest_support as unittest -from numba import config, jit, npdatetime, types, vectorize, numpy_support +from numba import config, jit, npdatetime, vectorize, numpy_support from numba.numpy_support import numpy_version +from numba.core import types from numba.core.errors import TypingError from .support import TestCase, tag diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index d89fd8f42f9..405806cb08a 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -7,7 +7,8 @@ import numpy as np from numba import unittest_support as unittest -from numba import njit, targets, typing, types +from numba import njit, targets +from numba.core import typing, types from numba.compiler import compile_isolated, Flags from numba.runtime import ( rtsys, diff --git a/numba/tests/test_numberctor.py b/numba/tests/test_numberctor.py index 71bb71f32d7..3a7f5382c7f 100644 --- a/numba/tests/test_numberctor.py +++ b/numba/tests/test_numberctor.py @@ -2,9 +2,10 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated -from numba import jit, types +from numba import jit +from numba.core import types -from .support import TestCase, tag +from numba.tests.support import TestCase, tag def dobool(a): diff --git a/numba/tests/test_numbers.py b/numba/tests/test_numbers.py index a3b30db2fe6..58aecdfc9ae 100644 --- a/numba/tests/test_numbers.py +++ b/numba/tests/test_numbers.py @@ -2,9 +2,10 @@ import numpy as np -from numba import njit, types +from numba import njit +from numba.core import types from numba.core.errors import TypingError -from .support import TestCase +from numba.tests.support import TestCase def gen_view(a,b): diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index 0150deb3680..b07e4d71ffc 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -9,9 +9,10 @@ import numpy as np import numba.unittest_support as unittest -from numba import numpy_support, types -from .support import TestCase -from .enum_usecases import Shake, RequestError +from numba import numpy_support +from numba.core import types +from numba.tests.support import TestCase +from numba.tests.enum_usecases import Shake, RequestError class TestFromDtype(TestCase): diff --git a/numba/tests/test_object_mode.py b/numba/tests/test_object_mode.py index 156b278155b..f629d1552a8 100644 --- a/numba/tests/test_object_mode.py +++ b/numba/tests/test_object_mode.py @@ -7,8 +7,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import utils, jit -from .support import TestCase +from numba import jit +from numba.core import utils +from numba.support import TestCase def complex_constant(n): diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 18fa76e52e2..5ae1ad4a366 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -8,9 +8,11 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import jit, types, typeinfer, utils, errors -from .support import TestCase, tag, needs_blas -from .matmul_usecase import (matmul_usecase, imatmul_usecase, DumbMatrix,) +from numba import jit, typeinfer +from numba.core import types, utils, errors +from numba.tests.support import TestCase, tag, needs_blas +from numba.tests.matmul_usecase import (matmul_usecase, imatmul_usecase, + DumbMatrix,) Noflags = Flags() diff --git a/numba/tests/test_optional.py b/numba/tests/test_optional.py index d855f812e72..b278b1a8eb5 100644 --- a/numba/tests/test_optional.py +++ b/numba/tests/test_optional.py @@ -4,9 +4,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, typeof, njit -from numba import lowering -from .support import TestCase +from numba import typeof, njit, lowering +from numba.core import types +from numba.tests.support import TestCase def return_double_or_none(x): diff --git a/numba/tests/test_overlap.py b/numba/tests/test_overlap.py index 29c3e631013..db6224aa3cd 100644 --- a/numba/tests/test_overlap.py +++ b/numba/tests/test_overlap.py @@ -1,8 +1,9 @@ import numpy as np from numba import unittest_support as unittest -from numba import jit, types -from .support import TestCase, tag +from numba import jit +from numba.core import types +from numba.tests.support import TestCase, tag # Array overlaps involving a displacement diff --git a/numba/tests/test_pipeline.py b/numba/tests/test_pipeline.py index 96274223429..d4700dc8412 100644 --- a/numba/tests/test_pipeline.py +++ b/numba/tests/test_pipeline.py @@ -1,7 +1,8 @@ from numba.compiler import Compiler -from numba import jit, generated_jit, types, objmode +from numba import jit, generated_jit, objmode +from numba.core import types from numba.ir import FunctionIR -from .support import TestCase +from numba.tests.support import TestCase class TestCustomPipeline(TestCase): diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index 8caac1c05e6..8849c8300fb 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -3,7 +3,8 @@ """ import numpy as np -from numba import njit, types, ir +from numba import njit, ir +from numba.core import types from numba.compiler import CompilerBase, DefaultPassBuilder from numba.typed_passes import NopythonTypeInference from numba.compiler_machinery import register_pass, FunctionPass diff --git a/numba/tests/test_print.py b/numba/tests/test_print.py index 578c2c145ce..3127bfb3373 100644 --- a/numba/tests/test_print.py +++ b/numba/tests/test_print.py @@ -4,8 +4,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import jit, types, errors, utils -from .support import captured_stdout, tag, TestCase +from numba import jit +from numba.core import types, errors, utils +from numba.tests.support import captured_stdout, tag, TestCase enable_pyobj_flags = Flags() diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index f6b1418fcae..408b51fa510 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -11,9 +11,10 @@ import numpy as np import numba.unittest_support as unittest -from numba import jit, _helperlib, types +from numba import jit, _helperlib +from numba.core import types from numba.compiler import compile_isolated -from .support import TestCase, compile_function, tag +from numba.tests.support import TestCase, compile_function, tag # State size of the Mersenne Twister diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index 5bd0a491df1..55fe5445c8f 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -5,8 +5,9 @@ import numpy from numba.compiler import compile_isolated -from numba import types, utils, jit, njit -from .support import tag +from numba import jit, njit +from numba.core import types, utils +from numba.tests.support import tag def loop1(n): diff --git a/numba/tests/test_recarray_usecases.py b/numba/tests/test_recarray_usecases.py index 8cf7792bb0a..6266ce007cc 100644 --- a/numba/tests/test_recarray_usecases.py +++ b/numba/tests/test_recarray_usecases.py @@ -2,10 +2,11 @@ import numpy as np -from numba import numpy_support, types +from numba import numpy_support +from numba.core import types from numba.compiler import compile_isolated from numba import unittest_support as unittest -from .support import captured_stdout, tag, TestCase +from numba.tests.support import captured_stdout, tag, TestCase def usecase1(arr1, arr2): diff --git a/numba/tests/test_sets.py b/numba/tests/test_sets.py index ac250fa43b1..d72ae5e62ef 100644 --- a/numba/tests/test_sets.py +++ b/numba/tests/test_sets.py @@ -10,10 +10,11 @@ import numpy as np from numba.compiler import compile_isolated, Flags -from numba import jit, types +from numba import jit +from numba.core import types import numba.unittest_support as unittest -from .support import (TestCase, enable_pyobj_flags, MemoryLeakMixin, tag, - compile_function) +from numba.tests.support import (TestCase, enable_pyobj_flags, MemoryLeakMixin, + tag, compile_function) Point = namedtuple('Point', ('a', 'b')) diff --git a/numba/tests/test_slices.py b/numba/tests/test_slices.py index d578a485ce7..73912216619 100644 --- a/numba/tests/test_slices.py +++ b/numba/tests/test_slices.py @@ -6,8 +6,9 @@ import numpy as np from numba import unittest_support as unittest -from numba import jit, typeof, utils, TypingError -from .support import TestCase, MemoryLeakMixin +from numba import jit, typeof, TypingError +from numba.core import utils +from numba.support import TestCase, MemoryLeakMixin def slice_passing(sl): diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index 56bddf4f09e..95bbc0c06d0 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -7,14 +7,15 @@ import numpy as np from numba.compiler import compile_isolated, Flags -from numba import jit, types, utils, njit, errors +from numba import jit, njit +from numba.core import types, utils, errors import numba.unittest_support as unittest from numba import testing -from .support import TestCase, MemoryLeakMixin, tag +from numba.tests.support import TestCase, MemoryLeakMixin, tag from numba.targets.quicksort import make_py_quicksort, make_jit_quicksort from numba.targets.mergesort import make_jit_mergesort -from .timsort import make_py_timsort, make_jit_timsort, MergeRun +from numba.tests.timsort import make_py_timsort, make_jit_timsort, MergeRun def make_temp_list(keys, n): diff --git a/numba/tests/test_storeslice.py b/numba/tests/test_storeslice.py index e47f9873e2b..d5da886e53d 100644 --- a/numba/tests/test_storeslice.py +++ b/numba/tests/test_storeslice.py @@ -2,8 +2,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, errors -from .support import TestCase +from numba.core import types, errors +from numba.tests.support import TestCase def setitem_slice(a, start, stop, step, scalar): diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index 6e24814c59f..b4deecc2d5d 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -5,8 +5,9 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated -from numba import njit, jit, types, errors, utils -from .support import TestCase, MemoryLeakMixin, tag +from numba import njit, jit +from numba.core import types, errors, utils +from numba.tests.support import TestCase, MemoryLeakMixin, tag Rect = collections.namedtuple('Rect', ('width', 'height')) diff --git a/numba/tests/test_typeconv.py b/numba/tests/test_typeconv.py index 96bd4960922..5345dccc15d 100644 --- a/numba/tests/test_typeconv.py +++ b/numba/tests/test_typeconv.py @@ -2,9 +2,9 @@ from numba import unittest_support as unittest from numba.core import types -from numba.typeconv.typeconv import TypeManager, TypeCastingRules -from numba.typeconv import rules -from numba.typeconv import castgraph, Conversion +from numba.core.typeconv.typeconv import TypeManager, TypeCastingRules +from numba.core.typeconv import rules +from numba.core.typeconv import castgraph, Conversion class CompatibilityTestMixin(unittest.TestCase): diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index e75cf1604cb..70aeaf0a056 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -4,7 +4,8 @@ import numpy as np from numba import njit -from numba import int32, float32, types, prange +from numba import int32, float32, prange +from numba.core import types from numba import jitclass, typeof from numba.typed import List, Dict from numba.core.errors import TypingError diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index 38e20e871e5..23f98b3aa3a 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -5,12 +5,12 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated -from numba import types, typeinfer, typing, jit, errors -from numba import utils -from numba.typeconv import Conversion +from numba import typeinfer, jit +from numba.core import types, typing, errors, utils +from numba.core.typeconv import Conversion -from .support import TestCase, tag -from .test_typeconv import CompatibilityTestMixin +from numba.tests.support import TestCase, tag +from numba.tests.test_typeconv import CompatibilityTestMixin i8 = types.int8 diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 44e096dd54c..818850831fb 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -21,7 +21,8 @@ import numpy as np from numba import unittest_support as unittest -from numba import sigutils, types, typing, errors +from numba import sigutils +from numba.core import types, typing, errors from numba.core.types.abstract import _typecache from numba.typing.templates import make_overload_template from numba import jit, njit, numpy_support, typeof diff --git a/numba/tests/test_typingerror.py b/numba/tests/test_typingerror.py index c6e5a664ac1..9ab89fd51c4 100644 --- a/numba/tests/test_typingerror.py +++ b/numba/tests/test_typingerror.py @@ -7,9 +7,10 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated -from numba import jit, types +from numba import jit +from numba.core import types from numba.core.errors import TypingError -from .support import TestCase +from numba.tests.support import TestCase def what(): diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index ba098263713..b90962fa623 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -9,12 +9,13 @@ import numpy as np import numba.unittest_support as unittest -from numba import types, typing, utils, typeof, numpy_support, njit +from numba import typeof, numpy_support, njit +from numba.core import types, typing, utils from numba.compiler import compile_isolated, Flags, DEFAULT_FLAGS from numba.numpy_support import from_dtype from numba import jit, vectorize from numba.core.errors import LoweringError, TypingError -from .support import TestCase, CompilationCache, MemoryLeakMixin, tag +from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin, tag from numba.typing.npydecl import supported_ufuncs, all_ufuncs is32bits = tuple.__itemsize__ == 4 diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 885bf9ecd25..890f918588b 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -2,9 +2,10 @@ from itertools import product from itertools import permutations -from numba import njit, types, utils +from numba import njit +from numba.core import types, utils import numba.unittest_support as unittest -from .support import (TestCase, no_pyobj_flags, MemoryLeakMixin) +from numba.tests.support import (TestCase, no_pyobj_flags, MemoryLeakMixin) from numba.core.errors import TypingError diff --git a/numba/tests/test_unicode_array.py b/numba/tests/test_unicode_array.py index 0727d5e67ef..47be52267d1 100644 --- a/numba/tests/test_unicode_array.py +++ b/numba/tests/test_unicode_array.py @@ -2,7 +2,8 @@ import numpy as np import numba.unittest_support as unittest -from numba import jit, utils, from_dtype, types +from numba import jit, from_dtype +from numba.core import types, utils from numba.typed import Dict from numba.tests.support import TestCase diff --git a/numba/tests/test_usecases.py b/numba/tests/test_usecases.py index dcef9b11df5..c097ebc260b 100644 --- a/numba/tests/test_usecases.py +++ b/numba/tests/test_usecases.py @@ -3,9 +3,9 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import types, utils +from numba.core import types, utils from numba.tests import usecases -from .support import TestCase, tag +from numba.tests.support import TestCase, tag enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index 05317f0e799..f14db4add79 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -8,13 +8,14 @@ from numba.withcontexts import bypass_context, call_context, objmode_context from numba.bytecode import FunctionIdentity, ByteCode from numba.interpreter import Interpreter -from numba import typing, errors +from numba.core import typing, errors from numba.targets.registry import cpu_target from numba.targets import cpu from numba.compiler import compile_ir, DEFAULT_FLAGS from numba import njit, typeof, objmode from numba.extending import overload -from .support import MemoryLeak, TestCase, captured_stdout, skip_unless_scipy +from numba.tests.support import (MemoryLeak, TestCase, captured_stdout, + skip_unless_scipy) def get_func_ir(func): diff --git a/numba/tests/test_wrapper.py b/numba/tests/test_wrapper.py index 24519279e6f..7a5463f54e9 100644 --- a/numba/tests/test_wrapper.py +++ b/numba/tests/test_wrapper.py @@ -1,7 +1,8 @@ import numpy as np import numba.unittest_support as unittest -from numba import compiler, types, utils +from numba import compiler +from numba.core import types, utils from numba.targets import registry diff --git a/numba/unsafe/bytes.py b/numba/unsafe/bytes.py index 629985c9d45..7d2c0b3f13a 100644 --- a/numba/unsafe/bytes.py +++ b/numba/unsafe/bytes.py @@ -5,7 +5,8 @@ from numba.extending import intrinsic from llvmlite import ir -from numba import types, cgutils +from numba.core import types +from numba import cgutils @intrinsic diff --git a/numba/unsafe/eh.py b/numba/unsafe/eh.py index 0a488a211b9..3f3b1f4a4bc 100644 --- a/numba/unsafe/eh.py +++ b/numba/unsafe/eh.py @@ -2,7 +2,8 @@ Exception handling intrinsics. """ -from numba import types, cgutils, errors +from numba.core import types, errors +from numba import cgutils from numba.extending import intrinsic From 4e73e131ed0c2eb9077fa60b3124a1aea7669307 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 16:21:09 +0000 Subject: [PATCH 318/595] Move npdatetime --- numba/core/types/scalars.py | 2 +- numba/core/typing/npdatetime.py | 2 +- numba/{ => np}/npdatetime.py | 0 numba/targets/npdatetime.py | 3 ++- numba/tests/test_npdatetime.py | 3 ++- 5 files changed, 6 insertions(+), 4 deletions(-) rename numba/{ => np}/npdatetime.py (100%) diff --git a/numba/core/types/scalars.py b/numba/core/types/scalars.py index 892d8adce68..57241446f78 100644 --- a/numba/core/types/scalars.py +++ b/numba/core/types/scalars.py @@ -4,9 +4,9 @@ from .abstract import Dummy, Hashable, Literal, Number, Type from functools import total_ordering -from numba import npdatetime from numba.core import utils from numba.core.typeconv import Conversion +from numba.np import npdatetime class Boolean(Hashable): diff --git a/numba/core/typing/npdatetime.py b/numba/core/typing/npdatetime.py index f0369ce98f5..7450c0f899d 100644 --- a/numba/core/typing/npdatetime.py +++ b/numba/core/typing/npdatetime.py @@ -6,11 +6,11 @@ from itertools import product import operator -from numba import npdatetime from numba.core import types from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, infer_global, infer, infer_getattr, signature) +from numba.np import npdatetime # timedelta64-only operations diff --git a/numba/npdatetime.py b/numba/np/npdatetime.py similarity index 100% rename from numba/npdatetime.py rename to numba/np/npdatetime.py diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index e8448610e87..d887ba32949 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -8,10 +8,11 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba import npdatetime, cgutils, numpy_support +from numba import cgutils, numpy_support from numba.core import types from numba.targets.imputils import (lower_builtin, lower_constant, impl_ret_untracked) +from numba.np import npdatetime # datetime64 and timedelta64 use the same internal representation DATETIME64 = TIMEDELTA64 = Type.int(64) diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index ff91ee8c7c0..edb5d814631 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -12,11 +12,12 @@ import numpy as np import numba.unittest_support as unittest -from numba import config, jit, npdatetime, vectorize, numpy_support +from numba import config, jit, vectorize, numpy_support from numba.numpy_support import numpy_version from numba.core import types from numba.core.errors import TypingError from .support import TestCase, tag +from numba.np import npdatetime def value_unit(val): From 9cbed84b243d1919ddafdc29bafa1e97b1fcfa55 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 16:35:48 +0000 Subject: [PATCH 319/595] move dataflow.py --- numba/{ => core}/dataflow.py | 0 numba/interpreter.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{ => core}/dataflow.py (100%) diff --git a/numba/dataflow.py b/numba/core/dataflow.py similarity index 100% rename from numba/dataflow.py rename to numba/core/dataflow.py diff --git a/numba/interpreter.py b/numba/interpreter.py index b3e3917d704..319ab9a5768 100644 --- a/numba/interpreter.py +++ b/numba/interpreter.py @@ -4,8 +4,8 @@ import operator import logging -from numba.core import errors -from numba import config, ir, controlflow, dataflow +from numba.core import errors, dataflow +from numba import config, ir, controlflow from numba.core.errors import NotDefinedError from numba.core.utils import ( PYVERSION, From d36344b61aee78709f2527920e53e197ad88b786 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 16:36:32 +0000 Subject: [PATCH 320/595] move controlflow.py --- numba/analysis.py | 2 +- numba/byteflow.py | 2 +- numba/{ => core}/controlflow.py | 0 numba/interpreter.py | 4 ++-- numba/parfor.py | 2 +- numba/tests/test_flow_control.py | 2 +- numba/tests/test_obj_lifetime.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename numba/{ => core}/controlflow.py (100%) diff --git a/numba/analysis.py b/numba/analysis.py index d51de11c7fd..210cf1d4c9f 100644 --- a/numba/analysis.py +++ b/numba/analysis.py @@ -6,7 +6,7 @@ from collections import namedtuple, defaultdict from numba import ir, errors -from numba.controlflow import CFGraph +from numba.core.controlflow import CFGraph from numba import consts, special from numba.core import types diff --git a/numba/byteflow.py b/numba/byteflow.py index 23107102b56..f68f4d1fc78 100644 --- a/numba/byteflow.py +++ b/numba/byteflow.py @@ -8,7 +8,7 @@ from functools import total_ordering from numba.core.utils import UniqueDict, PYVERSION -from numba.controlflow import NEW_BLOCKERS, CFGraph +from numba.core.controlflow import NEW_BLOCKERS, CFGraph from numba.ir import Loc from numba.core.errors import UnsupportedError diff --git a/numba/controlflow.py b/numba/core/controlflow.py similarity index 100% rename from numba/controlflow.py rename to numba/core/controlflow.py diff --git a/numba/interpreter.py b/numba/interpreter.py index 319ab9a5768..9883cff6a45 100644 --- a/numba/interpreter.py +++ b/numba/interpreter.py @@ -4,8 +4,8 @@ import operator import logging -from numba.core import errors, dataflow -from numba import config, ir, controlflow +from numba.core import errors, dataflow, controlflow +from numba import config, ir from numba.core.errors import NotDefinedError from numba.core.utils import ( PYVERSION, diff --git a/numba/parfor.py b/numba/parfor.py index 7fdf20c84cc..97dbfd87fff 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -82,7 +82,7 @@ from numba.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) -from numba.controlflow import CFGraph +from numba.core.controlflow import CFGraph from numba.core.typing import npydecl, signature from numba.core.types.functions import Function from numba.array_analysis import (random_int_args, random_1arg_size, diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index d38c7988d71..2e0e6155a3b 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -1,7 +1,7 @@ import itertools import numba.unittest_support as unittest -from numba.controlflow import CFGraph, ControlFlowAnalysis +from numba.core.controlflow import CFGraph, ControlFlowAnalysis from numba.compiler import compile_isolated, Flags from numba.core import types from numba.bytecode import FunctionIdentity, ByteCode diff --git a/numba/tests/test_obj_lifetime.py b/numba/tests/test_obj_lifetime.py index 4ef851d92c3..01c8e3edbaa 100644 --- a/numba/tests/test_obj_lifetime.py +++ b/numba/tests/test_obj_lifetime.py @@ -4,7 +4,7 @@ import gc import numba.unittest_support as unittest -from numba.controlflow import CFGraph, Loop +from numba.core.controlflow import CFGraph, Loop from numba.compiler import compile_extra, compile_isolated, Flags from numba.core import types from .support import TestCase From 99cd4b8a0c200cd0ce9fb55c3f310fb0ea48f3c6 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 16:42:35 +0000 Subject: [PATCH 321/595] abs imports --- numba/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/numba/__init__.py b/numba/__init__.py index db6affd580e..13105e857e2 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -11,7 +11,7 @@ __version__ = get_versions()['version'] del get_versions -from . import config, _runtests as runtests +from numba import config, _runtests as runtests from numba.core import types, errors # Re-export typeof @@ -27,16 +27,16 @@ from numba.core.types import * # Re-export decorators -from .decorators import (cfunc, generated_jit, jit, njit, stencil, jit_module) +from numba.decorators import cfunc, generated_jit, jit, njit, stencil, jit_module # Re-export vectorize decorators and the thread layer querying function -from .npyufunc import vectorize, guvectorize, threading_layer +from numba.npyufunc import vectorize, guvectorize, threading_layer # Re-export Numpy helpers -from .numpy_support import carray, farray, from_dtype +from numba.numpy_support import carray, farray, from_dtype # Re-export jitclass -from .jitclass import jitclass +from numba.jitclass import jitclass # Initialize withcontexts import numba.withcontexts From 543b7df438d8f2785c5863babc7193ca901ea06c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 16:45:23 +0000 Subject: [PATCH 322/595] abs imports 2 --- numba/cuda/tests/cudasim/test_cudasim_issues.py | 2 +- numba/tests/test_alignment.py | 2 +- numba/tests/test_api.py | 2 +- numba/tests/test_array_reductions.py | 2 +- numba/tests/test_array_return.py | 2 +- numba/tests/test_buffer_protocol.py | 2 +- numba/tests/test_caching.py | 2 +- numba/tests/test_chained_assign.py | 2 +- numba/tests/test_cli.py | 2 +- numba/tests/test_closure.py | 2 +- numba/tests/test_codegen.py | 2 +- numba/tests/test_compiler_lock.py | 2 +- numba/tests/test_complex.py | 2 +- numba/tests/test_config.py | 2 +- numba/tests/test_debug.py | 2 +- numba/tests/test_del.py | 2 +- numba/tests/test_dictimpl.py | 2 +- numba/tests/test_dictobject.py | 2 +- numba/tests/test_dicts.py | 2 +- numba/tests/test_dyn_func.py | 2 +- numba/tests/test_entrypoints.py | 2 +- numba/tests/test_enums.py | 2 +- numba/tests/test_errorhandling.py | 2 +- numba/tests/test_extended_arg.py | 2 +- numba/tests/test_extending.py | 2 +- numba/tests/test_gdb.py | 2 +- numba/tests/test_gil.py | 2 +- numba/tests/test_heapq.py | 2 +- numba/tests/test_help.py | 2 +- numba/tests/test_indexing.py | 2 +- numba/tests/test_inlining.py | 2 +- numba/tests/test_ir_utils.py | 2 +- numba/tests/test_linalg.py | 2 +- numba/tests/test_listimpl.py | 2 +- numba/tests/test_looplifting.py | 2 +- numba/tests/test_npdatetime.py | 2 +- numba/tests/test_nrt.py | 2 +- numba/tests/test_nrt_refct.py | 2 +- numba/tests/test_obj_lifetime.py | 2 +- numba/tests/test_objects.py | 2 +- numba/tests/test_parallel_backend.py | 2 +- numba/tests/test_parfors.py | 2 +- numba/tests/test_parfors_caching.py | 2 +- numba/tests/test_polynomial.py | 2 +- numba/tests/test_practical_lowering_issues.py | 2 +- numba/tests/test_profiler.py | 2 +- numba/tests/test_pycc.py | 2 +- numba/tests/test_recursion.py | 2 +- numba/tests/test_remove_dead.py | 2 +- numba/tests/test_serialize.py | 2 +- numba/tests/test_support.py | 2 +- numba/tests/test_svml.py | 2 +- numba/tests/test_threadsafety.py | 2 +- numba/tests/test_try_except.py | 2 +- numba/tests/test_typedlist.py | 2 +- numba/tests/test_typedobjectutils.py | 2 +- numba/tests/test_unicode_names.py | 2 +- 57 files changed, 57 insertions(+), 57 deletions(-) diff --git a/numba/cuda/tests/cudasim/test_cudasim_issues.py b/numba/cuda/tests/cudasim/test_cudasim_issues.py index 39b7c70a99b..699c98aa2b0 100644 --- a/numba/cuda/tests/cudasim/test_cudasim_issues.py +++ b/numba/cuda/tests/cudasim/test_cudasim_issues.py @@ -16,7 +16,7 @@ def test_cuda_module_in_device_function(self): When the `cuda` module is referenced in a device function, it does not have the kernel API (e.g. cuda.threadIdx, cuda.shared) """ - from .support import cuda_module_in_device_function as inner + from numba.tests.support import cuda_module_in_device_function as inner @cuda.jit def outer(out): diff --git a/numba/tests/test_alignment.py b/numba/tests/test_alignment.py index 1b3a7395d8b..77eee17b26e 100644 --- a/numba/tests/test_alignment.py +++ b/numba/tests/test_alignment.py @@ -2,7 +2,7 @@ import numpy as np from numba import from_dtype, njit, void -from .support import TestCase +from numba.tests.support import TestCase class TestAlignment(TestCase): diff --git a/numba/tests/test_api.py b/numba/tests/test_api.py index 19fcd16d484..4429ee0b879 100644 --- a/numba/tests/test_api.py +++ b/numba/tests/test_api.py @@ -1,7 +1,7 @@ import numba from numba import unittest_support as unittest -from .support import TestCase +from numba.tests.support import TestCase class TestNumbaModule(TestCase): diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index dc2f0504bc6..b4b66373127 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -5,7 +5,7 @@ from numba import unittest_support as unittest from numba import jit, typeof from numba.compiler import compile_isolated -from .support import TestCase, MemoryLeakMixin, tag +from numba.tests.support import TestCase, MemoryLeakMixin, tag def array_all(arr): diff --git a/numba/tests/test_array_return.py b/numba/tests/test_array_return.py index 2caf24f5112..0b208ec2272 100644 --- a/numba/tests/test_array_return.py +++ b/numba/tests/test_array_return.py @@ -3,7 +3,7 @@ from numba.compiler import compile_isolated from numba import typeof from numba import unittest_support as unittest -from .support import MemoryLeakMixin +from numba.tests.support import MemoryLeakMixin def array_return(a, i): diff --git a/numba/tests/test_buffer_protocol.py b/numba/tests/test_buffer_protocol.py index bad1ab67c92..01731daf902 100644 --- a/numba/tests/test_buffer_protocol.py +++ b/numba/tests/test_buffer_protocol.py @@ -4,7 +4,7 @@ from numba import unittest_support as unittest from numba import jit -from .support import TestCase, compile_function, MemoryLeakMixin +from numba.tests.support import TestCase, compile_function, MemoryLeakMixin @jit(nopython=True) diff --git a/numba/tests/test_caching.py b/numba/tests/test_caching.py index 2260d3bc971..501d893c873 100644 --- a/numba/tests/test_caching.py +++ b/numba/tests/test_caching.py @@ -1,5 +1,5 @@ from numba import njit -from .support import ( +from numba.tests.support import ( TestCase, SerialMixin, run_in_new_process_caching diff --git a/numba/tests/test_chained_assign.py b/numba/tests/test_chained_assign.py index 8aec31dc7cd..eee9327a222 100644 --- a/numba/tests/test_chained_assign.py +++ b/numba/tests/test_chained_assign.py @@ -2,7 +2,7 @@ import numba.unittest_support as unittest import numpy as np import copy -from .support import MemoryLeakMixin +from numba.tests.support import MemoryLeakMixin try: diff --git a/numba/tests/test_cli.py b/numba/tests/test_cli.py index f2321dde7ae..c9a2de1d441 100644 --- a/numba/tests/test_cli.py +++ b/numba/tests/test_cli.py @@ -6,7 +6,7 @@ import threading import numba.unittest_support as unittest -from .support import TestCase +from numba.tests.support import TestCase def run_cmd(cmdline, env=os.environ, timeout=60): diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 62ec28923cf..4d740a0bff0 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -5,7 +5,7 @@ import numba.unittest_support as unittest from numba import njit, jit, testing from numba.core.errors import TypingError, UnsupportedError -from .support import TestCase +from numba.tests.support import TestCase class TestClosure(TestCase): diff --git a/numba/tests/test_codegen.py b/numba/tests/test_codegen.py index 959d5e9164e..26fec0b7072 100644 --- a/numba/tests/test_codegen.py +++ b/numba/tests/test_codegen.py @@ -16,7 +16,7 @@ import numba.unittest_support as unittest from numba.targets.codegen import JITCPUCodegen from numba.compiler_lock import global_compiler_lock -from .support import TestCase +from numba.tests.support import TestCase asm_sum = r""" diff --git a/numba/tests/test_compiler_lock.py b/numba/tests/test_compiler_lock.py index 733a9384057..dbeb09c9207 100644 --- a/numba/tests/test_compiler_lock.py +++ b/numba/tests/test_compiler_lock.py @@ -3,7 +3,7 @@ global_compiler_lock, require_global_compiler_lock, ) -from .support import TestCase +from numba.tests.support import TestCase class TestCompilerLock(TestCase): diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index 46fee534995..51f7bcdcfb4 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -6,7 +6,7 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags, utils from numba.core import types -from .support import TestCase, tag +from numba.tests.support import TestCase, tag from .complex_usecases import * enable_pyobj_flags = Flags() diff --git a/numba/tests/test_config.py b/numba/tests/test_config.py index de8371b8b2d..4a096f398a2 100644 --- a/numba/tests/test_config.py +++ b/numba/tests/test_config.py @@ -1,7 +1,7 @@ import os import tempfile import unittest -from .support import TestCase, temp_directory, override_env_config +from numba.tests.support import TestCase, temp_directory, override_env_config from numba import config try: diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 2bfe792f8f3..75ecbd1bad3 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -6,7 +6,7 @@ import numpy as np -from .support import (TestCase, override_config, override_env_config, +from numba.tests.support import (TestCase, override_config, override_env_config, captured_stdout, forbid_codegen, skip_parfors_unsupported, needs_blas) from numba import unittest_support as unittest diff --git a/numba/tests/test_del.py b/numba/tests/test_del.py index eab43d5d97b..0f81f97e5bd 100644 --- a/numba/tests/test_del.py +++ b/numba/tests/test_del.py @@ -1,7 +1,7 @@ import re from numba.compiler import compile_isolated -from .support import TestCase +from numba.tests.support import TestCase import numba.unittest_support as unittest from numba import testing diff --git a/numba/tests/test_dictimpl.py b/numba/tests/test_dictimpl.py index ba88b3f0018..4d7002a6bb8 100644 --- a/numba/tests/test_dictimpl.py +++ b/numba/tests/test_dictimpl.py @@ -5,7 +5,7 @@ import ctypes import random -from .support import TestCase +from numba.tests.support import TestCase from numba import _helperlib from numba.config import IS_32BITS diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 2a66ff5082c..5e0574e2f30 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -18,7 +18,7 @@ from numba.typedobjectutils import _sentry_safe_cast from numba.core.errors import TypingError from numba.core import types -from .support import (TestCase, MemoryLeakMixin, unittest, override_config, +from numba.tests.support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) diff --git a/numba/tests/test_dicts.py b/numba/tests/test_dicts.py index 9e862cd338b..adc626844d1 100644 --- a/numba/tests/test_dicts.py +++ b/numba/tests/test_dicts.py @@ -1,7 +1,7 @@ from numba import njit from numba.core.errors import TypingError import numba.unittest_support as unittest -from .support import TestCase, force_pyobj_flags +from numba.tests.support import TestCase, force_pyobj_flags def build_map(): diff --git a/numba/tests/test_dyn_func.py b/numba/tests/test_dyn_func.py index d58b7606dc3..df3b7aac1c1 100644 --- a/numba/tests/test_dyn_func.py +++ b/numba/tests/test_dyn_func.py @@ -1,7 +1,7 @@ import numpy as np import numba -from .support import TestCase +from numba.tests.support import TestCase class Issue455(object): diff --git a/numba/tests/test_entrypoints.py b/numba/tests/test_entrypoints.py index 79650716ec4..fd0fca4f294 100644 --- a/numba/tests/test_entrypoints.py +++ b/numba/tests/test_entrypoints.py @@ -3,7 +3,7 @@ import pkg_resources -from .support import TestCase +from numba.tests.support import TestCase class TestEntrypoints(TestCase): diff --git a/numba/tests/test_enums.py b/numba/tests/test_enums.py index cf65a1abc0d..dbc4f5ad9a7 100644 --- a/numba/tests/test_enums.py +++ b/numba/tests/test_enums.py @@ -7,7 +7,7 @@ import numba.unittest_support as unittest from numba import jit, vectorize -from .support import TestCase +from numba.tests.support import TestCase from .enum_usecases import Color, Shape, Shake, Planet, RequestError diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index a989de061fb..1154cae9e03 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -17,7 +17,7 @@ from numba.compiler_machinery import FunctionPass, PassManager, register_pass -from .support import skip_parfors_unsupported +from numba.tests.support import skip_parfors_unsupported # used in TestMiscErrorHandling::test_handling_of_write_to_*_global _global_list = [1, 2, 3, 4] diff --git a/numba/tests/test_extended_arg.py b/numba/tests/test_extended_arg.py index 87654762907..046698b9c6c 100644 --- a/numba/tests/test_extended_arg.py +++ b/numba/tests/test_extended_arg.py @@ -5,7 +5,7 @@ import sys from numba import jit -from .support import TestCase, tweak_code +from numba.tests.support import TestCase, tweak_code class TestExtendedArg(TestCase): diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 29b2d7e00c2..04b52c5d7dd 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -15,7 +15,7 @@ from numba.typed_passes import type_inference_stage from numba.targets.registry import cpu_target from numba.compiler import compile_isolated -from .support import (TestCase, captured_stdout, tag, temp_directory, +from numba.tests.support import (TestCase, captured_stdout, tag, temp_directory, override_config) from numba.core.errors import LoweringError diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index 0c9391711a3..cf213168d76 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -13,7 +13,7 @@ from numba import unittest_support as unittest from numba.targets.gdb_hook import _confirm_gdb -from .support import (TestCase, captured_stdout, tag, skip_parfors_unsupported) +from numba.tests.support import (TestCase, captured_stdout, tag, skip_parfors_unsupported) _platform = sys.platform diff --git a/numba/tests/test_gil.py b/numba/tests/test_gil.py index f25f8ea634e..54530c70a6e 100644 --- a/numba/tests/test_gil.py +++ b/numba/tests/test_gil.py @@ -10,7 +10,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba import errors, jit -from .support import TestCase, tag +from numba.tests.support import TestCase, tag # This CPython API function is a portable way to get the current thread id. diff --git a/numba/tests/test_heapq.py b/numba/tests/test_heapq.py index 8c557d16d2a..2e2a83ef2f4 100644 --- a/numba/tests/test_heapq.py +++ b/numba/tests/test_heapq.py @@ -5,7 +5,7 @@ from numba import jit from numba.compiler import Flags -from .support import TestCase, CompilationCache, MemoryLeakMixin +from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin no_pyobj_flags = Flags() no_pyobj_flags.set("nrt") diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index 5a74e7081cc..9f905f6328e 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -7,7 +7,7 @@ import builtins from numba.core import types -from .support import TestCase, temp_directory +from numba.tests.support import TestCase, temp_directory from numba.help.inspector import inspect_function, inspect_module diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index d6b6af75e35..116ab314443 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -7,7 +7,7 @@ from numba.compiler import compile_isolated, Flags from numba import utils, njit, typeof from numba.core import types, errors -from .support import TestCase, tag +from numba.tests.support import TestCase, tag enable_pyobj_flags = Flags() diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 50d999acfdc..e8953fee0f8 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -1,7 +1,7 @@ import re import numpy as np -from .support import (TestCase, override_config, captured_stdout, +from numba.tests.support import (TestCase, override_config, captured_stdout, skip_parfors_unsupported) import numba from numba import unittest_support as unittest diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index ea29605edb1..95d9421b314 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -1,5 +1,5 @@ import numba -from .support import TestCase, unittest +from numba.tests.support import TestCase, unittest from numba import compiler, jitclass, ir from numba.targets.registry import cpu_target from numba.compiler import CompilerBase, Flags diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index 6cd6c622138..052e40752bb 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -10,7 +10,7 @@ from numba import unittest_support as unittest from numba import jit, errors -from .support import TestCase, tag, needs_lapack, needs_blas, _is_armv7l +from numba.tests.support import TestCase, tag, needs_lapack, needs_blas, _is_armv7l from .matmul_usecase import matmul_usecase diff --git a/numba/tests/test_listimpl.py b/numba/tests/test_listimpl.py index d7249b9a6b0..0cd38e9b2a3 100644 --- a/numba/tests/test_listimpl.py +++ b/numba/tests/test_listimpl.py @@ -5,7 +5,7 @@ import ctypes import struct -from .support import TestCase +from numba.tests.support import TestCase from numba import _helperlib diff --git a/numba/tests/test_looplifting.py b/numba/tests/test_looplifting.py index 01f99aea04c..08eed6b5a71 100644 --- a/numba/tests/test_looplifting.py +++ b/numba/tests/test_looplifting.py @@ -4,7 +4,7 @@ from numba.core import types from numba import unittest_support as unittest from numba.compiler import compile_isolated, Flags -from .support import TestCase, tag, MemoryLeakMixin +from numba.tests.support import TestCase, tag, MemoryLeakMixin looplift_flags = Flags() diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index edb5d814631..246bb3241a8 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -16,7 +16,7 @@ from numba.numpy_support import numpy_version from numba.core import types from numba.core.errors import TypingError -from .support import TestCase, tag +from numba.tests.support import TestCase, tag from numba.np import npdatetime diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 405806cb08a..226a9dcce5a 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -24,7 +24,7 @@ from numba import cffi_support from numba.unsafe.nrt import NRT_get_api -from .support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic +from numba.tests.support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic enable_nrt_flags = Flags() enable_nrt_flags.set("nrt") diff --git a/numba/tests/test_nrt_refct.py b/numba/tests/test_nrt_refct.py index ed182e43788..5a2333adc1c 100644 --- a/numba/tests/test_nrt_refct.py +++ b/numba/tests/test_nrt_refct.py @@ -10,7 +10,7 @@ import numba.unittest_support as unittest from numba import njit from numba.runtime import rtsys -from .support import TestCase +from numba.tests.support import TestCase class TestNrtRefCt(TestCase): diff --git a/numba/tests/test_obj_lifetime.py b/numba/tests/test_obj_lifetime.py index 01c8e3edbaa..c5a43c8968b 100644 --- a/numba/tests/test_obj_lifetime.py +++ b/numba/tests/test_obj_lifetime.py @@ -7,7 +7,7 @@ from numba.core.controlflow import CFGraph, Loop from numba.compiler import compile_extra, compile_isolated, Flags from numba.core import types -from .support import TestCase +from numba.tests.support import TestCase enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_objects.py b/numba/tests/test_objects.py index 7f31341d4e4..b9ac335da10 100644 --- a/numba/tests/test_objects.py +++ b/numba/tests/test_objects.py @@ -6,7 +6,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba.core import types -from .support import TestCase +from numba.tests.support import TestCase enable_pyobj_flags = Flags() diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index be07d50f1cd..b9fb493491f 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -18,7 +18,7 @@ from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize -from .support import (temp_directory, override_config, TestCase, tag, +from numba.tests.support import (temp_directory, override_config, TestCase, tag, skip_parfors_unsupported, linux_only) import queue as t_queue diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index e42afeb926e..9aca4e92ccb 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -34,7 +34,7 @@ from numba.unsafe.ndarray import empty_inferred as unsafe_empty from numba.compiler import compile_isolated, Flags from numba.bytecode import ByteCodeIter -from .support import (TestCase, captured_stdout, MemoryLeakMixin, +from numba.tests.support import (TestCase, captured_stdout, MemoryLeakMixin, override_env_config, linux_only, tag, skip_parfors_unsupported, _32bit, needs_blas, needs_lapack) diff --git a/numba/tests/test_parfors_caching.py b/numba/tests/test_parfors_caching.py index 8360b92ec58..e7df59c814f 100644 --- a/numba/tests/test_parfors_caching.py +++ b/numba/tests/test_parfors_caching.py @@ -2,7 +2,7 @@ import numpy as np -from .support import skip_parfors_unsupported +from numba.tests.support import skip_parfors_unsupported from .test_dispatcher import BaseCacheUsecasesTest diff --git a/numba/tests/test_polynomial.py b/numba/tests/test_polynomial.py index 2d210e04112..9f85c4f04c1 100644 --- a/numba/tests/test_polynomial.py +++ b/numba/tests/test_polynomial.py @@ -5,7 +5,7 @@ from numba import unittest_support as unittest from numba import jit -from .support import TestCase, tag, needs_lapack +from numba.tests.support import TestCase, tag, needs_lapack def roots_fn(p): diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index 8849c8300fb..67433dfb5bc 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -9,7 +9,7 @@ from numba.typed_passes import NopythonTypeInference from numba.compiler_machinery import register_pass, FunctionPass -from .support import MemoryLeakMixin, TestCase +from numba.tests.support import MemoryLeakMixin, TestCase class TestLowering(MemoryLeakMixin, TestCase): diff --git a/numba/tests/test_profiler.py b/numba/tests/test_profiler.py index a95a8a34e0e..2a52784f5cc 100644 --- a/numba/tests/test_profiler.py +++ b/numba/tests/test_profiler.py @@ -8,7 +8,7 @@ from numba import jit from numba import unittest_support as unittest -from .support import needs_blas +from numba.tests.support import needs_blas def dot(a, b): diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index 293bbd52cc2..59b4db72f09 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -31,7 +31,7 @@ _windows_only = unittest.skipIf(not sys.platform.startswith('win'), _skip_reason) -from .support import TestCase, tag, import_dynamic, temp_directory, has_blas +from numba.tests.support import TestCase, tag, import_dynamic, temp_directory, has_blas base_path = os.path.dirname(os.path.abspath(__file__)) diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index 35251fa9d1a..461264f7aaf 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -4,7 +4,7 @@ from numba import jit from numba import unittest_support as unittest from numba.core.errors import TypingError, NumbaWarning -from .support import TestCase +from numba.tests.support import TestCase class TestSelfRecursion(TestCase): diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index e59e14e7610..0937c4f9adc 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -28,7 +28,7 @@ IRLegalization, NoPythonBackend) from numba import unittest_support as unittest import numpy as np -from .support import skip_parfors_unsupported, needs_blas +from numba.tests.support import skip_parfors_unsupported, needs_blas def test_will_propagate(b, z, w): diff --git a/numba/tests/test_serialize.py b/numba/tests/test_serialize.py index 00c7aaa8be6..2d69daf67b5 100644 --- a/numba/tests/test_serialize.py +++ b/numba/tests/test_serialize.py @@ -7,7 +7,7 @@ from numba import unittest_support as unittest from numba.core.errors import TypingError from numba.targets import registry -from .support import TestCase, tag +from numba.tests.support import TestCase, tag from .serialize_usecases import * diff --git a/numba/tests/test_support.py b/numba/tests/test_support.py index b350e419323..5c872b5b3f7 100644 --- a/numba/tests/test_support.py +++ b/numba/tests/test_support.py @@ -4,7 +4,7 @@ from numba import jit, utils from numba import unittest_support as unittest -from .support import TestCase, forbid_codegen +from numba.tests.support import TestCase, forbid_codegen from .enum_usecases import * DBL_EPSILON = 2**-52 diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 6b4b43340fb..9ba042e4005 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -11,7 +11,7 @@ from numba import prange, njit, unittest_support as unittest from numba.targets import cpu from numba.compiler import compile_isolated, Flags -from .support import TestCase, tag, override_env_config +from numba.tests.support import TestCase, tag, override_env_config needs_svml = unittest.skipUnless(numba.config.USING_SVML, "SVML tests need SVML to be present") diff --git a/numba/tests/test_threadsafety.py b/numba/tests/test_threadsafety.py index fab1f0412d9..b407140e5bd 100644 --- a/numba/tests/test_threadsafety.py +++ b/numba/tests/test_threadsafety.py @@ -11,7 +11,7 @@ from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize -from .support import temp_directory, override_config +from numba.tests.support import temp_directory, override_config def foo(n, v): diff --git a/numba/tests/test_try_except.py b/numba/tests/test_try_except.py index 1e8d184b4cc..492beef9bca 100644 --- a/numba/tests/test_try_except.py +++ b/numba/tests/test_try_except.py @@ -7,7 +7,7 @@ from numba.core.errors import ( UnsupportedError, CompilerError, NumbaPerformanceWarning, TypingError, ) -from .support import ( +from numba.tests.support import ( TestCase, unittest, captured_stdout, skip_tryexcept_unsupported, skip_tryexcept_supported, MemoryLeakMixin, skip_parfors_unsupported, skip_unless_scipy, diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 70aeaf0a056..0bf38245b9d 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -9,7 +9,7 @@ from numba import jitclass, typeof from numba.typed import List, Dict from numba.core.errors import TypingError -from .support import (TestCase, MemoryLeakMixin, override_config, +from numba.tests.support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen, skip_parfors_unsupported) from numba.unsafe.refcount import get_refcount diff --git a/numba/tests/test_typedobjectutils.py b/numba/tests/test_typedobjectutils.py index e504e207be9..2ffd9165f50 100644 --- a/numba/tests/test_typedobjectutils.py +++ b/numba/tests/test_typedobjectutils.py @@ -6,7 +6,7 @@ from numba.core import types -from .support import TestCase +from numba.tests.support import TestCase from numba.typedobjectutils import _sentry_safe_cast diff --git a/numba/tests/test_unicode_names.py b/numba/tests/test_unicode_names.py index 3979f5313a1..7e82adef61e 100644 --- a/numba/tests/test_unicode_names.py +++ b/numba/tests/test_unicode_names.py @@ -2,7 +2,7 @@ from numba import njit, cfunc, cgutils -from .support import TestCase, unittest +from numba.tests.support import TestCase, unittest unicode_name1 = u""" def unicode_name1(ಠ_ರೃ, ಠਊಠ): From ef68fe99413d6441286061e5ed649de49767dc17 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 17:06:42 +0000 Subject: [PATCH 323/595] move byteflow.py --- numba/{ => core}/byteflow.py | 0 numba/interpreter.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => core}/byteflow.py (100%) diff --git a/numba/byteflow.py b/numba/core/byteflow.py similarity index 100% rename from numba/byteflow.py rename to numba/core/byteflow.py diff --git a/numba/interpreter.py b/numba/interpreter.py index 9883cff6a45..7f9839a5e14 100644 --- a/numba/interpreter.py +++ b/numba/interpreter.py @@ -15,7 +15,7 @@ OPERATORS_TO_BUILTINS, get_function_globals ) -from numba.byteflow import Flow, AdaptDFA, AdaptCFA +from numba.core.byteflow import Flow, AdaptDFA, AdaptCFA from numba.unsafe import eh From 185ef175080e454af822db1d05d575818f4f4b39 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 17:07:57 +0000 Subject: [PATCH 324/595] move interpreter.py --- numba/compiler.py | 4 ++-- numba/{ => core}/interpreter.py | 0 numba/tests/test_withlifting.py | 2 +- numba/untyped_passes.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename numba/{ => core}/interpreter.py (100%) diff --git a/numba/compiler.py b/numba/compiler.py index e08801c751b..16681db8031 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -3,8 +3,8 @@ import warnings from numba.tracing import event -from numba import (bytecode, interpreter, postproc, config,) -from numba.core import utils, errors, typing +from numba import bytecode, postproc, config +from numba.core import utils, errors, typing, interpreter from numba.targets import cpu, callconv from numba.parfor import ParforDiagnostics from numba.inline_closurecall import InlineClosureCallPass diff --git a/numba/interpreter.py b/numba/core/interpreter.py similarity index 100% rename from numba/interpreter.py rename to numba/core/interpreter.py diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index f14db4add79..9ab2d4a4893 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -7,7 +7,7 @@ from numba.transforms import find_setupwiths, with_lifting from numba.withcontexts import bypass_context, call_context, objmode_context from numba.bytecode import FunctionIdentity, ByteCode -from numba.interpreter import Interpreter +from numba.core.interpreter import Interpreter from numba.core import typing, errors from numba.targets.registry import cpu_target from numba.targets import cpu diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index d5735e6f8b5..a7beb5f1bf3 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -2,8 +2,7 @@ from copy import deepcopy, copy from .compiler_machinery import FunctionPass, register_pass -from . import (config, bytecode, interpreter, postproc, errors, types, rewrites, - transforms, ir) +from . import config, bytecode, postproc, errors, types, rewrites, transforms, ir from .special import literal_unroll import warnings from .analysis import ( @@ -22,6 +21,7 @@ compile_to_numba_ir, get_definition, find_max_label, rename_labels, ) +import numba.core.interpreter @contextmanager @@ -83,7 +83,7 @@ def run_pass(self, state): """ func_id = state['func_id'] bc = state['bc'] - interp = interpreter.Interpreter(func_id) + interp = numba.core.interpreter.Interpreter(func_id) func_ir = interp.interpret(bc) state["func_ir"] = func_ir return True From 4b416c553c851bb618a3d6d4d9b0df2bdd001dfb Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 17:11:26 +0000 Subject: [PATCH 325/595] move datamodel --- numba/cgutils.py | 5 +++-- numba/{ => core}/datamodel/__init__.py | 0 numba/{ => core}/datamodel/manager.py | 0 numba/{ => core}/datamodel/models.py | 2 +- numba/{ => core}/datamodel/packer.py | 0 numba/{ => core}/datamodel/registry.py | 0 numba/{ => core}/datamodel/testing.py | 2 +- numba/extending.py | 6 +++--- numba/jitclass/base.py | 2 +- numba/roc/target.py | 3 +-- numba/targets/base.py | 3 +-- numba/tests/pdlike_usecase.py | 2 +- numba/tests/test_datamodel.py | 5 ++--- numba/tests/test_generators.py | 2 +- numba/tests/test_ir_inlining.py | 2 +- numba/tests/test_literal_dispatch.py | 2 +- numba/unicode.py | 2 +- 17 files changed, 18 insertions(+), 20 deletions(-) rename numba/{ => core}/datamodel/__init__.py (100%) rename numba/{ => core}/datamodel/manager.py (100%) rename numba/{ => core}/datamodel/models.py (99%) rename numba/{ => core}/datamodel/packer.py (100%) rename numba/{ => core}/datamodel/registry.py (100%) rename numba/{ => core}/datamodel/testing.py (99%) diff --git a/numba/cgutils.py b/numba/cgutils.py index db2021d1b0d..f4b95e2914b 100644 --- a/numba/cgutils.py +++ b/numba/cgutils.py @@ -11,6 +11,7 @@ from numba.core import utils, types from numba import config +import numba.core.datamodel bool_t = ir.IntType(1) @@ -97,10 +98,10 @@ class _StructProxy(object): _fe_type = None def __init__(self, context, builder, value=None, ref=None): - from numba import datamodel # Avoid circular import + from numba.core import datamodel # Avoid circular import self._context = context self._datamodel = self._context.data_model_manager[self._fe_type] - if not isinstance(self._datamodel, datamodel.StructModel): + if not isinstance(self._datamodel, numba.core.datamodel.StructModel): raise TypeError( "Not a structure model: {0}".format(self._datamodel)) self._builder = builder diff --git a/numba/datamodel/__init__.py b/numba/core/datamodel/__init__.py similarity index 100% rename from numba/datamodel/__init__.py rename to numba/core/datamodel/__init__.py diff --git a/numba/datamodel/manager.py b/numba/core/datamodel/manager.py similarity index 100% rename from numba/datamodel/manager.py rename to numba/core/datamodel/manager.py diff --git a/numba/datamodel/models.py b/numba/core/datamodel/models.py similarity index 99% rename from numba/datamodel/models.py rename to numba/core/datamodel/models.py index ec01008d1e6..3bf954e35dc 100644 --- a/numba/datamodel/models.py +++ b/numba/core/datamodel/models.py @@ -3,7 +3,7 @@ from llvmlite import ir from numba import cgutils, numpy_support -from numba.datamodel.registry import register_default +from numba.core.datamodel.registry import register_default from numba.core import types diff --git a/numba/datamodel/packer.py b/numba/core/datamodel/packer.py similarity index 100% rename from numba/datamodel/packer.py rename to numba/core/datamodel/packer.py diff --git a/numba/datamodel/registry.py b/numba/core/datamodel/registry.py similarity index 100% rename from numba/datamodel/registry.py rename to numba/core/datamodel/registry.py diff --git a/numba/datamodel/testing.py b/numba/core/datamodel/testing.py similarity index 99% rename from numba/datamodel/testing.py rename to numba/core/datamodel/testing.py index bf19124b46a..8f5d3484dc5 100644 --- a/numba/datamodel/testing.py +++ b/numba/core/datamodel/testing.py @@ -1,8 +1,8 @@ from llvmlite import ir from llvmlite import binding as ll -from numba import datamodel from numba import unittest_support as unittest +from numba.core import datamodel class DataModelTester(unittest.TestCase): diff --git a/numba/extending.py b/numba/extending.py index 064f2194244..b4e3cacdd55 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -14,7 +14,7 @@ from numba.targets.imputils import ( lower_builtin, lower_getattr, lower_getattr_generic, lower_setattr, lower_setattr_generic, lower_cast) -from numba.datamodel import models, register_default as register_model +from numba.core.datamodel import models, register_default as register_model from numba.pythonapi import box, unbox, reflect, NativeValue from numba._helperlib import _import_cython_function @@ -222,8 +222,8 @@ def make_attribute_wrapper(typeclass, struct_attr, python_attr): The given *typeclass*'s model must be a StructModel subclass. """ from numba.core.typing.templates import AttributeTemplate - from numba.datamodel import default_manager - from numba.datamodel.models import StructModel + from numba.core.datamodel import default_manager + from numba.core.datamodel.models import StructModel from numba.targets.imputils import impl_ret_borrowed from numba import cgutils diff --git a/numba/jitclass/base.py b/numba/jitclass/base.py index 28778e85498..4bae51ab706 100644 --- a/numba/jitclass/base.py +++ b/numba/jitclass/base.py @@ -10,7 +10,7 @@ from numba.targets.registry import cpu_target from numba import njit from numba.core.typing import templates -from numba.datamodel import default_manager, models +from numba.core.datamodel import default_manager, models from numba.targets import imputils from numba import cgutils from numba.jitclass import _box diff --git a/numba/roc/target.py b/numba/roc/target.py index 000c55b0141..b7aa880ea94 100644 --- a/numba/roc/target.py +++ b/numba/roc/target.py @@ -5,9 +5,8 @@ from llvmlite import binding as ll from numba import cgutils -from numba.core import typing, types, utils +from numba.core import typing, types, utils, datamodel from numba.core.utils import cached_property -from numba import datamodel from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv from . import codegen diff --git a/numba/targets/base.py b/numba/targets/base.py index 251ac2655fc..adea10c8dd0 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -12,7 +12,7 @@ from llvmlite.llvmpy.core import Type, Constant, LLVMException import llvmlite.binding as ll -from numba.core import types, utils, typing +from numba.core import types, utils, typing, datamodel from numba import cgutils, funcdesc, debuginfo, config from numba import _dynfunc, _helperlib from numba.compiler_lock import global_compiler_lock @@ -22,7 +22,6 @@ from .imputils import (user_function, user_generator, builtin_registry, impl_ret_borrowed, RegistryLoader) -from numba import datamodel GENERIC_POINTER = Type.pointer(Type.int(8)) PYOBJECT = GENERIC_POINTER diff --git a/numba/tests/pdlike_usecase.py b/numba/tests/pdlike_usecase.py index 76abb1d0248..c91f0ef02e3 100644 --- a/numba/tests/pdlike_usecase.py +++ b/numba/tests/pdlike_usecase.py @@ -6,7 +6,7 @@ from numba.core import types from numba import cgutils -from numba.datamodel import models +from numba.core.datamodel import models from numba.extending import ( typeof_impl, type_callable, register_model, lower_builtin, box, unbox, NativeValue, diff --git a/numba/tests/test_datamodel.py b/numba/tests/test_datamodel.py index bc9515cef04..60278e20815 100644 --- a/numba/tests/test_datamodel.py +++ b/numba/tests/test_datamodel.py @@ -1,9 +1,8 @@ from llvmlite import ir, binding as ll -from numba.core import types +from numba.core import types, datamodel from numba import unittest_support as unittest -from numba import datamodel -from numba.datamodel.testing import test_factory +from numba.core.datamodel.testing import test_factory class TestBool(test_factory()): diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index c73f721478d..77d62363190 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -7,7 +7,7 @@ from numba.core import types from numba.tests.support import TestCase, MemoryLeakMixin from numba import testing -from numba.datamodel.testing import test_factory +from numba.core.datamodel.testing import test_factory enable_pyobj_flags = Flags() diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index 3ae914a0b6d..a622d4c779f 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -19,7 +19,7 @@ NativeValue, register_jitable, ) -from numba.datamodel.models import OpaqueModel +from numba.core.datamodel.models import OpaqueModel from numba.targets.cpu import InlineOptions from numba.compiler import DefaultPassBuilder from numba.typed_passes import DeadCodeElimination, IRLegalization diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index e788f1afea0..1e03a12099c 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -6,7 +6,7 @@ from numba import njit, cgutils from numba.core import types, errors from numba.typing import signature -from numba.datamodel import models +from numba.core.datamodel import models from numba.extending import ( overload, SentryLiteralArgs, overload_method, register_model, intrinsic, ) diff --git a/numba/unicode.py b/numba/unicode.py index 7b361549108..317151cc1e5 100644 --- a/numba/unicode.py +++ b/numba/unicode.py @@ -18,7 +18,7 @@ ) from numba.targets.imputils import (lower_constant, lower_cast, lower_builtin, iternext_impl, impl_ret_new_ref, RefType) -from numba.datamodel import register_default, StructModel +from numba.core.datamodel import register_default, StructModel from numba import cgutils from numba.core import utils, types from numba.pythonapi import ( From afdf52fbc83e429207570c6d76f3cf29af09c72c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 29 Jan 2020 17:12:29 +0000 Subject: [PATCH 326/595] move compiler_lock.py --- numba/ccallback.py | 2 +- numba/compiler_machinery.py | 2 +- numba/{ => core}/compiler_lock.py | 0 numba/cuda/compiler.py | 2 +- numba/dispatcher.py | 2 +- numba/npyufunc/ufuncbuilder.py | 2 +- numba/npyufunc/wrappers.py | 2 +- numba/pycc/cc.py | 2 +- numba/pycc/compiler.py | 2 +- numba/roc/compiler.py | 2 +- numba/runtime/nrt.py | 2 +- numba/targets/base.py | 2 +- numba/targets/codegen.py | 2 +- numba/targets/cpu.py | 2 +- numba/tests/test_cgutils.py | 2 +- numba/tests/test_codegen.py | 2 +- numba/tests/test_compiler_lock.py | 2 +- 17 files changed, 16 insertions(+), 16 deletions(-) rename numba/{ => core}/compiler_lock.py (100%) diff --git a/numba/ccallback.py b/numba/ccallback.py index cf6b32a0469..731ca9f3586 100644 --- a/numba/ccallback.py +++ b/numba/ccallback.py @@ -14,7 +14,7 @@ from numba.targets import registry from numba.core.typing import signature from numba.core.typing.ctypes_utils import to_ctypes -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock class _CFuncCompiler(_FunctionCompiler): diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index 063406d5b07..c744ff87a56 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -2,7 +2,7 @@ from abc import abstractmethod, ABCMeta from collections import namedtuple, OrderedDict import inspect -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from numba.core import errors from numba import config, transforms from numba.core.utils import add_metaclass diff --git a/numba/compiler_lock.py b/numba/core/compiler_lock.py similarity index 100% rename from numba/compiler_lock.py rename to numba/core/compiler_lock.py diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index e313aed60c3..ab27d811040 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -12,7 +12,7 @@ from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate from numba import funcdesc, serialize from numba.core import types, typing, utils -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner from .cudadrv.devices import get_context diff --git a/numba/dispatcher.py b/numba/dispatcher.py index c35e4c14ccd..fe15c18b1b2 100644 --- a/numba/dispatcher.py +++ b/numba/dispatcher.py @@ -13,7 +13,7 @@ from numba import _dispatcher, compiler, config from numba.core import utils, types, errors, typing -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from numba.core.typeconv.rules import default_type_manager from numba import sigutils, serialize from numba.core.typing.templates import fold_arguments diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index ea86529aa7e..9ce87b93591 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -16,7 +16,7 @@ from numba.npyufunc.sigparse import parse_signature from numba.npyufunc.wrappers import build_ufunc_wrapper, build_gufunc_wrapper from numba.caching import FunctionCache, NullCache -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock class UFuncTargetOptions(TargetOptions): diff --git a/numba/npyufunc/wrappers.py b/numba/npyufunc/wrappers.py index 0c9ae3ad18f..8510833bc77 100644 --- a/numba/npyufunc/wrappers.py +++ b/numba/npyufunc/wrappers.py @@ -6,7 +6,7 @@ from numba import cgutils from numba.core import types -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from ..caching import make_library_cache, NullCache diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index b24d9fafe56..56cba248ba1 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -7,7 +7,7 @@ import tempfile from numba import sigutils, typing -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from .compiler import ModuleCompiler, ExportEntry from .platform import Toolchain from numba import cext diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index 06662a87292..5afc0d66edf 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -11,7 +11,7 @@ from numba import cgutils from . import llvm_types as lt from numba.compiler import compile_extra, Flags -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from numba.targets.registry import cpu_target from numba.runtime import nrtdynmod diff --git a/numba/roc/compiler.py b/numba/roc/compiler.py index 02d1491b521..7e903d8a599 100644 --- a/numba/roc/compiler.py +++ b/numba/roc/compiler.py @@ -16,7 +16,7 @@ from .hsadrv import devicearray from numba.core.typing.templates import AbstractTemplate from numba import config -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock @global_compiler_lock def compile_hsa(pyfunc, return_type, args, debug): diff --git a/numba/runtime/nrt.py b/numba/runtime/nrt.py index 72638f5589b..53531789393 100644 --- a/numba/runtime/nrt.py +++ b/numba/runtime/nrt.py @@ -4,7 +4,7 @@ from numba.runtime import nrtdynmod from llvmlite import binding as ll -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from numba.core.typing.typeof import typeof_impl from numba.core import types from numba.runtime import _nrt_python as _nrt diff --git a/numba/targets/base.py b/numba/targets/base.py index adea10c8dd0..f06509cfeca 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -15,7 +15,7 @@ from numba.core import types, utils, typing, datamodel from numba import cgutils, funcdesc, debuginfo, config from numba import _dynfunc, _helperlib -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from numba.pythonapi import PythonAPI from numba.np import arrayobj from . import builtins, imputils diff --git a/numba/targets/codegen.py b/numba/targets/codegen.py index e0e95d351ff..3ab9bcdbcca 100644 --- a/numba/targets/codegen.py +++ b/numba/targets/codegen.py @@ -13,7 +13,7 @@ from numba import config, cgutils from numba.runtime.nrtopt import remove_redundant_nrt_refct from numba.runtime import rtsys -from numba.compiler_lock import require_global_compiler_lock +from numba.core.compiler_lock import require_global_compiler_lock _x86arch = frozenset(['x86', 'i386', 'i486', 'i586', 'i686', 'i786', 'i886', 'i986']) diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index f29b4805092..1e6532aacdb 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -15,7 +15,7 @@ ) from numba.targets.options import TargetOptions from numba.runtime import rtsys -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock import numba.entrypoints from numba.targets import fastmathpass from numba.targets.cpu_options import (ParallelOptions, FastMathOptions, diff --git a/numba/tests/test_cgutils.py b/numba/tests/test_cgutils.py index 868a2d17dc7..d2ae1353b85 100644 --- a/numba/tests/test_cgutils.py +++ b/numba/tests/test_cgutils.py @@ -9,7 +9,7 @@ import numba.unittest_support as unittest from numba import cgutils from numba.core import types, typing -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from numba.targets import cpu from numba.tests.support import TestCase diff --git a/numba/tests/test_codegen.py b/numba/tests/test_codegen.py index 26fec0b7072..161fab27c5d 100644 --- a/numba/tests/test_codegen.py +++ b/numba/tests/test_codegen.py @@ -15,7 +15,7 @@ import numba.unittest_support as unittest from numba.targets.codegen import JITCPUCodegen -from numba.compiler_lock import global_compiler_lock +from numba.core.compiler_lock import global_compiler_lock from numba.tests.support import TestCase diff --git a/numba/tests/test_compiler_lock.py b/numba/tests/test_compiler_lock.py index dbeb09c9207..7e25a8fd66c 100644 --- a/numba/tests/test_compiler_lock.py +++ b/numba/tests/test_compiler_lock.py @@ -1,5 +1,5 @@ import unittest -from numba.compiler_lock import ( +from numba.core.compiler_lock import ( global_compiler_lock, require_global_compiler_lock, ) From 02e198fa99facd994fdd1b96790b01f42e321062 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 11:50:07 +0000 Subject: [PATCH 327/595] fix more imports --- numba/analysis.py | 4 ++-- numba/core/errors.py | 6 ++---- numba/cuda/cudadecl.py | 8 ++++---- numba/cuda/cudadrv/driver.py | 4 ++-- numba/dummyarray.py | 2 +- numba/ir.py | 3 ++- numba/pycc/cc.py | 7 ++++--- numba/pycc/decorators.py | 5 +++-- numba/rewrites/ir_print.py | 5 +++-- numba/rewrites/macros.py | 5 +++-- numba/rewrites/static_binop.py | 5 +++-- numba/rewrites/static_getitem.py | 5 +++-- numba/rewrites/static_raise.py | 5 +++-- numba/roc/codegen.py | 2 +- numba/roc/tests/hsapy/test_math.py | 2 +- numba/tests/test_blackscholes.py | 2 +- numba/tests/test_errorhandling.py | 2 +- numba/tests/test_gdb.py | 3 ++- numba/tests/test_gil.py | 3 ++- numba/tests/test_indexing.py | 4 ++-- numba/tests/test_linalg.py | 3 ++- numba/tests/test_make_function_to_jit_function.py | 3 ++- numba/tests/test_parfors.py | 6 +++--- numba/tests/test_pycc.py | 2 +- numba/tests/test_recursion.py | 4 ++-- numba/tests/test_support.py | 3 ++- numba/transforms.py | 3 ++- 27 files changed, 59 insertions(+), 47 deletions(-) diff --git a/numba/analysis.py b/numba/analysis.py index 210cf1d4c9f..d4e28966e19 100644 --- a/numba/analysis.py +++ b/numba/analysis.py @@ -5,10 +5,10 @@ from functools import reduce from collections import namedtuple, defaultdict -from numba import ir, errors +from numba import ir from numba.core.controlflow import CFGraph from numba import consts, special -from numba.core import types +from numba.core import types, errors # # Analysis related to variable lifetime diff --git a/numba/core/errors.py b/numba/core/errors.py index 8104d035d3b..b40a14de5ec 100644 --- a/numba/core/errors.py +++ b/numba/core/errors.py @@ -11,7 +11,7 @@ import numba import numpy as np from collections import defaultdict -from numba.core.utils import add_metaclass, reraise +from numba.core.utils import add_metaclass, reraise, chain_exception from functools import wraps from abc import abstractmethod @@ -658,11 +658,9 @@ def __init__(self, arg_indices, fold_arguments=None, loc=None): def bind_fold_arguments(self, fold_arguments): """Bind the fold_arguments function """ - from numba import utils - e = ForceLiteralArg(self.requested_args, fold_arguments, loc=self.loc) - return utils.chain_exception(e, self) + return chain_exception(e, self) def combine(self, other): """Returns a new instance by or'ing the requested_args. diff --git a/numba/cuda/cudadecl.py b/numba/cuda/cudadecl.py index 1664da77c9a..0d588047f32 100644 --- a/numba/cuda/cudadecl.py +++ b/numba/cuda/cudadecl.py @@ -1,8 +1,8 @@ from numba.core import types -from numba.typing.npydecl import register_number_classes -from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, - AbstractTemplate, MacroTemplate, - signature, Registry) +from numba.core.typing.npydecl import register_number_classes +from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, + AbstractTemplate, MacroTemplate, + signature, Registry) from numba import cuda diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index 9add85a48a5..5c0bf676ad7 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -28,12 +28,12 @@ from collections import namedtuple, deque from numba import mviewbuf -from numba.core import utils +from numba.core import utils, errors from .error import CudaSupportError, CudaDriverError from .drvapi import API_PROTOTYPES from .drvapi import cu_occupancy_b2d_size from . import enums, drvapi, _extras -from numba import config, serialize, errors +from numba import config, serialize from numba.core.utils import longint as long from numba.cuda.envvars import get_numba_envvar diff --git a/numba/dummyarray.py b/numba/dummyarray.py index 33b3f441b34..1f4a4856ae8 100644 --- a/numba/dummyarray.py +++ b/numba/dummyarray.py @@ -6,7 +6,7 @@ import numpy as np -from . import _helperlib +from numba import _helperlib Extent = namedtuple("Extent", ["begin", "end"]) diff --git a/numba/ir.py b/numba/ir.py index 88b4aeddf1f..63a58dd980d 100644 --- a/numba/ir.py +++ b/numba/ir.py @@ -10,7 +10,8 @@ from types import FunctionType, BuiltinFunctionType from functools import total_ordering -from numba import config, errors +from numba import config +from numba.core import errors from numba.core.utils import (BINOPS_TO_OPERATORS, INPLACE_BINOPS_TO_OPERATORS, UNARY_BUITINS_TO_OPERATORS, OPERATORS_TO_BUILTINS) from numba.core.errors import (NotDefinedError, RedefinedError, diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index 56cba248ba1..a5566d6de77 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -6,10 +6,11 @@ import sys import tempfile -from numba import sigutils, typing +from numba import sigutils +from numba.core import typing from numba.core.compiler_lock import global_compiler_lock -from .compiler import ModuleCompiler, ExportEntry -from .platform import Toolchain +from numba.pycc.compiler import ModuleCompiler, ExportEntry +from numba.pycc.platform import Toolchain from numba import cext diff --git a/numba/pycc/decorators.py b/numba/pycc/decorators.py index 7a9684be240..16e2faea91c 100644 --- a/numba/pycc/decorators.py +++ b/numba/pycc/decorators.py @@ -1,8 +1,9 @@ import re import warnings -from numba import sigutils, typing -from .compiler import ExportEntry +from numba import sigutils +from numba.core import typing +from numba.pycc.compiler import ExportEntry # Registry is okay to be a global because we are using pycc as a standalone # commandline tool. diff --git a/numba/rewrites/ir_print.py b/numba/rewrites/ir_print.py index 6d9fa35062a..1911c86f78a 100644 --- a/numba/rewrites/ir_print.py +++ b/numba/rewrites/ir_print.py @@ -1,5 +1,6 @@ -from numba import ir, errors -from . import register_rewrite, Rewrite +from numba import ir +from numba.core import errors +from numba.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/rewrites/macros.py b/numba/rewrites/macros.py index 24d7f0e444f..1563d360a22 100644 --- a/numba/rewrites/macros.py +++ b/numba/rewrites/macros.py @@ -1,5 +1,6 @@ -from numba import ir, errors -from . import register_rewrite, Rewrite +from numba import ir +from numba.core import errors +from numba.rewrites import register_rewrite, Rewrite class Macro(object): diff --git a/numba/rewrites/static_binop.py b/numba/rewrites/static_binop.py index 330115c2336..2e493f30d63 100644 --- a/numba/rewrites/static_binop.py +++ b/numba/rewrites/static_binop.py @@ -1,5 +1,6 @@ -from numba import ir, errors -from . import register_rewrite, Rewrite +from numba import ir +from numba.core import errors +from numba.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/rewrites/static_getitem.py b/numba/rewrites/static_getitem.py index 6a8eefc6938..a66e9b9a1cc 100644 --- a/numba/rewrites/static_getitem.py +++ b/numba/rewrites/static_getitem.py @@ -1,5 +1,6 @@ -from numba import ir, errors -from . import register_rewrite, Rewrite +from numba import ir +from numba.core import errors +from numba.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/rewrites/static_raise.py b/numba/rewrites/static_raise.py index 63384ea7d8f..72e1f9ac5b8 100644 --- a/numba/rewrites/static_raise.py +++ b/numba/rewrites/static_raise.py @@ -1,5 +1,6 @@ -from numba import ir, errors -from . import register_rewrite, Rewrite +from numba import ir +from numba.core import errors +from numba.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/roc/codegen.py b/numba/roc/codegen.py index 8102378d5fc..4de0625a948 100644 --- a/numba/roc/codegen.py +++ b/numba/roc/codegen.py @@ -1,6 +1,6 @@ from llvmlite import binding as ll from llvmlite.llvmpy import core as lc -from numba import utils +from numba.core import utils from numba.targets.codegen import BaseCPUCodegen, CodeLibrary from .hlc import DATALAYOUT, TRIPLE, hlc diff --git a/numba/roc/tests/hsapy/test_math.py b/numba/roc/tests/hsapy/test_math.py index 0e09fcf5dc8..a30c59f9d08 100644 --- a/numba/roc/tests/hsapy/test_math.py +++ b/numba/roc/tests/hsapy/test_math.py @@ -3,7 +3,7 @@ import numba.unittest_support as unittest from numba import roc -from numba import utils +from numba.core import utils class TestMath(unittest.TestCase): diff --git a/numba/tests/test_blackscholes.py b/numba/tests/test_blackscholes.py index d6df9f02b92..88d9826f233 100644 --- a/numba/tests/test_blackscholes.py +++ b/numba/tests/test_blackscholes.py @@ -5,7 +5,7 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, compile_extra, Flags from numba.core import types, typing -from numb.support import TestCase +from numba.tests.support import TestCase RISKFREE = 0.02 diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index 1154cae9e03..2751f158ba9 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -4,7 +4,7 @@ from numba import jit, njit, typed, int64 from numba import unittest_support as unittest -from numba import errors, utils +from numba.core import errors, utils import numpy as np diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index cf213168d76..a008b319b73 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -8,7 +8,8 @@ import threading from itertools import permutations -from numba import njit, gdb, gdb_init, gdb_breakpoint, prange, errors +from numba import njit, gdb, gdb_init, gdb_breakpoint, prange +from numba.core import errors from numba import jit from numba import unittest_support as unittest from numba.targets.gdb_hook import _confirm_gdb diff --git a/numba/tests/test_gil.py b/numba/tests/test_gil.py index 54530c70a6e..f20c54015af 100644 --- a/numba/tests/test_gil.py +++ b/numba/tests/test_gil.py @@ -9,7 +9,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import errors, jit +from numba import jit +from numba.core import errors from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index 116ab314443..d0d51c634c9 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -5,8 +5,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import utils, njit, typeof -from numba.core import types, errors +from numba import njit, typeof +from numba.core import utils, types, errors from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index 052e40752bb..7b2fd8145d5 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -9,7 +9,8 @@ import numpy as np from numba import unittest_support as unittest -from numba import jit, errors +from numba import jit +from numba.core import errors from numba.tests.support import TestCase, tag, needs_lapack, needs_blas, _is_armv7l from .matmul_usecase import matmul_usecase diff --git a/numba/tests/test_make_function_to_jit_function.py b/numba/tests/test_make_function_to_jit_function.py index 362e16431c2..ce31d58b109 100644 --- a/numba/tests/test_make_function_to_jit_function.py +++ b/numba/tests/test_make_function_to_jit_function.py @@ -1,4 +1,5 @@ -from numba import njit, errors +from numba import njit +from numba.core import errors from numba.extending import overload import numpy as np diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 9aca4e92ccb..dcc1b4f6b64 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -20,10 +20,10 @@ import numba from numba import unittest_support as unittest -from numba import njit, prange, stencil, inline_closurecall, utils -from numba import compiler, typing, errors, typed_passes +from numba import njit, prange, stencil, inline_closurecall +from numba import compiler, typed_passes from numba.targets import cpu -from numba.core import types +from numba.core import types, utils, typing, errors from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index 59b4db72f09..c51626182a5 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -17,7 +17,7 @@ import llvmlite.binding as ll from numba import unittest_support as unittest -from numba import utils +from numba.core import utils from numba.pycc import main from numba.pycc.decorators import clear_export_registry from numba.pycc.platform import find_shared_ending, find_pyext_ending diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index 461264f7aaf..be47504425c 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -12,7 +12,7 @@ class TestSelfRecursion(TestCase): def setUp(self): # Avoid importing this module at toplevel, as it triggers compilation # and can therefore fail - from . import recursion_usecases + from numba.tests import recursion_usecases self.mod = recursion_usecases def check_fib(self, cfunc): @@ -64,7 +64,7 @@ def test_growing_return_tuple(self): class TestMutualRecursion(TestCase): def setUp(self): - from . import recursion_usecases + from numba.tests import recursion_usecases self.mod = recursion_usecases def test_mutual_1(self): diff --git a/numba/tests/test_support.py b/numba/tests/test_support.py index 5c872b5b3f7..94c165054cb 100644 --- a/numba/tests/test_support.py +++ b/numba/tests/test_support.py @@ -2,7 +2,8 @@ import numpy as np -from numba import jit, utils +from numba import jit +from numba.core import utils from numba import unittest_support as unittest from numba.tests.support import TestCase, forbid_codegen from .enum_usecases import * diff --git a/numba/transforms.py b/numba/transforms.py index b1c5c3c65b5..6a835ce48f5 100644 --- a/numba/transforms.py +++ b/numba/transforms.py @@ -7,7 +7,8 @@ import logging from numba.analysis import compute_cfg_from_blocks, find_top_level_loops -from numba import ir, errors, ir_utils +from numba import ir, ir_utils +from numba.core import errors from numba.analysis import compute_use_defs From bb94f84f7ca6cf0bc7d77f0e807c6e12d1288de3 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 12:21:07 +0000 Subject: [PATCH 328/595] fix more imports 2 --- numba/numpy_support.py | 2 +- numba/parfor.py | 2 +- numba/roc/hsadecl.py | 6 +++--- numba/roc/mathdecl.py | 4 ++-- numba/tests/test_array_analysis.py | 5 ++--- numba/tests/test_copy_propagate.py | 4 ++-- numba/tests/test_ctypes.py | 2 +- numba/tests/test_dicts.py | 2 +- numba/tests/test_extending.py | 2 +- numba/tests/test_literal_dispatch.py | 2 +- numba/tests/test_np_functions.py | 2 +- numba/tests/test_nrt.py | 2 +- numba/tests/test_remove_dead.py | 4 ++-- numba/tests/test_types.py | 6 +++--- numba/tests/test_ufuncs.py | 2 +- numba/unsafe/nrt.py | 2 +- 16 files changed, 24 insertions(+), 25 deletions(-) diff --git a/numba/numpy_support.py b/numba/numpy_support.py index 2563a89ab65..4e58e951799 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -484,7 +484,7 @@ def carray(ptr, shape, dtype=None): given *shape*, in C order. If *dtype* is given, it is used as the array's dtype, otherwise the array's dtype is inferred from *ptr*'s type. """ - from .typing.ctypes_utils import from_ctypes + from numba.core.typing.ctypes_utils import from_ctypes try: # Use ctypes parameter protocol if available diff --git a/numba/parfor.py b/numba/parfor.py index 97dbfd87fff..c8c915e0dd6 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -1463,7 +1463,7 @@ def replace_func(): break def find_template(op): - for ft in numba.typing.templates.builtin_registry.functions: + for ft in numba.core.typing.templates.builtin_registry.functions: if ft.key == op: return ft diff --git a/numba/roc/hsadecl.py b/numba/roc/hsadecl.py index a51f56537ff..464eb185fa8 100644 --- a/numba/roc/hsadecl.py +++ b/numba/roc/hsadecl.py @@ -1,7 +1,7 @@ from numba.core import types -from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, - AbstractTemplate, - MacroTemplate, signature, Registry) +from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, + AbstractTemplate, + MacroTemplate, signature, Registry) from numba import roc registry = Registry() diff --git a/numba/roc/mathdecl.py b/numba/roc/mathdecl.py index 6b541b04edc..ed89f261c32 100644 --- a/numba/roc/mathdecl.py +++ b/numba/roc/mathdecl.py @@ -1,7 +1,7 @@ import math from numba.core import types, utils -from numba.typing.templates import (AttributeTemplate, ConcreteTemplate, - signature, Registry) +from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, + signature, Registry) registry = Registry() builtin_attr = registry.register_attr diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index a6296b28705..879a3449738 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -6,9 +6,8 @@ from io import StringIO from numba import unittest_support as unittest -from numba import (njit, typeof, typing, typeof, ir, bytecode, jitclass, - prange, postproc) -from numba.core import types +from numba import njit, typeof, ir, bytecode, jitclass, prange, postproc +from numba.core import types, typing from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 5037326fb65..85aeee1738b 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -3,9 +3,9 @@ # SPDX-License-Identifier: BSD-2-Clause # -from numba import compiler, typing +from numba import compiler from numba.targets import cpu -from numba.core import types +from numba.core import types, typing from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index f3964bc2e11..461f7d6126a 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -9,7 +9,7 @@ from numba.compiler import compile_isolated from numba import jit from numba.core import types, errors -from numba.typing import ctypes_utils +from numba.core.typing import ctypes_utils from numba.tests.support import MemoryLeakMixin, tag, TestCase from numba.tests.ctypes_usecases import * diff --git a/numba/tests/test_dicts.py b/numba/tests/test_dicts.py index adc626844d1..814090b3b5a 100644 --- a/numba/tests/test_dicts.py +++ b/numba/tests/test_dicts.py @@ -39,7 +39,7 @@ def foo(): def test_unsupported_dict_usage(self): # Test dict(dict()) - from numba.typing.dictdecl import _message_dict_support + from numba.core.typing.dictdecl import _message_dict_support @njit def foo(): diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 04b52c5d7dd..b6a9235c5bd 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -30,7 +30,7 @@ register_jitable, get_cython_function_address ) -from numba.typing.templates import ( +from numba.core.typing.templates import ( ConcreteTemplate, signature, infer, infer_global, AbstractTemplate) # Pandas-like API implementation diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index 1e03a12099c..589ef33248a 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -5,7 +5,7 @@ from numba.tests.support import TestCase from numba import njit, cgutils from numba.core import types, errors -from numba.typing import signature +from numba.core.typing import signature from numba.core.datamodel import models from numba.extending import ( overload, SentryLiteralArgs, overload_method, register_model, intrinsic, diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 1fb93e469f9..77570d08869 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -14,7 +14,7 @@ from numba.numpy_support import numpy_version from numba.core.errors import TypingError from numba.config import IS_WIN32, IS_32BITS -from numba.utils import pysignature +from numba.core.utils import pysignature from numba.targets.arraymath import cross2d from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, needs_blas) diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 226a9dcce5a..be2d90e3442 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -17,7 +17,7 @@ nrt, ) from numba.extending import intrinsic, include_path -from numba.typing import signature +from numba.core.typing import signature from numba.targets.imputils import impl_ret_untracked from llvmlite import ir import llvmlite.binding as llvm diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 0937c4f9adc..f2bb7985d97 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -4,10 +4,10 @@ # import numba -from numba import compiler, typing +from numba import compiler from numba.compiler import compile_isolated, Flags from numba.targets import cpu -from numba.core import types +from numba.core import types, typing from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 818850831fb..bb348b28ed7 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -24,7 +24,7 @@ from numba import sigutils from numba.core import types, typing, errors from numba.core.types.abstract import _typecache -from numba.typing.templates import make_overload_template +from numba.core.typing.templates import make_overload_template from numba import jit, njit, numpy_support, typeof from numba.extending import (overload, register_model, models, unbox, NativeValue, typeof_impl) @@ -500,8 +500,8 @@ def test_generator(self): # call templates are not picklable @unittest.expectedFailure def test_external_function_pointers(self): - from numba.typing import ctypes_utils - from .ctypes_usecases import c_sin, c_cos + from numba.core.typing import ctypes_utils + from numba.tests.ctypes_usecases import c_sin, c_cos for fnptr in (c_sin, c_cos): ty = ctypes_utils.make_function_type(fnptr) self.assertIsInstance(ty, types.ExternalFunctionPointer) diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index b90962fa623..d9129aca0b6 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -16,7 +16,7 @@ from numba import jit, vectorize from numba.core.errors import LoweringError, TypingError from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin, tag -from numba.typing.npydecl import supported_ufuncs, all_ufuncs +from numba.core.typing.npydecl import supported_ufuncs, all_ufuncs is32bits = tuple.__itemsize__ == 4 iswindows = sys.platform.startswith('win32') diff --git a/numba/unsafe/nrt.py b/numba/unsafe/nrt.py index 1dc2a72cd63..dfc1638a84c 100644 --- a/numba/unsafe/nrt.py +++ b/numba/unsafe/nrt.py @@ -3,7 +3,7 @@ """ from numba.core import types -from numba.typing import signature +from numba.core.typing import signature from numba.extending import intrinsic From 69356131560842781326b75055fc18b7721988a3 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 13:03:29 +0000 Subject: [PATCH 329/595] fix more imports 3 --- numba/core/typeconv/typeconv.py | 8 ++++---- numba/core/types/abstract.py | 2 +- numba/core/types/functions.py | 9 +++++---- numba/core/types/iterators.py | 4 ++-- numba/core/types/npytypes.py | 4 ++-- numba/core/typing/context.py | 6 +++--- numba/core/typing/ctypes_utils.py | 2 +- numba/core/typing/listdecl.py | 4 ++-- numba/core/typing/setdecl.py | 4 ++-- numba/core/typing/typeof.py | 4 ++-- numba/cuda/cudadrv/devicearray.py | 4 ++-- numba/cuda/cudadrv/driver.py | 2 +- numba/cuda/cudadrv/drvapi.py | 2 +- numba/cuda/cudadrv/ndarray.py | 2 +- numba/cuda/cudaimpl.py | 2 +- numba/cuda/device_init.py | 2 +- numba/cuda/printimpl.py | 2 +- numba/cuda/simulator/__init__.py | 2 +- numba/cuda/simulator/cudadrv/__init__.py | 2 +- numba/cuda/target.py | 2 +- numba/cuda/vectorizers.py | 2 +- numba/decorators.py | 4 ++-- numba/generators.py | 3 ++- numba/ir.py | 2 +- numba/jitclass/__init__.py | 2 +- numba/jitclass/boxing.py | 2 +- numba/lowering.py | 2 +- numba/npyufunc/__init__.py | 2 +- numba/npyufunc/decorators.py | 2 +- numba/npyufunc/parallel.py | 6 +++--- numba/pycc/__init__.py | 2 +- numba/pycc/compiler.py | 2 +- numba/rewrites/__init__.py | 3 ++- numba/roc/compiler.py | 2 +- numba/roc/hlc/__init__.py | 2 +- numba/roc/hlc/hlc.py | 2 +- numba/roc/hsadrv/devicearray.py | 2 +- numba/roc/hsadrv/driver.py | 2 +- numba/roc/hsadrv/drvapi.py | 2 +- numba/roc/hsaimpl.py | 8 ++++---- numba/roc/target.py | 2 +- numba/roc/tests/hsapy/test_large_code.py | 2 +- numba/serialize.py | 2 +- numba/targets/base.py | 10 +++++----- numba/targets/boxing.py | 7 ++++--- numba/targets/cmathimpl.py | 2 +- numba/targets/cpu.py | 4 ++-- numba/targets/imputils.py | 2 +- numba/targets/numbers.py | 2 +- numba/targets/ufunc_db.py | 4 ++-- numba/testing/__main__.py | 2 +- numba/tests/test_cfunc.py | 2 +- numba/tests/test_object_mode.py | 2 +- numba/tests/test_pycc.py | 2 +- numba/tests/test_slices.py | 2 +- numba/tests/test_sort.py | 4 ++-- numba/tests/test_typeof.py | 2 +- numba/tests/test_unpack_sequence.py | 2 +- numba/tracing.py | 2 +- numba/unittest_support.py | 2 +- numba/untyped_passes.py | 3 ++- 61 files changed, 95 insertions(+), 90 deletions(-) diff --git a/numba/core/typeconv/typeconv.py b/numba/core/typeconv/typeconv.py index 57e425cedc5..6f05e276a7f 100644 --- a/numba/core/typeconv/typeconv.py +++ b/numba/core/typeconv/typeconv.py @@ -1,9 +1,9 @@ try: # This is usually the the first C extension import performed when importing # Numba, if it fails to import, provide some feedback - from . import _typeconv + from numba.core.typeconv import _typeconv except ImportError as e: - from ..errors import feedback_details as reportme + from numba.core.errors import feedback_details as reportme import sys url = "http://numba.pydata.org/numba-doc/latest/developer/contributing.html" dashes = '-' * 80 @@ -16,8 +16,8 @@ "sys.executable: %s\n") raise ImportError(msg % (url, reportme, str(e), sys.executable)) -from . import castgraph, Conversion -from .. import types +from numba.core.typeconv import castgraph, Conversion +from numba.core import types class TypeManager(object): diff --git a/numba/core/types/abstract.py b/numba/core/types/abstract.py index 3c19d908e71..0dc3d9c4d55 100644 --- a/numba/core/types/abstract.py +++ b/numba/core/types/abstract.py @@ -182,7 +182,7 @@ def __getitem__(self, args): """ Return an array of this type. """ - from . import Array + from numba.core.types import Array ndim, layout = self._determine_array_spec(args) return Array(dtype=self, ndim=ndim, layout=layout) diff --git a/numba/core/types/functions.py b/numba/core/types/functions.py index 35e67964a04..94e556ee480 100644 --- a/numba/core/types/functions.py +++ b/numba/core/types/functions.py @@ -312,9 +312,10 @@ class ExternalFunctionPointer(BaseFunction): and returning the raw pointer value as an int. """ def __init__(self, sig, get_pointer, cconv=None): - from ..typing.templates import (AbstractTemplate, make_concrete_template, - signature) - from . import ffi_forced_object + from numba.core.typing.templates import (AbstractTemplate, + make_concrete_template, + signature) + from numba.core.types import ffi_forced_object if sig.return_type == ffi_forced_object: raise TypeError("Cannot return a pyobject from a external function") self.sig = sig @@ -352,7 +353,7 @@ class ExternalFunction(Function): """ def __init__(self, symbol, sig): - from .. import typing + from numba.core import typing self.symbol = symbol self.sig = sig template = typing.make_concrete_template(symbol, symbol, [sig]) diff --git a/numba/core/types/iterators.py b/numba/core/types/iterators.py index 9023627fb2c..4279ce7c6ab 100644 --- a/numba/core/types/iterators.py +++ b/numba/core/types/iterators.py @@ -58,7 +58,7 @@ class EnumerateType(SimpleIteratorType): """ def __init__(self, iterable_type): - from . import Tuple, intp + from numba.core.types import Tuple, intp self.source_type = iterable_type.iterator_type yield_type = Tuple([intp, self.source_type.yield_type]) name = 'enumerate(%s)' % (self.source_type) @@ -76,7 +76,7 @@ class ZipType(SimpleIteratorType): """ def __init__(self, iterable_types): - from . import Tuple + from numba.core.types import Tuple self.source_types = tuple(tp.iterator_type for tp in iterable_types) yield_type = Tuple([tp.yield_type for tp in self.source_types]) name = 'zip(%s)' % ', '.join(str(tp) for tp in self.source_types) diff --git a/numba/core/types/npytypes.py b/numba/core/types/npytypes.py index 637ff472ad9..61cc1694982 100644 --- a/numba/core/types/npytypes.py +++ b/numba/core/types/npytypes.py @@ -4,8 +4,8 @@ from .abstract import DTypeSpec, IteratorType, MutableSequence, Number, Type from .common import Buffer, Opaque, SimpleIteratorType -from ..typeconv import Conversion -from .. import utils +from numba.core.typeconv import Conversion +from numba.core import utils from .misc import UnicodeType from .containers import Bytes diff --git a/numba/core/typing/context.py b/numba/core/typing/context.py index 98f06bbd817..069d71dabe3 100644 --- a/numba/core/typing/context.py +++ b/numba/core/typing/context.py @@ -9,7 +9,7 @@ import numba from numba.core import types, errors from numba.core.typeconv import Conversion, rules -from . import templates +from numba.core.typing import templates from .typeof import typeof, Purpose from numba.core import utils @@ -394,8 +394,8 @@ def _get_global_type(self, gv): def _load_builtins(self): # Initialize declarations - from . import builtins, arraydecl, npdatetime # noqa: F401 - from . import ctypes_utils, bufproto # noqa: F401 + from numba.core.typing import builtins, arraydecl, npdatetime # noqa: F401 + from numba.core.typing import ctypes_utils, bufproto # noqa: F401 from numba.unsafe import eh # noqa: F401 self.install_registry(templates.builtin_registry) diff --git a/numba/core/typing/ctypes_utils.py b/numba/core/typing/ctypes_utils.py index 4622e02622e..91d194f3a7d 100644 --- a/numba/core/typing/ctypes_utils.py +++ b/numba/core/typing/ctypes_utils.py @@ -7,7 +7,7 @@ import sys from numba.core import types -from . import templates +from numba.core.typing import templates from .typeof import typeof_impl diff --git a/numba/core/typing/listdecl.py b/numba/core/typing/listdecl.py index ed2db02090c..cf4440567e8 100644 --- a/numba/core/typing/listdecl.py +++ b/numba/core/typing/listdecl.py @@ -1,10 +1,10 @@ import operator -from .. import types +from numba.core import types from .templates import (ConcreteTemplate, AbstractTemplate, AttributeTemplate, CallableTemplate, Registry, signature, bound_function, make_callable_template) # Ensure list is typed as a collection as well -from . import collections +from numba.core.typing import collections registry = Registry() diff --git a/numba/core/typing/setdecl.py b/numba/core/typing/setdecl.py index 7889093d957..6241ac0e145 100644 --- a/numba/core/typing/setdecl.py +++ b/numba/core/typing/setdecl.py @@ -1,11 +1,11 @@ import operator -from .. import types +from numba.core import types from .templates import (ConcreteTemplate, AbstractTemplate, AttributeTemplate, CallableTemplate, Registry, signature, bound_function, make_callable_template) # Ensure set is typed as a collection as well -from . import collections +from numba.core.typing import collections registry = Registry() diff --git a/numba/core/typing/typeof.py b/numba/core/typing/typeof.py index 575f3962076..6b92bb2dfc1 100644 --- a/numba/core/typing/typeof.py +++ b/numba/core/typing/typeof.py @@ -45,7 +45,7 @@ def typeof_impl(val, c): # cffi is handled here as it does not expose a public base class # for exported functions or CompiledFFI instances. - from . import cffi_utils + from numba.core.typing import cffi_utils if cffi_utils.SUPPORTED: if cffi_utils.is_cffi_func(val): return cffi_utils.make_function_type(val) @@ -56,7 +56,7 @@ def typeof_impl(val, c): def _typeof_buffer(val, c): - from . import bufproto + from numba.core.typing import bufproto try: m = memoryview(val) except TypeError: diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index d0639f30aae..0744d046211 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -14,8 +14,8 @@ import numpy as np import numba -from . import driver as _driver -from . import devices +from numba.cuda.cudadrv import driver as _driver +from numba.cuda.cudadrv import devices from numba import dummyarray, numpy_support from numba.core import types from numba.unsafe.ndarray import to_fixed_tuple diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index 5c0bf676ad7..56df70556df 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -32,7 +32,7 @@ from .error import CudaSupportError, CudaDriverError from .drvapi import API_PROTOTYPES from .drvapi import cu_occupancy_b2d_size -from . import enums, drvapi, _extras +from numba.cuda.cudadrv import enums, drvapi, _extras from numba import config, serialize from numba.core.utils import longint as long from numba.cuda.envvars import get_numba_envvar diff --git a/numba/cuda/cudadrv/drvapi.py b/numba/cuda/cudadrv/drvapi.py index e48ff5e7ae4..13e0efe34fa 100644 --- a/numba/cuda/cudadrv/drvapi.py +++ b/numba/cuda/cudadrv/drvapi.py @@ -1,6 +1,6 @@ from ctypes import * -from . import _extras +from numba.cuda.cudadrv import _extras cu_device = c_int cu_device_attribute = c_int # enum diff --git a/numba/cuda/cudadrv/ndarray.py b/numba/cuda/cudadrv/ndarray.py index 5a9f77aaca5..63964e57ceb 100644 --- a/numba/cuda/cudadrv/ndarray.py +++ b/numba/cuda/cudadrv/ndarray.py @@ -1,4 +1,4 @@ -from . import devices, driver +from numba.cuda.cudadrv import devices, driver from numba.targets.registry import cpu_target diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index 32e973aaf3d..cd5de9dc58c 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -10,7 +10,7 @@ from numba import cgutils from numba.core import types from .cudadrv import nvvm -from . import nvvmutils, stubs +from numba.cuda import nvvmutils, stubs registry = Registry() lower = registry.lower diff --git a/numba/cuda/device_init.py b/numba/cuda/device_init.py index 9a955cf1310..c38338eaee2 100644 --- a/numba/cuda/device_init.py +++ b/numba/cuda/device_init.py @@ -8,7 +8,7 @@ threadfence, selp, popc, brev, clz, ffs, fma) from .cudadrv.error import CudaSupportError from .cudadrv import nvvm -from . import initialize +from numba.cuda import initialize from .errors import KernelRuntimeError from .decorators import jit, autojit, declare_device diff --git a/numba/cuda/printimpl.py b/numba/cuda/printimpl.py index f64c6335cd8..6695612695a 100644 --- a/numba/cuda/printimpl.py +++ b/numba/cuda/printimpl.py @@ -5,7 +5,7 @@ from numba import cgutils from numba.core import types, typing from numba.targets.imputils import Registry -from . import nvvmutils +from numba.cuda import nvvmutils registry = Registry() lower = registry.lower diff --git a/numba/cuda/simulator/__init__.py b/numba/cuda/simulator/__init__.py index ed6511b3d7e..daf2b8085ee 100644 --- a/numba/cuda/simulator/__init__.py +++ b/numba/cuda/simulator/__init__.py @@ -13,7 +13,7 @@ from numba import config if config.ENABLE_CUDASIM: import sys - from . import cudadrv + from numba.cuda.simulator import cudadrv sys.modules['numba.cuda.cudadrv'] = cudadrv sys.modules['numba.cuda.cudadrv.devicearray'] = cudadrv.devicearray sys.modules['numba.cuda.cudadrv.devices'] = cudadrv.devices diff --git a/numba/cuda/simulator/cudadrv/__init__.py b/numba/cuda/simulator/cudadrv/__init__.py index ee3f3c3bf90..5663500803e 100644 --- a/numba/cuda/simulator/cudadrv/__init__.py +++ b/numba/cuda/simulator/cudadrv/__init__.py @@ -1 +1 @@ -from . import devicearray, devices, driver, drvapi, nvvm +from numba.cuda.simulator.cudadrv import devicearray, devices, driver, drvapi, nvvm diff --git a/numba/cuda/target.py b/numba/cuda/target.py index a54e47d32ee..c801f247f1a 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -14,7 +14,7 @@ from numba import itanium_mangler from .cudadrv import nvvm -from . import codegen, nvvmutils +from numba.cuda import codegen, nvvmutils from .decorators import jitdevice diff --git a/numba/cuda/vectorizers.py b/numba/cuda/vectorizers.py index cbbf8183426..c808e3cd6ab 100644 --- a/numba/cuda/vectorizers.py +++ b/numba/cuda/vectorizers.py @@ -1,6 +1,6 @@ from numba import cuda from numba.npyufunc import deviceufunc -from . import dispatcher +from numba.cuda import dispatcher vectorizer_stager_source = ''' def __vectorized_{name}({args}, __out__): diff --git a/numba/decorators.py b/numba/decorators.py index 7553432f955..191ec51d377 100644 --- a/numba/decorators.py +++ b/numba/decorators.py @@ -181,7 +181,7 @@ def _jit(sigs, locals, target, cache, targetoptions, **dispatcher_args): def wrapper(func): if config.ENABLE_CUDASIM and target == 'cuda': - from . import cuda + from numba import cuda return cuda.jit(func) if config.DISABLE_JIT and not target == 'npyufunc': return func @@ -193,7 +193,7 @@ def wrapper(func): if sigs is not None: # Register the Dispatcher to the type inference mechanism, # even though the decorator hasn't returned yet. - from . import typeinfer + from numba import typeinfer with typeinfer.register_dispatcher(disp): for sig in sigs: disp.compile(sig) diff --git a/numba/generators.py b/numba/generators.py index ae19dbb6297..079f373376b 100644 --- a/numba/generators.py +++ b/numba/generators.py @@ -4,7 +4,8 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from . import cgutils, types, config +from numba import cgutils, config +from numba.core import types from .funcdesc import FunctionDescriptor diff --git a/numba/ir.py b/numba/ir.py index 63a58dd980d..8bfd141e492 100644 --- a/numba/ir.py +++ b/numba/ir.py @@ -1337,7 +1337,7 @@ def get_pad(ablock, l): return '\n'.join(msg) def _reset_analysis_variables(self): - from . import consts + from numba import consts self._consts = consts.ConstantInference(self) diff --git a/numba/jitclass/__init__.py b/numba/jitclass/__init__.py index e92e657fdd4..cf098e7689a 100644 --- a/numba/jitclass/__init__.py +++ b/numba/jitclass/__init__.py @@ -1,2 +1,2 @@ from .decorators import jitclass -from . import boxing # Has import-time side effect +from numba.jitclass import boxing # Has import-time side effect diff --git a/numba/jitclass/boxing.py b/numba/jitclass/boxing.py index 6d3116fbde4..8bece162561 100644 --- a/numba/jitclass/boxing.py +++ b/numba/jitclass/boxing.py @@ -11,7 +11,7 @@ from numba.core import types from numba.pythonapi import box, unbox, NativeValue from numba import njit -from . import _box +from numba.jitclass import _box _getter_code_template = """ diff --git a/numba/lowering.py b/numba/lowering.py index fd59a963772..c7a9c4c0d8a 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -12,7 +12,7 @@ LiteralTypingError) from .targets import removerefctpass from .funcdesc import default_mangler -from . import debuginfo +from numba import debuginfo class Environment(_dynfunc.Environment): diff --git a/numba/npyufunc/__init__.py b/numba/npyufunc/__init__.py index 2485895a13c..ff2e5cd43d5 100644 --- a/numba/npyufunc/__init__.py +++ b/numba/npyufunc/__init__.py @@ -2,7 +2,7 @@ from .decorators import Vectorize, GUVectorize, vectorize, guvectorize from ._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One -from . import _internal, array_exprs, parfor +from numba.npyufunc import _internal, array_exprs, parfor from .parallel import threading_layer if hasattr(_internal, 'PyUFunc_ReorderableNone'): PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone diff --git a/numba/npyufunc/decorators.py b/numba/npyufunc/decorators.py index a73fda4aef5..e6a783c1630 100644 --- a/numba/npyufunc/decorators.py +++ b/numba/npyufunc/decorators.py @@ -1,6 +1,6 @@ import inspect -from . import _internal, dufunc +from numba.npyufunc import _internal, dufunc from .ufuncbuilder import GUFuncBuilder from .parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 6d61034b955..5da51219764 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -330,18 +330,18 @@ def select_known_backend(backend): lib = None if backend.startswith("tbb"): try: - from . import tbbpool as lib + from numba.npyufunc import tbbpool as lib except ImportError: pass elif backend.startswith("omp"): # TODO: Check that if MKL is present that it is a version # that understands GNU OMP might be present try: - from . import omppool as lib + from numba.npyufunc import omppool as lib except ImportError: pass elif backend.startswith("workqueue"): - from . import workqueue as lib + from numba.npyufunc import workqueue as lib else: msg = "Unknown value specified for threading layer: %s" raise ValueError(msg % backend) diff --git a/numba/pycc/__init__.py b/numba/pycc/__init__.py index 8c8c24c4bde..bda809ad180 100644 --- a/numba/pycc/__init__.py +++ b/numba/pycc/__init__.py @@ -28,7 +28,7 @@ def main(args=None): from .compiler import ModuleCompiler from .platform import Toolchain, find_shared_ending, find_pyext_ending - from . import decorators + from numba.pycc import decorators parser = argparse.ArgumentParser( description="DEPRECATED - Compile Python modules to a single shared library") diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index 5afc0d66edf..a175447b7f1 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -9,7 +9,7 @@ import llvmlite.llvmpy.core as lc from numba import cgutils -from . import llvm_types as lt +from numba.pycc import llvm_types as lt from numba.compiler import compile_extra, Flags from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/rewrites/__init__.py b/numba/rewrites/__init__.py index 84495b13e47..8c06cd4705e 100644 --- a/numba/rewrites/__init__.py +++ b/numba/rewrites/__init__.py @@ -5,4 +5,5 @@ from .registry import register_rewrite, rewrite_registry, Rewrite # Register various built-in rewrite passes -from . import static_getitem, static_raise, static_binop, ir_print, macros +from numba.rewrites import (static_getitem, static_raise, static_binop, + ir_print, macros) diff --git a/numba/roc/compiler.py b/numba/roc/compiler.py index 7e903d8a599..759b078687a 100644 --- a/numba/roc/compiler.py +++ b/numba/roc/compiler.py @@ -11,7 +11,7 @@ from .hlc import hlc from .hsadrv import devices, driver, enums, drvapi from .hsadrv.error import HsaKernelLaunchError -from . import gcn_occupancy +from numba.roc import gcn_occupancy from numba.roc.hsadrv.driver import hsa, dgpu_present from .hsadrv import devicearray from numba.core.typing.templates import AbstractTemplate diff --git a/numba/roc/hlc/__init__.py b/numba/roc/hlc/__init__.py index 26e32a9ba60..fbbeeb05269 100644 --- a/numba/roc/hlc/__init__.py +++ b/numba/roc/hlc/__init__.py @@ -14,4 +14,4 @@ # Allow user to use "NUMBA_USE_LIBHLC" env-var to use cmdline HLC. if os.environ.get('NUMBA_USE_LIBHLC', '').lower() not in ['0', 'no', 'false']: - from . import libhlc as hlc + from numba.roc.hlc import libhlc as hlc diff --git a/numba/roc/hlc/hlc.py b/numba/roc/hlc/hlc.py index cc2b67b0622..ab787bb59a6 100644 --- a/numba/roc/hlc/hlc.py +++ b/numba/roc/hlc/hlc.py @@ -11,7 +11,7 @@ from numba.roc.hsadrv import devices from .common import AMDGCNModule from .config import ROCM_BC_PATH -from . import TRIPLE +from numba.roc.hlc import TRIPLE from datetime import datetime from contextlib import contextmanager from numba.core import utils diff --git a/numba/roc/hsadrv/devicearray.py b/numba/roc/hsadrv/devicearray.py index a219a81a447..5efcd5a2575 100644 --- a/numba/roc/hsadrv/devicearray.py +++ b/numba/roc/hsadrv/devicearray.py @@ -10,7 +10,7 @@ from ctypes import c_void_p import numpy as np from numba.roc.hsadrv import driver as _driver -from . import devices +from numba.roc.hsadrv import devices from numba import dummyarray, numpy_support from numba.core import types from .error import HsaContextMismatchError diff --git a/numba/roc/hsadrv/driver.py b/numba/roc/hsadrv/driver.py index 340bda40231..958247c3210 100644 --- a/numba/roc/hsadrv/driver.py +++ b/numba/roc/hsadrv/driver.py @@ -20,7 +20,7 @@ from numba.core import utils from numba import config from .error import HsaSupportError, HsaDriverError, HsaApiError -from . import enums, enums_ext, drvapi +from numba.roc.hsadrv import enums, enums_ext, drvapi from numba.core.utils import longint as long import numpy as np diff --git a/numba/roc/hsadrv/drvapi.py b/numba/roc/hsadrv/drvapi.py index d112ddd2c00..48d34852fca 100644 --- a/numba/roc/hsadrv/drvapi.py +++ b/numba/roc/hsadrv/drvapi.py @@ -3,7 +3,7 @@ from numba.core import utils -from . import enums +from numba.roc.hsadrv import enums from .error import HsaApiError, HsaWarning _PTR = ctypes.POINTER diff --git a/numba/roc/hsaimpl.py b/numba/roc/hsaimpl.py index a0e5d45ac35..53bdd528d5a 100644 --- a/numba/roc/hsaimpl.py +++ b/numba/roc/hsaimpl.py @@ -10,10 +10,10 @@ from numba import cgutils from numba.core import types from numba.itanium_mangler import mangle_c, mangle, mangle_type -from . import target -from . import stubs -from . import hlc -from . import enums +from numba.roc import target +from numba.roc import stubs +from numba.roc import hlc +from numba.roc import enums registry = Registry() lower = registry.lower diff --git a/numba/roc/target.py b/numba/roc/target.py index b7aa880ea94..2f5886e7781 100644 --- a/numba/roc/target.py +++ b/numba/roc/target.py @@ -9,7 +9,7 @@ from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv -from . import codegen +from numba.roc import codegen from .hlc import DATALAYOUT CC_SPIR_KERNEL = "spir_kernel" diff --git a/numba/roc/tests/hsapy/test_large_code.py b/numba/roc/tests/hsapy/test_large_code.py index cf3f2cdcfc9..46e98318a57 100644 --- a/numba/roc/tests/hsapy/test_large_code.py +++ b/numba/roc/tests/hsapy/test_large_code.py @@ -10,7 +10,7 @@ class TestLargeCode(unittest.TestCase): def test_far_jump(self): - from . import run_far_branch + from numba.roc.tests.hsapy import run_far_branch pyinterp = sys.executable numba_dir = os.path.abspath(os.path.join(os.path.dirname(numba.__file__), os.pardir)) diff --git a/numba/serialize.py b/numba/serialize.py index 6994b723f1b..ddb124889ba 100644 --- a/numba/serialize.py +++ b/numba/serialize.py @@ -9,7 +9,7 @@ import sys from types import FunctionType, ModuleType -from . import bytecode, compiler +from numba import bytecode, compiler # diff --git a/numba/targets/base.py b/numba/targets/base.py index f06509cfeca..297be14ae73 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -18,7 +18,7 @@ from numba.core.compiler_lock import global_compiler_lock from numba.pythonapi import PythonAPI from numba.np import arrayobj -from . import builtins, imputils +from numba.targets import builtins, imputils from .imputils import (user_function, user_generator, builtin_registry, impl_ret_borrowed, RegistryLoader) @@ -269,14 +269,14 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from . import (arraymath, enumimpl, iterators, numbers, - optional, polynomial, rangeobj, tupleobj, - gdb_hook, hashing, heapq, literal) + from numba.targets import (arraymath, enumimpl, iterators, numbers, + optional, polynomial, rangeobj, tupleobj, + gdb_hook, hashing, heapq, literal) from numba.core import slicing from numba.np import linalg try: - from . import npdatetime + from numba.targets import npdatetime except NotImplementedError: pass self.install_registry(builtin_registry) diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 01613dceaf9..0ae49cc0227 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -4,10 +4,11 @@ from llvmlite import ir -from .. import cgutils, numpy_support, types -from ..pythonapi import box, unbox, reflect, NativeValue +from numba import cgutils, numpy_support +from numba.core import types +from numba.pythonapi import box, unbox, reflect, NativeValue -from . import listobj, setobj +from numba.targets import listobj, setobj # # Scalar types diff --git a/numba/targets/cmathimpl.py b/numba/targets/cmathimpl.py index eb984ea5d0c..7ec726ecb14 100644 --- a/numba/targets/cmathimpl.py +++ b/numba/targets/cmathimpl.py @@ -13,7 +13,7 @@ from numba import cgutils from numba.core import types from numba.core.typing import signature -from . import builtins, mathimpl +from numba.targets import builtins, mathimpl registry = Registry() lower = registry.lower diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 1e6532aacdb..3f99173f1c2 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -65,8 +65,8 @@ def init(self): def load_additional_registries(self): # Add target specific implementations - from . import (cffiimpl, cmathimpl, mathimpl, npyimpl, - printimpl, randomimpl) + from numba.targets import (cffiimpl, cmathimpl, mathimpl, npyimpl, + printimpl, randomimpl) self.install_registry(cmathimpl.registry) self.install_registry(cffiimpl.registry) self.install_registry(mathimpl.registry) diff --git a/numba/targets/imputils.py b/numba/targets/imputils.py index 6bbd3574728..4c6afcea4ef 100644 --- a/numba/targets/imputils.py +++ b/numba/targets/imputils.py @@ -449,7 +449,7 @@ def force_error_model(context, model_name='numpy'): """ Temporarily change the context's error model. """ - from . import callconv + from numba.targets import callconv old_error_model = context.error_model context.error_model = callconv.create_error_model(model_name, context) diff --git a/numba/targets/numbers.py b/numba/targets/numbers.py index ec396ecb8a9..131fe7c308e 100644 --- a/numba/targets/numbers.py +++ b/numba/targets/numbers.py @@ -849,7 +849,7 @@ def real_abs_impl(context, builder, sig, args): def real_negate_impl(context, builder, sig, args): - from . import mathimpl + from numba.targets import mathimpl res = mathimpl.negate_real(builder, args[0]) return impl_ret_untracked(context, builder, sig.return_type, res) diff --git a/numba/targets/ufunc_db.py b/numba/targets/ufunc_db.py index 452e5734502..31d7aff909a 100644 --- a/numba/targets/ufunc_db.py +++ b/numba/targets/ufunc_db.py @@ -47,7 +47,7 @@ def _fill_ufunc_db(ufunc_db): # some of these imports would cause a problem of circular # imports if done at global scope when importing the numba # module. - from . import numbers, npyfuncs, mathimpl, cmathimpl + from numba.targets import numbers, npyfuncs, mathimpl, cmathimpl from numba.numpy_support import numpy_version ufunc_db[np.negative] = { @@ -987,7 +987,7 @@ def _fill_ufunc_db(ufunc_db): } # Inject datetime64 support - from . import npdatetime + from numba.targets import npdatetime ufunc_db[np.negative].update({ 'm->m': npdatetime.timedelta_neg_impl, }) diff --git a/numba/testing/__main__.py b/numba/testing/__main__.py index 4049fa208e2..964b0ce910f 100644 --- a/numba/testing/__main__.py +++ b/numba/testing/__main__.py @@ -1,4 +1,4 @@ import sys -from . import run_tests +from numba.testing import run_tests sys.exit(0 if run_tests(sys.argv).wasSuccessful() else 1) diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index e2fd49a9134..78ac85d2948 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -132,7 +132,7 @@ def test_basic(self): @skip_cffi_unsupported def test_cffi(self): - from . import cffi_usecases + from numba.tests import cffi_usecases ffi, lib = cffi_usecases.load_inline_module() f = cfunc(square_sig)(square_usecase) diff --git a/numba/tests/test_object_mode.py b/numba/tests/test_object_mode.py index f629d1552a8..50bff7aacd0 100644 --- a/numba/tests/test_object_mode.py +++ b/numba/tests/test_object_mode.py @@ -9,7 +9,7 @@ from numba.compiler import compile_isolated, Flags from numba import jit from numba.core import utils -from numba.support import TestCase +from numba.tests.support import TestCase def complex_constant(n): diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index c51626182a5..14806c8cb47 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -164,7 +164,7 @@ class TestCC(BasePYCCTest): def setUp(self): super(TestCC, self).setUp() - from . import compile_with_pycc + from numba.tests import compile_with_pycc self._test_module = compile_with_pycc imp.reload(self._test_module) diff --git a/numba/tests/test_slices.py b/numba/tests/test_slices.py index 73912216619..f3346ace859 100644 --- a/numba/tests/test_slices.py +++ b/numba/tests/test_slices.py @@ -8,7 +8,7 @@ from numba import unittest_support as unittest from numba import jit, typeof, TypingError from numba.core import utils -from numba.support import TestCase, MemoryLeakMixin +from numba.tests.support import TestCase, MemoryLeakMixin def slice_passing(sl): diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index 95bbc0c06d0..efc3b04e969 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -13,8 +13,8 @@ from numba import testing from numba.tests.support import TestCase, MemoryLeakMixin, tag -from numba.targets.quicksort import make_py_quicksort, make_jit_quicksort -from numba.targets.mergesort import make_jit_mergesort +from numba.misc.quicksort import make_py_quicksort, make_jit_quicksort +from numba.misc.mergesort import make_jit_mergesort from numba.tests.timsort import make_py_timsort, make_jit_timsort, MergeRun diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 1d212c1c0f8..3482562a9e5 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -268,7 +268,7 @@ def test_ctypes(self): @unittest.skipUnless(cffi_support.SUPPORTED, "CFFI not supported") def test_cffi(self): - from . import cffi_usecases as mod + from numba.tests import cffi_usecases as mod mod.init() ty_cffi_cos = typeof(mod.cffi_cos) ty_cffi_sin = typeof(mod.cffi_sin) diff --git a/numba/tests/test_unpack_sequence.py b/numba/tests/test_unpack_sequence.py index e2b7bf615da..a7fed5032cd 100644 --- a/numba/tests/test_unpack_sequence.py +++ b/numba/tests/test_unpack_sequence.py @@ -4,7 +4,7 @@ from numba.compiler import compile_isolated, Flags from numba.core import errors, types from numba import typeof -from numba.testes.support import TestCase, MemoryLeakMixin, tag +from numba.tests.support import TestCase, MemoryLeakMixin, tag enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tracing.py b/numba/tracing.py index 5121a4a993b..a263102d7fe 100644 --- a/numba/tracing.py +++ b/numba/tracing.py @@ -5,7 +5,7 @@ import inspect from functools import wraps from itertools import chain -from . import config +from numba import config class TLS(threading.local): """Use a subclass to properly initialize the TLS variables in all threads.""" diff --git a/numba/unittest_support.py b/numba/unittest_support.py index 82eeb3fd0f1..681f749fe1c 100644 --- a/numba/unittest_support.py +++ b/numba/unittest_support.py @@ -3,5 +3,5 @@ """ import sys import warnings -from . import config +from numba import config from unittest import * diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index a7beb5f1bf3..26e8fc6bb68 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -2,7 +2,8 @@ from copy import deepcopy, copy from .compiler_machinery import FunctionPass, register_pass -from . import config, bytecode, postproc, errors, types, rewrites, transforms, ir +from numba import config, bytecode, postproc, rewrites, transforms, ir +from numba.core import errors, types from .special import literal_unroll import warnings from .analysis import ( From d2dfa6afbfb151dd080fcc2dcd033e821ddcb0cc Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 13:15:42 +0000 Subject: [PATCH 330/595] move ir.py --- docs/source/developer/compiler_pass_example.py | 2 +- docs/source/developer/inline_example.py | 3 ++- numba/analysis.py | 3 +-- numba/annotations/type_annotations.py | 2 +- numba/array_analysis.py | 4 ++-- numba/consts.py | 2 +- numba/core/byteflow.py | 2 +- numba/core/controlflow.py | 2 +- numba/core/dataflow.py | 2 +- numba/core/interpreter.py | 4 ++-- numba/{ => core}/ir.py | 0 numba/cuda/stubs.py | 4 ++-- numba/inline_closurecall.py | 4 ++-- numba/ir_utils.py | 4 ++-- numba/lowering.py | 5 ++--- numba/npyufunc/array_exprs.py | 4 ++-- numba/npyufunc/parfor.py | 4 ++-- numba/parfor.py | 10 +++++----- numba/postproc.py | 4 ++-- numba/pylowering.py | 4 ++-- numba/rewrites/ir_print.py | 3 +-- numba/rewrites/macros.py | 3 +-- numba/rewrites/static_binop.py | 3 +-- numba/rewrites/static_getitem.py | 3 +-- numba/rewrites/static_raise.py | 3 +-- numba/roc/stubs.py | 4 ++-- numba/stencil.py | 4 ++-- numba/stencilparfor.py | 4 ++-- numba/tests/test_analysis.py | 4 ++-- numba/tests/test_array_analysis.py | 4 ++-- numba/tests/test_array_exprs.py | 4 ++-- numba/tests/test_copy_propagate.py | 3 +-- numba/tests/test_inlining.py | 4 ++-- numba/tests/test_ir.py | 3 ++- numba/tests/test_ir_inlining.py | 4 ++-- numba/tests/test_ir_utils.py | 4 ++-- numba/tests/test_mixed_tuple_unroller.py | 4 ++-- numba/tests/test_parfors.py | 3 +-- numba/tests/test_pipeline.py | 2 +- numba/tests/test_practical_lowering_issues.py | 4 ++-- numba/tests/test_remove_dead.py | 3 +-- numba/transforms.py | 4 ++-- numba/typed_passes.py | 4 ++-- numba/typeinfer.py | 4 ++-- numba/untyped_passes.py | 4 ++-- numba/withcontexts.py | 4 ++-- 46 files changed, 77 insertions(+), 85 deletions(-) rename numba/{ => core}/ir.py (100%) diff --git a/docs/source/developer/compiler_pass_example.py b/docs/source/developer/compiler_pass_example.py index 224dba650fb..2b59b0b9158 100644 --- a/docs/source/developer/compiler_pass_example.py +++ b/docs/source/developer/compiler_pass_example.py @@ -2,7 +2,7 @@ def ex_compiler_pass(): # magictoken.ex_compiler_pass.begin from numba import njit - from numba import ir + from numba.core import ir from numba.compiler import CompilerBase, DefaultPassBuilder from numba.compiler_machinery import FunctionPass, register_pass from numba.untyped_passes import IRProcessing diff --git a/docs/source/developer/inline_example.py b/docs/source/developer/inline_example.py index 2942780c524..e57ba5c5818 100644 --- a/docs/source/developer/inline_example.py +++ b/docs/source/developer/inline_example.py @@ -1,5 +1,6 @@ -from numba import njit, ir +from numba import njit import numba +from numba.core import ir @njit(inline='never') diff --git a/numba/analysis.py b/numba/analysis.py index d4e28966e19..c3f1b747b2e 100644 --- a/numba/analysis.py +++ b/numba/analysis.py @@ -5,10 +5,9 @@ from functools import reduce from collections import namedtuple, defaultdict -from numba import ir from numba.core.controlflow import CFGraph from numba import consts, special -from numba.core import types, errors +from numba.core import types, errors, ir # # Analysis related to variable lifetime diff --git a/numba/annotations/type_annotations.py b/numba/annotations/type_annotations.py index 28cb6bf2605..3edd29ea33f 100644 --- a/numba/annotations/type_annotations.py +++ b/numba/annotations/type_annotations.py @@ -9,8 +9,8 @@ import textwrap from io import StringIO -from numba import ir import numba.dispatcher +from numba.core import ir class SourceLines(Mapping): diff --git a/numba/array_analysis.py b/numba/array_analysis.py index a9dd69e4a61..3cdfc994121 100644 --- a/numba/array_analysis.py +++ b/numba/array_analysis.py @@ -6,8 +6,8 @@ import types as pytypes # avoid confusion with numba.types import numpy import operator -from numba import ir, analysis, config, cgutils -from numba.core import types, typing +from numba import analysis, config, cgutils +from numba.core import types, typing, ir from numba.ir_utils import ( mk_unique_var, replace_vars_inner, diff --git a/numba/consts.py b/numba/consts.py index abcd833756b..698b26cfc92 100644 --- a/numba/consts.py +++ b/numba/consts.py @@ -2,8 +2,8 @@ import weakref -from numba import ir from numba.core.errors import ConstantInferenceError, NumbaError +from numba.core import ir class ConstantInference(object): diff --git a/numba/core/byteflow.py b/numba/core/byteflow.py index f68f4d1fc78..9cf77b54c87 100644 --- a/numba/core/byteflow.py +++ b/numba/core/byteflow.py @@ -9,7 +9,7 @@ from numba.core.utils import UniqueDict, PYVERSION from numba.core.controlflow import NEW_BLOCKERS, CFGraph -from numba.ir import Loc +from numba.core.ir import Loc from numba.core.errors import UnsupportedError diff --git a/numba/core/controlflow.py b/numba/core/controlflow.py index 6893c9657a6..e6ae3e1d989 100644 --- a/numba/core/controlflow.py +++ b/numba/core/controlflow.py @@ -3,7 +3,7 @@ import sys from numba.core import utils -from numba.ir import Loc +from numba.core.ir import Loc from numba.core.errors import UnsupportedError # List of bytecodes creating a new block in the control flow graph diff --git a/numba/core/dataflow.py b/numba/core/dataflow.py index c4386d87124..1146f90d550 100644 --- a/numba/core/dataflow.py +++ b/numba/core/dataflow.py @@ -5,7 +5,7 @@ from numba.core import utils from numba.core.errors import UnsupportedError -from numba.ir import Loc +from numba.core.ir import Loc class DataFlowAnalysis(object): diff --git a/numba/core/interpreter.py b/numba/core/interpreter.py index 7f9839a5e14..c4be7ef032f 100644 --- a/numba/core/interpreter.py +++ b/numba/core/interpreter.py @@ -4,8 +4,8 @@ import operator import logging -from numba.core import errors, dataflow, controlflow -from numba import config, ir +from numba.core import errors, dataflow, controlflow, ir +from numba import config from numba.core.errors import NotDefinedError from numba.core.utils import ( PYVERSION, diff --git a/numba/ir.py b/numba/core/ir.py similarity index 100% rename from numba/ir.py rename to numba/core/ir.py diff --git a/numba/cuda/stubs.py b/numba/cuda/stubs.py index 1828bfa8a59..300b61c7cd8 100644 --- a/numba/cuda/stubs.py +++ b/numba/cuda/stubs.py @@ -4,8 +4,8 @@ import operator import numpy import llvmlite.llvmpy.core as lc -from numba import ir, macro -from numba.core import types, typing +from numba import macro +from numba.core import types, typing, ir from .cudadrv import nvvm diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 776ed76b180..82905ef5aff 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -1,8 +1,8 @@ import types as pytypes # avoid confusion with numba.types import ctypes import numba -from numba.core import utils, types, typing, errors -from numba import (config, ir, ir_utils, prange, rewrites,) +from numba.core import utils, types, typing, errors, ir +from numba import config, ir_utils, prange, rewrites from numba.parfor import internal_prange from numba.ir_utils import ( mk_unique_var, diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 31c1d1a77a6..5309c4f2d6d 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -13,8 +13,8 @@ from llvmlite import ir as lir import numba -from numba.core import types, utils, typing -from numba import ir, config, analysis, cgutils, rewrites +from numba.core import types, utils, typing, ir +from numba import config, analysis, cgutils, rewrites from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) from numba.targets.imputils import impl_ret_untracked diff --git a/numba/lowering.py b/numba/lowering.py index c7a9c4c0d8a..b2834dea09c 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -5,9 +5,8 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import (_dynfunc, cgutils, config, funcdesc, generators, ir, - ir_utils) -from numba.core import typing, utils, types +from numba import _dynfunc, cgutils, config, funcdesc, generators, ir_utils +from numba.core import typing, utils, types, ir from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) from .targets import removerefctpass diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index c731d828579..c2d7b4e9694 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -6,8 +6,8 @@ import numpy as np import operator -from numba import compiler, ir, rewrites -from numba.core import types, utils +from numba import compiler, rewrites +from numba.core import types, utils, ir from numba.core.typing import npydecl from numba.npyufunc.dufunc import DUFunc diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index ca7a2a3549d..9ae785b6f75 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -10,8 +10,8 @@ import llvmlite.ir.values as liv import numba -from numba import compiler, ir, cgutils, sigutils, lowering, parfor -from numba.core import types +from numba import compiler, cgutils, sigutils, lowering, parfor +from numba.core import types, ir from numba.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, diff --git a/numba/parfor.py b/numba/parfor.py index c8c915e0dd6..d48a7227f77 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -24,9 +24,9 @@ from contextlib import contextmanager import operator -import numba -from numba.core import types, typing, utils, errors -from numba import ir, ir_utils, rewrites, config, analysis, prange, pndindex +import numba.core.ir +from numba.core import types, typing, utils, errors, ir +from numba import ir_utils, rewrites, config, analysis, prange, pndindex from numba import array_analysis, postproc, typeinfer from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate @@ -4033,13 +4033,13 @@ def repr_arrayexpr(arrayexpr): else: opr = ' ' + opr + ' ' return '({})'.format(opr.join([ repr_arrayexpr(x) for x in args ])) - elif isinstance(arrayexpr, numba.ir.Var): + elif isinstance(arrayexpr, numba.core.ir.Var): name = arrayexpr.name if name.startswith('$'): return '\'%s\' (temporary variable)' % name else: return name - elif isinstance(arrayexpr, numba.ir.Const): + elif isinstance(arrayexpr, numba.core.ir.Const): return repr(arrayexpr.value) else: return '_' diff --git a/numba/postproc.py b/numba/postproc.py index 98f08190e94..5d37e9f93cf 100644 --- a/numba/postproc.py +++ b/numba/postproc.py @@ -1,5 +1,5 @@ -from numba import analysis, ir, transforms -from numba.core import utils +from numba import analysis, transforms +from numba.core import utils, ir class YieldPoint(object): diff --git a/numba/pylowering.py b/numba/pylowering.py index 7301dcdc6b7..e117beed965 100644 --- a/numba/pylowering.py +++ b/numba/pylowering.py @@ -9,8 +9,8 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba import cgutils, generators, ir -from numba.core import types, utils +from numba import cgutils, generators +from numba.core import types, utils, ir from numba.core.errors import ForbiddenConstruct from numba.lowering import BaseLower diff --git a/numba/rewrites/ir_print.py b/numba/rewrites/ir_print.py index 1911c86f78a..5f2f92e88ae 100644 --- a/numba/rewrites/ir_print.py +++ b/numba/rewrites/ir_print.py @@ -1,5 +1,4 @@ -from numba import ir -from numba.core import errors +from numba.core import errors, ir from numba.rewrites import register_rewrite, Rewrite diff --git a/numba/rewrites/macros.py b/numba/rewrites/macros.py index 1563d360a22..10f6402d7af 100644 --- a/numba/rewrites/macros.py +++ b/numba/rewrites/macros.py @@ -1,5 +1,4 @@ -from numba import ir -from numba.core import errors +from numba.core import errors, ir from numba.rewrites import register_rewrite, Rewrite diff --git a/numba/rewrites/static_binop.py b/numba/rewrites/static_binop.py index 2e493f30d63..aa37fd87fae 100644 --- a/numba/rewrites/static_binop.py +++ b/numba/rewrites/static_binop.py @@ -1,5 +1,4 @@ -from numba import ir -from numba.core import errors +from numba.core import errors, ir from numba.rewrites import register_rewrite, Rewrite diff --git a/numba/rewrites/static_getitem.py b/numba/rewrites/static_getitem.py index a66e9b9a1cc..f5706b4609b 100644 --- a/numba/rewrites/static_getitem.py +++ b/numba/rewrites/static_getitem.py @@ -1,5 +1,4 @@ -from numba import ir -from numba.core import errors +from numba.core import errors, ir from numba.rewrites import register_rewrite, Rewrite diff --git a/numba/rewrites/static_raise.py b/numba/rewrites/static_raise.py index 72e1f9ac5b8..6dc2a700470 100644 --- a/numba/rewrites/static_raise.py +++ b/numba/rewrites/static_raise.py @@ -1,5 +1,4 @@ -from numba import ir -from numba.core import errors +from numba.core import errors, ir from numba.rewrites import register_rewrite, Rewrite diff --git a/numba/roc/stubs.py b/numba/roc/stubs.py index 180ecf409c2..d02e1a79d1f 100644 --- a/numba/roc/stubs.py +++ b/numba/roc/stubs.py @@ -1,5 +1,5 @@ -from numba import ir, macro -from numba.core import types, typing +from numba import macro +from numba.core import types, typing, ir _stub_error = NotImplementedError("This is a stub.") diff --git a/numba/stencil.py b/numba/stencil.py index 2107eb16049..c00d6e22e30 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -8,8 +8,8 @@ import numpy as np from llvmlite import ir as lir -from numba import (compiler, ir_utils, ir, numpy_support, typed_passes) -from numba.core import types, typing, utils +from numba import compiler, ir_utils, numpy_support, typed_passes +from numba.core import types, typing, utils, ir from numba import config from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 2ad4fcd82c2..5a8ea9f718d 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -12,11 +12,11 @@ import numpy as np import numba -from numba.core import types +from numba.core import types, ir from numba.core.typing.templates import infer_global, AbstractTemplate from numba.core.typing import signature from numba.core import utils, typing -from numba import ir_utils, ir, config +from numba import ir_utils, config from numba.ir_utils import (get_call_table, mk_unique_var, compile_to_numba_ir, replace_arg_nodes, guard, find_callname, require, find_const, GuardException) diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index 399d73583f7..63dd1e8c8bd 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -3,8 +3,8 @@ import numpy as np from numba.compiler import compile_isolated, run_frontend, Flags, StateDict -from numba import rewrites, ir, jit, ir_utils, njit -from numba.core import types, errors +from numba import rewrites, jit, ir_utils, njit +from numba.core import types, errors, ir from numba.tests.support import TestCase, MemoryLeakMixin, SerialMixin from numba.analysis import dead_branch_prune, rewrite_semantic_constants diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 879a3449738..c60f203ac04 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -6,8 +6,8 @@ from io import StringIO from numba import unittest_support as unittest -from numba import njit, typeof, ir, bytecode, jitclass, prange, postproc -from numba.core import types, typing +from numba import njit, typeof, bytecode, jitclass, prange, postproc +from numba.core import types, typing, ir from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index e454f913da0..4f38bcafefc 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -5,8 +5,8 @@ from numba import njit, vectorize from numba import unittest_support as unittest -from numba import compiler, typeof, ir -from numba.core import utils, types, typing +from numba import compiler, typeof +from numba.core import utils, types, typing, ir from numba.compiler import Compiler, Flags from numba.targets import cpu from numba.tests.support import MemoryLeakMixin, TestCase diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 85aeee1738b..d61e4c7280a 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -5,13 +5,12 @@ from numba import compiler from numba.targets import cpu -from numba.core import types, typing +from numba.core import types, typing, ir from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) -from numba import ir from numba.typed_passes import type_inference_stage from numba import unittest_support as unittest diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index e8953fee0f8..0b3f5cc9f57 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -5,8 +5,8 @@ skip_parfors_unsupported) import numba from numba import unittest_support as unittest -from numba import jit, njit, ir, compiler -from numba.core import types +from numba import jit, njit, compiler +from numba.core import types, ir from numba.ir_utils import guard, find_callname, find_const, get_definition from numba.targets.registry import CPUDispatcher from numba.inline_closurecall import inline_closure_call diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index 39156a16e24..2aa4514f680 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -1,6 +1,7 @@ import numba.unittest_support as unittest -from numba import compiler, ir, objmode +from numba import compiler, objmode import numpy as np +from numba.core import ir class TestIR(unittest.TestCase): diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index a622d4c779f..b7e3e41bd47 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -7,8 +7,8 @@ import numpy as np import numba -from numba import njit, ir -from numba.core import types +from numba import njit +from numba.core import types, ir from numba.extending import ( overload, overload_method, diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index 95d9421b314..ef88d2f1aee 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -1,12 +1,12 @@ import numba from numba.tests.support import TestCase, unittest -from numba import compiler, jitclass, ir +from numba import compiler, jitclass from numba.targets.registry import cpu_target from numba.compiler import CompilerBase, Flags from numba.compiler_machinery import PassManager from numba.targets import registry from numba import ir_utils, bytecode -from numba.core import types +from numba.core import types, ir from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 3f03bbea933..218481d0233 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -2,8 +2,8 @@ from numba.tests.support import (TestCase, MemoryLeakMixin, skip_parfors_unsupported) -from numba import njit, typed, ir, literal_unroll, prange -from numba.core import types, errors +from numba import njit, typed, literal_unroll, prange +from numba.core import types, errors, ir from numba.testing import unittest from numba.extending import overload from numba.compiler_machinery import PassManager, register_pass, FunctionPass diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index dcc1b4f6b64..9e25018443c 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -23,14 +23,13 @@ from numba import njit, prange, stencil, inline_closurecall from numba import compiler, typed_passes from numba.targets import cpu -from numba.core import types, utils, typing, errors +from numba.core import types, utils, typing, errors, ir from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations from numba.ir_utils import (find_callname, guard, build_definitions, get_definition, is_getitem, is_setitem, index_var_of_get_setitem) -from numba import ir from numba.unsafe.ndarray import empty_inferred as unsafe_empty from numba.compiler import compile_isolated, Flags from numba.bytecode import ByteCodeIter diff --git a/numba/tests/test_pipeline.py b/numba/tests/test_pipeline.py index d4700dc8412..516ac78f572 100644 --- a/numba/tests/test_pipeline.py +++ b/numba/tests/test_pipeline.py @@ -1,7 +1,7 @@ from numba.compiler import Compiler from numba import jit, generated_jit, objmode from numba.core import types -from numba.ir import FunctionIR +from numba.core.ir import FunctionIR from numba.tests.support import TestCase diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index 67433dfb5bc..9dcf730a8b5 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -3,8 +3,8 @@ """ import numpy as np -from numba import njit, ir -from numba.core import types +from numba import njit +from numba.core import types, ir from numba.compiler import CompilerBase, DefaultPassBuilder from numba.typed_passes import NopythonTypeInference from numba.compiler_machinery import register_pass, FunctionPass diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index f2bb7985d97..a890ffb5943 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -7,7 +7,7 @@ from numba import compiler from numba.compiler import compile_isolated, Flags from numba.targets import cpu -from numba.core import types, typing +from numba.core import types, typing, ir from numba.targets.registry import cpu_target from numba import config from numba.annotations import type_annotations @@ -15,7 +15,6 @@ get_name_var_table, remove_dels, remove_dead, remove_call_handlers, alias_func_extensions) from numba.typed_passes import type_inference_stage -from numba import ir from numba.compiler_machinery import FunctionPass, register_pass, PassManager from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, diff --git a/numba/transforms.py b/numba/transforms.py index 6a835ce48f5..ee3085f821d 100644 --- a/numba/transforms.py +++ b/numba/transforms.py @@ -7,8 +7,8 @@ import logging from numba.analysis import compute_cfg_from_blocks, find_top_level_loops -from numba import ir, ir_utils -from numba.core import errors +from numba import ir_utils +from numba.core import errors, ir from numba.analysis import compute_use_defs diff --git a/numba/typed_passes.py b/numba/typed_passes.py index fe4309b5714..76a588cd04a 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -1,8 +1,8 @@ from contextlib import contextmanager import warnings -from numba import (config, rewrites, typeinfer, funcdesc, lowering, ir) -from numba.core import errors, types, typing +from numba import config, rewrites, typeinfer, funcdesc, lowering +from numba.core import errors, types, typing, ir from numba.parfor import PreParforPass as _parfor_PreParforPass from numba.parfor import ParforPass as _parfor_ParforPass diff --git a/numba/typeinfer.py b/numba/typeinfer.py index 5787106a552..6fc71f38c93 100644 --- a/numba/typeinfer.py +++ b/numba/typeinfer.py @@ -21,8 +21,8 @@ from collections import OrderedDict, defaultdict from functools import reduce -from numba import ir, config -from numba.core import types, utils, typing +from numba import config +from numba.core import types, utils, typing, ir from numba.core.typing.templates import Signature from numba.core.errors import (TypingError, UntypedAttributeError, new_error_context, termcolor, UnsupportedError, diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index 26e8fc6bb68..b7bebf6d2f3 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -2,8 +2,8 @@ from copy import deepcopy, copy from .compiler_machinery import FunctionPass, register_pass -from numba import config, bytecode, postproc, rewrites, transforms, ir -from numba.core import errors, types +from numba import config, bytecode, postproc, rewrites, transforms +from numba.core import errors, types, ir from .special import literal_unroll import warnings from .analysis import ( diff --git a/numba/withcontexts.py b/numba/withcontexts.py index 3de88dca01e..b88428e0683 100644 --- a/numba/withcontexts.py +++ b/numba/withcontexts.py @@ -1,5 +1,5 @@ -from numba import ir, ir_utils, sigutils -from numba.core import types, errors +from numba import ir_utils, sigutils +from numba.core import types, errors, ir from numba.core.typing.typeof import typeof_impl from numba.transforms import find_region_inout_vars From 9ef03257c717daa694d21c788784c0599b4d3b0c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 13:28:42 +0000 Subject: [PATCH 331/595] move dispatcher.py --- numba/annotations/type_annotations.py | 4 ++-- numba/ccallback.py | 2 +- numba/{ => core}/dispatcher.py | 0 numba/cuda/target.py | 4 ++-- numba/npyufunc/dufunc.py | 2 +- numba/pylowering.py | 2 +- numba/targets/registry.py | 3 +-- numba/tests/test_dispatcher.py | 22 +++++++++++----------- numba/tests/test_jit_module.py | 2 +- numba/tests/test_typeof.py | 2 +- numba/transforms.py | 4 ++-- numba/typed/typedlist.py | 2 +- 12 files changed, 24 insertions(+), 25 deletions(-) rename numba/{ => core}/dispatcher.py (100%) diff --git a/numba/annotations/type_annotations.py b/numba/annotations/type_annotations.py index 3edd29ea33f..dffdd83be77 100644 --- a/numba/annotations/type_annotations.py +++ b/numba/annotations/type_annotations.py @@ -9,7 +9,7 @@ import textwrap from io import StringIO -import numba.dispatcher +import numba.core.dispatcher from numba.core import ir @@ -92,7 +92,7 @@ def prepare_annotations(self): inst.value.op == 'call'): atype = self.calltypes[inst.value] elif (isinstance(inst.value, ir.Const) and - isinstance(inst.value.value, numba.dispatcher.LiftedLoop)): + isinstance(inst.value.value, numba.core.dispatcher.LiftedLoop)): atype = 'XXX Lifted Loop XXX' found_lifted_loop = True else: diff --git a/numba/ccallback.py b/numba/ccallback.py index 731ca9f3586..dec9afe1135 100644 --- a/numba/ccallback.py +++ b/numba/ccallback.py @@ -10,7 +10,7 @@ from numba.core import utils from numba import compiler from numba.caching import NullCache, FunctionCache -from numba.dispatcher import _FunctionCompiler +from numba.core.dispatcher import _FunctionCompiler from numba.targets import registry from numba.core.typing import signature from numba.core.typing.ctypes_utils import to_ctypes diff --git a/numba/dispatcher.py b/numba/core/dispatcher.py similarity index 100% rename from numba/dispatcher.py rename to numba/core/dispatcher.py diff --git a/numba/cuda/target.py b/numba/cuda/target.py index c801f247f1a..314ffa6339d 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -4,8 +4,8 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba.core import typing, types -from numba import cgutils, debuginfo, dispatcher +from numba.core import typing, types, dispatcher +from numba import cgutils, debuginfo from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv diff --git a/numba/npyufunc/dufunc.py b/numba/npyufunc/dufunc.py index 066fba029b2..8bc6a1afc92 100644 --- a/numba/npyufunc/dufunc.py +++ b/numba/npyufunc/dufunc.py @@ -5,7 +5,7 @@ from numba.core.typing import npydecl from numba.core.typing.templates import AbstractTemplate, signature from numba.npyufunc import _internal, ufuncbuilder -from numba.dispatcher import Dispatcher +from numba.core.dispatcher import Dispatcher from numba import array_analysis diff --git a/numba/pylowering.py b/numba/pylowering.py index e117beed965..4a98a1e9146 100644 --- a/numba/pylowering.py +++ b/numba/pylowering.py @@ -77,7 +77,7 @@ def pre_lower(self): super(PyLower, self).pre_lower() self.init_pyapi() # Pre-computed for later use - from numba.dispatcher import OmittedArg + from numba.core.dispatcher import OmittedArg self.omitted_typobj = self.pyapi.unserialize( self.pyapi.serialize_object(OmittedArg)) diff --git a/numba/targets/registry.py b/numba/targets/registry.py index 3930682463d..ba13efdfa93 100644 --- a/numba/targets/registry.py +++ b/numba/targets/registry.py @@ -2,8 +2,7 @@ from numba.targets import cpu from numba.targets.descriptors import TargetDescriptor -from numba import dispatcher -from numba.core import utils, typing +from numba.core import utils, typing, dispatcher # ----------------------------------------------------------------------------- # Default CPU target descriptors diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 28592970e15..06af2be262d 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -13,16 +13,6 @@ from itertools import chain from io import StringIO -try: - import jinja2 -except ImportError: - jinja2 = None - -try: - import pygments -except ImportError: - pygments = None - import numpy as np from numba import unittest_support as unittest @@ -37,12 +27,22 @@ from numba.numpy_support import as_dtype from numba.targets import codegen from numba.caching import _UserWideCacheLocator -from numba.dispatcher import Dispatcher +from numba.core.dispatcher import Dispatcher from numba import parfor from numba.tests.support import skip_parfors_unsupported, needs_lapack import llvmlite.binding as ll +try: + import jinja2 +except ImportError: + jinja2 = None + +try: + import pygments +except ImportError: + pygments = None + _is_armv7l = platform.machine() == 'armv7l' diff --git a/numba/tests/test_jit_module.py b/numba/tests/test_jit_module.py index ffa7e878293..2275769a942 100644 --- a/numba/tests/test_jit_module.py +++ b/numba/tests/test_jit_module.py @@ -10,8 +10,8 @@ from io import StringIO import numba.unittest_support as unittest -from numba import dispatcher from numba.tests.support import temp_directory, SerialMixin +from numba.core import dispatcher @contextlib.contextmanager diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 3482562a9e5..25a173f0dd9 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -12,7 +12,7 @@ from numba import cffi_support, numpy_support from numba.core import types from numba.special import typeof -from numba.dispatcher import OmittedArg +from numba.core.dispatcher import OmittedArg from numba._dispatcher import compute_fingerprint from numba.tests.support import TestCase, tag diff --git a/numba/transforms.py b/numba/transforms.py index ee3085f821d..a17f6b39078 100644 --- a/numba/transforms.py +++ b/numba/transforms.py @@ -178,7 +178,7 @@ def _loop_lift_modify_blocks(func_ir, loopinfo, blocks, Modify the block inplace to call to the lifted-loop. Returns a dictionary of blocks of the lifted-loop. """ - from numba.dispatcher import LiftedLoop + from numba.core.dispatcher import LiftedLoop # Copy loop blocks loop = loopinfo.loop @@ -325,7 +325,7 @@ def with_lifting(func_ir, typingctx, targetctx, flags, locals): from numba import postproc def dispatcher_factory(func_ir, objectmode=False, **kwargs): - from numba.dispatcher import LiftedWith, ObjModeLiftedWith + from numba.core.dispatcher import LiftedWith, ObjModeLiftedWith myflags = flags.copy() if objectmode: diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index d61eac2d241..9767a1874d2 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -13,7 +13,7 @@ from numba.core.types import ListType, TypeRef from numba.targets.imputils import numba_typeref_ctor from numba import listobject -from numba.dispatcher import Dispatcher +from numba.core.dispatcher import Dispatcher from numba import config from numba.core import types, errors from numba import njit, cgutils, typeof From a8b696aa1fabeeffb476e373cb8f63da98c8377d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 13:38:12 +0000 Subject: [PATCH 332/595] move bytecode.py --- numba/compiler.py | 4 ++-- numba/{ => core}/bytecode.py | 0 numba/core/dispatcher.py | 2 +- numba/serialize.py | 3 ++- numba/tests/test_array_analysis.py | 4 ++-- numba/tests/test_flow_control.py | 2 +- numba/tests/test_ir_utils.py | 4 ++-- numba/tests/test_parfors.py | 2 +- numba/tests/test_withlifting.py | 2 +- numba/untyped_passes.py | 4 ++-- 10 files changed, 14 insertions(+), 13 deletions(-) rename numba/{ => core}/bytecode.py (100%) diff --git a/numba/compiler.py b/numba/compiler.py index 16681db8031..45e42e43849 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -3,8 +3,8 @@ import warnings from numba.tracing import event -from numba import bytecode, postproc, config -from numba.core import utils, errors, typing, interpreter +from numba import postproc, config +from numba.core import utils, errors, typing, interpreter, bytecode from numba.targets import cpu, callconv from numba.parfor import ParforDiagnostics from numba.inline_closurecall import InlineClosureCallPass diff --git a/numba/bytecode.py b/numba/core/bytecode.py similarity index 100% rename from numba/bytecode.py rename to numba/core/bytecode.py diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py index fe15c18b1b2..c1302e4f255 100644 --- a/numba/core/dispatcher.py +++ b/numba/core/dispatcher.py @@ -18,7 +18,7 @@ from numba import sigutils, serialize from numba.core.typing.templates import fold_arguments from numba.core.typing.typeof import Purpose, typeof -from numba.bytecode import get_code_object +from numba.core.bytecode import get_code_object from numba.core.utils import reraise from numba.caching import NullCache, FunctionCache diff --git a/numba/serialize.py b/numba/serialize.py index ddb124889ba..819507c4fcc 100644 --- a/numba/serialize.py +++ b/numba/serialize.py @@ -9,7 +9,8 @@ import sys from types import FunctionType, ModuleType -from numba import bytecode, compiler +from numba import compiler +from numba.core import bytecode # diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index c60f203ac04..7630c2f59a0 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -6,8 +6,8 @@ from io import StringIO from numba import unittest_support as unittest -from numba import njit, typeof, bytecode, jitclass, prange, postproc -from numba.core import types, typing, ir +from numba import njit, typeof, jitclass, prange, postproc +from numba.core import types, typing, ir, bytecode from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index 2e0e6155a3b..cd1eeb227dd 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -4,7 +4,7 @@ from numba.core.controlflow import CFGraph, ControlFlowAnalysis from numba.compiler import compile_isolated, Flags from numba.core import types -from numba.bytecode import FunctionIdentity, ByteCode +from numba.core.bytecode import FunctionIdentity, ByteCode from numba.tests.support import TestCase enable_pyobj_flags = Flags() diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index ef88d2f1aee..b10cc45e551 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -5,8 +5,8 @@ from numba.compiler import CompilerBase, Flags from numba.compiler_machinery import PassManager from numba.targets import registry -from numba import ir_utils, bytecode -from numba.core import types, ir +from numba import ir_utils +from numba.core import types, ir, bytecode from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 9e25018443c..c8118734595 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -32,7 +32,7 @@ index_var_of_get_setitem) from numba.unsafe.ndarray import empty_inferred as unsafe_empty from numba.compiler import compile_isolated, Flags -from numba.bytecode import ByteCodeIter +from numba.core.bytecode import ByteCodeIter from numba.tests.support import (TestCase, captured_stdout, MemoryLeakMixin, override_env_config, linux_only, tag, skip_parfors_unsupported, _32bit, needs_blas, diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index 9ab2d4a4893..f646d00f21a 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -6,7 +6,7 @@ from numba import unittest_support as unittest from numba.transforms import find_setupwiths, with_lifting from numba.withcontexts import bypass_context, call_context, objmode_context -from numba.bytecode import FunctionIdentity, ByteCode +from numba.core.bytecode import FunctionIdentity, ByteCode from numba.core.interpreter import Interpreter from numba.core import typing, errors from numba.targets.registry import cpu_target diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index b7bebf6d2f3..7b039c0d6ad 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -2,8 +2,8 @@ from copy import deepcopy, copy from .compiler_machinery import FunctionPass, register_pass -from numba import config, bytecode, postproc, rewrites, transforms -from numba.core import errors, types, ir +from numba import config, postproc, rewrites, transforms +from numba.core import errors, types, ir, bytecode from .special import literal_unroll import warnings from .analysis import ( From 5bed20ef83d816d645e68f8dc291e3fc6dba261c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 17:07:45 +0000 Subject: [PATCH 333/595] move numba/annotations --- numba/{ => core}/annotations/__init__.py | 0 numba/{ => core}/annotations/template.html | 0 numba/{ => core}/annotations/type_annotations.py | 0 numba/stencilparfor.py | 2 +- numba/tests/test_copy_propagate.py | 2 +- numba/tests/test_parfors.py | 2 +- numba/tests/test_remove_dead.py | 4 ++-- numba/typed_passes.py | 2 +- 8 files changed, 6 insertions(+), 6 deletions(-) rename numba/{ => core}/annotations/__init__.py (100%) rename numba/{ => core}/annotations/template.html (100%) rename numba/{ => core}/annotations/type_annotations.py (100%) diff --git a/numba/annotations/__init__.py b/numba/core/annotations/__init__.py similarity index 100% rename from numba/annotations/__init__.py rename to numba/core/annotations/__init__.py diff --git a/numba/annotations/template.html b/numba/core/annotations/template.html similarity index 100% rename from numba/annotations/template.html rename to numba/core/annotations/template.html diff --git a/numba/annotations/type_annotations.py b/numba/core/annotations/type_annotations.py similarity index 100% rename from numba/annotations/type_annotations.py rename to numba/core/annotations/type_annotations.py diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 5a8ea9f718d..3a91d6c40d5 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -650,7 +650,7 @@ def get_stencil_ir(sf, typingctx, args, scope, loc, input_dict, typemap, """ from numba.targets.cpu import CPUContext from numba.targets.registry import cpu_target - from numba.annotations import type_annotations + from numba.core.annotations import type_annotations from numba.typed_passes import type_inference_stage # get untyped IR diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index d61e4c7280a..ae59112f468 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -8,7 +8,7 @@ from numba.core import types, typing, ir from numba.targets.registry import cpu_target from numba import config -from numba.annotations import type_annotations +from numba.core.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) from numba.typed_passes import type_inference_stage diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index c8118734595..591249efa1a 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -26,7 +26,7 @@ from numba.core import types, utils, typing, errors, ir from numba.targets.registry import cpu_target from numba import config -from numba.annotations import type_annotations +from numba.core.annotations import type_annotations from numba.ir_utils import (find_callname, guard, build_definitions, get_definition, is_getitem, is_setitem, index_var_of_get_setitem) diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index a890ffb5943..e8154a73825 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -10,7 +10,7 @@ from numba.core import types, typing, ir from numba.targets.registry import cpu_target from numba import config -from numba.annotations import type_annotations +from numba.core.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table, remove_dels, remove_dead, remove_call_handlers, alias_func_extensions) @@ -159,7 +159,7 @@ def func(A, i): @needs_blas def test_alias_ctypes(self): # use xxnrm2 to test call a C function with ctypes - from numba.targets.linalg import _BLAS + from numba.np.linalg import _BLAS xxnrm2 = _BLAS().numba_xxnrm2(types.float64) def remove_dead_xxnrm2(rhs, lives, call_list): diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 76a588cd04a..4d872408626 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -9,7 +9,7 @@ from numba.parfor import Parfor from numba.compiler_machinery import FunctionPass, LoweringPass, register_pass -from numba.annotations import type_annotations +from numba.core.annotations import type_annotations from numba.ir_utils import (raise_on_unsupported_feature, warn_deprecated, check_and_legalize_ir, guard, dead_code_elimination, simplify_CFG, get_definition) From f5edaa71fef599b456c381ade84182cb1b88f633 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 17:10:33 +0000 Subject: [PATCH 334/595] move appdirs --- numba/caching.py | 2 +- numba/{ => misc}/appdirs.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => misc}/appdirs.py (100%) diff --git a/numba/caching.py b/numba/caching.py index 5a9fd0a06aa..c6e31b3f019 100644 --- a/numba/caching.py +++ b/numba/caching.py @@ -15,7 +15,7 @@ import tempfile import warnings -from numba.appdirs import AppDirs +from numba.misc.appdirs import AppDirs from numba.core.utils import add_metaclass, file_replace import numba diff --git a/numba/appdirs.py b/numba/misc/appdirs.py similarity index 100% rename from numba/appdirs.py rename to numba/misc/appdirs.py From 1a9be536515cf27ee6ef124f60f84a8b83d7e035 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 17:13:57 +0000 Subject: [PATCH 335/595] Make numba/parfors submodule --- numba/parfors/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/parfors/__init__.py diff --git a/numba/parfors/__init__.py b/numba/parfors/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 46f598eb8a23c3fad76107f15126e7a0b9e05fbc Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 18:01:15 +0000 Subject: [PATCH 336/595] Move array_analysis to numba/parfors --- numba/ir_utils.py | 3 ++- numba/npyufunc/dufunc.py | 2 +- numba/parfor.py | 13 +++++++------ numba/{ => parfors}/array_analysis.py | 2 +- numba/tests/test_array_analysis.py | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) rename numba/{ => parfors}/array_analysis.py (99%) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 5309c4f2d6d..3b3342ab9b4 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -648,6 +648,7 @@ def has_no_side_effect(rhs, lives, call_table): """ Returns True if this expression has no side effects that would prevent re-ordering. """ + from numba.parfors import array_analysis if isinstance(rhs, ir.Expr) and rhs.op == 'call': func_name = rhs.func.name if func_name not in call_table or call_table[func_name] == []: @@ -658,7 +659,7 @@ def has_no_side_effect(rhs, lives, call_table): call_list == ['stencil', numba] or call_list == ['log', numpy] or call_list == ['dtype', numpy] or - call_list == [numba.array_analysis.wrap_index] or + call_list == [array_analysis.wrap_index] or call_list == [numba.special.prange] or call_list == [numba.parfor.internal_prange]): return True diff --git a/numba/npyufunc/dufunc.py b/numba/npyufunc/dufunc.py index 8bc6a1afc92..8701a72e2e1 100644 --- a/numba/npyufunc/dufunc.py +++ b/numba/npyufunc/dufunc.py @@ -6,7 +6,7 @@ from numba.core.typing.templates import AbstractTemplate, signature from numba.npyufunc import _internal, ufuncbuilder from numba.core.dispatcher import Dispatcher -from numba import array_analysis +from numba.parfors import array_analysis def make_dufunc_kernel(_dufunc): diff --git a/numba/parfor.py b/numba/parfor.py index d48a7227f77..830c2533635 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -27,7 +27,7 @@ import numba.core.ir from numba.core import types, typing, utils, errors, ir from numba import ir_utils, rewrites, config, analysis, prange, pndindex -from numba import array_analysis, postproc, typeinfer +from numba import postproc, typeinfer from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate from numba import stencilparfor @@ -85,13 +85,14 @@ from numba.core.controlflow import CFGraph from numba.core.typing import npydecl, signature from numba.core.types.functions import Function -from numba.array_analysis import (random_int_args, random_1arg_size, +from numba.parfors.array_analysis import (random_int_args, random_1arg_size, random_2arg_sizelast, random_3arg_sizelast, random_calls, assert_equiv) from numba.extending import overload import copy import numpy import numpy as np +from numba.parfors import array_analysis # circular dependency: import numba.npyufunc.dufunc.DUFunc # wrapped pretty print @@ -171,9 +172,9 @@ def argmin_parallel_impl(in_arr): argmin_checker(len(in_arr)) A = in_arr.ravel() init_val = numba.targets.builtins.get_type_max_value(A.dtype) - ival = numba.typing.builtins.IndexValue(0, init_val) + ival = typing.builtins.IndexValue(0, init_val) for i in numba.parfor.internal_prange(len(A)): - curr_ival = numba.typing.builtins.IndexValue(i, A[i]) + curr_ival = typing.builtins.IndexValue(i, A[i]) ival = min(ival, curr_ival) return ival.index @@ -182,9 +183,9 @@ def argmax_parallel_impl(in_arr): argmax_checker(len(in_arr)) A = in_arr.ravel() init_val = numba.targets.builtins.get_type_min_value(A.dtype) - ival = numba.typing.builtins.IndexValue(0, init_val) + ival = typing.builtins.IndexValue(0, init_val) for i in numba.parfor.internal_prange(len(A)): - curr_ival = numba.typing.builtins.IndexValue(i, A[i]) + curr_ival = typing.builtins.IndexValue(i, A[i]) ival = max(ival, curr_ival) return ival.index diff --git a/numba/array_analysis.py b/numba/parfors/array_analysis.py similarity index 99% rename from numba/array_analysis.py rename to numba/parfors/array_analysis.py index 3cdfc994121..5bc5e0fb78f 100644 --- a/numba/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: BSD-2-Clause # -import types as pytypes # avoid confusion with numba.types +import types as pytypes import numpy import operator from numba import analysis, config, cgutils diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 7630c2f59a0..b759a824864 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -9,7 +9,7 @@ from numba import njit, typeof, jitclass, prange, postproc from numba.core import types, typing, ir, bytecode from numba.tests.support import TestCase, tag, skip_parfors_unsupported -from numba.array_analysis import EquivSet, ArrayAnalysis +from numba.parfors.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager from numba.targets import cpu, registry from numba.ir_utils import remove_dead From 294a035b3af3b3d68679ab02bb3f49d018268c7c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 18:09:24 +0000 Subject: [PATCH 337/595] Move analysis to numba/core --- numba/{ => core}/analysis.py | 6 +++--- numba/inline_closurecall.py | 6 +++--- numba/ir_utils.py | 6 +++--- numba/npyufunc/parfor.py | 2 +- numba/parfor.py | 6 +++--- numba/parfors/array_analysis.py | 6 +++--- numba/postproc.py | 4 ++-- numba/tests/test_analysis.py | 2 +- numba/transforms.py | 4 ++-- numba/untyped_passes.py | 8 +------- 10 files changed, 22 insertions(+), 28 deletions(-) rename numba/{ => core}/analysis.py (99%) diff --git a/numba/analysis.py b/numba/core/analysis.py similarity index 99% rename from numba/analysis.py rename to numba/core/analysis.py index c3f1b747b2e..85691c6ef33 100644 --- a/numba/analysis.py +++ b/numba/core/analysis.py @@ -5,7 +5,7 @@ from functools import reduce from collections import namedtuple, defaultdict -from numba.core.controlflow import CFGraph +from .controlflow import CFGraph from numba import consts, special from numba.core import types, errors, ir @@ -292,7 +292,7 @@ def dead_branch_prune(func_ir, called_args): func_ir is the IR called_args are the actual arguments with which the function is called """ - from .ir_utils import get_definition, guard, find_const, GuardException + from numba.ir_utils import get_definition, guard, find_const, GuardException DEBUG = 0 @@ -507,7 +507,7 @@ def rewrite_tuple_len(val, func_ir, called_args): if isinstance(argty, types.BaseTuple): rewrite_statement(func_ir, stmt, argty.count) - from .ir_utils import get_definition, guard + from numba.ir_utils import get_definition, guard for blk in func_ir.blocks.values(): for stmt in blk.body: if isinstance(stmt, ir.Assign): diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 82905ef5aff..934183110d9 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -1,6 +1,6 @@ import types as pytypes # avoid confusion with numba.types import ctypes -import numba +import numba.core.analysis from numba.core import utils, types, typing, errors, ir from numba import config, ir_utils, prange, rewrites from numba.parfor import internal_prange @@ -26,7 +26,7 @@ dead_code_elimination, ) -from numba.analysis import ( +from numba.core.analysis import ( compute_cfg_from_blocks, compute_use_defs, compute_live_variables) @@ -353,7 +353,7 @@ def inline_closure_call(func_ir, glbls, block, i, callee, typingctx=None, from numba import typed_passes # call branch pruning to simplify IR and avoid inference errors callee_ir._definitions = ir_utils.build_definitions(callee_ir.blocks) - numba.analysis.dead_branch_prune(callee_ir, arg_typs) + numba.core.analysis.dead_branch_prune(callee_ir, arg_typs) try: f_typemap, f_return_type, f_calltypes = typed_passes.type_inference_stage( typingctx, callee_ir, arg_typs, None) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 3b3342ab9b4..f23c631b03d 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -13,12 +13,12 @@ from llvmlite import ir as lir import numba -from numba.core import types, utils, typing, ir -from numba import config, analysis, cgutils, rewrites +from numba.core import types, utils, typing, ir, analysis +from numba import config, cgutils, rewrites from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) from numba.targets.imputils import impl_ret_untracked -from numba.analysis import (compute_live_map, compute_use_defs, +from numba.core.analysis import (compute_live_map, compute_use_defs, compute_cfg_from_blocks) from numba.core.errors import (TypingError, UnsupportedError, NumbaPendingDeprecationWarning, NumbaWarning, diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 9ae785b6f75..56770f782d3 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -19,7 +19,7 @@ get_call_table, is_pure, get_np_ufunc_typ, get_unused_var_name, find_potential_aliases, is_const_call) -from numba.analysis import (compute_use_defs, compute_live_map, +from numba.core.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) from numba.core.typing import signature from numba import config diff --git a/numba/parfor.py b/numba/parfor.py index 830c2533635..d9e31b23542 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -25,8 +25,8 @@ import operator import numba.core.ir -from numba.core import types, typing, utils, errors, ir -from numba import ir_utils, rewrites, config, analysis, prange, pndindex +from numba.core import types, typing, utils, errors, ir, analysis +from numba import ir_utils, rewrites, config, prange, pndindex from numba import postproc, typeinfer from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate @@ -80,7 +80,7 @@ find_potential_aliases, replace_var_names) -from numba.analysis import (compute_use_defs, compute_live_map, +from numba.core.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) from numba.core.controlflow import CFGraph from numba.core.typing import npydecl, signature diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index 5bc5e0fb78f..19d307491fa 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -6,8 +6,8 @@ import types as pytypes import numpy import operator -from numba import analysis, config, cgutils -from numba.core import types, typing, ir +from numba import config, cgutils +from numba.core import types, typing, ir, analysis from numba.ir_utils import ( mk_unique_var, replace_vars_inner, @@ -22,7 +22,7 @@ find_const, is_namedtuple_class, build_definitions) -from numba.analysis import (compute_cfg_from_blocks) +from numba.core.analysis import (compute_cfg_from_blocks) from numba.core.typing import npydecl, signature import collections import copy diff --git a/numba/postproc.py b/numba/postproc.py index 5d37e9f93cf..423cb82bb2b 100644 --- a/numba/postproc.py +++ b/numba/postproc.py @@ -1,5 +1,5 @@ -from numba import analysis, transforms -from numba.core import utils, ir +from numba import transforms +from numba.core import utils, ir, analysis class YieldPoint(object): diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index 63dd1e8c8bd..78cc4122170 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -7,7 +7,7 @@ from numba.core import types, errors, ir from numba.tests.support import TestCase, MemoryLeakMixin, SerialMixin -from numba.analysis import dead_branch_prune, rewrite_semantic_constants +from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants _GLOBAL = 123 diff --git a/numba/transforms.py b/numba/transforms.py index a17f6b39078..faf6e7ff117 100644 --- a/numba/transforms.py +++ b/numba/transforms.py @@ -6,10 +6,10 @@ from collections import namedtuple, defaultdict import logging -from numba.analysis import compute_cfg_from_blocks, find_top_level_loops +from numba.core.analysis import compute_cfg_from_blocks, find_top_level_loops from numba import ir_utils from numba.core import errors, ir -from numba.analysis import compute_use_defs +from numba.core.analysis import compute_use_defs _logger = logging.getLogger(__name__) diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index 7b039c0d6ad..216490413cf 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -6,13 +6,7 @@ from numba.core import errors, types, ir, bytecode from .special import literal_unroll import warnings -from .analysis import ( - dead_branch_prune, - rewrite_semantic_constants, - find_literally_calls, - compute_cfg_from_blocks, - compute_use_defs, -) +from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls,compute_cfg_from_blocks, compute_use_defs from contextlib import contextmanager from .inline_closurecall import InlineClosureCallPass, inline_closure_call from .ir_utils import (guard, resolve_func_from_module, simplify_CFG, From 7badf852d83da830e82d01b24185170cbf86899d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 18:10:00 +0000 Subject: [PATCH 338/595] Create cpython submodule --- numba/cpython/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/cpython/__init__.py diff --git a/numba/cpython/__init__.py b/numba/cpython/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 7d538df80e474e59d7430bdc81b6b971b58ea5c4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 18:11:10 +0000 Subject: [PATCH 339/595] Move slicing.py to numba/cpython --- numba/{core => cpython}/slicing.py | 0 numba/np/arrayobj.py | 3 ++- numba/targets/base.py | 2 +- numba/targets/boxing.py | 2 +- numba/targets/listobj.py | 3 ++- numba/targets/setobj.py | 2 +- numba/unicode.py | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) rename numba/{core => cpython}/slicing.py (100%) diff --git a/numba/core/slicing.py b/numba/cpython/slicing.py similarity index 100% rename from numba/core/slicing.py rename to numba/cpython/slicing.py diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 6256b48476c..ab6dbc58ed7 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -15,7 +15,7 @@ import numpy as np from numba import cgutils, extending, pndindex -from numba.core import types, utils, typing, errors, slicing +from numba.core import types, utils, typing, errors from numba.numpy_support import (as_dtype, carray, farray, is_contiguous, is_fortran) from numba.numpy_support import type_can_asarray, is_nonelike @@ -29,6 +29,7 @@ from numba.core.typing import signature from numba.extending import register_jitable, overload, overload_method from numba.misc import quicksort, mergesort +from numba.cpython import slicing def set_range_metadata(builder, load, lower_bound, upper_bound): diff --git a/numba/targets/base.py b/numba/targets/base.py index 297be14ae73..d33e3847c3f 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -272,7 +272,7 @@ def refresh(self): from numba.targets import (arraymath, enumimpl, iterators, numbers, optional, polynomial, rangeobj, tupleobj, gdb_hook, hashing, heapq, literal) - from numba.core import slicing + from numba.cpython import slicing from numba.np import linalg try: diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 0ae49cc0227..4c0dc47f0b7 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -368,7 +368,7 @@ def unbox_slice(typ, obj, c): """ Convert object *obj* to a native slice structure. """ - from numba.core import slicing + from numba.cpython import slicing ok, start, stop, step = c.pyapi.slice_as_ints(obj) sli = c.context.make_helper(c.builder, typ) sli.start = start diff --git a/numba/targets/listobj.py b/numba/targets/listobj.py index 727fe3d5010..1ae623bd39d 100644 --- a/numba/targets/listobj.py +++ b/numba/targets/listobj.py @@ -8,7 +8,7 @@ from llvmlite import ir from numba import cgutils -from numba.core import types, typing, errors, slicing +from numba.core import types, typing, errors from numba.targets.imputils import (lower_builtin, lower_cast, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, @@ -16,6 +16,7 @@ from numba.extending import overload_method, overload from numba.core.utils import cached_property from numba.misc import quicksort +from numba.cpython import slicing def get_list_payload(context, builder, list_type, value): diff --git a/numba/targets/setobj.py b/numba/targets/setobj.py index b0bcdfc69b6..a4f17d622ee 100644 --- a/numba/targets/setobj.py +++ b/numba/targets/setobj.py @@ -17,7 +17,7 @@ for_iter, call_len, RefType) from numba.core.utils import cached_property from numba.misc import quicksort -from numba.core import slicing +from numba.cpython import slicing def get_payload_struct(context, builder, set_type, ptr): diff --git a/numba/unicode.py b/numba/unicode.py index 317151cc1e5..33cdc6bcb6b 100644 --- a/numba/unicode.py +++ b/numba/unicode.py @@ -27,7 +27,6 @@ PY_UNICODE_4BYTE_KIND, PY_UNICODE_WCHAR_KIND, ) -from numba.core import slicing from numba._helperlib import c_helpers from numba.targets.hashing import _Py_hash_t from numba.unsafe.bytes import memcpy_region @@ -63,6 +62,7 @@ _Py_ISALPHA, _PyUnicode_IsDigit, _PyUnicode_IsDecimalDigit) +from numba.cpython import slicing _py38_or_later = utils.PYVERSION >= (3, 8) From 97b921e366a83e7ac0c25067d3c040364732cfa1 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 18:16:56 +0000 Subject: [PATCH 340/595] Move targets/tupleobj.py to numba/cpython --- numba/{targets => cpython}/tupleobj.py | 0 numba/targets/base.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{targets => cpython}/tupleobj.py (100%) diff --git a/numba/targets/tupleobj.py b/numba/cpython/tupleobj.py similarity index 100% rename from numba/targets/tupleobj.py rename to numba/cpython/tupleobj.py diff --git a/numba/targets/base.py b/numba/targets/base.py index d33e3847c3f..27073ff5592 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -270,9 +270,9 @@ def refresh(self): """ # Populate built-in registry from numba.targets import (arraymath, enumimpl, iterators, numbers, - optional, polynomial, rangeobj, tupleobj, + optional, polynomial, rangeobj, gdb_hook, hashing, heapq, literal) - from numba.cpython import slicing + from numba.cpython import slicing, tupleobj from numba.np import linalg try: From 8a83fd9682120afd64f67ad9453c5e423d9fd21f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 18:24:55 +0000 Subject: [PATCH 341/595] Move targets/setobj.py to numba/cpython --- numba/{targets => cpython}/setobj.py | 0 numba/targets/boxing.py | 3 ++- numba/targets/cpu.py | 5 ++--- 3 files changed, 4 insertions(+), 4 deletions(-) rename numba/{targets => cpython}/setobj.py (100%) diff --git a/numba/targets/setobj.py b/numba/cpython/setobj.py similarity index 100% rename from numba/targets/setobj.py rename to numba/cpython/setobj.py diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 4c0dc47f0b7..083a44aad72 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -8,7 +8,8 @@ from numba.core import types from numba.pythonapi import box, unbox, reflect, NativeValue -from numba.targets import listobj, setobj +from numba.targets import listobj +from numba.cpython import setobj # # Scalar types diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 3f99173f1c2..a1c488adea1 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -10,9 +10,7 @@ from numba.core import utils, types from numba import cgutils from numba.core.utils import cached_property -from numba.targets import ( - callconv, codegen, externals, intrinsics, listobj, setobj, dictimpl, -) +from numba.targets import callconv, codegen, externals, intrinsics, listobj, dictimpl from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock @@ -20,6 +18,7 @@ from numba.targets import fastmathpass from numba.targets.cpu_options import (ParallelOptions, FastMathOptions, InlineOptions) +from numba.cpython import setobj # Keep those structures in sync with _dynfunc.c. From 6b49da57c02ca56fe6486e1931c9499f2faf8930 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 19:35:37 +0000 Subject: [PATCH 342/595] Move targets/charseq.py to numba/cpython --- numba/__init__.py | 2 +- numba/{ => cpython}/charseq.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => cpython}/charseq.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index 13105e857e2..2b506b57d26 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -43,7 +43,7 @@ from numba.withcontexts import objmode_context as objmode # Enable bytes/unicode array support -import numba.charseq +import numba.cpython.charseq # Keep this for backward compatibility. test = runtests.main diff --git a/numba/charseq.py b/numba/cpython/charseq.py similarity index 100% rename from numba/charseq.py rename to numba/cpython/charseq.py From fb6c25e269eb98604d8680e5e51ceba8b7819f9e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 19:43:08 +0000 Subject: [PATCH 343/595] Move targets/builtins.py to numba/cpython --- numba/core/typing/builtins.py | 2 +- numba/{targets => cpython}/builtins.py | 6 +----- numba/parfor.py | 13 +++++++------ numba/targets/base.py | 3 ++- numba/targets/cmathimpl.py | 3 ++- numba/targets/npyimpl.py | 3 ++- 6 files changed, 15 insertions(+), 15 deletions(-) rename numba/{targets => cpython}/builtins.py (98%) diff --git a/numba/core/typing/builtins.py b/numba/core/typing/builtins.py index 97aafc56a68..74ca102e2db 100644 --- a/numba/core/typing/builtins.py +++ b/numba/core/typing/builtins.py @@ -1010,7 +1010,7 @@ def generic_resolve(self, deferred, attr): #------------------------------------------------------------------------------ -from numba.targets.builtins import get_type_min_value, get_type_max_value +from numba.cpython.builtins import get_type_min_value, get_type_max_value @infer_global(get_type_min_value) @infer_global(get_type_max_value) diff --git a/numba/targets/builtins.py b/numba/cpython/builtins.py similarity index 98% rename from numba/targets/builtins.py rename to numba/cpython/builtins.py index fa1c0496e51..216823d7c50 100644 --- a/numba/targets/builtins.py +++ b/numba/cpython/builtins.py @@ -8,11 +8,7 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from .imputils import (lower_builtin, lower_getattr, lower_getattr_generic, - lower_cast, lower_constant, iternext_impl, - call_getiter, call_iternext, - impl_ret_borrowed, impl_ret_untracked, - numba_typeref_ctor) +from numba.targets.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, iternext_impl, call_getiter, call_iternext, impl_ret_borrowed, impl_ret_untracked, numba_typeref_ctor from numba.core import typing, types, utils from numba import cgutils from numba.extending import overload, intrinsic diff --git a/numba/parfor.py b/numba/parfor.py index d9e31b23542..96b53e82345 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -93,6 +93,7 @@ import numpy import numpy as np from numba.parfors import array_analysis +import numba.cpython.builtins # circular dependency: import numba.npyufunc.dufunc.DUFunc # wrapped pretty print @@ -131,7 +132,7 @@ def min_1(in_arr): def min_1(in_arr): numba.parfor.init_prange() min_checker(len(in_arr)) - val = numba.targets.builtins.get_type_max_value(in_arr.dtype) + val = numba.cpython.builtins.get_type_max_value(in_arr.dtype) for i in numba.parfor.internal_prange(len(in_arr)): val = min(val, in_arr[i]) return val @@ -139,7 +140,7 @@ def min_1(in_arr): def min_1(in_arr): numba.parfor.init_prange() min_checker(len(in_arr)) - val = numba.targets.builtins.get_type_max_value(in_arr.dtype) + val = numba.cpython.builtins.get_type_max_value(in_arr.dtype) for i in numba.pndindex(in_arr.shape): val = min(val, in_arr[i]) return val @@ -153,7 +154,7 @@ def max_1(in_arr): def max_1(in_arr): numba.parfor.init_prange() max_checker(len(in_arr)) - val = numba.targets.builtins.get_type_min_value(in_arr.dtype) + val = numba.cpython.builtins.get_type_min_value(in_arr.dtype) for i in numba.parfor.internal_prange(len(in_arr)): val = max(val, in_arr[i]) return val @@ -161,7 +162,7 @@ def max_1(in_arr): def max_1(in_arr): numba.parfor.init_prange() max_checker(len(in_arr)) - val = numba.targets.builtins.get_type_min_value(in_arr.dtype) + val = numba.cpython.builtins.get_type_min_value(in_arr.dtype) for i in numba.pndindex(in_arr.shape): val = max(val, in_arr[i]) return val @@ -171,7 +172,7 @@ def argmin_parallel_impl(in_arr): numba.parfor.init_prange() argmin_checker(len(in_arr)) A = in_arr.ravel() - init_val = numba.targets.builtins.get_type_max_value(A.dtype) + init_val = numba.cpython.builtins.get_type_max_value(A.dtype) ival = typing.builtins.IndexValue(0, init_val) for i in numba.parfor.internal_prange(len(A)): curr_ival = typing.builtins.IndexValue(i, A[i]) @@ -182,7 +183,7 @@ def argmax_parallel_impl(in_arr): numba.parfor.init_prange() argmax_checker(len(in_arr)) A = in_arr.ravel() - init_val = numba.targets.builtins.get_type_min_value(A.dtype) + init_val = numba.cpython.builtins.get_type_min_value(A.dtype) ival = typing.builtins.IndexValue(0, init_val) for i in numba.parfor.internal_prange(len(A)): curr_ival = typing.builtins.IndexValue(i, A[i]) diff --git a/numba/targets/base.py b/numba/targets/base.py index 27073ff5592..7724e1592c8 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -18,10 +18,11 @@ from numba.core.compiler_lock import global_compiler_lock from numba.pythonapi import PythonAPI from numba.np import arrayobj -from numba.targets import builtins, imputils +from numba.targets import imputils from .imputils import (user_function, user_generator, builtin_registry, impl_ret_borrowed, RegistryLoader) +from numba.cpython import builtins GENERIC_POINTER = Type.pointer(Type.int(8)) PYOBJECT = GENERIC_POINTER diff --git a/numba/targets/cmathimpl.py b/numba/targets/cmathimpl.py index 7ec726ecb14..72256f02da2 100644 --- a/numba/targets/cmathimpl.py +++ b/numba/targets/cmathimpl.py @@ -13,7 +13,8 @@ from numba import cgutils from numba.core import types from numba.core.typing import signature -from numba.targets import builtins, mathimpl +from numba.targets import mathimpl +from numba.cpython import builtins registry = Registry() lower = registry.lower diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index 18ac79b0485..bc06ccd37d3 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -13,7 +13,7 @@ import numpy as np import operator -from numba.targets import builtins, callconv, ufunc_db +from numba.targets import callconv, ufunc_db from numba.np import arrayobj from numba.targets.imputils import Registry, impl_ret_new_ref, force_error_model from numba import cgutils, numpy_support @@ -23,6 +23,7 @@ from numba.extending import overload, intrinsic from numba.core import errors +from numba.cpython import builtins registry = Registry() lower = registry.lower From 38e4f5f426da46fcd603be6d569577d640f88561 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 19:52:05 +0000 Subject: [PATCH 344/595] Move targets/cmathimpl.py to numba/cpython --- numba/{targets => cpython}/cmathimpl.py | 0 numba/cuda/target.py | 2 +- numba/targets/cpu.py | 5 +++-- numba/targets/npyfuncs.py | 3 ++- numba/targets/ufunc_db.py | 3 ++- 5 files changed, 8 insertions(+), 5 deletions(-) rename numba/{targets => cpython}/cmathimpl.py (100%) diff --git a/numba/targets/cmathimpl.py b/numba/cpython/cmathimpl.py similarity index 100% rename from numba/targets/cmathimpl.py rename to numba/cpython/cmathimpl.py diff --git a/numba/cuda/target.py b/numba/cuda/target.py index 314ffa6339d..65e375551ad 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -9,13 +9,13 @@ from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv -from numba.targets import cmathimpl from numba.core.typing import cmathdecl from numba import itanium_mangler from .cudadrv import nvvm from numba.cuda import codegen, nvvmutils from .decorators import jitdevice +from numba.cpython import cmathimpl # ----------------------------------------------------------------------------- diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index a1c488adea1..56cd1d1799f 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -64,8 +64,9 @@ def init(self): def load_additional_registries(self): # Add target specific implementations - from numba.targets import (cffiimpl, cmathimpl, mathimpl, npyimpl, - printimpl, randomimpl) + from numba.targets import (cffiimpl, mathimpl, npyimpl, printimpl, + randomimpl) + from numba.cpython import cmathimpl self.install_registry(cmathimpl.registry) self.install_registry(cffiimpl.registry) self.install_registry(mathimpl.registry) diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index b796cdc3e58..dd5eb3dcef0 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -12,7 +12,8 @@ from numba.targets.imputils import impl_ret_untracked from numba import cgutils, lowering from numba.core import typing, types, errors -from numba.targets import cmathimpl, mathimpl, numbers, npdatetime +from numba.targets import mathimpl, numbers, npdatetime +from numba.cpython import cmathimpl # some NumPy constants. Note that we could generate some of them using # the math library, but having the values copied from npy_math seems to diff --git a/numba/targets/ufunc_db.py b/numba/targets/ufunc_db.py index 31d7aff909a..31c9697cbf7 100644 --- a/numba/targets/ufunc_db.py +++ b/numba/targets/ufunc_db.py @@ -47,7 +47,8 @@ def _fill_ufunc_db(ufunc_db): # some of these imports would cause a problem of circular # imports if done at global scope when importing the numba # module. - from numba.targets import numbers, npyfuncs, mathimpl, cmathimpl + from numba.targets import numbers, npyfuncs, mathimpl + from numba.cpython import cmathimpl from numba.numpy_support import numpy_version ufunc_db[np.negative] = { From e70113681e12a574e85f1a502d1d350e2d040446 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 19:54:10 +0000 Subject: [PATCH 345/595] Move targets/enumimpl.py to numba/cpython --- numba/{targets => cpython}/enumimpl.py | 5 ++--- numba/targets/base.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) rename numba/{targets => cpython}/enumimpl.py (93%) diff --git a/numba/targets/enumimpl.py b/numba/cpython/enumimpl.py similarity index 93% rename from numba/targets/enumimpl.py rename to numba/cpython/enumimpl.py index ed10d816105..d6787dbd06f 100644 --- a/numba/targets/enumimpl.py +++ b/numba/cpython/enumimpl.py @@ -3,9 +3,8 @@ """ import operator -from .imputils import (lower_builtin, lower_getattr, lower_getattr_generic, - lower_cast, lower_constant, impl_ret_untracked) -from .. import types +from numba.targets.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, impl_ret_untracked +from numba.core import types @lower_builtin(operator.eq, types.EnumMember, types.EnumMember) diff --git a/numba/targets/base.py b/numba/targets/base.py index 7724e1592c8..b06b8a3f2d5 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -270,10 +270,10 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, enumimpl, iterators, numbers, + from numba.targets import (arraymath, iterators, numbers, optional, polynomial, rangeobj, gdb_hook, hashing, heapq, literal) - from numba.cpython import slicing, tupleobj + from numba.cpython import slicing, tupleobj, enumimpl from numba.np import linalg try: From d73f3cd06c3909438a52106dece5651498abd60f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:00:22 +0000 Subject: [PATCH 346/595] Move targets/hashing.py to numba/cpython --- numba/{targets => cpython}/hashing.py | 0 numba/targets/base.py | 4 ++-- numba/tests/test_hashing.py | 2 +- numba/unicode.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename numba/{targets => cpython}/hashing.py (100%) diff --git a/numba/targets/hashing.py b/numba/cpython/hashing.py similarity index 100% rename from numba/targets/hashing.py rename to numba/cpython/hashing.py diff --git a/numba/targets/base.py b/numba/targets/base.py index b06b8a3f2d5..796415af0b6 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -272,8 +272,8 @@ def refresh(self): # Populate built-in registry from numba.targets import (arraymath, iterators, numbers, optional, polynomial, rangeobj, - gdb_hook, hashing, heapq, literal) - from numba.cpython import slicing, tupleobj, enumimpl + gdb_hook, heapq, literal) + from numba.cpython import slicing, tupleobj, enumimpl, hashing from numba.np import linalg try: diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index 773a9d139b7..662755a6aa2 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -14,9 +14,9 @@ from numba.core import types, utils import numba.unittest_support as unittest from numba.tests.support import TestCase, tag, CompilationCache -from numba.targets import hashing from numba.unicode import compile_time_get_string_data +from numba.cpython import hashing def hash_usecase(x): diff --git a/numba/unicode.py b/numba/unicode.py index 33cdc6bcb6b..db0bc0cfbf3 100644 --- a/numba/unicode.py +++ b/numba/unicode.py @@ -28,7 +28,7 @@ PY_UNICODE_WCHAR_KIND, ) from numba._helperlib import c_helpers -from numba.targets.hashing import _Py_hash_t +from numba.cpython.hashing import _Py_hash_t from numba.unsafe.bytes import memcpy_region from numba.core.errors import TypingError from numba.unicode_support import (_Py_TOUPPER, _Py_TOLOWER, _Py_UCS4, From 0643d5afb13545af16ec244bf72dcab953ee38e1 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:03:48 +0000 Subject: [PATCH 347/595] Move targets/heapq.py to numba/cpython --- numba/{targets => cpython}/heapq.py | 0 numba/targets/base.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{targets => cpython}/heapq.py (100%) diff --git a/numba/targets/heapq.py b/numba/cpython/heapq.py similarity index 100% rename from numba/targets/heapq.py rename to numba/cpython/heapq.py diff --git a/numba/targets/base.py b/numba/targets/base.py index 796415af0b6..b595de3f8e5 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -272,8 +272,8 @@ def refresh(self): # Populate built-in registry from numba.targets import (arraymath, iterators, numbers, optional, polynomial, rangeobj, - gdb_hook, heapq, literal) - from numba.cpython import slicing, tupleobj, enumimpl, hashing + gdb_hook, literal) + from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq) from numba.np import linalg try: From 1ca5922911df282da445b7bdfc0ce5e94ced9758 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:05:31 +0000 Subject: [PATCH 348/595] Move targets/iterators.py to numba/cpython --- numba/{targets => cpython}/iterators.py | 0 numba/targets/base.py | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) rename numba/{targets => cpython}/iterators.py (100%) diff --git a/numba/targets/iterators.py b/numba/cpython/iterators.py similarity index 100% rename from numba/targets/iterators.py rename to numba/cpython/iterators.py diff --git a/numba/targets/base.py b/numba/targets/base.py index b595de3f8e5..7134d8a6698 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -270,10 +270,11 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, iterators, numbers, + from numba.targets import (arraymath, numbers, optional, polynomial, rangeobj, gdb_hook, literal) - from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq) + from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, + iterators) from numba.np import linalg try: From 191751073e56bcaa50608c3ec508b0099e1942fe Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:08:05 +0000 Subject: [PATCH 349/595] Move targets/listobj.py to numba/cpython --- numba/{targets => cpython}/listobj.py | 0 numba/listobject.py | 2 +- numba/targets/boxing.py | 3 +-- numba/targets/cpu.py | 4 ++-- numba/targets/rangeobj.py | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) rename numba/{targets => cpython}/listobj.py (100%) diff --git a/numba/targets/listobj.py b/numba/cpython/listobj.py similarity index 100% rename from numba/targets/listobj.py rename to numba/cpython/listobj.py diff --git a/numba/listobject.py b/numba/listobject.py index 458f3c1d79f..a50bd197baa 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -38,7 +38,7 @@ _container_get_data, _container_get_meminfo, ) -from numba.targets import listobj +from numba.cpython import listobj ll_list_type = cgutils.voidptr_t ll_listiter_type = cgutils.voidptr_t diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 083a44aad72..dade7b141f1 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -8,8 +8,7 @@ from numba.core import types from numba.pythonapi import box, unbox, reflect, NativeValue -from numba.targets import listobj -from numba.cpython import setobj +from numba.cpython import setobj, listobj # # Scalar types diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 56cd1d1799f..5b352e61f8c 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -10,7 +10,7 @@ from numba.core import utils, types from numba import cgutils from numba.core.utils import cached_property -from numba.targets import callconv, codegen, externals, intrinsics, listobj, dictimpl +from numba.targets import callconv, codegen, externals, intrinsics, dictimpl from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock @@ -18,7 +18,7 @@ from numba.targets import fastmathpass from numba.targets.cpu_options import (ParallelOptions, FastMathOptions, InlineOptions) -from numba.cpython import setobj +from numba.cpython import setobj, listobj # Keep those structures in sync with _dynfunc.c. diff --git a/numba/targets/rangeobj.py b/numba/targets/rangeobj.py index 43ad6efaa8f..537fc401d03 100644 --- a/numba/targets/rangeobj.py +++ b/numba/targets/rangeobj.py @@ -8,7 +8,7 @@ from numba import cgutils, prange from numba.core import types -from numba.targets.listobj import ListIterInstance +from numba.cpython.listobj import ListIterInstance from numba.np.arrayobj import make_array from numba.targets.imputils import (lower_builtin, lower_cast, iterator_impl, impl_ret_untracked) From 186cb52a349e959d7b1de37bc5118267c28310e3 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:12:44 +0000 Subject: [PATCH 350/595] Move targets/mathimpl.py to numba/cpython --- numba/cpython/cmathimpl.py | 3 +-- numba/{targets => cpython}/mathimpl.py | 0 numba/targets/cpu.py | 5 ++--- numba/targets/npyfuncs.py | 4 ++-- numba/targets/numbers.py | 7 +++---- numba/targets/ufunc_db.py | 4 ++-- 6 files changed, 10 insertions(+), 13 deletions(-) rename numba/{targets => cpython}/mathimpl.py (100%) diff --git a/numba/cpython/cmathimpl.py b/numba/cpython/cmathimpl.py index 72256f02da2..4015a658840 100644 --- a/numba/cpython/cmathimpl.py +++ b/numba/cpython/cmathimpl.py @@ -13,8 +13,7 @@ from numba import cgutils from numba.core import types from numba.core.typing import signature -from numba.targets import mathimpl -from numba.cpython import builtins +from numba.cpython import builtins, mathimpl registry = Registry() lower = registry.lower diff --git a/numba/targets/mathimpl.py b/numba/cpython/mathimpl.py similarity index 100% rename from numba/targets/mathimpl.py rename to numba/cpython/mathimpl.py diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 5b352e61f8c..30c611d6433 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -64,9 +64,8 @@ def init(self): def load_additional_registries(self): # Add target specific implementations - from numba.targets import (cffiimpl, mathimpl, npyimpl, printimpl, - randomimpl) - from numba.cpython import cmathimpl + from numba.targets import (cffiimpl, npyimpl, printimpl, randomimpl) + from numba.cpython import cmathimpl, mathimpl self.install_registry(cmathimpl.registry) self.install_registry(cffiimpl.registry) self.install_registry(mathimpl.registry) diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index dd5eb3dcef0..82d453c1f3e 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -12,8 +12,8 @@ from numba.targets.imputils import impl_ret_untracked from numba import cgutils, lowering from numba.core import typing, types, errors -from numba.targets import mathimpl, numbers, npdatetime -from numba.cpython import cmathimpl +from numba.targets import numbers, npdatetime +from numba.cpython import cmathimpl, mathimpl # some NumPy constants. Note that we could generate some of them using # the math library, but having the values copied from npy_math seems to diff --git a/numba/targets/numbers.py b/numba/targets/numbers.py index 131fe7c308e..aac2f513966 100644 --- a/numba/targets/numbers.py +++ b/numba/targets/numbers.py @@ -18,7 +18,6 @@ from numba.extending import intrinsic, overload_method from numba.unsafe.numbers import viewer - def _int_arith_flags(rettype): """ Return the modifier flags for integer arithmetic. @@ -849,7 +848,7 @@ def real_abs_impl(context, builder, sig, args): def real_negate_impl(context, builder, sig, args): - from numba.targets import mathimpl + from numba.cpython import mathimpl res = mathimpl.negate_real(builder, args[0]) return impl_ret_untracked(context, builder, sig.return_type, res) @@ -938,7 +937,7 @@ def complex_imag_impl(context, builder, typ, value): @lower_builtin("complex.conjugate", types.Complex) def complex_conjugate_impl(context, builder, sig, args): - from . import mathimpl + from numba.cpython import mathimpl z = context.make_complex(builder, sig.args[0], args[0]) z.imag = mathimpl.negate_real(builder, z.imag) res = z._getvalue() @@ -1094,7 +1093,7 @@ def complex_div(a, b): def complex_negate_impl(context, builder, sig, args): - from . import mathimpl + from numba.cpython import mathimpl [typ] = sig.args [val] = args cmplx = context.make_complex(builder, typ, value=val) diff --git a/numba/targets/ufunc_db.py b/numba/targets/ufunc_db.py index 31c9697cbf7..d7b3357e296 100644 --- a/numba/targets/ufunc_db.py +++ b/numba/targets/ufunc_db.py @@ -47,8 +47,8 @@ def _fill_ufunc_db(ufunc_db): # some of these imports would cause a problem of circular # imports if done at global scope when importing the numba # module. - from numba.targets import numbers, npyfuncs, mathimpl - from numba.cpython import cmathimpl + from numba.targets import numbers, npyfuncs + from numba.cpython import cmathimpl, mathimpl from numba.numpy_support import numpy_version ufunc_db[np.negative] = { From 085c3d5ce9183f20b0efd7462471c0a818e572a6 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:16:54 +0000 Subject: [PATCH 351/595] Move targets/numbers.py to numba/cpython --- numba/{targets => cpython}/numbers.py | 0 numba/targets/base.py | 5 ++--- numba/targets/npyfuncs.py | 4 ++-- numba/targets/ufunc_db.py | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) rename numba/{targets => cpython}/numbers.py (100%) diff --git a/numba/targets/numbers.py b/numba/cpython/numbers.py similarity index 100% rename from numba/targets/numbers.py rename to numba/cpython/numbers.py diff --git a/numba/targets/base.py b/numba/targets/base.py index 7134d8a6698..9b75c19da7a 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -270,11 +270,10 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, numbers, - optional, polynomial, rangeobj, + from numba.targets import (arraymath, optional, polynomial, rangeobj, gdb_hook, literal) from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, - iterators) + iterators, numbers) from numba.np import linalg try: diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index 82d453c1f3e..476e20aab77 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -12,8 +12,8 @@ from numba.targets.imputils import impl_ret_untracked from numba import cgutils, lowering from numba.core import typing, types, errors -from numba.targets import numbers, npdatetime -from numba.cpython import cmathimpl, mathimpl +from numba.targets import npdatetime +from numba.cpython import cmathimpl, mathimpl, numbers # some NumPy constants. Note that we could generate some of them using # the math library, but having the values copied from npy_math seems to diff --git a/numba/targets/ufunc_db.py b/numba/targets/ufunc_db.py index d7b3357e296..2d42b94d825 100644 --- a/numba/targets/ufunc_db.py +++ b/numba/targets/ufunc_db.py @@ -47,8 +47,8 @@ def _fill_ufunc_db(ufunc_db): # some of these imports would cause a problem of circular # imports if done at global scope when importing the numba # module. - from numba.targets import numbers, npyfuncs - from numba.cpython import cmathimpl, mathimpl + from numba.targets import npyfuncs + from numba.cpython import cmathimpl, mathimpl, numbers from numba.numpy_support import numpy_version ufunc_db[np.negative] = { From 993a64ca2cb4bfb79403f3fb85cf91d9b0620c4b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:17:55 +0000 Subject: [PATCH 352/595] Move targets/printimpl.py to numba/cpython --- numba/{targets => cpython}/printimpl.py | 0 numba/targets/cpu.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{targets => cpython}/printimpl.py (100%) diff --git a/numba/targets/printimpl.py b/numba/cpython/printimpl.py similarity index 100% rename from numba/targets/printimpl.py rename to numba/cpython/printimpl.py diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 30c611d6433..bdef9bd022e 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -64,8 +64,8 @@ def init(self): def load_additional_registries(self): # Add target specific implementations - from numba.targets import (cffiimpl, npyimpl, printimpl, randomimpl) - from numba.cpython import cmathimpl, mathimpl + from numba.targets import (cffiimpl, npyimpl, randomimpl) + from numba.cpython import cmathimpl, mathimpl, printimpl self.install_registry(cmathimpl.registry) self.install_registry(cffiimpl.registry) self.install_registry(mathimpl.registry) From 4f71b1a478b66f5527e0968bd93e1b20116774e5 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:21:03 +0000 Subject: [PATCH 353/595] Move targets/randomimpl.py to numba/cpython --- numba/{targets => cpython}/randomimpl.py | 0 numba/targets/cpu.py | 5 ++--- 2 files changed, 2 insertions(+), 3 deletions(-) rename numba/{targets => cpython}/randomimpl.py (100%) diff --git a/numba/targets/randomimpl.py b/numba/cpython/randomimpl.py similarity index 100% rename from numba/targets/randomimpl.py rename to numba/cpython/randomimpl.py diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index bdef9bd022e..56bee0f316c 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -64,15 +64,14 @@ def init(self): def load_additional_registries(self): # Add target specific implementations - from numba.targets import (cffiimpl, npyimpl, randomimpl) - from numba.cpython import cmathimpl, mathimpl, printimpl + from numba.targets import (cffiimpl, npyimpl) + from numba.cpython import cmathimpl, mathimpl, printimpl, randomimpl self.install_registry(cmathimpl.registry) self.install_registry(cffiimpl.registry) self.install_registry(mathimpl.registry) self.install_registry(npyimpl.registry) self.install_registry(printimpl.registry) self.install_registry(randomimpl.registry) - self.install_registry(randomimpl.registry) # load 3rd party extensions numba.entrypoints.init_all() From b852d8f2a098de2d17f1eaf37f3417cca69c4af6 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:23:13 +0000 Subject: [PATCH 354/595] Move targets/rangeobj.py to numba/cpython --- numba/{targets => cpython}/rangeobj.py | 0 numba/inline_closurecall.py | 2 +- numba/targets/base.py | 4 ++-- numba/tests/test_range.py | 4 +--- 4 files changed, 4 insertions(+), 6 deletions(-) rename numba/{targets => cpython}/rangeobj.py (100%) diff --git a/numba/targets/rangeobj.py b/numba/cpython/rangeobj.py similarity index 100% rename from numba/targets/rangeobj.py rename to numba/cpython/rangeobj.py diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 934183110d9..78c010618c7 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -31,7 +31,7 @@ compute_use_defs, compute_live_variables) -from numba.targets.rangeobj import range_iter_len +from numba.cpython.rangeobj import range_iter_len from numba.unsafe.ndarray import empty_inferred as unsafe_empty_inferred import numpy as np import operator diff --git a/numba/targets/base.py b/numba/targets/base.py index 9b75c19da7a..30475d26e19 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -270,10 +270,10 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, optional, polynomial, rangeobj, + from numba.targets import (arraymath, optional, polynomial, gdb_hook, literal) from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, - iterators, numbers) + iterators, numbers, rangeobj) from numba.np import linalg try: diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index 55fe5445c8f..6585034efaa 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -9,7 +9,7 @@ from numba.core import types, utils from numba.tests.support import tag - +from numba.cpython.rangeobj import range_iter_len def loop1(n): s = 0 for i in range(n): @@ -45,8 +45,6 @@ def range_len2(a, b): def range_len3(a, b, c): return len(range(a, b, c)) - -from numba.targets.rangeobj import range_iter_len def range_iter_len1(a): return range_iter_len(iter(range(a))) From c49920c2aebe776484e10a02c1b2780a41954708 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:27:26 +0000 Subject: [PATCH 355/595] Move unicode.py to numba/cpython --- numba/cpython/charseq.py | 3 ++- numba/cpython/hashing.py | 2 +- numba/{ => cpython}/unicode.py | 0 numba/targets/cpu.py | 2 +- numba/tests/test_hashing.py | 2 +- numba/unicode_support.py | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) rename numba/{ => cpython}/unicode.py (100%) diff --git a/numba/cpython/charseq.py b/numba/cpython/charseq.py index 74f3229fcf3..7dfcb2104e7 100644 --- a/numba/cpython/charseq.py +++ b/numba/cpython/charseq.py @@ -4,10 +4,11 @@ from llvmlite import ir from numba.core import types -from numba import cgutils, unicode +from numba import cgutils from numba.extending import (overload, intrinsic, overload_method, lower_cast, register_jitable) from numba.cgutils import is_nonelike +from numba.cpython import unicode # bytes and str arrays items are of type CharSeq and UnicodeCharSeq, # respectively. See numpy/types/npytypes.py for CharSeq, diff --git a/numba/cpython/hashing.py b/numba/cpython/hashing.py index e447482e18e..494e97330bd 100644 --- a/numba/cpython/hashing.py +++ b/numba/cpython/hashing.py @@ -684,7 +684,7 @@ def _Py_HashBytes(val, _len): @overload_method(types.UnicodeType, '__hash__') def unicode_hash(val): - from numba.unicode import _kind_to_byte_width + from numba.cpython.unicode import _kind_to_byte_width def impl(val): kindwidth = _kind_to_byte_width(val._kind) diff --git a/numba/unicode.py b/numba/cpython/unicode.py similarity index 100% rename from numba/unicode.py rename to numba/cpython/unicode.py diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 56bee0f316c..05c41e622bf 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -60,7 +60,7 @@ def init(self): rtsys.initialize(self) # Initialize additional implementations - import numba.unicode + import numba.cpython.unicode def load_additional_registries(self): # Add target specific implementations diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index 662755a6aa2..f8a277a3108 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -15,7 +15,7 @@ import numba.unittest_support as unittest from numba.tests.support import TestCase, tag, CompilationCache -from numba.unicode import compile_time_get_string_data +from numba.cpython.unicode import compile_time_get_string_data from numba.cpython import hashing diff --git a/numba/unicode_support.py b/numba/unicode_support.py index e4ed4defb33..48b850cb9fc 100644 --- a/numba/unicode_support.py +++ b/numba/unicode_support.py @@ -136,7 +136,7 @@ def gettyperecord_impl(a): single character strings and code points. """ if isinstance(a, types.UnicodeType): - from numba.unicode import _get_code_point + from numba.cpython.unicode import _get_code_point def impl(a): if len(a) > 1: From 5a83f06ecb9b77d934ee209f3bdb0da395b0faae Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:32:55 +0000 Subject: [PATCH 356/595] Move unicode_support.py to numba/cpython --- numba/cpython/unicode.py | 2 +- numba/{ => cpython}/unicode_support.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => cpython}/unicode_support.py (100%) diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index db0bc0cfbf3..1a0199deafc 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -31,7 +31,7 @@ from numba.cpython.hashing import _Py_hash_t from numba.unsafe.bytes import memcpy_region from numba.core.errors import TypingError -from numba.unicode_support import (_Py_TOUPPER, _Py_TOLOWER, _Py_UCS4, +from numba.cpython.unicode_support import (_Py_TOUPPER, _Py_TOLOWER, _Py_UCS4, _Py_ISALNUM, _PyUnicode_ToUpperFull, _PyUnicode_ToLowerFull, diff --git a/numba/unicode_support.py b/numba/cpython/unicode_support.py similarity index 100% rename from numba/unicode_support.py rename to numba/cpython/unicode_support.py From 5766316e85013d8f96db61be02be9b13c0bdb7ce Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:33:29 +0000 Subject: [PATCH 357/595] Add cpython/unsafe dir --- numba/cpython/unsafe/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/cpython/unsafe/__init__.py diff --git a/numba/cpython/unsafe/__init__.py b/numba/cpython/unsafe/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 22dc2e03c8ee428d218b898487fa73e800b24034 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:37:15 +0000 Subject: [PATCH 358/595] Move unsafe/numbers.py to numba/cpython/unsafe --- numba/cpython/mathimpl.py | 2 +- numba/cpython/numbers.py | 2 +- numba/{ => cpython}/unsafe/numbers.py | 4 ++-- numba/tests/test_unsafe_intrinsics.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename numba/{ => cpython}/unsafe/numbers.py (96%) diff --git a/numba/cpython/mathimpl.py b/numba/cpython/mathimpl.py index 813b79418af..ac2a8e120e7 100644 --- a/numba/cpython/mathimpl.py +++ b/numba/cpython/mathimpl.py @@ -15,7 +15,7 @@ from numba.core import types, utils from numba.extending import overload from numba.core.typing import signature -from numba.unsafe.numbers import trailing_zeros +from numba.cpython.unsafe.numbers import trailing_zeros registry = Registry() diff --git a/numba/cpython/numbers.py b/numba/cpython/numbers.py index aac2f513966..01b264eecab 100644 --- a/numba/cpython/numbers.py +++ b/numba/cpython/numbers.py @@ -16,7 +16,7 @@ from numba.core import typing, types, utils, errors from numba import cgutils from numba.extending import intrinsic, overload_method -from numba.unsafe.numbers import viewer +from numba.cpython.unsafe.numbers import viewer def _int_arith_flags(rettype): """ diff --git a/numba/unsafe/numbers.py b/numba/cpython/unsafe/numbers.py similarity index 96% rename from numba/unsafe/numbers.py rename to numba/cpython/unsafe/numbers.py index 7902ece0e7c..50a95be26ec 100644 --- a/numba/unsafe/numbers.py +++ b/numba/cpython/unsafe/numbers.py @@ -1,7 +1,7 @@ """ This module provides the unsafe things for targets/numbers.py """ -from .. import types -from ..extending import intrinsic +from numba.core import types +from numba.extending import intrinsic from llvmlite import ir diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index 38e9e460203..2aed30c510b 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -8,7 +8,7 @@ from numba.unsafe.ndarray import to_fixed_tuple, empty_inferred from numba.unsafe.bytes import memcpy_region from numba.unsafe.refcount import dump_refcount -from numba.unsafe.numbers import trailing_zeros, leading_zeros +from numba.cpython.unsafe.numbers import trailing_zeros, leading_zeros from numba.core.errors import TypingError From 5336718fca28348462818743df90017024fe5007 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 30 Jan 2020 20:39:11 +0000 Subject: [PATCH 359/595] Move unsafe/tuple.py to numba/cpython/unsafe --- numba/{ => cpython}/unsafe/tuple.py | 0 numba/tests/test_unsafe_intrinsics.py | 2 +- numba/unsafe/ndarray.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename numba/{ => cpython}/unsafe/tuple.py (100%) diff --git a/numba/unsafe/tuple.py b/numba/cpython/unsafe/tuple.py similarity index 100% rename from numba/unsafe/tuple.py rename to numba/cpython/unsafe/tuple.py diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index 2aed30c510b..49b9dc0e74e 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -4,7 +4,7 @@ from numba.tests.support import TestCase, captured_stdout from numba import njit from numba.core import types -from numba.unsafe.tuple import tuple_setitem +from numba.cpython.unsafe.tuple import tuple_setitem from numba.unsafe.ndarray import to_fixed_tuple, empty_inferred from numba.unsafe.bytes import memcpy_region from numba.unsafe.refcount import dump_refcount diff --git a/numba/unsafe/ndarray.py b/numba/unsafe/ndarray.py index cc756e13cb9..d1e5cf818bb 100644 --- a/numba/unsafe/ndarray.py +++ b/numba/unsafe/ndarray.py @@ -8,7 +8,7 @@ from numba.targets.imputils import impl_ret_new_ref from numba.core.errors import RequireLiteralValue, TypingError -from .tuple import tuple_setitem +from numba.cpython.unsafe.tuple import tuple_setitem @intrinsic From e166bcb55d23dd317bcc350d9e79841cc311fd8f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:14:57 +0000 Subject: [PATCH 360/595] Move numba/_runtests.py to numba/testing --- numba/__init__.py | 3 ++- numba/runtests.py | 2 +- numba/{ => testing}/_runtests.py | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename numba/{ => testing}/_runtests.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index 2b506b57d26..2a87da94a85 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -11,7 +11,8 @@ __version__ = get_versions()['version'] del get_versions -from numba import config, _runtests as runtests +from numba import config +from numba.testing import _runtests as runtests from numba.core import types, errors # Re-export typeof diff --git a/numba/runtests.py b/numba/runtests.py index 6097a331f84..3c4bb4a4993 100644 --- a/numba/runtests.py +++ b/numba/runtests.py @@ -1,4 +1,4 @@ -from numba._runtests import _main, main +from numba.testing._runtests import _main, main if __name__ == '__main__': diff --git a/numba/_runtests.py b/numba/testing/_runtests.py similarity index 100% rename from numba/_runtests.py rename to numba/testing/_runtests.py From 95b5923adc26bb5655ddb1c823478cc0fe916160 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:16:59 +0000 Subject: [PATCH 361/595] Move numba/caching.py to numba/core --- numba/ccallback.py | 2 +- numba/{ => core}/caching.py | 0 numba/core/dispatcher.py | 2 +- numba/npyufunc/ufuncbuilder.py | 2 +- numba/npyufunc/wrappers.py | 2 +- numba/tests/test_dispatcher.py | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename numba/{ => core}/caching.py (100%) diff --git a/numba/ccallback.py b/numba/ccallback.py index dec9afe1135..3072a689782 100644 --- a/numba/ccallback.py +++ b/numba/ccallback.py @@ -9,7 +9,7 @@ from numba.core import utils from numba import compiler -from numba.caching import NullCache, FunctionCache +from numba.core.caching import NullCache, FunctionCache from numba.core.dispatcher import _FunctionCompiler from numba.targets import registry from numba.core.typing import signature diff --git a/numba/caching.py b/numba/core/caching.py similarity index 100% rename from numba/caching.py rename to numba/core/caching.py diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py index c1302e4f255..d12bbf3c707 100644 --- a/numba/core/dispatcher.py +++ b/numba/core/dispatcher.py @@ -20,7 +20,7 @@ from numba.core.typing.typeof import Purpose, typeof from numba.core.bytecode import get_code_object from numba.core.utils import reraise -from numba.caching import NullCache, FunctionCache +from numba.core.caching import NullCache, FunctionCache class OmittedArg(object): diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 9ce87b93591..6243ac197ab 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -15,7 +15,7 @@ from numba.npyufunc import _internal from numba.npyufunc.sigparse import parse_signature from numba.npyufunc.wrappers import build_ufunc_wrapper, build_gufunc_wrapper -from numba.caching import FunctionCache, NullCache +from numba.core.caching import FunctionCache, NullCache from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/npyufunc/wrappers.py b/numba/npyufunc/wrappers.py index 8510833bc77..e8ac18eceb1 100644 --- a/numba/npyufunc/wrappers.py +++ b/numba/npyufunc/wrappers.py @@ -7,7 +7,7 @@ from numba import cgutils from numba.core import types from numba.core.compiler_lock import global_compiler_lock -from ..caching import make_library_cache, NullCache +from numba.core.caching import make_library_cache, NullCache _wrapper_info = namedtuple('_wrapper_info', ['library', 'env', 'name']) diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 06af2be262d..46f1e96fa34 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -26,7 +26,7 @@ captured_stdout) from numba.numpy_support import as_dtype from numba.targets import codegen -from numba.caching import _UserWideCacheLocator +from numba.core.caching import _UserWideCacheLocator from numba.core.dispatcher import Dispatcher from numba import parfor from numba.tests.support import skip_parfors_unsupported, needs_lapack From 31476dce743cd767e5644ed87ae761bce6d1f50c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:17:53 +0000 Subject: [PATCH 362/595] Move numba/callwrapper.py to numba/core --- numba/{ => core}/callwrapper.py | 0 numba/targets/cpu.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => core}/callwrapper.py (100%) diff --git a/numba/callwrapper.py b/numba/core/callwrapper.py similarity index 100% rename from numba/callwrapper.py rename to numba/core/callwrapper.py diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 05c41e622bf..951f4124ac9 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -5,7 +5,7 @@ import llvmlite.llvmpy.core as lc from numba import _dynfunc, config -from numba.callwrapper import PyCallWrapper +from numba.core.callwrapper import PyCallWrapper from numba.targets.base import BaseContext, PYOBJECT from numba.core import utils, types from numba import cgutils From f088381adadabbe4499a500d45fd1eba66059cf6 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:20:05 +0000 Subject: [PATCH 363/595] Move numba/ccallback.py to numba/core --- numba/{ => core}/ccallback.py | 0 numba/decorators.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => core}/ccallback.py (100%) diff --git a/numba/ccallback.py b/numba/core/ccallback.py similarity index 100% rename from numba/ccallback.py rename to numba/core/ccallback.py diff --git a/numba/decorators.py b/numba/decorators.py index 191ec51d377..b17c6c3eeea 100644 --- a/numba/decorators.py +++ b/numba/decorators.py @@ -251,7 +251,7 @@ def add(a, b): sig = sigutils.normalize_signature(sig) def wrapper(func): - from .ccallback import CFunc + from numba.core.ccallback import CFunc res = CFunc(func, sig, locals=locals, options=options) if cache: res.enable_caching() From 5d7c43dc94f27bc37bb927d100d6047aa69b3921 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:23:22 +0000 Subject: [PATCH 364/595] Move numba/consts.py to numba/core --- numba/core/analysis.py | 4 ++-- numba/{ => core}/consts.py | 0 numba/core/ir.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename numba/{ => core}/consts.py (100%) diff --git a/numba/core/analysis.py b/numba/core/analysis.py index 85691c6ef33..e8a58bda641 100644 --- a/numba/core/analysis.py +++ b/numba/core/analysis.py @@ -6,8 +6,8 @@ from collections import namedtuple, defaultdict from .controlflow import CFGraph -from numba import consts, special -from numba.core import types, errors, ir +from numba import special +from numba.core import types, errors, ir, consts # # Analysis related to variable lifetime diff --git a/numba/consts.py b/numba/core/consts.py similarity index 100% rename from numba/consts.py rename to numba/core/consts.py diff --git a/numba/core/ir.py b/numba/core/ir.py index 8bfd141e492..251c4236cf4 100644 --- a/numba/core/ir.py +++ b/numba/core/ir.py @@ -9,6 +9,7 @@ import operator from types import FunctionType, BuiltinFunctionType from functools import total_ordering +from io import StringIO from numba import config from numba.core import errors @@ -16,7 +17,7 @@ UNARY_BUITINS_TO_OPERATORS, OPERATORS_TO_BUILTINS) from numba.core.errors import (NotDefinedError, RedefinedError, VerificationError, ConstantInferenceError) -from io import StringIO +from numba.core import consts # terminal color markup _termcolor = errors.termcolor() @@ -1337,7 +1338,6 @@ def get_pad(ablock, l): return '\n'.join(msg) def _reset_analysis_variables(self): - from numba import consts self._consts = consts.ConstantInference(self) From 1ee3e270650605bab26961d58421b36adc3ff055 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:35:27 +0000 Subject: [PATCH 365/595] Move numba/debuginfo.py to numba/core --- numba/{ => core}/debuginfo.py | 0 numba/cuda/target.py | 4 ++-- numba/lowering.py | 3 +-- numba/targets/base.py | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) rename numba/{ => core}/debuginfo.py (100%) diff --git a/numba/debuginfo.py b/numba/core/debuginfo.py similarity index 100% rename from numba/debuginfo.py rename to numba/core/debuginfo.py diff --git a/numba/cuda/target.py b/numba/cuda/target.py index 65e375551ad..f0c8b104135 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -4,8 +4,8 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba.core import typing, types, dispatcher -from numba import cgutils, debuginfo +from numba.core import typing, types, dispatcher, debuginfo +from numba import cgutils from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv diff --git a/numba/lowering.py b/numba/lowering.py index b2834dea09c..f91e38ac221 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -6,12 +6,11 @@ from llvmlite.llvmpy.core import Constant, Type, Builder from numba import _dynfunc, cgutils, config, funcdesc, generators, ir_utils -from numba.core import typing, utils, types, ir +from numba.core import typing, utils, types, ir, debuginfo from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) from .targets import removerefctpass from .funcdesc import default_mangler -from numba import debuginfo class Environment(_dynfunc.Environment): diff --git a/numba/targets/base.py b/numba/targets/base.py index 30475d26e19..bf31c6fc74e 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -12,8 +12,8 @@ from llvmlite.llvmpy.core import Type, Constant, LLVMException import llvmlite.binding as ll -from numba.core import types, utils, typing, datamodel -from numba import cgutils, funcdesc, debuginfo, config +from numba.core import types, utils, typing, datamodel, debuginfo +from numba import cgutils, funcdesc, config from numba import _dynfunc, _helperlib from numba.core.compiler_lock import global_compiler_lock from numba.pythonapi import PythonAPI From a31ed8beac434d8da785ece44cf4ef85d4becf0f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:38:43 +0000 Subject: [PATCH 366/595] Move numba/entrypoints.py to numba/core --- numba/{ => core}/entrypoints.py | 0 numba/targets/cpu.py | 4 ++-- numba/tests/test_entrypoints.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) rename numba/{ => core}/entrypoints.py (100%) diff --git a/numba/entrypoints.py b/numba/core/entrypoints.py similarity index 100% rename from numba/entrypoints.py rename to numba/core/entrypoints.py diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 951f4124ac9..86b7196214d 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -14,7 +14,7 @@ from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock -import numba.entrypoints +import numba.core.entrypoints from numba.targets import fastmathpass from numba.targets.cpu_options import (ParallelOptions, FastMathOptions, InlineOptions) @@ -74,7 +74,7 @@ def load_additional_registries(self): self.install_registry(randomimpl.registry) # load 3rd party extensions - numba.entrypoints.init_all() + numba.core.entrypoints.init_all() @property def target_data(self): diff --git a/numba/tests/test_entrypoints.py b/numba/tests/test_entrypoints.py index fd0fca4f294..ef302c8fa67 100644 --- a/numba/tests/test_entrypoints.py +++ b/numba/tests/test_entrypoints.py @@ -42,17 +42,17 @@ def init_function(): entrypoints.setdefault('numba_extensions', {})['init'] = my_entrypoint - import numba.entrypoints + from numba.core import entrypoints # Allow reinitialization - numba.entrypoints._already_initialized = False + entrypoints._already_initialized = False - numba.entrypoints.init_all() + entrypoints.init_all() # was our init function called? self.assertEqual(counters['init'], 1) # ensure we do not initialize twice - numba.entrypoints.init_all() + entrypoints.init_all() self.assertEqual(counters['init'], 1) finally: # remove fake module From faeb2b1e3472f29c1f2f0544a2c1b8515df67a5a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:43:08 +0000 Subject: [PATCH 367/595] Move numba/funcdesc.py to numba/core --- numba/{ => core}/funcdesc.py | 0 numba/cuda/compiler.py | 4 ++-- numba/generators.py | 2 +- numba/lowering.py | 10 +++++----- numba/object_mode_passes.py | 4 ++-- numba/targets/base.py | 4 ++-- numba/tests/test_mangling.py | 2 +- numba/typed_passes.py | 4 ++-- numba/typeinfer.py | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) rename numba/{ => core}/funcdesc.py (100%) diff --git a/numba/funcdesc.py b/numba/core/funcdesc.py similarity index 100% rename from numba/funcdesc.py rename to numba/core/funcdesc.py diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index ab27d811040..2756201e267 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -10,8 +10,8 @@ from numba import config, compiler, sigutils from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate -from numba import funcdesc, serialize -from numba.core import types, typing, utils +from numba import serialize +from numba.core import types, typing, utils, funcdesc from numba.core.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner diff --git a/numba/generators.py b/numba/generators.py index 079f373376b..8457cff6b5a 100644 --- a/numba/generators.py +++ b/numba/generators.py @@ -6,7 +6,7 @@ from numba import cgutils, config from numba.core import types -from .funcdesc import FunctionDescriptor +from numba.core.funcdesc import FunctionDescriptor class GeneratorDescriptor(FunctionDescriptor): diff --git a/numba/lowering.py b/numba/lowering.py index f91e38ac221..827671dbf09 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -5,12 +5,12 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import _dynfunc, cgutils, config, funcdesc, generators, ir_utils -from numba.core import typing, utils, types, ir, debuginfo +from numba import _dynfunc, cgutils, config, generators, ir_utils +from numba.core import typing, utils, types, ir, debuginfo, funcdesc from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) -from .targets import removerefctpass -from .funcdesc import default_mangler +from numba.targets import removerefctpass +from numba.core.funcdesc import default_mangler class Environment(_dynfunc.Environment): @@ -48,7 +48,7 @@ def __del__(self): def _rebuild_env(modname, consts, env_name): if env_name in Environment._memo: return Environment._memo[env_name] - from . import serialize + from numba import serialize mod = serialize._rebuild_module(modname) env = Environment(mod.__dict__) env.consts[:] = consts diff --git a/numba/object_mode_passes.py b/numba/object_mode_passes.py index 0947a7216cd..02fbd8cd94d 100644 --- a/numba/object_mode_passes.py +++ b/numba/object_mode_passes.py @@ -1,7 +1,7 @@ from contextlib import contextmanager import warnings -from numba import (config, funcdesc, pylowering, transforms) -from numba.core import errors, types, typing +from numba import config, pylowering, transforms +from numba.core import errors, types, typing, funcdesc from numba.compiler_machinery import FunctionPass, LoweringPass, register_pass from collections import defaultdict diff --git a/numba/targets/base.py b/numba/targets/base.py index bf31c6fc74e..3e169b5a607 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -12,8 +12,8 @@ from llvmlite.llvmpy.core import Type, Constant, LLVMException import llvmlite.binding as ll -from numba.core import types, utils, typing, datamodel, debuginfo -from numba import cgutils, funcdesc, config +from numba.core import types, utils, typing, datamodel, debuginfo, funcdesc +from numba import cgutils, config from numba import _dynfunc, _helperlib from numba.core.compiler_lock import global_compiler_lock from numba.pythonapi import PythonAPI diff --git a/numba/tests/test_mangling.py b/numba/tests/test_mangling.py index e648478edc6..39627b93586 100644 --- a/numba/tests/test_mangling.py +++ b/numba/tests/test_mangling.py @@ -5,7 +5,7 @@ """ from numba.core import types, utils -from numba.funcdesc import default_mangler +from numba.core.funcdesc import default_mangler from numba.tests.support import unittest, TestCase diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 4d872408626..0d56800d5f7 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -1,8 +1,8 @@ from contextlib import contextmanager import warnings -from numba import config, rewrites, typeinfer, funcdesc, lowering -from numba.core import errors, types, typing, ir +from numba import config, rewrites, typeinfer, lowering +from numba.core import errors, types, typing, ir, funcdesc from numba.parfor import PreParforPass as _parfor_PreParforPass from numba.parfor import ParforPass as _parfor_ParforPass diff --git a/numba/typeinfer.py b/numba/typeinfer.py index 6fc71f38c93..d5aec2552b2 100644 --- a/numba/typeinfer.py +++ b/numba/typeinfer.py @@ -27,7 +27,7 @@ from numba.core.errors import (TypingError, UntypedAttributeError, new_error_context, termcolor, UnsupportedError, ForceLiteralArg) -from numba.funcdesc import qualifying_prefix +from numba.core.funcdesc import qualifying_prefix _logger = logging.getLogger(__name__) From 363532f54b2cc215935ab062919dba30effb04fa Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:47:10 +0000 Subject: [PATCH 368/595] Move numba/generators.py to numba/core --- numba/{ => core}/generators.py | 0 numba/lowering.py | 4 ++-- numba/pylowering.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename numba/{ => core}/generators.py (100%) diff --git a/numba/generators.py b/numba/core/generators.py similarity index 100% rename from numba/generators.py rename to numba/core/generators.py diff --git a/numba/lowering.py b/numba/lowering.py index 827671dbf09..846fe8183dd 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -5,8 +5,8 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import _dynfunc, cgutils, config, generators, ir_utils -from numba.core import typing, utils, types, ir, debuginfo, funcdesc +from numba import _dynfunc, cgutils, config, ir_utils +from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) from numba.targets import removerefctpass diff --git a/numba/pylowering.py b/numba/pylowering.py index 4a98a1e9146..d4ed77cde10 100644 --- a/numba/pylowering.py +++ b/numba/pylowering.py @@ -9,8 +9,8 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba import cgutils, generators -from numba.core import types, utils, ir +from numba import cgutils +from numba.core import types, utils, ir, generators from numba.core.errors import ForbiddenConstruct from numba.lowering import BaseLower From f7279bd24df9f421de03a0d6f4d06d0a7dd844c3 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:49:43 +0000 Subject: [PATCH 369/595] Move numba/itanium_mangler.py to numba/core --- numba/core/funcdesc.py | 3 +-- numba/{ => core}/itanium_mangler.py | 0 numba/cuda/target.py | 3 +-- numba/roc/hsaimpl.py | 2 +- numba/roc/mathimpl.py | 2 +- numba/tests/test_itanium_mangler.py | 2 +- numba/tests/test_record_dtype.py | 2 +- 7 files changed, 6 insertions(+), 8 deletions(-) rename numba/{ => core}/itanium_mangler.py (100%) diff --git a/numba/core/funcdesc.py b/numba/core/funcdesc.py index 6030759c288..6c1f8c0bc2f 100644 --- a/numba/core/funcdesc.py +++ b/numba/core/funcdesc.py @@ -5,8 +5,7 @@ from collections import defaultdict import sys -from numba import itanium_mangler -from numba.core import types +from numba.core import types, itanium_mangler from numba.core.utils import _dynamic_modname, _dynamic_module diff --git a/numba/itanium_mangler.py b/numba/core/itanium_mangler.py similarity index 100% rename from numba/itanium_mangler.py rename to numba/core/itanium_mangler.py diff --git a/numba/cuda/target.py b/numba/cuda/target.py index f0c8b104135..44c69486e37 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -4,14 +4,13 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba.core import typing, types, dispatcher, debuginfo +from numba.core import typing, types, dispatcher, debuginfo, itanium_mangler from numba import cgutils from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv from numba.core.typing import cmathdecl -from numba import itanium_mangler from .cudadrv import nvvm from numba.cuda import codegen, nvvmutils from .decorators import jitdevice diff --git a/numba/roc/hsaimpl.py b/numba/roc/hsaimpl.py index 53bdd528d5a..74d867c24e4 100644 --- a/numba/roc/hsaimpl.py +++ b/numba/roc/hsaimpl.py @@ -9,7 +9,7 @@ from numba.targets.imputils import Registry from numba import cgutils from numba.core import types -from numba.itanium_mangler import mangle_c, mangle, mangle_type +from numba.core.itanium_mangler import mangle_c, mangle, mangle_type from numba.roc import target from numba.roc import stubs from numba.roc import hlc diff --git a/numba/roc/mathimpl.py b/numba/roc/mathimpl.py index 624c8cb4fc6..80c898b7ea2 100644 --- a/numba/roc/mathimpl.py +++ b/numba/roc/mathimpl.py @@ -3,7 +3,7 @@ from numba.targets.imputils import Registry from numba.core import types -from numba.itanium_mangler import mangle +from numba.core.itanium_mangler import mangle from .hsaimpl import _declare_function registry = Registry() diff --git a/numba/tests/test_itanium_mangler.py b/numba/tests/test_itanium_mangler.py index 981e56fcb92..54bb0f827d0 100644 --- a/numba/tests/test_itanium_mangler.py +++ b/numba/tests/test_itanium_mangler.py @@ -3,9 +3,9 @@ import re from numba import unittest_support as unittest -from numba import itanium_mangler from numba import int32, int64, uint32, uint64, float32, float64 from numba.core.types import range_iter32_type +from numba.core import itanium_mangler class TestItaniumManager(unittest.TestCase): diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 076c55b0e61..1e60661aed5 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -6,7 +6,7 @@ from numba.core import types from numba import unittest_support as unittest from numba.compiler import compile_isolated -from numba.itanium_mangler import mangle_type +from numba.core.itanium_mangler import mangle_type from numba.config import IS_WIN32 from numba.numpy_support import numpy_version From da5a7dba9016b44193f6e47777d05c39cd377aca Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 09:54:20 +0000 Subject: [PATCH 370/595] Move numba/object_mode_passes.py to numba/core --- numba/compiler.py | 37 +++++++++++++------------- numba/{ => core}/object_mode_passes.py | 0 2 files changed, 19 insertions(+), 18 deletions(-) rename numba/{ => core}/object_mode_passes.py (100%) diff --git a/numba/compiler.py b/numba/compiler.py index 45e42e43849..c50dd6e9534 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -10,24 +10,25 @@ from numba.inline_closurecall import InlineClosureCallPass from numba.core.errors import CompilerError -from .compiler_machinery import PassManager - -from .untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, - IRProcessing, DeadBranchPrune, - RewriteSemanticConstants, InlineClosureLikes, - GenericRewrites, WithLifting, InlineInlinables, - FindLiterallyCalls, MakeFunctionToJitFunction, - CanonicalizeLoopExit, CanonicalizeLoopEntry, - LiteralUnroll, - ) - -from .typed_passes import (NopythonTypeInference, AnnotateTypes, - NopythonRewrites, PreParforPass, ParforPass, - DumpParforDiagnostics, IRLegalization, - NoPythonBackend, InlineOverloads) - -from .object_mode_passes import (ObjectModeFrontEnd, ObjectModeBackEnd, - CompileInterpMode) +from numba.compiler_machinery import PassManager + +from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, + IRProcessing, DeadBranchPrune, + RewriteSemanticConstants, InlineClosureLikes, + GenericRewrites, WithLifting, + InlineInlinables, FindLiterallyCalls, + MakeFunctionToJitFunction, + CanonicalizeLoopExit, CanonicalizeLoopEntry, + LiteralUnroll, + ) + +from numba.typed_passes import (NopythonTypeInference, AnnotateTypes, + NopythonRewrites, PreParforPass, ParforPass, + DumpParforDiagnostics, IRLegalization, + NoPythonBackend, InlineOverloads) + +from numba.core.object_mode_passes import (ObjectModeFrontEnd, ObjectModeBackEnd, + CompileInterpMode) class Flags(utils.ConfigOptions): diff --git a/numba/object_mode_passes.py b/numba/core/object_mode_passes.py similarity index 100% rename from numba/object_mode_passes.py rename to numba/core/object_mode_passes.py From 34ec3673ea00fd48be62d39412fc6e477717184d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 10:16:12 +0000 Subject: [PATCH 371/595] Move numba/postproc.py to numba/core --- numba/compiler.py | 4 ++-- numba/compiler_machinery.py | 2 +- numba/{ => core}/postproc.py | 0 numba/ir_utils.py | 7 +++---- numba/parfor.py | 4 ++-- numba/rewrites/registry.py | 2 +- numba/tests/test_array_analysis.py | 4 ++-- numba/tests/test_inlining.py | 4 ++-- numba/transforms.py | 2 +- numba/untyped_passes.py | 4 ++-- 10 files changed, 16 insertions(+), 17 deletions(-) rename numba/{ => core}/postproc.py (100%) diff --git a/numba/compiler.py b/numba/compiler.py index c50dd6e9534..defa4da7c89 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -3,8 +3,8 @@ import warnings from numba.tracing import event -from numba import postproc, config -from numba.core import utils, errors, typing, interpreter, bytecode +from numba import config +from numba.core import utils, errors, typing, interpreter, bytecode, postproc from numba.targets import cpu, callconv from numba.parfor import ParforDiagnostics from numba.inline_closurecall import InlineClosureCallPass diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index c744ff87a56..cf96e03b5de 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -7,7 +7,7 @@ from numba import config, transforms from numba.core.utils import add_metaclass from numba.tracing import event -from numba.postproc import PostProcessor +from numba.core.postproc import PostProcessor # terminal color markup _termcolor = errors.termcolor() diff --git a/numba/postproc.py b/numba/core/postproc.py similarity index 100% rename from numba/postproc.py rename to numba/core/postproc.py diff --git a/numba/ir_utils.py b/numba/ir_utils.py index f23c631b03d..2f16857f189 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -13,7 +13,7 @@ from llvmlite import ir as lir import numba -from numba.core import types, utils, typing, ir, analysis +from numba.core import types, utils, typing, ir, analysis, postproc from numba import config, cgutils, rewrites from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) @@ -519,7 +519,7 @@ def dead_code_elimination(func_ir, typemap=None, alias_map=None, do_post_proc = True if do_post_proc: - post_proc = numba.postproc.PostProcessor(func_ir) + post_proc = postproc.PostProcessor(func_ir) post_proc.run() @@ -1663,7 +1663,6 @@ def __init__(self, f_ir): inline_pass = numba.inline_closurecall.InlineClosureCallPass( ir, numba.targets.cpu.ParallelOptions(False), swapped) inline_pass.run() - from numba import postproc post_proc = postproc.PostProcessor(ir) post_proc.run() return ir @@ -2061,7 +2060,7 @@ def check_and_legalize_ir(func_ir): This checks that the IR presented is legal, warns and legalizes if not """ orig_ir = func_ir.copy() - post_proc = numba.postproc.PostProcessor(func_ir) + post_proc = postproc.PostProcessor(func_ir) post_proc.run() msg = ("\nNumba has detected inconsistencies in its internal " "representation of the code at %s. Numba can probably recover from " diff --git a/numba/parfor.py b/numba/parfor.py index 96b53e82345..8ee2eb91130 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -25,9 +25,9 @@ import operator import numba.core.ir -from numba.core import types, typing, utils, errors, ir, analysis +from numba.core import types, typing, utils, errors, ir, analysis, postproc from numba import ir_utils, rewrites, config, prange, pndindex -from numba import postproc, typeinfer +from numba import typeinfer from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate from numba import stencilparfor diff --git a/numba/rewrites/registry.py b/numba/rewrites/registry.py index 97494e216c7..0e77e57ef23 100644 --- a/numba/rewrites/registry.py +++ b/numba/rewrites/registry.py @@ -89,7 +89,7 @@ def apply(self, kind, state): # fix-up the IR so that ref counts are valid and optimally placed, # see #4093 for context. This has to be run here opposed to in # apply() as the CFG needs computing so full IR is needed. - from numba import postproc + from numba.core import postproc post_proc = postproc.PostProcessor(state.func_ir) post_proc.run() diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index b759a824864..c5ad05d1ae3 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -6,8 +6,8 @@ from io import StringIO from numba import unittest_support as unittest -from numba import njit, typeof, jitclass, prange, postproc -from numba.core import types, typing, ir, bytecode +from numba import njit, typeof, jitclass, prange +from numba.core import types, typing, ir, bytecode, postproc from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.parfors.array_analysis import EquivSet, ArrayAnalysis from numba.compiler import Compiler, Flags, PassManager diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 0b3f5cc9f57..57f8268b1fe 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -6,7 +6,7 @@ import numba from numba import unittest_support as unittest from numba import jit, njit, compiler -from numba.core import types, ir +from numba.core import types, ir, postproc from numba.ir_utils import guard, find_callname, find_const, get_definition from numba.targets.registry import CPUDispatcher from numba.inline_closurecall import inline_closure_call @@ -59,7 +59,7 @@ def run_pass(self, state): state.type_annotation.calltypes) # also fix up the IR so that ir.Dels appear correctly/in correct # locations - post_proc = numba.postproc.PostProcessor(state.func_ir) + post_proc = postproc.PostProcessor(state.func_ir) post_proc.run() break return True diff --git a/numba/transforms.py b/numba/transforms.py index faf6e7ff117..2f0943322fc 100644 --- a/numba/transforms.py +++ b/numba/transforms.py @@ -322,7 +322,7 @@ def with_lifting(func_ir, typingctx, targetctx, flags, locals): Only the top-level withs are extracted. Returns the (the_new_ir, the_lifted_with_ir) """ - from numba import postproc + from numba.core import postproc def dispatcher_factory(func_ir, objectmode=False, **kwargs): from numba.core.dispatcher import LiftedWith, ObjModeLiftedWith diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index 216490413cf..2efa62e6e09 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -2,8 +2,8 @@ from copy import deepcopy, copy from .compiler_machinery import FunctionPass, register_pass -from numba import config, postproc, rewrites, transforms -from numba.core import errors, types, ir, bytecode +from numba import config, rewrites, transforms +from numba.core import errors, types, ir, bytecode, postproc from .special import literal_unroll import warnings from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls,compute_cfg_from_blocks, compute_use_defs From fafe41cc59b3982d00145c3c0862d1db92a80705 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 10:20:05 +0000 Subject: [PATCH 372/595] Move numba/pretty_annotate.py to numba/core/annotations --- numba/{ => core/annotations}/pretty_annotate.py | 0 numba/core/dispatcher.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => core/annotations}/pretty_annotate.py (100%) diff --git a/numba/pretty_annotate.py b/numba/core/annotations/pretty_annotate.py similarity index 100% rename from numba/pretty_annotate.py rename to numba/core/annotations/pretty_annotate.py diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py index d12bbf3c707..a9a9d13d836 100644 --- a/numba/core/dispatcher.py +++ b/numba/core/dispatcher.py @@ -510,7 +510,7 @@ def inspect_types(self, file=None, signature=None, else: if file is not None: raise ValueError("`file` must be None if `pretty=True`") - from .pretty_annotate import Annotate + from numba.core.annotations.pretty_annotate import Annotate return Annotate(self, signature=signature, style=style) def inspect_cfg(self, signature=None, show_wrapper=None): From 6e300570692a000525e98efcdb650ba16a4e25d1 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 10:29:26 +0000 Subject: [PATCH 373/595] Move numba/rewrites to numba/core --- numba/{ => core}/rewrites/__init__.py | 5 ++--- numba/{ => core}/rewrites/ir_print.py | 2 +- numba/{ => core}/rewrites/macros.py | 2 +- numba/{ => core}/rewrites/registry.py | 0 numba/{ => core}/rewrites/static_binop.py | 2 +- numba/{ => core}/rewrites/static_getitem.py | 2 +- numba/{ => core}/rewrites/static_raise.py | 2 +- numba/inline_closurecall.py | 4 ++-- numba/ir_utils.py | 4 ++-- numba/macro.py | 2 +- numba/npyufunc/array_exprs.py | 4 ++-- numba/parfor.py | 4 ++-- numba/stencilparfor.py | 5 ++--- numba/tests/test_analysis.py | 4 ++-- numba/tests/test_parfors.py | 6 +++--- numba/typed_passes.py | 4 ++-- numba/untyped_passes.py | 4 ++-- 17 files changed, 27 insertions(+), 29 deletions(-) rename numba/{ => core}/rewrites/__init__.py (56%) rename numba/{ => core}/rewrites/ir_print.py (98%) rename numba/{ => core}/rewrites/macros.py (98%) rename numba/{ => core}/rewrites/registry.py (100%) rename numba/{ => core}/rewrites/static_binop.py (94%) rename numba/{ => core}/rewrites/static_getitem.py (98%) rename numba/{ => core}/rewrites/static_raise.py (98%) diff --git a/numba/rewrites/__init__.py b/numba/core/rewrites/__init__.py similarity index 56% rename from numba/rewrites/__init__.py rename to numba/core/rewrites/__init__.py index 8c06cd4705e..3abc74db886 100644 --- a/numba/rewrites/__init__.py +++ b/numba/core/rewrites/__init__.py @@ -3,7 +3,6 @@ """ from .registry import register_rewrite, rewrite_registry, Rewrite - # Register various built-in rewrite passes -from numba.rewrites import (static_getitem, static_raise, static_binop, - ir_print, macros) +from numba.core.rewrites import (static_getitem, static_raise, static_binop, + ir_print, macros) diff --git a/numba/rewrites/ir_print.py b/numba/core/rewrites/ir_print.py similarity index 98% rename from numba/rewrites/ir_print.py rename to numba/core/rewrites/ir_print.py index 5f2f92e88ae..6d678381bb1 100644 --- a/numba/rewrites/ir_print.py +++ b/numba/core/rewrites/ir_print.py @@ -1,5 +1,5 @@ from numba.core import errors, ir -from numba.rewrites import register_rewrite, Rewrite +from numba.core.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/rewrites/macros.py b/numba/core/rewrites/macros.py similarity index 98% rename from numba/rewrites/macros.py rename to numba/core/rewrites/macros.py index 10f6402d7af..e0cc7ff79b1 100644 --- a/numba/rewrites/macros.py +++ b/numba/core/rewrites/macros.py @@ -1,5 +1,5 @@ from numba.core import errors, ir -from numba.rewrites import register_rewrite, Rewrite +from numba.core.rewrites import register_rewrite, Rewrite class Macro(object): diff --git a/numba/rewrites/registry.py b/numba/core/rewrites/registry.py similarity index 100% rename from numba/rewrites/registry.py rename to numba/core/rewrites/registry.py diff --git a/numba/rewrites/static_binop.py b/numba/core/rewrites/static_binop.py similarity index 94% rename from numba/rewrites/static_binop.py rename to numba/core/rewrites/static_binop.py index aa37fd87fae..33487a67549 100644 --- a/numba/rewrites/static_binop.py +++ b/numba/core/rewrites/static_binop.py @@ -1,5 +1,5 @@ from numba.core import errors, ir -from numba.rewrites import register_rewrite, Rewrite +from numba.core.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/rewrites/static_getitem.py b/numba/core/rewrites/static_getitem.py similarity index 98% rename from numba/rewrites/static_getitem.py rename to numba/core/rewrites/static_getitem.py index f5706b4609b..42f280d260e 100644 --- a/numba/rewrites/static_getitem.py +++ b/numba/core/rewrites/static_getitem.py @@ -1,5 +1,5 @@ from numba.core import errors, ir -from numba.rewrites import register_rewrite, Rewrite +from numba.core.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/rewrites/static_raise.py b/numba/core/rewrites/static_raise.py similarity index 98% rename from numba/rewrites/static_raise.py rename to numba/core/rewrites/static_raise.py index 6dc2a700470..61f7b5742b5 100644 --- a/numba/rewrites/static_raise.py +++ b/numba/core/rewrites/static_raise.py @@ -1,5 +1,5 @@ from numba.core import errors, ir -from numba.rewrites import register_rewrite, Rewrite +from numba.core.rewrites import register_rewrite, Rewrite @register_rewrite('before-inference') diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 78c010618c7..24a687e3691 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -1,8 +1,8 @@ import types as pytypes # avoid confusion with numba.types import ctypes import numba.core.analysis -from numba.core import utils, types, typing, errors, ir -from numba import config, ir_utils, prange, rewrites +from numba.core import utils, types, typing, errors, ir, rewrites +from numba import config, ir_utils, prange from numba.parfor import internal_prange from numba.ir_utils import ( mk_unique_var, diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 2f16857f189..4cb11d90c64 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -13,8 +13,8 @@ from llvmlite import ir as lir import numba -from numba.core import types, utils, typing, ir, analysis, postproc -from numba import config, cgutils, rewrites +from numba.core import types, utils, typing, ir, analysis, postproc, rewrites +from numba import config, cgutils from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) from numba.targets.imputils import impl_ret_untracked diff --git a/numba/macro.py b/numba/macro.py index 1c928a9798c..ff125aa0c78 100644 --- a/numba/macro.py +++ b/numba/macro.py @@ -5,4 +5,4 @@ """ # Expose the Macro object from the corresponding IR rewrite pass -from .rewrites.macros import Macro +from numba.core.rewrites.macros import Macro diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index c2d7b4e9694..62d3ed807b3 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -6,8 +6,8 @@ import numpy as np import operator -from numba import compiler, rewrites -from numba.core import types, utils, ir +from numba import compiler +from numba.core import types, utils, ir, rewrites from numba.core.typing import npydecl from numba.npyufunc.dufunc import DUFunc diff --git a/numba/parfor.py b/numba/parfor.py index 8ee2eb91130..c72f13a07c8 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -25,8 +25,8 @@ import operator import numba.core.ir -from numba.core import types, typing, utils, errors, ir, analysis, postproc -from numba import ir_utils, rewrites, config, prange, pndindex +from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites +from numba import ir_utils, config, prange, pndindex from numba import typeinfer from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 3a91d6c40d5..98e664f8843 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -12,7 +12,7 @@ import numpy as np import numba -from numba.core import types, ir +from numba.core import types, ir, rewrites from numba.core.typing.templates import infer_global, AbstractTemplate from numba.core.typing import signature from numba.core import utils, typing @@ -668,8 +668,7 @@ def get_stencil_ir(sf, typingctx, args, scope, loc, input_dict, typemap, with cpu_target.nested_context(typingctx, targetctx): tp = DummyPipeline(typingctx, targetctx, args, stencil_func_ir) - numba.rewrites.rewrite_registry.apply( - 'before-inference', tp.state) + rewrites.rewrite_registry.apply('before-inference', tp.state) tp.state.typemap, tp.state.return_type, tp.state.calltypes = type_inference_stage( tp.state.typingctx, tp.state.func_ir, tp.state.args, None) diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index 78cc4122170..e04547905c8 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -3,8 +3,8 @@ import numpy as np from numba.compiler import compile_isolated, run_frontend, Flags, StateDict -from numba import rewrites, jit, ir_utils, njit -from numba.core import types, errors, ir +from numba import jit, ir_utils, njit +from numba.core import types, errors, ir, rewrites from numba.tests.support import TestCase, MemoryLeakMixin, SerialMixin from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 591249efa1a..b529cecc95f 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -23,7 +23,7 @@ from numba import njit, prange, stencil, inline_closurecall from numba import compiler, typed_passes from numba.targets import cpu -from numba.core import types, utils, typing, errors, ir +from numba.core import types, utils, typing, errors, ir, rewrites from numba.targets.registry import cpu_target from numba import config from numba.core.annotations import type_annotations @@ -311,7 +311,7 @@ def get_optimized_numba_ir(test_func, args, **kws): typed=True) inline_pass.run() - numba.rewrites.rewrite_registry.apply('before-inference', tp.state) + rewrites.rewrite_registry.apply('before-inference', tp.state) tp.state.typemap, tp.state.return_type, tp.state.calltypes = \ typed_passes.type_inference_stage(tp.state.typingctx, tp.state.func_ir, @@ -335,7 +335,7 @@ def get_optimized_numba_ir(test_func, args, **kws): swapped=diagnostics.replaced_fns) preparfor_pass.run() - numba.rewrites.rewrite_registry.apply('after-inference', tp.state) + rewrites.rewrite_registry.apply('after-inference', tp.state) flags = compiler.Flags() parfor_pass = numba.parfor.ParforPass( diff --git a/numba/typed_passes.py b/numba/typed_passes.py index 0d56800d5f7..c05a5749b24 100644 --- a/numba/typed_passes.py +++ b/numba/typed_passes.py @@ -1,8 +1,8 @@ from contextlib import contextmanager import warnings -from numba import config, rewrites, typeinfer, lowering -from numba.core import errors, types, typing, ir, funcdesc +from numba import config, typeinfer, lowering +from numba.core import errors, types, typing, ir, funcdesc, rewrites from numba.parfor import PreParforPass as _parfor_PreParforPass from numba.parfor import ParforPass as _parfor_ParforPass diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index 2efa62e6e09..c1612a6116c 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -2,8 +2,8 @@ from copy import deepcopy, copy from .compiler_machinery import FunctionPass, register_pass -from numba import config, rewrites, transforms -from numba.core import errors, types, ir, bytecode, postproc +from numba import config, transforms +from numba.core import errors, types, ir, bytecode, postproc, rewrites from .special import literal_unroll import warnings from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls,compute_cfg_from_blocks, compute_use_defs From 136ecdee376500b1db1880f44fce36d4d3ee396c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 10:30:47 +0000 Subject: [PATCH 374/595] Move numba/pythonapi.py to numba/core --- numba/{ => core}/pythonapi.py | 0 numba/cpython/unicode.py | 2 +- numba/extending.py | 2 +- numba/jitclass/boxing.py | 2 +- numba/targets/base.py | 2 +- numba/targets/boxing.py | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename numba/{ => core}/pythonapi.py (100%) diff --git a/numba/pythonapi.py b/numba/core/pythonapi.py similarity index 100% rename from numba/pythonapi.py rename to numba/core/pythonapi.py diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index 1a0199deafc..a3977a8f655 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -21,7 +21,7 @@ from numba.core.datamodel import register_default, StructModel from numba import cgutils from numba.core import utils, types -from numba.pythonapi import ( +from numba.core.pythonapi import ( PY_UNICODE_1BYTE_KIND, PY_UNICODE_2BYTE_KIND, PY_UNICODE_4BYTE_KIND, diff --git a/numba/extending.py b/numba/extending.py index b4e3cacdd55..94c5931ceaf 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -15,7 +15,7 @@ lower_builtin, lower_getattr, lower_getattr_generic, lower_setattr, lower_setattr_generic, lower_cast) from numba.core.datamodel import models, register_default as register_model -from numba.pythonapi import box, unbox, reflect, NativeValue +from numba.core.pythonapi import box, unbox, reflect, NativeValue from numba._helperlib import _import_cython_function diff --git a/numba/jitclass/boxing.py b/numba/jitclass/boxing.py index 8bece162561..5b44cd765d9 100644 --- a/numba/jitclass/boxing.py +++ b/numba/jitclass/boxing.py @@ -9,7 +9,7 @@ from numba import cgutils from numba.core import types -from numba.pythonapi import box, unbox, NativeValue +from numba.core.pythonapi import box, unbox, NativeValue from numba import njit from numba.jitclass import _box diff --git a/numba/targets/base.py b/numba/targets/base.py index 3e169b5a607..79900eaf742 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -16,7 +16,7 @@ from numba import cgutils, config from numba import _dynfunc, _helperlib from numba.core.compiler_lock import global_compiler_lock -from numba.pythonapi import PythonAPI +from numba.core.pythonapi import PythonAPI from numba.np import arrayobj from numba.targets import imputils from .imputils import (user_function, user_generator, diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index dade7b141f1..085d936cbe2 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -6,7 +6,7 @@ from numba import cgutils, numpy_support from numba.core import types -from numba.pythonapi import box, unbox, reflect, NativeValue +from numba.core.pythonapi import box, unbox, reflect, NativeValue from numba.cpython import setobj, listobj From 5ae40f216da5543600f898c5d78b7d3043c8380c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 10:44:33 +0000 Subject: [PATCH 375/595] Move numba/serialize.py to numba/core --- numba/core/dispatcher.py | 4 ++-- numba/{ => core}/serialize.py | 0 numba/cuda/compiler.py | 3 +-- numba/cuda/cudadrv/driver.py | 4 ++-- numba/extending.py | 4 ++-- numba/lowering.py | 2 +- numba/npyufunc/dufunc.py | 4 +--- numba/npyufunc/ufuncbuilder.py | 3 +-- 8 files changed, 10 insertions(+), 14 deletions(-) rename numba/{ => core}/serialize.py (100%) diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py index a9a9d13d836..ca64682f323 100644 --- a/numba/core/dispatcher.py +++ b/numba/core/dispatcher.py @@ -12,10 +12,10 @@ from copy import deepcopy from numba import _dispatcher, compiler, config -from numba.core import utils, types, errors, typing +from numba.core import utils, types, errors, typing, serialize from numba.core.compiler_lock import global_compiler_lock from numba.core.typeconv.rules import default_type_manager -from numba import sigutils, serialize +from numba import sigutils from numba.core.typing.templates import fold_arguments from numba.core.typing.typeof import Purpose, typeof from numba.core.bytecode import get_code_object diff --git a/numba/serialize.py b/numba/core/serialize.py similarity index 100% rename from numba/serialize.py rename to numba/core/serialize.py diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index 2756201e267..b3c754985c7 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -10,8 +10,7 @@ from numba import config, compiler, sigutils from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate -from numba import serialize -from numba.core import types, typing, utils, funcdesc +from numba.core import types, typing, utils, funcdesc, serialize from numba.core.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index 56df70556df..f6d939122c9 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -28,12 +28,12 @@ from collections import namedtuple, deque from numba import mviewbuf -from numba.core import utils, errors +from numba.core import utils, errors, serialize from .error import CudaSupportError, CudaDriverError from .drvapi import API_PROTOTYPES from .drvapi import cu_occupancy_b2d_size from numba.cuda.cudadrv import enums, drvapi, _extras -from numba import config, serialize +from numba import config from numba.core.utils import longint as long from numba.cuda.envvars import get_numba_envvar diff --git a/numba/extending.py b/numba/extending.py index 94c5931ceaf..febab3eb408 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -311,7 +311,7 @@ def __repr__(self): return "".format(self._name) def __reduce__(self): - from numba import serialize + from numba.core import serialize def reduce_func(fn): gs = serialize._get_function_globals_for_reduction(fn) @@ -323,7 +323,7 @@ def reduce_func(fn): @classmethod def _rebuild(cls, uuid, name, defn_reduced): - from numba import serialize + from numba.core import serialize try: return cls._memo[uuid] diff --git a/numba/lowering.py b/numba/lowering.py index 846fe8183dd..a7404c127c9 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -48,7 +48,7 @@ def __del__(self): def _rebuild_env(modname, consts, env_name): if env_name in Environment._memo: return Environment._memo[env_name] - from numba import serialize + from numba.core import serialize mod = serialize._rebuild_module(modname) env = Environment(mod.__dict__) env.consts[:] = consts diff --git a/numba/npyufunc/dufunc.py b/numba/npyufunc/dufunc.py index 8701a72e2e1..aa5c5c7fb53 100644 --- a/numba/npyufunc/dufunc.py +++ b/numba/npyufunc/dufunc.py @@ -1,7 +1,5 @@ -from numba import serialize - from numba import jit, typeof, numpy_support, sigutils -from numba.core import types, utils +from numba.core import types, utils, serialize from numba.core.typing import npydecl from numba.core.typing.templates import AbstractTemplate, signature from numba.npyufunc import _internal, ufuncbuilder diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 6243ac197ab..034ea14cae0 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -3,14 +3,13 @@ import inspect from contextlib import contextmanager -from numba import serialize from numba.decorators import jit from numba.targets.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target from numba.targets.cpu import FastMathOptions from numba import compiler, sigutils -from numba.core import utils, types +from numba.core import utils, types, serialize from numba.numpy_support import as_dtype from numba.npyufunc import _internal from numba.npyufunc.sigparse import parse_signature From 9bc230563e9fa87ac59e3dfd8c8a5772a2d39a5b Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 10:52:10 +0000 Subject: [PATCH 376/595] Move numba/untyped_passes.py to numba/core --- .../source/developer/compiler_pass_example.py | 2 +- numba/compiler.py | 19 ++++++++------- numba/{ => core}/untyped_passes.py | 24 +++++++------------ numba/tests/test_array_analysis.py | 2 +- numba/tests/test_errorhandling.py | 2 +- numba/tests/test_inlining.py | 2 +- numba/tests/test_ir_inlining.py | 2 +- numba/tests/test_ir_utils.py | 2 +- numba/tests/test_mixed_tuple_unroller.py | 2 +- numba/tests/test_remove_dead.py | 2 +- 10 files changed, 27 insertions(+), 32 deletions(-) rename numba/{ => core}/untyped_passes.py (98%) diff --git a/docs/source/developer/compiler_pass_example.py b/docs/source/developer/compiler_pass_example.py index 2b59b0b9158..020bb30aabf 100644 --- a/docs/source/developer/compiler_pass_example.py +++ b/docs/source/developer/compiler_pass_example.py @@ -5,7 +5,7 @@ def ex_compiler_pass(): from numba.core import ir from numba.compiler import CompilerBase, DefaultPassBuilder from numba.compiler_machinery import FunctionPass, register_pass - from numba.untyped_passes import IRProcessing + from numba.core.untyped_passes import IRProcessing from numbers import Number # Register this pass with the compiler framework, declare that it will not diff --git a/numba/compiler.py b/numba/compiler.py index defa4da7c89..032d23f7d90 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -12,15 +12,16 @@ from numba.compiler_machinery import PassManager -from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, - IRProcessing, DeadBranchPrune, - RewriteSemanticConstants, InlineClosureLikes, - GenericRewrites, WithLifting, - InlineInlinables, FindLiterallyCalls, - MakeFunctionToJitFunction, - CanonicalizeLoopExit, CanonicalizeLoopEntry, - LiteralUnroll, - ) +from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, + FixupArgs, IRProcessing, DeadBranchPrune, + RewriteSemanticConstants, + InlineClosureLikes, GenericRewrites, + WithLifting, InlineInlinables, + FindLiterallyCalls, + MakeFunctionToJitFunction, + CanonicalizeLoopExit, + CanonicalizeLoopEntry, LiteralUnroll, + ) from numba.typed_passes import (NopythonTypeInference, AnnotateTypes, NopythonRewrites, PreParforPass, ParforPass, diff --git a/numba/untyped_passes.py b/numba/core/untyped_passes.py similarity index 98% rename from numba/untyped_passes.py rename to numba/core/untyped_passes.py index c1612a6116c..13547146441 100644 --- a/numba/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -1,22 +1,16 @@ from collections import defaultdict, namedtuple +from contextlib import contextmanager from copy import deepcopy, copy +import warnings -from .compiler_machinery import FunctionPass, register_pass +from numba.compiler_machinery import FunctionPass, register_pass from numba import config, transforms from numba.core import errors, types, ir, bytecode, postproc, rewrites -from .special import literal_unroll -import warnings -from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls,compute_cfg_from_blocks, compute_use_defs -from contextlib import contextmanager -from .inline_closurecall import InlineClosureCallPass, inline_closure_call -from .ir_utils import (guard, resolve_func_from_module, simplify_CFG, - GuardException, convert_code_obj_to_function, - mk_unique_var, build_definitions, - replace_var_names, get_name_var_table, - compile_to_numba_ir, get_definition, - find_max_label, rename_labels, - ) -import numba.core.interpreter +from numba.special import literal_unroll +from .analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls, compute_cfg_from_blocks, compute_use_defs +from numba.inline_closurecall import InlineClosureCallPass, inline_closure_call +from numba.ir_utils import guard, resolve_func_from_module, simplify_CFG, GuardException, convert_code_obj_to_function, mk_unique_var, build_definitions, replace_var_names, get_name_var_table, compile_to_numba_ir, get_definition, find_max_label, rename_labels +from numba.core import interpreter @contextmanager @@ -78,7 +72,7 @@ def run_pass(self, state): """ func_id = state['func_id'] bc = state['bc'] - interp = numba.core.interpreter.Interpreter(func_id) + interp = interpreter.Interpreter(func_id) func_ir = interp.interpret(bc) state["func_ir"] = func_ir return True diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index c5ad05d1ae3..122760d1593 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -13,7 +13,7 @@ from numba.compiler import Compiler, Flags, PassManager from numba.targets import cpu, registry from numba.ir_utils import remove_dead -from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, +from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, RewriteSemanticConstants, GenericRewrites, WithLifting, PreserveIR, InlineClosureLikes) diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index 2751f158ba9..94444ba410a 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -8,7 +8,7 @@ import numpy as np -from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, +from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) from numba.typed_passes import (NopythonTypeInference, DeadCodeElimination, diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 57f8268b1fe..665c6a8ebac 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -11,7 +11,7 @@ from numba.targets.registry import CPUDispatcher from numba.inline_closurecall import inline_closure_call -from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, +from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, RewriteSemanticConstants, GenericRewrites, WithLifting, PreserveIR, InlineClosureLikes) diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index b7e3e41bd47..9ef076d65d5 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -23,7 +23,7 @@ from numba.targets.cpu import InlineOptions from numba.compiler import DefaultPassBuilder from numba.typed_passes import DeadCodeElimination, IRLegalization -from numba.untyped_passes import PreserveIR +from numba.core.untyped_passes import PreserveIR from itertools import product from numba.tests.support import TestCase, unittest, skip_py38_or_later diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index b10cc45e551..c1b92bc7b67 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -7,7 +7,7 @@ from numba.targets import registry from numba import ir_utils from numba.core import types, ir, bytecode -from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, +from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) from numba.typed_passes import (NopythonTypeInference, type_inference_stage, diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 218481d0233..22f713fed77 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -8,7 +8,7 @@ from numba.extending import overload from numba.compiler_machinery import PassManager, register_pass, FunctionPass from numba.compiler import CompilerBase -from numba.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, +from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, InlineClosureLikes, SimplifyCFG, IterLoopCanonicalization, LiteralUnroll) from numba.typed_passes import (NopythonTypeInference, IRLegalization, diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index e8154a73825..87a8eec8ec0 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -16,7 +16,7 @@ remove_call_handlers, alias_func_extensions) from numba.typed_passes import type_inference_stage from numba.compiler_machinery import FunctionPass, register_pass, PassManager -from numba.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, +from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, RewriteSemanticConstants, GenericRewrites, WithLifting, PreserveIR, InlineClosureLikes) From bf9bb9f02c2cc654a25260234f2b5369d77a7441 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 11:01:59 +0000 Subject: [PATCH 377/595] Move numba/typed_passes.py to numba/core --- numba/compiler.py | 15 ++++++++------- numba/{ => core}/typed_passes.py | 0 numba/core/typing/templates.py | 3 ++- numba/core/untyped_passes.py | 2 +- numba/inline_closurecall.py | 2 +- numba/ir_utils.py | 2 +- numba/stencil.py | 4 ++-- numba/stencilparfor.py | 2 +- numba/tests/test_array_analysis.py | 2 +- numba/tests/test_copy_propagate.py | 2 +- numba/tests/test_errorhandling.py | 8 ++++---- numba/tests/test_extending.py | 2 +- numba/tests/test_inlining.py | 2 +- numba/tests/test_ir_inlining.py | 2 +- numba/tests/test_ir_utils.py | 2 +- numba/tests/test_mixed_tuple_unroller.py | 2 +- numba/tests/test_parfors.py | 4 ++-- numba/tests/test_practical_lowering_issues.py | 2 +- numba/tests/test_remove_dead.py | 4 ++-- 19 files changed, 32 insertions(+), 30 deletions(-) rename numba/{ => core}/typed_passes.py (100%) diff --git a/numba/compiler.py b/numba/compiler.py index 032d23f7d90..e4f71a8563c 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -23,13 +23,14 @@ CanonicalizeLoopEntry, LiteralUnroll, ) -from numba.typed_passes import (NopythonTypeInference, AnnotateTypes, - NopythonRewrites, PreParforPass, ParforPass, - DumpParforDiagnostics, IRLegalization, - NoPythonBackend, InlineOverloads) - -from numba.core.object_mode_passes import (ObjectModeFrontEnd, ObjectModeBackEnd, - CompileInterpMode) +from numba.core.typed_passes import (NopythonTypeInference, AnnotateTypes, + NopythonRewrites, PreParforPass, + ParforPass, DumpParforDiagnostics, + IRLegalization, NoPythonBackend, + InlineOverloads) + +from numba.core.object_mode_passes import (ObjectModeFrontEnd, + ObjectModeBackEnd, CompileInterpMode) class Flags(utils.ConfigOptions): diff --git a/numba/typed_passes.py b/numba/core/typed_passes.py similarity index 100% rename from numba/typed_passes.py rename to numba/core/typed_passes.py diff --git a/numba/core/typing/templates.py b/numba/core/typing/templates.py index c62845fbb90..20847253d1f 100644 --- a/numba/core/typing/templates.py +++ b/numba/core/typing/templates.py @@ -455,7 +455,8 @@ def generic(self, args, kws): if not self._inline.is_never_inline: # need to run the compiler front end up to type inference to compute # a signature - from numba import compiler, typed_passes + from numba import compiler + from numba.core import typed_passes ir = compiler.run_frontend(disp_type.dispatcher.py_func) resolve = disp_type.dispatcher.get_call_template template, pysig, folded_args, kws = resolve(new_args, kws) diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 13547146441..1b585cbfb97 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -1404,7 +1404,7 @@ def run_pass(self, state): # run as subpipeline from numba.compiler_machinery import PassManager - from numba.typed_passes import PartialTypeInference + from numba.core.typed_passes import PartialTypeInference pm = PassManager("literal_unroll_subpipeline") # get types where possible to help with list->tuple change pm.add_pass(PartialTypeInference, "performs partial type inference") diff --git a/numba/inline_closurecall.py b/numba/inline_closurecall.py index 24a687e3691..afa71d7823a 100644 --- a/numba/inline_closurecall.py +++ b/numba/inline_closurecall.py @@ -350,7 +350,7 @@ def inline_closure_call(func_ir, glbls, block, i, callee, typingctx=None, _debug_dump(callee_ir) if typingctx: - from numba import typed_passes + from numba.core import typed_passes # call branch pruning to simplify IR and avoid inference errors callee_ir._definitions = ir_utils.build_definitions(callee_ir.blocks) numba.core.analysis.dead_branch_prune(callee_ir, arg_typs) diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 4cb11d90c64..54cbb096cd7 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -1573,7 +1573,7 @@ def compile_to_numba_ir(mk_func, glbls, typingctx=None, arg_typs=None, if typingctx and other typing inputs are available and update typemap and calltypes. """ - from numba import typed_passes + from numba.core import typed_passes # mk_func can be actual function or make_function node, or a njit function if hasattr(mk_func, 'code'): code = mk_func.code diff --git a/numba/stencil.py b/numba/stencil.py index c00d6e22e30..3e17176f6ee 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -8,8 +8,8 @@ import numpy as np from llvmlite import ir as lir -from numba import compiler, ir_utils, numpy_support, typed_passes -from numba.core import types, typing, utils, ir +from numba import compiler, ir_utils, numpy_support +from numba.core import types, typing, utils, ir, typed_passes from numba import config from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 98e664f8843..3c6e5cff5d0 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -651,7 +651,7 @@ def get_stencil_ir(sf, typingctx, args, scope, loc, input_dict, typemap, from numba.targets.cpu import CPUContext from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations - from numba.typed_passes import type_inference_stage + from numba.core.typed_passes import type_inference_stage # get untyped IR stencil_func_ir = sf.kernel_ir.copy() diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 122760d1593..fbde2e65fad 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -18,7 +18,7 @@ RewriteSemanticConstants, GenericRewrites, WithLifting, PreserveIR, InlineClosureLikes) -from numba.typed_passes import (NopythonTypeInference, AnnotateTypes, +from numba.core.typed_passes import (NopythonTypeInference, AnnotateTypes, NopythonRewrites, IRLegalization) from numba.compiler_machinery import FunctionPass, PassManager, register_pass diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index ae59112f468..25a7d707db4 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -11,7 +11,7 @@ from numba.core.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) -from numba.typed_passes import type_inference_stage +from numba.core.typed_passes import type_inference_stage from numba import unittest_support as unittest def test_will_propagate(b, z, w): diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index 94444ba410a..7760649ae59 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -9,11 +9,11 @@ from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, - IRProcessing,) + IRProcessing,) -from numba.typed_passes import (NopythonTypeInference, DeadCodeElimination, - NativeLowering, - IRLegalization, NoPythonBackend) +from numba.core.typed_passes import (NopythonTypeInference, DeadCodeElimination, + NativeLowering, IRLegalization, + NoPythonBackend) from numba.compiler_machinery import FunctionPass, PassManager, register_pass diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index b6a9235c5bd..091067ae562 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -12,7 +12,7 @@ from numba import unittest_support as unittest from numba import njit, jit, compiler from numba.core import types, errors, typing -from numba.typed_passes import type_inference_stage +from numba.core.typed_passes import type_inference_stage from numba.targets.registry import cpu_target from numba.compiler import compile_isolated from numba.tests.support import (TestCase, captured_stdout, tag, temp_directory, diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 665c6a8ebac..aa5c9139c47 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -16,7 +16,7 @@ RewriteSemanticConstants, GenericRewrites, WithLifting, PreserveIR, InlineClosureLikes) -from numba.typed_passes import (NopythonTypeInference, AnnotateTypes, +from numba.core.typed_passes import (NopythonTypeInference, AnnotateTypes, NopythonRewrites, PreParforPass, ParforPass, DumpParforDiagnostics, NativeLowering, IRLegalization, NoPythonBackend) diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index 9ef076d65d5..75cfdd89777 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -22,7 +22,7 @@ from numba.core.datamodel.models import OpaqueModel from numba.targets.cpu import InlineOptions from numba.compiler import DefaultPassBuilder -from numba.typed_passes import DeadCodeElimination, IRLegalization +from numba.core.typed_passes import DeadCodeElimination, IRLegalization from numba.core.untyped_passes import PreserveIR from itertools import product from numba.tests.support import TestCase, unittest, skip_py38_or_later diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index c1b92bc7b67..e5e939ee769 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -10,7 +10,7 @@ from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) -from numba.typed_passes import (NopythonTypeInference, type_inference_stage, +from numba.core.typed_passes import (NopythonTypeInference, type_inference_stage, DeadCodeElimination) # global constant for testing find_const diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 22f713fed77..a4bf65ff568 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -11,7 +11,7 @@ from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, InlineClosureLikes, SimplifyCFG, IterLoopCanonicalization, LiteralUnroll) -from numba.typed_passes import (NopythonTypeInference, IRLegalization, +from numba.core.typed_passes import (NopythonTypeInference, IRLegalization, NoPythonBackend, PartialTypeInference) from numba.ir_utils import (compute_cfg_from_blocks, flatten_labels) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index b529cecc95f..985d3e8fb6d 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -21,9 +21,9 @@ import numba from numba import unittest_support as unittest from numba import njit, prange, stencil, inline_closurecall -from numba import compiler, typed_passes +from numba import compiler from numba.targets import cpu -from numba.core import types, utils, typing, errors, ir, rewrites +from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes from numba.targets.registry import cpu_target from numba import config from numba.core.annotations import type_annotations diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index 9dcf730a8b5..0b4f56c7048 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -6,7 +6,7 @@ from numba import njit from numba.core import types, ir from numba.compiler import CompilerBase, DefaultPassBuilder -from numba.typed_passes import NopythonTypeInference +from numba.core.typed_passes import NopythonTypeInference from numba.compiler_machinery import register_pass, FunctionPass from numba.tests.support import MemoryLeakMixin, TestCase diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 87a8eec8ec0..cd7a8262d23 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -14,14 +14,14 @@ from numba.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table, remove_dels, remove_dead, remove_call_handlers, alias_func_extensions) -from numba.typed_passes import type_inference_stage +from numba.core.typed_passes import type_inference_stage from numba.compiler_machinery import FunctionPass, register_pass, PassManager from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, RewriteSemanticConstants, GenericRewrites, WithLifting, PreserveIR, InlineClosureLikes) -from numba.typed_passes import (NopythonTypeInference, AnnotateTypes, +from numba.core.typed_passes import (NopythonTypeInference, AnnotateTypes, NopythonRewrites, PreParforPass, ParforPass, DumpParforDiagnostics, NativeLowering, IRLegalization, NoPythonBackend) From 054f7eb7c9ed8f3ef46c50e9f936199aeb67f4f7 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 11:07:49 +0000 Subject: [PATCH 378/595] Move numba/typeinfer.py to numba/core --- numba/core/typed_passes.py | 4 ++-- numba/{ => core}/typeinfer.py | 0 numba/decorators.py | 2 +- numba/parfor.py | 3 +-- numba/tests/test_operators.py | 4 ++-- numba/tests/test_typeinfer.py | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) rename numba/{ => core}/typeinfer.py (100%) diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index c05a5749b24..bd949e2ec94 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -1,8 +1,8 @@ from contextlib import contextmanager import warnings -from numba import config, typeinfer, lowering -from numba.core import errors, types, typing, ir, funcdesc, rewrites +from numba import config, lowering +from numba.core import errors, types, typing, ir, funcdesc, rewrites, typeinfer from numba.parfor import PreParforPass as _parfor_PreParforPass from numba.parfor import ParforPass as _parfor_ParforPass diff --git a/numba/typeinfer.py b/numba/core/typeinfer.py similarity index 100% rename from numba/typeinfer.py rename to numba/core/typeinfer.py diff --git a/numba/decorators.py b/numba/decorators.py index b17c6c3eeea..72bf2252849 100644 --- a/numba/decorators.py +++ b/numba/decorators.py @@ -193,7 +193,7 @@ def wrapper(func): if sigs is not None: # Register the Dispatcher to the type inference mechanism, # even though the decorator hasn't returned yet. - from numba import typeinfer + from numba.core import typeinfer with typeinfer.register_dispatcher(disp): for sig in sigs: disp.compile(sig) diff --git a/numba/parfor.py b/numba/parfor.py index c72f13a07c8..c49c6512d58 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -25,9 +25,8 @@ import operator import numba.core.ir -from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites +from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites, typeinfer from numba import ir_utils, config, prange, pndindex -from numba import typeinfer from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate from numba import stencilparfor diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 5ae1ad4a366..40599e62a8a 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -8,8 +8,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import jit, typeinfer -from numba.core import types, utils, errors +from numba import jit +from numba.core import types, utils, errors, typeinfer from numba.tests.support import TestCase, tag, needs_blas from numba.tests.matmul_usecase import (matmul_usecase, imatmul_usecase, DumbMatrix,) diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index 23f98b3aa3a..1e01c924d04 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -5,8 +5,8 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated -from numba import typeinfer, jit -from numba.core import types, typing, errors, utils +from numba import jit +from numba.core import types, typing, errors, typeinfer, utils from numba.core.typeconv import Conversion from numba.tests.support import TestCase, tag From 3bcb01cc4a11e17ef3449885ee21bd6ad0cc6343 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 11:09:28 +0000 Subject: [PATCH 379/595] Move numba/tracing.py to numba/core --- numba/compiler.py | 2 +- numba/compiler_machinery.py | 2 +- numba/{ => core}/tracing.py | 0 numba/tests/test_tracing.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename numba/{ => core}/tracing.py (100%) diff --git a/numba/compiler.py b/numba/compiler.py index e4f71a8563c..645cde27cd1 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -1,7 +1,7 @@ from collections import namedtuple import copy import warnings -from numba.tracing import event +from numba.core.tracing import event from numba import config from numba.core import utils, errors, typing, interpreter, bytecode, postproc diff --git a/numba/compiler_machinery.py b/numba/compiler_machinery.py index cf96e03b5de..6b2b423ae79 100644 --- a/numba/compiler_machinery.py +++ b/numba/compiler_machinery.py @@ -6,7 +6,7 @@ from numba.core import errors from numba import config, transforms from numba.core.utils import add_metaclass -from numba.tracing import event +from numba.core.tracing import event from numba.core.postproc import PostProcessor # terminal color markup diff --git a/numba/tracing.py b/numba/core/tracing.py similarity index 100% rename from numba/tracing.py rename to numba/core/tracing.py diff --git a/numba/tests/test_tracing.py b/numba/tests/test_tracing.py index c6d80bcab3d..9e3b222135d 100644 --- a/numba/tests/test_tracing.py +++ b/numba/tests/test_tracing.py @@ -2,7 +2,7 @@ import logging import numba.unittest_support as unittest -from numba import tracing +from numba.core import tracing logger = logging.getLogger('trace') logger.setLevel(logging.INFO) From b1794bd11e199bae5997a46abce0dab079c0ba67 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 11:15:10 +0000 Subject: [PATCH 380/595] Move numba/withcontexts.py to numba/core --- numba/__init__.py | 4 ++-- numba/{ => core}/withcontexts.py | 0 numba/tests/test_withlifting.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename numba/{ => core}/withcontexts.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index 2a87da94a85..2e278a46775 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -40,8 +40,8 @@ from numba.jitclass import jitclass # Initialize withcontexts -import numba.withcontexts -from numba.withcontexts import objmode_context as objmode +import numba.core.withcontexts +from numba.core.withcontexts import objmode_context as objmode # Enable bytes/unicode array support import numba.cpython.charseq diff --git a/numba/withcontexts.py b/numba/core/withcontexts.py similarity index 100% rename from numba/withcontexts.py rename to numba/core/withcontexts.py diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index f646d00f21a..fc85c14cd8d 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -5,7 +5,7 @@ import numba from numba import unittest_support as unittest from numba.transforms import find_setupwiths, with_lifting -from numba.withcontexts import bypass_context, call_context, objmode_context +from numba.core.withcontexts import bypass_context, call_context, objmode_context from numba.core.bytecode import FunctionIdentity, ByteCode from numba.core.interpreter import Interpreter from numba.core import typing, errors From df934b4adc7aa4db4c0b798ba7648631d48d9656 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 11:19:37 +0000 Subject: [PATCH 381/595] Move numba/inline_closurecall.py to numba/core --- numba/compiler.py | 2 +- numba/{ => core}/inline_closurecall.py | 0 numba/core/typed_passes.py | 2 +- numba/core/untyped_passes.py | 4 ++-- numba/ir_utils.py | 2 +- numba/parfor.py | 4 ++-- numba/tests/test_inlining.py | 2 +- numba/tests/test_parfors.py | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) rename numba/{ => core}/inline_closurecall.py (100%) diff --git a/numba/compiler.py b/numba/compiler.py index 645cde27cd1..dbe1ec16a81 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -7,7 +7,7 @@ from numba.core import utils, errors, typing, interpreter, bytecode, postproc from numba.targets import cpu, callconv from numba.parfor import ParforDiagnostics -from numba.inline_closurecall import InlineClosureCallPass +from numba.core.inline_closurecall import InlineClosureCallPass from numba.core.errors import CompilerError from numba.compiler_machinery import PassManager diff --git a/numba/inline_closurecall.py b/numba/core/inline_closurecall.py similarity index 100% rename from numba/inline_closurecall.py rename to numba/core/inline_closurecall.py diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index bd949e2ec94..8ae45ef9c94 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -597,7 +597,7 @@ def _run_inliner( self, state, inline_type, sig, template, arg_typs, expr, i, impl, block, work_list, is_method, ): - from numba.inline_closurecall import (inline_closure_call, + from numba.core.inline_closurecall import (inline_closure_call, callee_ir_validator) do_inline = True diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 1b585cbfb97..54870d1ccf3 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -8,7 +8,7 @@ from numba.core import errors, types, ir, bytecode, postproc, rewrites from numba.special import literal_unroll from .analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls, compute_cfg_from_blocks, compute_use_defs -from numba.inline_closurecall import InlineClosureCallPass, inline_closure_call +from numba.core.inline_closurecall import InlineClosureCallPass, inline_closure_call from numba.ir_utils import guard, resolve_func_from_module, simplify_CFG, GuardException, convert_code_obj_to_function, mk_unique_var, build_definitions, replace_var_names, get_name_var_table, compile_to_numba_ir, get_definition, find_max_label, rename_labels from numba.core import interpreter @@ -305,7 +305,7 @@ def run_pass(self, state): return True def _do_work(self, state, work_list, block, i, expr): - from numba.inline_closurecall import (inline_closure_call, + from numba.core.inline_closurecall import (inline_closure_call, callee_ir_validator) from numba.compiler import run_frontend from numba.targets.cpu import InlineOptions diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 54cbb096cd7..1723425d31b 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -1660,7 +1660,7 @@ def __init__(self, f_ir): rewrites.rewrite_registry.apply('before-inference', DummyPipeline(ir).state) # call inline pass to handle cases like stencils and comprehensions swapped = {} # TODO: get this from diagnostics store - inline_pass = numba.inline_closurecall.InlineClosureCallPass( + inline_pass = numba.core.inline_closurecall.InlineClosureCallPass( ir, numba.targets.cpu.ParallelOptions(False), swapped) inline_pass.run() post_proc = postproc.PostProcessor(ir) diff --git a/numba/parfor.py b/numba/parfor.py index c49c6512d58..aee7a91444f 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -1346,7 +1346,7 @@ def _replace_parallel_functions(self, blocks): The implementation code is inlined to enable more optimization. """ swapped = self.swapped - from numba.inline_closurecall import inline_closure_call + from numba.core.inline_closurecall import inline_closure_call work_list = list(blocks.items()) while work_list: label, block = work_list.pop() @@ -2432,7 +2432,7 @@ def _mk_reduction_body(self, call_name, scope, loc, """ Produce the body blocks for a reduction function indicated by call_name. """ - from numba.inline_closurecall import check_reduce_func + from numba.core.inline_closurecall import check_reduce_func reduce_func = get_definition(self.func_ir, call_name) fcode = check_reduce_func(self.func_ir, reduce_func) diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index aa5c9139c47..d7fcbd5b170 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -9,7 +9,7 @@ from numba.core import types, ir, postproc from numba.ir_utils import guard, find_callname, find_const, get_definition from numba.targets.registry import CPUDispatcher -from numba.inline_closurecall import inline_closure_call +from numba.core.inline_closurecall import inline_closure_call from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 985d3e8fb6d..b6e70045e84 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -20,10 +20,10 @@ import numba from numba import unittest_support as unittest -from numba import njit, prange, stencil, inline_closurecall +from numba import njit, prange, stencil from numba import compiler from numba.targets import cpu -from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes +from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall from numba.targets.registry import cpu_target from numba import config from numba.core.annotations import type_annotations From 5943e563be71a7a341c940e7a19a4968bbf887d5 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 11:21:52 +0000 Subject: [PATCH 382/595] Move targets/compiler_machinery.py to numba/cpython --- docs/source/developer/compiler_pass_example.py | 2 +- numba/compiler.py | 2 +- numba/{ => core}/compiler_machinery.py | 0 numba/core/object_mode_passes.py | 2 +- numba/core/typed_passes.py | 2 +- numba/core/untyped_passes.py | 4 ++-- numba/tests/test_array_analysis.py | 2 +- numba/tests/test_errorhandling.py | 2 +- numba/tests/test_inlining.py | 2 +- numba/tests/test_ir_utils.py | 2 +- numba/tests/test_mixed_tuple_unroller.py | 2 +- numba/tests/test_practical_lowering_issues.py | 2 +- numba/tests/test_remove_dead.py | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) rename numba/{ => core}/compiler_machinery.py (100%) diff --git a/docs/source/developer/compiler_pass_example.py b/docs/source/developer/compiler_pass_example.py index 020bb30aabf..e64ed81b9a2 100644 --- a/docs/source/developer/compiler_pass_example.py +++ b/docs/source/developer/compiler_pass_example.py @@ -4,7 +4,7 @@ def ex_compiler_pass(): from numba import njit from numba.core import ir from numba.compiler import CompilerBase, DefaultPassBuilder - from numba.compiler_machinery import FunctionPass, register_pass + from numba.core.compiler_machinery import FunctionPass, register_pass from numba.core.untyped_passes import IRProcessing from numbers import Number diff --git a/numba/compiler.py b/numba/compiler.py index dbe1ec16a81..5f8a11e0aaa 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -10,7 +10,7 @@ from numba.core.inline_closurecall import InlineClosureCallPass from numba.core.errors import CompilerError -from numba.compiler_machinery import PassManager +from numba.core.compiler_machinery import PassManager from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, diff --git a/numba/compiler_machinery.py b/numba/core/compiler_machinery.py similarity index 100% rename from numba/compiler_machinery.py rename to numba/core/compiler_machinery.py diff --git a/numba/core/object_mode_passes.py b/numba/core/object_mode_passes.py index 02fbd8cd94d..7e4538dfe6f 100644 --- a/numba/core/object_mode_passes.py +++ b/numba/core/object_mode_passes.py @@ -2,7 +2,7 @@ import warnings from numba import config, pylowering, transforms from numba.core import errors, types, typing, funcdesc -from numba.compiler_machinery import FunctionPass, LoweringPass, register_pass +from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass from collections import defaultdict diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index 8ae45ef9c94..619d161cb3c 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -8,7 +8,7 @@ from numba.parfor import ParforPass as _parfor_ParforPass from numba.parfor import Parfor -from numba.compiler_machinery import FunctionPass, LoweringPass, register_pass +from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass from numba.core.annotations import type_annotations from numba.ir_utils import (raise_on_unsupported_feature, warn_deprecated, check_and_legalize_ir, guard, dead_code_elimination, diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 54870d1ccf3..95850a1d57d 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -3,7 +3,7 @@ from copy import deepcopy, copy import warnings -from numba.compiler_machinery import FunctionPass, register_pass +from numba.core.compiler_machinery import FunctionPass, register_pass from numba import config, transforms from numba.core import errors, types, ir, bytecode, postproc, rewrites from numba.special import literal_unroll @@ -1403,7 +1403,7 @@ def run_pass(self, state): return False # run as subpipeline - from numba.compiler_machinery import PassManager + from numba.core.compiler_machinery import PassManager from numba.core.typed_passes import PartialTypeInference pm = PassManager("literal_unroll_subpipeline") # get types where possible to help with list->tuple change diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index fbde2e65fad..2caa40212ec 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -21,7 +21,7 @@ from numba.core.typed_passes import (NopythonTypeInference, AnnotateTypes, NopythonRewrites, IRLegalization) -from numba.compiler_machinery import FunctionPass, PassManager, register_pass +from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass skip_unsupported = skip_parfors_unsupported diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index 7760649ae59..3b3feab0eae 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -15,7 +15,7 @@ NativeLowering, IRLegalization, NoPythonBackend) -from numba.compiler_machinery import FunctionPass, PassManager, register_pass +from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass from numba.tests.support import skip_parfors_unsupported diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index d7fcbd5b170..a1d4568ea30 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -21,7 +21,7 @@ DumpParforDiagnostics, NativeLowering, IRLegalization, NoPythonBackend) -from numba.compiler_machinery import FunctionPass, PassManager, register_pass +from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass @jit((types.int32,), nopython=True) def inner(a): diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index e5e939ee769..d5b86eca6df 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -3,7 +3,7 @@ from numba import compiler, jitclass from numba.targets.registry import cpu_target from numba.compiler import CompilerBase, Flags -from numba.compiler_machinery import PassManager +from numba.core.compiler_machinery import PassManager from numba.targets import registry from numba import ir_utils from numba.core import types, ir, bytecode diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index a4bf65ff568..663d9e306e9 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -6,7 +6,7 @@ from numba.core import types, errors, ir from numba.testing import unittest from numba.extending import overload -from numba.compiler_machinery import PassManager, register_pass, FunctionPass +from numba.core.compiler_machinery import PassManager, register_pass, FunctionPass from numba.compiler import CompilerBase from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, InlineClosureLikes, SimplifyCFG, diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index 0b4f56c7048..e81459c04d0 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -7,7 +7,7 @@ from numba.core import types, ir from numba.compiler import CompilerBase, DefaultPassBuilder from numba.core.typed_passes import NopythonTypeInference -from numba.compiler_machinery import register_pass, FunctionPass +from numba.core.compiler_machinery import register_pass, FunctionPass from numba.tests.support import MemoryLeakMixin, TestCase diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index cd7a8262d23..ecca3a5783f 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -15,7 +15,7 @@ get_name_var_table, remove_dels, remove_dead, remove_call_handlers, alias_func_extensions) from numba.core.typed_passes import type_inference_stage -from numba.compiler_machinery import FunctionPass, register_pass, PassManager +from numba.core.compiler_machinery import FunctionPass, register_pass, PassManager from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, RewriteSemanticConstants, GenericRewrites, From 4736aa804d249170f4e5c94e958c102ea42bf081 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 11:47:09 +0000 Subject: [PATCH 383/595] Move targets/config.py to numba/cpython --- numba/__init__.py | 2 +- numba/cgutils.py | 3 +-- numba/compiler.py | 3 +-- numba/core/caching.py | 3 ++- numba/core/callwrapper.py | 4 ++-- numba/core/compiler_machinery.py | 4 ++-- numba/{ => core}/config.py | 0 numba/core/dispatcher.py | 4 ++-- numba/core/errors.py | 6 +++--- numba/core/generators.py | 4 ++-- numba/core/inline_closurecall.py | 4 ++-- numba/core/interpreter.py | 3 +-- numba/core/ir.py | 3 +-- numba/core/object_mode_passes.py | 4 ++-- numba/core/pythonapi.py | 4 ++-- numba/core/rewrites/registry.py | 2 +- numba/core/tracing.py | 2 +- numba/core/typed_passes.py | 4 ++-- numba/core/typeinfer.py | 3 +-- numba/core/typing/npydecl.py | 3 +-- numba/core/untyped_passes.py | 4 ++-- numba/core/utils.py | 2 +- numba/cpython/mathimpl.py | 4 ++-- numba/cuda/__init__.py | 2 +- numba/cuda/compiler.py | 4 ++-- numba/cuda/cuda_paths.py | 2 +- numba/cuda/cudadrv/__init__.py | 2 +- numba/cuda/cudadrv/driver.py | 3 +-- numba/cuda/cudadrv/nvvm.py | 2 +- numba/cuda/decorators.py | 4 ++-- numba/cuda/simulator/__init__.py | 3 +-- numba/cuda/testing.py | 3 ++- numba/cuda/tests/cudadrv/test_deallocations.py | 3 ++- numba/cuda/tests/cudapy/test_atomics.py | 2 +- numba/cuda/tests/cudapy/test_constmem.py | 2 +- numba/cuda/tests/cudapy/test_exception.py | 3 ++- numba/cuda/tests/cudapy/test_laplace.py | 3 ++- numba/cuda/tests/cudapy/test_matmul.py | 3 ++- numba/cuda/tests/cudapy/test_random.py | 3 ++- numba/cuda/tests/cudapy/test_reduction.py | 2 +- numba/cuda/tests/cudapy/test_sync.py | 2 +- numba/cuda/tests/cudapy/test_userexc.py | 3 ++- numba/cuda/tests/cudapy/test_vectorize.py | 2 +- .../cuda/tests/cudapy/test_vectorize_scalar_arg.py | 2 +- numba/cuda/tests/cudapy/test_warp_ops.py | 3 ++- numba/cuda/tests/nocuda/test_library_lookup.py | 2 +- numba/decorators.py | 3 ++- numba/extending.py | 3 +-- numba/ir_utils.py | 4 ++-- numba/jitclass/decorators.py | 3 +-- numba/lowering.py | 4 ++-- numba/npyufunc/parallel.py | 3 +-- numba/npyufunc/parfor.py | 3 +-- numba/numba_entry.py | 2 +- numba/parfor.py | 4 ++-- numba/parfors/array_analysis.py | 4 ++-- numba/roc/compiler.py | 3 +-- numba/roc/hlc/hlc.py | 3 +-- numba/roc/hlc/libhlc.py | 2 +- numba/roc/hsadrv/driver.py | 3 +-- numba/roc/tests/hsadrv/test_driver.py | 11 ++++++----- numba/runtime/nrtdynmod.py | 2 +- numba/stencil.py | 3 +-- numba/stencilparfor.py | 6 +++--- numba/targets/base.py | 4 ++-- numba/targets/codegen.py | 4 ++-- numba/targets/cpu.py | 4 ++-- numba/targets/gdb_hook.py | 4 ++-- numba/targets/options.py | 2 +- numba/testing/__init__.py | 2 +- numba/testing/main.py | 2 +- numba/tests/npyufunc/test_caching.py | 2 +- numba/tests/npyufunc/test_parallel_env_variable.py | 2 +- numba/tests/npyufunc/test_ufuncbuilding.py | 3 ++- numba/tests/support.py | 14 ++++++++------ numba/tests/test_boundscheck.py | 3 ++- numba/tests/test_builtins.py | 4 ++-- numba/tests/test_config.py | 2 +- numba/tests/test_copy_propagate.py | 3 +-- numba/tests/test_dictimpl.py | 2 +- numba/tests/test_dyn_array.py | 3 +-- numba/tests/test_jitmethod.py | 4 ++-- numba/tests/test_mathlib.py | 2 +- numba/tests/test_np_functions.py | 2 +- numba/tests/test_npdatetime.py | 4 ++-- numba/tests/test_parallel_backend.py | 3 +-- numba/tests/test_parfors.py | 3 +-- numba/tests/test_record_dtype.py | 2 +- numba/tests/test_remove_dead.py | 3 +-- numba/tests/test_svml.py | 7 ++++--- numba/tests/test_threadsafety.py | 2 +- numba/typed/typeddict.py | 3 +-- numba/typed/typedlist.py | 3 +-- numba/unittest_support.py | 2 +- 94 files changed, 147 insertions(+), 154 deletions(-) rename numba/{ => core}/config.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index 2e278a46775..39bf8838136 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -11,7 +11,7 @@ __version__ = get_versions()['version'] del get_versions -from numba import config +from numba.core import config from numba.testing import _runtests as runtests from numba.core import types, errors diff --git a/numba/cgutils.py b/numba/cgutils.py index f4b95e2914b..b43e40bbfd1 100644 --- a/numba/cgutils.py +++ b/numba/cgutils.py @@ -9,8 +9,7 @@ from llvmlite import ir -from numba.core import utils, types -from numba import config +from numba.core import utils, types, config import numba.core.datamodel diff --git a/numba/compiler.py b/numba/compiler.py index 5f8a11e0aaa..04a807f0f6a 100644 --- a/numba/compiler.py +++ b/numba/compiler.py @@ -3,8 +3,7 @@ import warnings from numba.core.tracing import event -from numba import config -from numba.core import utils, errors, typing, interpreter, bytecode, postproc +from numba.core import utils, errors, typing, interpreter, bytecode, postproc, config from numba.targets import cpu, callconv from numba.parfor import ParforDiagnostics from numba.core.inline_closurecall import InlineClosureCallPass diff --git a/numba/core/caching.py b/numba/core/caching.py index c6e31b3f019..86ec2dd1263 100644 --- a/numba/core/caching.py +++ b/numba/core/caching.py @@ -19,11 +19,12 @@ from numba.core.utils import add_metaclass, file_replace import numba -from numba import compiler, config +from numba import compiler from numba.core.errors import NumbaWarning from numba.targets.base import BaseContext from numba.targets.codegen import CodeLibrary from numba.compiler import CompileResult +from numba.core import config def _get_codegen(obj): diff --git a/numba/core/callwrapper.py b/numba/core/callwrapper.py index 9845e739525..733c62d320f 100644 --- a/numba/core/callwrapper.py +++ b/numba/core/callwrapper.py @@ -1,8 +1,8 @@ from llvmlite.llvmpy.core import Type, Builder, Constant import llvmlite.llvmpy.core as lc -from numba.core import types -from numba import cgutils, config +from numba.core import types, config +from numba import cgutils class _ArgManager(object): diff --git a/numba/core/compiler_machinery.py b/numba/core/compiler_machinery.py index 6b2b423ae79..286bf998d20 100644 --- a/numba/core/compiler_machinery.py +++ b/numba/core/compiler_machinery.py @@ -3,8 +3,8 @@ from collections import namedtuple, OrderedDict import inspect from numba.core.compiler_lock import global_compiler_lock -from numba.core import errors -from numba import config, transforms +from numba.core import errors, config +from numba import transforms from numba.core.utils import add_metaclass from numba.core.tracing import event from numba.core.postproc import PostProcessor diff --git a/numba/config.py b/numba/core/config.py similarity index 100% rename from numba/config.py rename to numba/core/config.py diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py index ca64682f323..7c7614c67e0 100644 --- a/numba/core/dispatcher.py +++ b/numba/core/dispatcher.py @@ -11,8 +11,8 @@ import weakref from copy import deepcopy -from numba import _dispatcher, compiler, config -from numba.core import utils, types, errors, typing, serialize +from numba import _dispatcher, compiler +from numba.core import utils, types, errors, typing, serialize, config from numba.core.compiler_lock import global_compiler_lock from numba.core.typeconv.rules import default_type_manager from numba import sigutils diff --git a/numba/core/errors.py b/numba/core/errors.py index b40a14de5ec..78b672df692 100644 --- a/numba/core/errors.py +++ b/numba/core/errors.py @@ -8,7 +8,7 @@ import os import sys import warnings -import numba +import numba.core.config import numpy as np from collections import defaultdict from numba.core.utils import add_metaclass, reraise, chain_exception @@ -280,7 +280,7 @@ def highlight(self, msg): def termcolor(): global _termcolor_inst if _termcolor_inst is None: - scheme = themes[numba.config.COLOR_SCHEME] + scheme = themes[numba.core.config.COLOR_SCHEME] _termcolor_inst = HighlightColorScheme(scheme) return _termcolor_inst @@ -718,7 +718,7 @@ def new_error_context(fmt_, *args, **kwargs): except Exception as e: newerr = errcls(e).add_context(_format_msg(fmt_, args, kwargs)) from numba import config - tb = sys.exc_info()[2] if config.FULL_TRACEBACKS else None + tb = sys.exc_info()[2] if numba.core.config.FULL_TRACEBACKS else None reraise(type(newerr), newerr, tb) diff --git a/numba/core/generators.py b/numba/core/generators.py index 8457cff6b5a..64af0bc2f81 100644 --- a/numba/core/generators.py +++ b/numba/core/generators.py @@ -4,8 +4,8 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import cgutils, config -from numba.core import types +from numba import cgutils +from numba.core import types, config from numba.core.funcdesc import FunctionDescriptor diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index afa71d7823a..0d8e4d56600 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -1,8 +1,8 @@ import types as pytypes # avoid confusion with numba.types import ctypes import numba.core.analysis -from numba.core import utils, types, typing, errors, ir, rewrites -from numba import config, ir_utils, prange +from numba.core import utils, types, typing, errors, ir, rewrites, config +from numba import ir_utils, prange from numba.parfor import internal_prange from numba.ir_utils import ( mk_unique_var, diff --git a/numba/core/interpreter.py b/numba/core/interpreter.py index c4be7ef032f..8ae8616c3e0 100644 --- a/numba/core/interpreter.py +++ b/numba/core/interpreter.py @@ -4,8 +4,7 @@ import operator import logging -from numba.core import errors, dataflow, controlflow, ir -from numba import config +from numba.core import errors, dataflow, controlflow, ir, config from numba.core.errors import NotDefinedError from numba.core.utils import ( PYVERSION, diff --git a/numba/core/ir.py b/numba/core/ir.py index 251c4236cf4..21ac931bfc0 100644 --- a/numba/core/ir.py +++ b/numba/core/ir.py @@ -11,8 +11,7 @@ from functools import total_ordering from io import StringIO -from numba import config -from numba.core import errors +from numba.core import errors, config from numba.core.utils import (BINOPS_TO_OPERATORS, INPLACE_BINOPS_TO_OPERATORS, UNARY_BUITINS_TO_OPERATORS, OPERATORS_TO_BUILTINS) from numba.core.errors import (NotDefinedError, RedefinedError, diff --git a/numba/core/object_mode_passes.py b/numba/core/object_mode_passes.py index 7e4538dfe6f..53e232dd1b2 100644 --- a/numba/core/object_mode_passes.py +++ b/numba/core/object_mode_passes.py @@ -1,7 +1,7 @@ from contextlib import contextmanager import warnings -from numba import config, pylowering, transforms -from numba.core import errors, types, typing, funcdesc +from numba import pylowering, transforms +from numba.core import errors, types, typing, funcdesc, config from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass from collections import defaultdict diff --git a/numba/core/pythonapi.py b/numba/core/pythonapi.py index dc2f9bc1d19..28378e85a0b 100644 --- a/numba/core/pythonapi.py +++ b/numba/core/pythonapi.py @@ -7,8 +7,8 @@ import llvmlite.llvmpy.core as lc import ctypes -from numba import config, cgutils, lowering, _helperlib -from numba.core import types, utils +from numba import cgutils, lowering, _helperlib +from numba.core import types, utils, config PY_UNICODE_1BYTE_KIND = _helperlib.py_unicode_1byte_kind diff --git a/numba/core/rewrites/registry.py b/numba/core/rewrites/registry.py index 0e77e57ef23..ea22fc8e354 100644 --- a/numba/core/rewrites/registry.py +++ b/numba/core/rewrites/registry.py @@ -1,6 +1,6 @@ from collections import defaultdict -from numba import config +from numba.core import config class Rewrite(object): diff --git a/numba/core/tracing.py b/numba/core/tracing.py index a263102d7fe..282e844200a 100644 --- a/numba/core/tracing.py +++ b/numba/core/tracing.py @@ -5,7 +5,7 @@ import inspect from functools import wraps from itertools import chain -from numba import config +from numba.core import config class TLS(threading.local): """Use a subclass to properly initialize the TLS variables in all threads.""" diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index 619d161cb3c..099034a9e96 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -1,8 +1,8 @@ from contextlib import contextmanager import warnings -from numba import config, lowering -from numba.core import errors, types, typing, ir, funcdesc, rewrites, typeinfer +from numba import lowering +from numba.core import errors, types, typing, ir, funcdesc, rewrites, typeinfer, config from numba.parfor import PreParforPass as _parfor_PreParforPass from numba.parfor import ParforPass as _parfor_ParforPass diff --git a/numba/core/typeinfer.py b/numba/core/typeinfer.py index d5aec2552b2..5c6549caf4c 100644 --- a/numba/core/typeinfer.py +++ b/numba/core/typeinfer.py @@ -21,8 +21,7 @@ from collections import OrderedDict, defaultdict from functools import reduce -from numba import config -from numba.core import types, utils, typing, ir +from numba.core import types, utils, typing, ir, config from numba.core.typing.templates import Signature from numba.core.errors import (TypingError, UntypedAttributeError, new_error_context, termcolor, UnsupportedError, diff --git a/numba/core/typing/npydecl.py b/numba/core/typing/npydecl.py index 139bbc25b2c..eebe8e682e2 100644 --- a/numba/core/typing/npydecl.py +++ b/numba/core/typing/npydecl.py @@ -3,8 +3,7 @@ import numpy as np import operator -from numba.core import types, utils -from numba import config +from numba.core import types, utils, config from numba.core.typing.templates import (AttributeTemplate, AbstractTemplate, CallableTemplate, Registry, signature) diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 95850a1d57d..1af04e06922 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -4,8 +4,8 @@ import warnings from numba.core.compiler_machinery import FunctionPass, register_pass -from numba import config, transforms -from numba.core import errors, types, ir, bytecode, postproc, rewrites +from numba import transforms +from numba.core import errors, types, ir, bytecode, postproc, rewrites, config from numba.special import literal_unroll from .analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls, compute_cfg_from_blocks, compute_use_defs from numba.core.inline_closurecall import InlineClosureCallPass, inline_closure_call diff --git a/numba/core/utils.py b/numba/core/utils.py index 01eb5b50769..ac5e26b5bfd 100644 --- a/numba/core/utils.py +++ b/numba/core/utils.py @@ -17,7 +17,7 @@ from inspect import Signature as pySignature # noqa: F401 from inspect import Parameter as pyParameter # noqa: F401 -from numba.config import PYVERSION, MACHINE_BITS, DEVELOPER_MODE # noqa: F401 +from numba.core.config import PYVERSION, MACHINE_BITS, DEVELOPER_MODE # noqa: F401 INT_TYPES = (int,) diff --git a/numba/cpython/mathimpl.py b/numba/cpython/mathimpl.py index ac2a8e120e7..3ded2050acc 100644 --- a/numba/cpython/mathimpl.py +++ b/numba/cpython/mathimpl.py @@ -11,8 +11,8 @@ from llvmlite.llvmpy.core import Type from numba.targets.imputils import Registry, impl_ret_untracked -from numba import typeof, cgutils, config -from numba.core import types, utils +from numba import typeof, cgutils +from numba.core import types, utils, config from numba.extending import overload from numba.core.typing import signature from numba.cpython.unsafe.numbers import trailing_zeros diff --git a/numba/cuda/__init__.py b/numba/cuda/__init__.py index 20b48949c5c..9d912c5e8cd 100644 --- a/numba/cuda/__init__.py +++ b/numba/cuda/__init__.py @@ -1,5 +1,5 @@ -from numba import config import numba.testing +from numba.core import config if config.ENABLE_CUDASIM: from .simulator_init import * diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index b3c754985c7..6ebc53f0639 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -8,9 +8,9 @@ import numpy as np -from numba import config, compiler, sigutils +from numba import compiler, sigutils from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate -from numba.core import types, typing, utils, funcdesc, serialize +from numba.core import types, typing, utils, funcdesc, serialize, config from numba.core.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner diff --git a/numba/cuda/cuda_paths.py b/numba/cuda/cuda_paths.py index 58e19f5a48e..a83fd799cea 100644 --- a/numba/cuda/cuda_paths.py +++ b/numba/cuda/cuda_paths.py @@ -3,7 +3,7 @@ import os from collections import defaultdict, namedtuple -from numba.config import IS_WIN32, IS_OSX +from numba.core.config import IS_WIN32, IS_OSX from numba.findlib import find_lib, find_file from numba.cuda.envvars import get_numbapro_envvar diff --git a/numba/cuda/cudadrv/__init__.py b/numba/cuda/cudadrv/__init__.py index 87af73c9344..33bfca34566 100644 --- a/numba/cuda/cudadrv/__init__.py +++ b/numba/cuda/cudadrv/__init__.py @@ -5,5 +5,5 @@ - Device array implementation """ -from numba import config +from numba.core import config assert not config.ENABLE_CUDASIM, 'Cannot use real driver API with simulator' diff --git a/numba/cuda/cudadrv/driver.py b/numba/cuda/cudadrv/driver.py index f6d939122c9..79c21754d86 100644 --- a/numba/cuda/cudadrv/driver.py +++ b/numba/cuda/cudadrv/driver.py @@ -28,12 +28,11 @@ from collections import namedtuple, deque from numba import mviewbuf -from numba.core import utils, errors, serialize +from numba.core import utils, errors, serialize, config from .error import CudaSupportError, CudaDriverError from .drvapi import API_PROTOTYPES from .drvapi import cu_occupancy_b2d_size from numba.cuda.cudadrv import enums, drvapi, _extras -from numba import config from numba.core.utils import longint as long from numba.cuda.envvars import get_numba_envvar diff --git a/numba/cuda/cudadrv/nvvm.py b/numba/cuda/cudadrv/nvvm.py index 8c6b56534e2..e5c40c04f76 100644 --- a/numba/cuda/cudadrv/nvvm.py +++ b/numba/cuda/cudadrv/nvvm.py @@ -9,9 +9,9 @@ from llvmlite import ir -from numba import config from .error import NvvmError, NvvmSupportError from .libs import get_libdevice, open_libdevice, open_cudalib +from numba.core import config logger = logging.getLogger(__name__) diff --git a/numba/cuda/decorators.py b/numba/cuda/decorators.py index bc252c4fe38..7ea671a53cd 100644 --- a/numba/cuda/decorators.py +++ b/numba/cuda/decorators.py @@ -1,6 +1,6 @@ from warnings import warn -from numba import config, sigutils -from numba.core import types +from numba import sigutils +from numba.core import types, config from .compiler import (compile_kernel, compile_device, declare_device_function, AutoJitCUDAKernel, compile_device_template) from .simulator.kernel import FakeCUDAKernel diff --git a/numba/cuda/simulator/__init__.py b/numba/cuda/simulator/__init__.py index daf2b8085ee..b41cafa423e 100644 --- a/numba/cuda/simulator/__init__.py +++ b/numba/cuda/simulator/__init__.py @@ -5,12 +5,11 @@ from .cudadrv import devicearray from .cudadrv.devices import require_context, gpus from .cudadrv.devices import get_context as current_context - +from numba.core import config reduce = Reduce # Ensure that any user code attempting to import cudadrv etc. gets the # simulator's version and not the real version if the simulator is enabled. -from numba import config if config.ENABLE_CUDASIM: import sys from numba.cuda.simulator import cudadrv diff --git a/numba/cuda/testing.py b/numba/cuda/testing.py index 765ced8235a..440580cc3b9 100644 --- a/numba/cuda/testing.py +++ b/numba/cuda/testing.py @@ -1,13 +1,14 @@ import contextlib import sys -from numba import config, unittest_support as unittest +from numba import unittest_support as unittest from numba.tests.support import ( captured_stdout, SerialMixin, redirect_c_stdout, ) from numba.cuda.cuda_paths import get_conda_ctk +from numba.core import config class CUDATestCase(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudadrv/test_deallocations.py b/numba/cuda/tests/cudadrv/test_deallocations.py index f53f33da293..f1b4136e190 100644 --- a/numba/cuda/tests/cudadrv/test_deallocations.py +++ b/numba/cuda/tests/cudadrv/test_deallocations.py @@ -2,9 +2,10 @@ import numpy as np -from numba import cuda, config +from numba import cuda from numba.cuda.testing import unittest, skip_on_cudasim, SerialMixin from numba.tests.support import captured_stderr +from numba.core import config @skip_on_cudasim('not supported on CUDASIM') diff --git a/numba/cuda/tests/cudapy/test_atomics.py b/numba/cuda/tests/cudapy/test_atomics.py index cf872815b6a..2871b30578a 100644 --- a/numba/cuda/tests/cudapy/test_atomics.py +++ b/numba/cuda/tests/cudapy/test_atomics.py @@ -1,9 +1,9 @@ import random import numpy as np -from numba import config from numba import cuda, uint32, uint64, float32, float64 from numba.cuda.testing import unittest, SerialMixin +from numba.core import config def cc_X_or_above(major, minor): diff --git a/numba/cuda/tests/cudapy/test_constmem.py b/numba/cuda/tests/cudapy/test_constmem.py index 0f916ff5489..5ac51bf1484 100644 --- a/numba/cuda/tests/cudapy/test_constmem.py +++ b/numba/cuda/tests/cudapy/test_constmem.py @@ -2,7 +2,7 @@ from numba import cuda from numba.cuda.testing import unittest, SerialMixin -from numba.config import ENABLE_CUDASIM +from numba.core.config import ENABLE_CUDASIM CONST_EMPTY = np.array([]) CONST1D = np.arange(10, dtype=np.float64) / 2. diff --git a/numba/cuda/tests/cudapy/test_exception.py b/numba/cuda/tests/cudapy/test_exception.py index 1044a8bf7e0..e6f55f108ac 100644 --- a/numba/cuda/tests/cudapy/test_exception.py +++ b/numba/cuda/tests/cudapy/test_exception.py @@ -1,7 +1,8 @@ import numpy as np -from numba import config, cuda, jit +from numba import cuda, jit from numba.cuda.testing import unittest, SerialMixin, skip_on_cudasim +from numba.core import config class TestException(SerialMixin, unittest.TestCase): def test_exception(self): diff --git a/numba/cuda/tests/cudapy/test_laplace.py b/numba/cuda/tests/cudapy/test_laplace.py index 9bd9a917d5b..0028e7c7645 100644 --- a/numba/cuda/tests/cudapy/test_laplace.py +++ b/numba/cuda/tests/cudapy/test_laplace.py @@ -1,7 +1,8 @@ import numpy as np import time -from numba import cuda, config, float64, void +from numba import cuda, float64, void from numba.cuda.testing import unittest, SerialMixin +from numba.core import config # NOTE: CUDA kernel does not return any value diff --git a/numba/cuda/tests/cudapy/test_matmul.py b/numba/cuda/tests/cudapy/test_matmul.py index 36755c0a178..78a03642eea 100644 --- a/numba/cuda/tests/cudapy/test_matmul.py +++ b/numba/cuda/tests/cudapy/test_matmul.py @@ -1,7 +1,8 @@ import numpy as np -from numba import cuda, config, float32 +from numba import cuda, float32 from numba.cuda.testing import unittest, SerialMixin +from numba.core import config # Ensure the test takes a reasonable amount of time in the simulator if config.ENABLE_CUDASIM: diff --git a/numba/cuda/tests/cudapy/test_random.py b/numba/cuda/tests/cudapy/test_random.py index 2ebfee76bfd..e71afa105f0 100644 --- a/numba/cuda/tests/cudapy/test_random.py +++ b/numba/cuda/tests/cudapy/test_random.py @@ -2,7 +2,7 @@ import numpy as np -from numba import cuda, config, float32 +from numba import cuda, float32 from numba.cuda.testing import unittest import numba.cuda.random from numba.cuda.testing import skip_on_cudasim, SerialMixin @@ -10,6 +10,7 @@ from numba.cuda.random import \ xoroshiro128p_uniform_float32, xoroshiro128p_normal_float32, \ xoroshiro128p_uniform_float64, xoroshiro128p_normal_float64 +from numba.core import config # Distributions diff --git a/numba/cuda/tests/cudapy/test_reduction.py b/numba/cuda/tests/cudapy/test_reduction.py index 9c87335b275..12337cc228a 100644 --- a/numba/cuda/tests/cudapy/test_reduction.py +++ b/numba/cuda/tests/cudapy/test_reduction.py @@ -1,7 +1,7 @@ import numpy as np from numba import cuda from numba import unittest_support as unittest -from numba.config import ENABLE_CUDASIM +from numba.core.config import ENABLE_CUDASIM from numba.cuda.testing import SerialMixin # Avoid recompilation of the sum_reduce function by keeping it at global scope diff --git a/numba/cuda/tests/cudapy/test_sync.py b/numba/cuda/tests/cudapy/test_sync.py index 70c39797c33..c7cfcc24556 100644 --- a/numba/cuda/tests/cudapy/test_sync.py +++ b/numba/cuda/tests/cudapy/test_sync.py @@ -1,7 +1,7 @@ import numpy as np from numba import cuda, int32, float32 from numba.cuda.testing import unittest, SerialMixin -from numba.config import ENABLE_CUDASIM +from numba.core.config import ENABLE_CUDASIM def useless_sync(ary): diff --git a/numba/cuda/tests/cudapy/test_userexc.py b/numba/cuda/tests/cudapy/test_userexc.py index 139c0f76a4a..f1862f362d4 100644 --- a/numba/cuda/tests/cudapy/test_userexc.py +++ b/numba/cuda/tests/cudapy/test_userexc.py @@ -1,5 +1,6 @@ from numba.cuda.testing import unittest, SerialMixin, skip_on_cudasim -from numba import cuda, config +from numba import cuda +from numba.core import config class MyError(Exception): diff --git a/numba/cuda/tests/cudapy/test_vectorize.py b/numba/cuda/tests/cudapy/test_vectorize.py index d2814207bc6..5823af409a9 100644 --- a/numba/cuda/tests/cudapy/test_vectorize.py +++ b/numba/cuda/tests/cudapy/test_vectorize.py @@ -5,7 +5,7 @@ from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim from numba.cuda.testing import CUDATestCase -from numba import config +from numba.core import config sig = [int32(int32, int32), float32(float32, float32), diff --git a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py index 61cc2d8dfb8..c8184561947 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +++ b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py @@ -3,7 +3,7 @@ from numba import cuda, float64 from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba import config +from numba.core import config sig = [float64(float64, float64)] diff --git a/numba/cuda/tests/cudapy/test_warp_ops.py b/numba/cuda/tests/cudapy/test_warp_ops.py index 99d724a5193..e0a5cd42faf 100644 --- a/numba/cuda/tests/cudapy/test_warp_ops.py +++ b/numba/cuda/tests/cudapy/test_warp_ops.py @@ -1,6 +1,7 @@ import numpy as np -from numba import cuda, config, int32, int64, float32, float64 +from numba import cuda, int32, int64, float32, float64 from numba.cuda.testing import unittest, SerialMixin, skip_on_cudasim +from numba.core import config def useful_syncwarp(ary): diff --git a/numba/cuda/tests/nocuda/test_library_lookup.py b/numba/cuda/tests/nocuda/test_library_lookup.py index 9d2dda414ca..ba22e14e427 100644 --- a/numba/cuda/tests/nocuda/test_library_lookup.py +++ b/numba/cuda/tests/nocuda/test_library_lookup.py @@ -3,7 +3,7 @@ import multiprocessing as mp import warnings -from numba.config import IS_WIN32, IS_OSX +from numba.core.config import IS_WIN32, IS_OSX from numba.core.errors import NumbaWarning from numba.cuda.cudadrv import nvvm from numba.cuda.testing import ( diff --git a/numba/decorators.py b/numba/decorators.py index 72bf2252849..eb58e175c05 100644 --- a/numba/decorators.py +++ b/numba/decorators.py @@ -8,10 +8,11 @@ import inspect import logging -from numba import config, sigutils +from numba import sigutils from numba.core.errors import DeprecationError, NumbaDeprecationWarning from numba.targets import registry from numba.stencil import stencil +from numba.core import config _logger = logging.getLogger(__name__) diff --git a/numba/extending.py b/numba/extending.py index febab3eb408..7dbb303cc97 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -5,8 +5,7 @@ import collections import numba -from numba.core import types, errors, utils -from numba import config +from numba.core import types, errors, utils, config # Exported symbols from numba.core.typing.typeof import typeof_impl diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 1723425d31b..8796631eb59 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -13,8 +13,8 @@ from llvmlite import ir as lir import numba -from numba.core import types, utils, typing, ir, analysis, postproc, rewrites -from numba import config, cgutils +from numba.core import types, utils, typing, ir, analysis, postproc, rewrites, config +from numba import cgutils from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) from numba.targets.imputils import impl_ret_untracked diff --git a/numba/jitclass/decorators.py b/numba/jitclass/decorators.py index d11c4e0b761..58909d2a5be 100644 --- a/numba/jitclass/decorators.py +++ b/numba/jitclass/decorators.py @@ -1,5 +1,4 @@ -from numba import config -from numba.core import types +from numba.core import types, config from .base import register_class_type, ClassBuilder diff --git a/numba/lowering.py b/numba/lowering.py index a7404c127c9..192b3fa786a 100644 --- a/numba/lowering.py +++ b/numba/lowering.py @@ -5,8 +5,8 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import _dynfunc, cgutils, config, ir_utils -from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators +from numba import _dynfunc, cgutils, ir_utils +from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) from numba.targets import removerefctpass diff --git a/numba/npyufunc/parallel.py b/numba/npyufunc/parallel.py index 5da51219764..eeb5e47839c 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/npyufunc/parallel.py @@ -24,8 +24,7 @@ from numba.npyufunc import ufuncbuilder from numba.numpy_support import as_dtype -from numba import config -from numba.core import types +from numba.core import types, config from numba.npyufunc.wrappers import _wrapper_info diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 56770f782d3..ed7ccc91a51 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -11,7 +11,7 @@ import numba from numba import compiler, cgutils, sigutils, lowering, parfor -from numba.core import types, ir +from numba.core import types, ir, config from numba.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, @@ -22,7 +22,6 @@ from numba.core.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) from numba.core.typing import signature -from numba import config from numba.targets.cpu import ParallelOptions from numba.parfor import print_wrapped, ensure_parallel_support from numba.core.errors import NumbaParallelSafetyWarning diff --git a/numba/numba_entry.py b/numba/numba_entry.py index e58fde14ca1..005b9b62412 100644 --- a/numba/numba_entry.py +++ b/numba/numba_entry.py @@ -10,7 +10,7 @@ def get_sys_info(): import platform import json import multiprocessing - from numba import config + from numba.core import config from numba import cuda as cu from numba.cuda import cudadrv from numba.cuda.cudadrv.driver import driver as cudriver diff --git a/numba/parfor.py b/numba/parfor.py index aee7a91444f..7f28ec24cb5 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -25,8 +25,8 @@ import operator import numba.core.ir -from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites, typeinfer -from numba import ir_utils, config, prange, pndindex +from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites, typeinfer, config +from numba import ir_utils, prange, pndindex from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate from numba import stencilparfor diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index 19d307491fa..9e9670b212e 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -6,8 +6,8 @@ import types as pytypes import numpy import operator -from numba import config, cgutils -from numba.core import types, typing, ir, analysis +from numba import cgutils +from numba.core import types, typing, ir, analysis, config from numba.ir_utils import ( mk_unique_var, replace_vars_inner, diff --git a/numba/roc/compiler.py b/numba/roc/compiler.py index 759b078687a..7e1a2748c5f 100644 --- a/numba/roc/compiler.py +++ b/numba/roc/compiler.py @@ -7,7 +7,7 @@ from numba.core.typing.templates import ConcreteTemplate from numba import compiler -from numba.core import types +from numba.core import types, config from .hlc import hlc from .hsadrv import devices, driver, enums, drvapi from .hsadrv.error import HsaKernelLaunchError @@ -15,7 +15,6 @@ from numba.roc.hsadrv.driver import hsa, dgpu_present from .hsadrv import devicearray from numba.core.typing.templates import AbstractTemplate -from numba import config from numba.core.compiler_lock import global_compiler_lock @global_compiler_lock diff --git a/numba/roc/hlc/hlc.py b/numba/roc/hlc/hlc.py index ab787bb59a6..e03434eec38 100644 --- a/numba/roc/hlc/hlc.py +++ b/numba/roc/hlc/hlc.py @@ -7,14 +7,13 @@ import os import re from collections import namedtuple -from numba import config from numba.roc.hsadrv import devices from .common import AMDGCNModule from .config import ROCM_BC_PATH from numba.roc.hlc import TRIPLE from datetime import datetime from contextlib import contextmanager -from numba.core import utils +from numba.core import utils, config from numba.roc.hsadrv.error import HsaSupportError _real_check_call = check_call diff --git a/numba/roc/hlc/libhlc.py b/numba/roc/hlc/libhlc.py index 8660412f018..3c2d0db3a88 100644 --- a/numba/roc/hlc/libhlc.py +++ b/numba/roc/hlc/libhlc.py @@ -8,11 +8,11 @@ import os import re import weakref -from numba import config from numba.roc.hsadrv import devices from .common import AMDGCNModule from numba.roc.hlc.hlc import CmdLine +from numba.core import config # the CLI tooling is needed for the linking phase at present cli = CmdLine() diff --git a/numba/roc/hsadrv/driver.py b/numba/roc/hsadrv/driver.py index 958247c3210..15b67c146b1 100644 --- a/numba/roc/hsadrv/driver.py +++ b/numba/roc/hsadrv/driver.py @@ -17,8 +17,7 @@ from collections import defaultdict, deque from functools import total_ordering from numba import mviewbuf -from numba.core import utils -from numba import config +from numba.core import utils, config from .error import HsaSupportError, HsaDriverError, HsaApiError from numba.roc.hsadrv import enums, enums_ext, drvapi from numba.core.utils import longint as long diff --git a/numba/roc/tests/hsadrv/test_driver.py b/numba/roc/tests/hsadrv/test_driver.py index 3deb16f20ad..d14c4458b34 100644 --- a/numba/roc/tests/hsadrv/test_driver.py +++ b/numba/roc/tests/hsadrv/test_driver.py @@ -1,10 +1,6 @@ import ctypes import os import threading -try: - import queue -except ImportError: - import Queue as queue import numpy as np @@ -20,7 +16,12 @@ from numba.roc.hsadrv import enums from numba.roc.hsadrv import enums_ext -from numba import config +from numba.core import config + +try: + import queue +except ImportError: + import Queue as queue class TestLowLevelApi(unittest.TestCase): """This test checks that all the functions defined in drvapi diff --git a/numba/runtime/nrtdynmod.py b/numba/runtime/nrtdynmod.py index 5da6b5ebd33..55f92b9021a 100644 --- a/numba/runtime/nrtdynmod.py +++ b/numba/runtime/nrtdynmod.py @@ -3,7 +3,7 @@ """ -from numba.config import MACHINE_BITS +from numba.core.config import MACHINE_BITS from numba import cgutils from numba.core import types from llvmlite import ir, binding diff --git a/numba/stencil.py b/numba/stencil.py index 3e17176f6ee..bcaa9323fe1 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -9,8 +9,7 @@ from llvmlite import ir as lir from numba import compiler, ir_utils, numpy_support -from numba.core import types, typing, utils, ir, typed_passes -from numba import config +from numba.core import types, typing, utils, ir, typed_passes, config from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) from numba.targets import registry diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 3c6e5cff5d0..b76d07f4167 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -12,11 +12,11 @@ import numpy as np import numba -from numba.core import types, ir, rewrites +from numba.core import types, ir, rewrites, config from numba.core.typing.templates import infer_global, AbstractTemplate from numba.core.typing import signature from numba.core import utils, typing -from numba import ir_utils, config +from numba import ir_utils from numba.ir_utils import (get_call_table, mk_unique_var, compile_to_numba_ir, replace_arg_nodes, guard, find_callname, require, find_const, GuardException) @@ -681,7 +681,7 @@ def get_stencil_ir(sf, typingctx, args, scope, loc, input_dict, typemap, lifted_from=None, args=tp.state.args, return_type=tp.state.return_type, - html_output=numba.config.HTML) + html_output=config.HTML) # make block labels unique stencil_blocks = ir_utils.add_offset_to_labels(stencil_blocks, diff --git a/numba/targets/base.py b/numba/targets/base.py index 79900eaf742..6fd4a6e94e6 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -12,8 +12,8 @@ from llvmlite.llvmpy.core import Type, Constant, LLVMException import llvmlite.binding as ll -from numba.core import types, utils, typing, datamodel, debuginfo, funcdesc -from numba import cgutils, config +from numba.core import types, utils, typing, datamodel, debuginfo, funcdesc, config +from numba import cgutils from numba import _dynfunc, _helperlib from numba.core.compiler_lock import global_compiler_lock from numba.core.pythonapi import PythonAPI diff --git a/numba/targets/codegen.py b/numba/targets/codegen.py index 3ab9bcdbcca..443d2451bff 100644 --- a/numba/targets/codegen.py +++ b/numba/targets/codegen.py @@ -9,8 +9,8 @@ import llvmlite.binding as ll import llvmlite.ir as llvmir -from numba.core import utils -from numba import config, cgutils +from numba.core import utils, config +from numba import cgutils from numba.runtime.nrtopt import remove_redundant_nrt_refct from numba.runtime import rtsys from numba.core.compiler_lock import require_global_compiler_lock diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 86b7196214d..aaab1044445 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -4,10 +4,10 @@ import llvmlite.binding as ll import llvmlite.llvmpy.core as lc -from numba import _dynfunc, config +from numba import _dynfunc from numba.core.callwrapper import PyCallWrapper from numba.targets.base import BaseContext, PYOBJECT -from numba.core import utils, types +from numba.core import utils, types, config from numba import cgutils from numba.core.utils import cached_property from numba.targets import callconv, codegen, externals, intrinsics, dictimpl diff --git a/numba/targets/gdb_hook.py b/numba/targets/gdb_hook.py index 5eb1b64c34d..45f3df6e42f 100644 --- a/numba/targets/gdb_hook.py +++ b/numba/targets/gdb_hook.py @@ -3,8 +3,8 @@ from llvmlite import ir -from numba.core import types, utils -from numba import gdb, gdb_init, gdb_breakpoint, cgutils, config +from numba.core import types, utils, config +from numba import gdb, gdb_init, gdb_breakpoint, cgutils from numba.extending import overload, intrinsic _path = os.path.dirname(__file__) diff --git a/numba/targets/options.py b/numba/targets/options.py index eb5e0006fc1..cf7e58755f3 100644 --- a/numba/targets/options.py +++ b/numba/targets/options.py @@ -2,7 +2,7 @@ Target Options """ -from .. import config +from numba.core import config class TargetOptions(object): OPTIONS = {} diff --git a/numba/testing/__init__.py b/numba/testing/__init__.py index aa9fd6b5451..6ed3aeb0821 100644 --- a/numba/testing/__init__.py +++ b/numba/testing/__init__.py @@ -6,8 +6,8 @@ from os.path import join, isfile, relpath, normpath, splitext from .main import NumbaTestProgram, SerialSuite, make_tag_decorator -from numba import config import numba.unittest_support as unittest +from numba.core import config def load_testsuite(loader, dir): diff --git a/numba/testing/main.py b/numba/testing/main.py index e8f99e1960c..286a725651b 100644 --- a/numba/testing/main.py +++ b/numba/testing/main.py @@ -16,7 +16,7 @@ from unittest import result, runner, signals, suite, loader, case from .loader import TestLoader -from numba import config +from numba.core import config try: from multiprocessing import TimeoutError diff --git a/numba/tests/npyufunc/test_caching.py b/numba/tests/npyufunc/test_caching.py index 02de5e2690c..72790b5c516 100644 --- a/numba/tests/npyufunc/test_caching.py +++ b/numba/tests/npyufunc/test_caching.py @@ -6,10 +6,10 @@ import numpy as np from numba import unittest_support as unittest -from numba import config from ..support import capture_cache_log from ..test_dispatcher import BaseCacheTest +from numba.core import config class UfuncCacheTest(BaseCacheTest): diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index c06e89f2eb8..8f3372461db 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -1,7 +1,7 @@ from numba import unittest_support as unittest from numba.npyufunc.parallel import get_thread_count from os import environ as env -from numba import config +from numba.core import config class TestParallelEnvVariable(unittest.TestCase): diff --git a/numba/tests/npyufunc/test_ufuncbuilding.py b/numba/tests/npyufunc/test_ufuncbuilding.py index 4903d6db999..8cc0baa9391 100644 --- a/numba/tests/npyufunc/test_ufuncbuilding.py +++ b/numba/tests/npyufunc/test_ufuncbuilding.py @@ -2,12 +2,13 @@ import numpy as np -from numba import config, unittest_support as unittest +from numba import unittest_support as unittest from numba.npyufunc.ufuncbuilder import GUFuncBuilder from numba import vectorize, guvectorize from numba.npyufunc import PyUFunc_One from numba.npyufunc.dufunc import DUFunc as UFuncBuilder from ..support import tag, TestCase +from numba.core import config def add(a, b): diff --git a/numba/tests/support.py b/numba/tests/support.py index dd95e1d81fd..5ab5fac6ed0 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -22,19 +22,21 @@ from contextlib import contextmanager import numpy as np -try: - import scipy -except ImportError: - scipy = None -from numba import config, numpy_support, testing -from numba.core import errors, typing, utils +from numba import numpy_support, testing +from numba.core import errors, typing, utils, config from numba.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS from numba.targets import cpu import numba.unittest_support as unittest from numba.runtime import rtsys +try: + import scipy +except ImportError: + scipy = None + + enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index b5df1766946..61cd30308ba 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -2,10 +2,11 @@ from numba.compiler import compile_isolated, DEFAULT_FLAGS from numba.cuda.testing import SerialMixin -from numba import typeof, config, cuda, njit +from numba import typeof, cuda, njit from numba.core.types import float64 from numba import unittest_support as unittest from numba.tests.support import MemoryLeakMixin, override_env_config +from numba.core import config BOUNDSCHECK_FLAGS = DEFAULT_FLAGS.copy() BOUNDSCHECK_FLAGS.set('boundscheck', True) diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index dd92edf62c1..28b996d16c2 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -7,8 +7,8 @@ import numba.unittest_support as unittest from numba.compiler import compile_isolated, Flags -from numba import jit, typeof, config, njit -from numba.core import errors, types, utils +from numba import jit, typeof, njit +from numba.core import errors, types, utils, config from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_config.py b/numba/tests/test_config.py index 4a096f398a2..f6dfd912ab0 100644 --- a/numba/tests/test_config.py +++ b/numba/tests/test_config.py @@ -2,7 +2,7 @@ import tempfile import unittest from numba.tests.support import TestCase, temp_directory, override_env_config -from numba import config +from numba.core import config try: import yaml diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 25a7d707db4..915d3fb0577 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -5,9 +5,8 @@ from numba import compiler from numba.targets import cpu -from numba.core import types, typing, ir +from numba.core import types, typing, ir, config from numba.targets.registry import cpu_target -from numba import config from numba.core.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) diff --git a/numba/tests/test_dictimpl.py b/numba/tests/test_dictimpl.py index 4d7002a6bb8..21861a98c0e 100644 --- a/numba/tests/test_dictimpl.py +++ b/numba/tests/test_dictimpl.py @@ -7,7 +7,7 @@ from numba.tests.support import TestCase from numba import _helperlib -from numba.config import IS_32BITS +from numba.core.config import IS_32BITS DKIX_EMPTY = -1 diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 3bc50dd4bbe..1247c450d20 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -7,9 +7,8 @@ from numba import unittest_support as unittest from numba.core.errors import TypingError -from numba import config from numba import njit -from numba.core import types, utils +from numba.core import types, utils, config from numba.tests.support import MemoryLeakMixin, TestCase, tag diff --git a/numba/tests/test_jitmethod.py b/numba/tests/test_jitmethod.py index 8bd35ee4a7f..e30000b51a6 100644 --- a/numba/tests/test_jitmethod.py +++ b/numba/tests/test_jitmethod.py @@ -2,8 +2,8 @@ import numpy as np -from numba import config, jit -from numba.core import types +from numba import jit +from numba.core import types, config from numba.compiler import compile_isolated from numba.tests.support import override_config diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index d11046538e4..493de792ec7 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -9,7 +9,7 @@ from numba.compiler import compile_isolated, Flags from numba import numpy_support from numba.core import utils, types -from numba.config import IS_WIN32, IS_32BITS +from numba.core.config import IS_WIN32, IS_32BITS from numba.tests.support import TestCase, CompilationCache, tag enable_pyobj_flags = Flags() diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 77570d08869..6c209d3ff25 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -13,7 +13,7 @@ from numba.core import types from numba.numpy_support import numpy_version from numba.core.errors import TypingError -from numba.config import IS_WIN32, IS_32BITS +from numba.core.config import IS_WIN32, IS_32BITS from numba.core.utils import pysignature from numba.targets.arraymath import cross2d from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 246bb3241a8..f73a86dc9b4 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -12,9 +12,9 @@ import numpy as np import numba.unittest_support as unittest -from numba import config, jit, vectorize, numpy_support +from numba import jit, vectorize, numpy_support from numba.numpy_support import numpy_version -from numba.core import types +from numba.core import types, config from numba.core.errors import TypingError from numba.tests.support import TestCase, tag from numba.np import npdatetime diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index b9fb493491f..cc6fee65c88 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -13,8 +13,6 @@ import numpy as np -from numba import config - from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize @@ -23,6 +21,7 @@ import queue as t_queue from numba.testing.main import _TIMEOUT as _RUNNER_TIMEOUT +from numba.core import config _TEST_TIMEOUT = _RUNNER_TIMEOUT - 60. diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index b6e70045e84..476490e094c 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -23,9 +23,8 @@ from numba import njit, prange, stencil from numba import compiler from numba.targets import cpu -from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall +from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config from numba.targets.registry import cpu_target -from numba import config from numba.core.annotations import type_annotations from numba.ir_utils import (find_callname, guard, build_definitions, get_definition, is_getitem, is_setitem, diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 1e60661aed5..063ea3c87c7 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -7,7 +7,7 @@ from numba import unittest_support as unittest from numba.compiler import compile_isolated from numba.core.itanium_mangler import mangle_type -from numba.config import IS_WIN32 +from numba.core.config import IS_WIN32 from numba.numpy_support import numpy_version diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index ecca3a5783f..80b4971011b 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -7,9 +7,8 @@ from numba import compiler from numba.compiler import compile_isolated, Flags from numba.targets import cpu -from numba.core import types, typing, ir +from numba.core import types, typing, ir, config from numba.targets.registry import cpu_target -from numba import config from numba.core.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table, remove_dels, remove_dead, diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 9ba042e4005..ccb17564451 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -8,12 +8,13 @@ from itertools import chain, combinations import numba +from numba.core import config from numba import prange, njit, unittest_support as unittest from numba.targets import cpu from numba.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, override_env_config -needs_svml = unittest.skipUnless(numba.config.USING_SVML, +needs_svml = unittest.skipUnless(config.USING_SVML, "SVML tests need SVML to be present") # a map of float64 vector lenghs with corresponding CPU architecture @@ -113,7 +114,7 @@ def func_patterns(func, args, res, dtype, mode, vlen, flags, pad=' '*8): v = vlen*2 if is_f32 else vlen # general expectations prec_suff = '' if getattr(flags, 'fastmath', False) else '_ha' - scalar_func = '$_'+f if numba.config.IS_OSX else '$'+f + scalar_func = '$_'+f if config.IS_OSX else '$'+f svml_func = '__svml_%s%d%s,' % (f, v, prec_suff) if mode == "scalar": contains = [scalar_func] @@ -331,7 +332,7 @@ def check_svml_presence(self, func, pattern): def test_scalar_context(self): # SVML will not be used. - pat = '$_sin' if numba.config.IS_OSX else '$sin' + pat = '$_sin' if config.IS_OSX else '$sin' self.check(math_sin_scalar, 7., std_pattern=pat) self.check(math_sin_scalar, 7., fast_pattern=pat) diff --git a/numba/tests/test_threadsafety.py b/numba/tests/test_threadsafety.py index b407140e5bd..941d1d74cd0 100644 --- a/numba/tests/test_threadsafety.py +++ b/numba/tests/test_threadsafety.py @@ -7,11 +7,11 @@ import numpy as np -from numba import config from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize from numba.tests.support import temp_directory, override_config +from numba.core import config def foo(n, v): diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index faa2a03453f..b02c09ee402 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -3,11 +3,10 @@ """ from collections.abc import MutableMapping -from numba import config from numba.core.types import DictType, TypeRef from numba.targets.imputils import numba_typeref_ctor from numba import njit, dictobject, cgutils, typeof -from numba.core import types, errors +from numba.core import types, errors, config from numba.extending import ( overload_method, overload, diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index 9767a1874d2..f0d0d4dd523 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -14,8 +14,7 @@ from numba.targets.imputils import numba_typeref_ctor from numba import listobject from numba.core.dispatcher import Dispatcher -from numba import config -from numba.core import types, errors +from numba.core import types, errors, config from numba import njit, cgutils, typeof from numba.extending import ( overload_method, diff --git a/numba/unittest_support.py b/numba/unittest_support.py index 681f749fe1c..4a5e8f2febc 100644 --- a/numba/unittest_support.py +++ b/numba/unittest_support.py @@ -3,5 +3,5 @@ """ import sys import warnings -from numba import config from unittest import * +from numba.core import config From 8f96fb0e51c9c74fb0b7ffdd151482281affd2f0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 12:15:26 +0000 Subject: [PATCH 384/595] Move numba/compiler.py to numba/cpython --- docs/source/developer/compiler_pass_example.py | 2 +- numba/core/caching.py | 5 ++--- numba/core/ccallback.py | 3 +-- numba/{ => core}/compiler.py | 2 +- numba/core/compiler_machinery.py | 2 +- numba/core/dispatcher.py | 4 ++-- numba/core/inline_closurecall.py | 2 +- numba/core/object_mode_passes.py | 10 +++++----- numba/core/serialize.py | 3 +-- numba/core/typed_passes.py | 4 ++-- numba/core/typing/templates.py | 3 +-- numba/core/untyped_passes.py | 4 ++-- numba/cuda/compiler.py | 4 ++-- numba/ir_utils.py | 2 +- numba/npyufunc/array_exprs.py | 3 +-- numba/npyufunc/parfor.py | 4 ++-- numba/npyufunc/ufuncbuilder.py | 4 ++-- numba/pycc/compiler.py | 2 +- numba/roc/compiler.py | 3 +-- numba/stencil.py | 4 ++-- numba/stencilparfor.py | 2 +- numba/targets/base.py | 11 ++++++----- numba/tests/support.py | 2 +- numba/tests/test_analysis.py | 2 +- numba/tests/test_annotations.py | 2 +- numba/tests/test_array_analysis.py | 2 +- numba/tests/test_array_attr.py | 2 +- numba/tests/test_array_constants.py | 2 +- numba/tests/test_array_exprs.py | 6 +++--- numba/tests/test_array_iterators.py | 2 +- numba/tests/test_array_manipulation.py | 2 +- numba/tests/test_array_methods.py | 2 +- numba/tests/test_array_reductions.py | 2 +- numba/tests/test_array_return.py | 2 +- numba/tests/test_auto_constants.py | 2 +- numba/tests/test_blackscholes.py | 2 +- numba/tests/test_boundscheck.py | 2 +- numba/tests/test_builtins.py | 2 +- numba/tests/test_byteflow.py | 2 +- numba/tests/test_casting.py | 2 +- numba/tests/test_cffi.py | 2 +- numba/tests/test_complex.py | 2 +- numba/tests/test_comprehension.py | 3 ++- numba/tests/test_conversion.py | 2 +- numba/tests/test_copy_propagate.py | 3 +-- numba/tests/test_ctypes.py | 2 +- numba/tests/test_dataflow.py | 2 +- numba/tests/test_debug.py | 6 +++--- numba/tests/test_del.py | 2 +- numba/tests/test_dispatcher.py | 2 +- numba/tests/test_errorhandling.py | 4 ++-- numba/tests/test_exceptions.py | 2 +- numba/tests/test_extending.py | 7 ++++--- numba/tests/test_flow_control.py | 2 +- numba/tests/test_generators.py | 2 +- numba/tests/test_gil.py | 2 +- numba/tests/test_heapq.py | 2 +- numba/tests/test_indexing.py | 2 +- numba/tests/test_inlining.py | 9 ++++----- numba/tests/test_ir.py | 4 ++-- numba/tests/test_ir_inlining.py | 4 ++-- numba/tests/test_ir_utils.py | 6 +++--- numba/tests/test_iteration.py | 2 +- numba/tests/test_jitmethod.py | 2 +- numba/tests/test_lists.py | 2 +- numba/tests/test_locals.py | 3 ++- numba/tests/test_looplifting.py | 2 +- numba/tests/test_mandelbrot.py | 2 +- numba/tests/test_mathlib.py | 2 +- numba/tests/test_maxmin.py | 2 +- numba/tests/test_mixed_tuple_unroller.py | 2 +- numba/tests/test_nan.py | 2 +- numba/tests/test_np_functions.py | 2 +- numba/tests/test_nrt.py | 2 +- numba/tests/test_numberctor.py | 2 +- numba/tests/test_numconv.py | 2 +- numba/tests/test_obj_lifetime.py | 2 +- numba/tests/test_object_mode.py | 2 +- numba/tests/test_objects.py | 2 +- numba/tests/test_operators.py | 2 +- numba/tests/test_optional.py | 2 +- numba/tests/test_parfors.py | 5 ++--- numba/tests/test_pipeline.py | 2 +- numba/tests/test_practical_lowering_issues.py | 2 +- numba/tests/test_print.py | 2 +- numba/tests/test_python_int.py | 2 +- numba/tests/test_random.py | 2 +- numba/tests/test_range.py | 2 +- numba/tests/test_recarray_usecases.py | 2 +- numba/tests/test_record_dtype.py | 2 +- numba/tests/test_remove_dead.py | 7 +++---- numba/tests/test_return_values.py | 2 +- numba/tests/test_sets.py | 2 +- numba/tests/test_sort.py | 2 +- numba/tests/test_stencils.py | 2 +- numba/tests/test_storeslice.py | 2 +- numba/tests/test_svml.py | 4 ++-- numba/tests/test_tuples.py | 2 +- numba/tests/test_typeinfer.py | 2 +- numba/tests/test_typingerror.py | 2 +- numba/tests/test_ufuncs.py | 2 +- numba/tests/test_unpack_sequence.py | 2 +- numba/tests/test_usecases.py | 2 +- numba/tests/test_withlifting.py | 2 +- numba/tests/test_wrapper.py | 3 +-- 105 files changed, 143 insertions(+), 150 deletions(-) rename numba/{ => core}/compiler.py (99%) diff --git a/docs/source/developer/compiler_pass_example.py b/docs/source/developer/compiler_pass_example.py index e64ed81b9a2..15a91bd0e50 100644 --- a/docs/source/developer/compiler_pass_example.py +++ b/docs/source/developer/compiler_pass_example.py @@ -3,7 +3,7 @@ def ex_compiler_pass(): # magictoken.ex_compiler_pass.begin from numba import njit from numba.core import ir - from numba.compiler import CompilerBase, DefaultPassBuilder + from numba.core.compiler import CompilerBase, DefaultPassBuilder from numba.core.compiler_machinery import FunctionPass, register_pass from numba.core.untyped_passes import IRProcessing from numbers import Number diff --git a/numba/core/caching.py b/numba/core/caching.py index 86ec2dd1263..396ff73f2c8 100644 --- a/numba/core/caching.py +++ b/numba/core/caching.py @@ -19,12 +19,11 @@ from numba.core.utils import add_metaclass, file_replace import numba -from numba import compiler from numba.core.errors import NumbaWarning from numba.targets.base import BaseContext from numba.targets.codegen import CodeLibrary -from numba.compiler import CompileResult -from numba.core import config +from numba.core.compiler import CompileResult +from numba.core import config, compiler def _get_codegen(obj): diff --git a/numba/core/ccallback.py b/numba/core/ccallback.py index 3072a689782..6379c179510 100644 --- a/numba/core/ccallback.py +++ b/numba/core/ccallback.py @@ -7,8 +7,7 @@ from llvmlite import ir -from numba.core import utils -from numba import compiler +from numba.core import utils, compiler from numba.core.caching import NullCache, FunctionCache from numba.core.dispatcher import _FunctionCompiler from numba.targets import registry diff --git a/numba/compiler.py b/numba/core/compiler.py similarity index 99% rename from numba/compiler.py rename to numba/core/compiler.py index 04a807f0f6a..32993b6a7a9 100644 --- a/numba/compiler.py +++ b/numba/core/compiler.py @@ -172,7 +172,7 @@ def compile_isolated(func, args, return_type=None, flags=DEFAULT_FLAGS, context). Good for testing. """ - from .targets.registry import cpu_target + from numba.targets.registry import cpu_target typingctx = typing.Context() targetctx = cpu.CPUContext(typingctx) # Register the contexts in case for nested @jit or @overload calls diff --git a/numba/core/compiler_machinery.py b/numba/core/compiler_machinery.py index 286bf998d20..f0ee40efe58 100644 --- a/numba/core/compiler_machinery.py +++ b/numba/core/compiler_machinery.py @@ -314,7 +314,7 @@ def run(self, state): """ Run the defined pipelines on the state. """ - from numba.compiler import _EarlyPipelineCompletion + from numba.core.compiler import _EarlyPipelineCompletion if not self.finalized: raise RuntimeError("Cannot run non-finalised pipeline") diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py index 7c7614c67e0..c96a40e0c0a 100644 --- a/numba/core/dispatcher.py +++ b/numba/core/dispatcher.py @@ -11,8 +11,8 @@ import weakref from copy import deepcopy -from numba import _dispatcher, compiler -from numba.core import utils, types, errors, typing, serialize, config +from numba import _dispatcher +from numba.core import utils, types, errors, typing, serialize, config, compiler from numba.core.compiler_lock import global_compiler_lock from numba.core.typeconv.rules import default_type_manager from numba import sigutils diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 0d8e4d56600..0fc74de7bff 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -285,7 +285,7 @@ def inline_closure_call(func_ir, glbls, block, i, callee, typingctx=None, callee_closure = callee.closure if hasattr(callee, 'closure') else callee.__closure__ # first, get the IR of the callee if isinstance(callee, pytypes.FunctionType): - from numba import compiler + from numba.core import compiler callee_ir = compiler.run_frontend(callee, inline_closures=True) else: callee_ir = get_ir_of_code(glbls, callee_code) diff --git a/numba/core/object_mode_passes.py b/numba/core/object_mode_passes.py index 53e232dd1b2..9191969bbd0 100644 --- a/numba/core/object_mode_passes.py +++ b/numba/core/object_mode_passes.py @@ -56,7 +56,7 @@ def _frontend_looplift(self, state): if config.DEBUG_FRONTEND or config.DEBUG: for loop in loops: print("Lifting loop", loop.get_source_location()) - from numba.compiler import compile_ir + from numba.core.compiler import compile_ir cres = compile_ir(state.typingctx, state.targetctx, main, state.args, state.return_type, outer_flags, state.locals, @@ -65,7 +65,7 @@ def _frontend_looplift(self, state): return cres def run_pass(self, state): - from numba.compiler import _EarlyPipelineCompletion + from numba.core.compiler import _EarlyPipelineCompletion # NOTE: That so much stuff, including going back into the compiler, is # captured in a single pass is not ideal. if state.flags.enable_looplift: @@ -101,7 +101,7 @@ def _py_lowering_stage(self, targetctx, library, interp, flags): env = lower.env call_helper = lower.call_helper del lower - from numba.compiler import _LowerResult # TODO: move this + from numba.core.compiler import _LowerResult # TODO: move this if flags.no_compile: return _LowerResult(fndesc, call_helper, cfunc=None, env=env) else: @@ -142,7 +142,7 @@ def backend_object_mode(): lowered = backend_object_mode() signature = typing.signature(state.return_type, *state.args) - from numba.compiler import compile_result + from numba.core.compiler import compile_result state.cr = compile_result( typing_context=state.typingctx, target_context=state.targetctx, @@ -207,7 +207,7 @@ def run_pass(self, state): """ args = [types.pyobject] * len(state.args) signature = typing.signature(types.pyobject, *args) - from numba.compiler import compile_result + from numba.core.compiler import compile_result state.cr = compile_result(typing_context=state.typingctx, target_context=state.targetctx, entry_point=state.func_id.func, diff --git a/numba/core/serialize.py b/numba/core/serialize.py index 819507c4fcc..ef8c5af80ab 100644 --- a/numba/core/serialize.py +++ b/numba/core/serialize.py @@ -9,8 +9,7 @@ import sys from types import FunctionType, ModuleType -from numba import compiler -from numba.core import bytecode +from numba.core import bytecode, compiler # diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index 099034a9e96..dd56d7b6929 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -351,7 +351,7 @@ def run_pass(self, state): call_helper = lower.call_helper del lower - from numba.compiler import _LowerResult # TODO: move this + from numba.core.compiler import _LowerResult # TODO: move this if flags.no_compile: state['cr'] = _LowerResult(fndesc, call_helper, cfunc=None, env=env) @@ -406,7 +406,7 @@ def run_pass(self, state): lowered = state['cr'] signature = typing.signature(state.return_type, *state.args) - from numba.compiler import compile_result + from numba.core.compiler import compile_result state.cr = compile_result( typing_context=state.typingctx, target_context=state.targetctx, diff --git a/numba/core/typing/templates.py b/numba/core/typing/templates.py index 20847253d1f..c6edfb540d6 100644 --- a/numba/core/typing/templates.py +++ b/numba/core/typing/templates.py @@ -455,8 +455,7 @@ def generic(self, args, kws): if not self._inline.is_never_inline: # need to run the compiler front end up to type inference to compute # a signature - from numba import compiler - from numba.core import typed_passes + from numba.core import typed_passes, compiler ir = compiler.run_frontend(disp_type.dispatcher.py_func) resolve = disp_type.dispatcher.get_call_template template, pysig, folded_args, kws = resolve(new_args, kws) diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 1af04e06922..4775de4ba74 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -244,7 +244,7 @@ def run_pass(self, state): locals=state.locals, ) if withs: - from numba.compiler import compile_ir, _EarlyPipelineCompletion + from numba.core.compiler import compile_ir, _EarlyPipelineCompletion cres = compile_ir(state.typingctx, state.targetctx, main, state.args, state.return_type, state.flags, state.locals, @@ -307,7 +307,7 @@ def run_pass(self, state): def _do_work(self, state, work_list, block, i, expr): from numba.core.inline_closurecall import (inline_closure_call, callee_ir_validator) - from numba.compiler import run_frontend + from numba.core.compiler import run_frontend from numba.targets.cpu import InlineOptions # try and get a definition for the call, this isn't always possible as diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index 6ebc53f0639..a909a6e8682 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -8,9 +8,9 @@ import numpy as np -from numba import compiler, sigutils +from numba import sigutils from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate -from numba.core import types, typing, utils, funcdesc, serialize, config +from numba.core import types, typing, utils, funcdesc, serialize, config, compiler from numba.core.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner diff --git a/numba/ir_utils.py b/numba/ir_utils.py index 8796631eb59..43d30b0adab 100644 --- a/numba/ir_utils.py +++ b/numba/ir_utils.py @@ -1642,7 +1642,7 @@ def get_ir_of_code(glbls, fcode): f = _create_function_from_code_obj(fcode, func_env, func_arg, func_clo, glbls) - from numba import compiler + from numba.core import compiler ir = compiler.run_frontend(f) # we need to run the before inference rewrite pass to normalize the IR # XXX: check rewrite pass flag? diff --git a/numba/npyufunc/array_exprs.py b/numba/npyufunc/array_exprs.py index 62d3ed807b3..367cf392279 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/npyufunc/array_exprs.py @@ -6,8 +6,7 @@ import numpy as np import operator -from numba import compiler -from numba.core import types, utils, ir, rewrites +from numba.core import types, utils, ir, rewrites, compiler from numba.core.typing import npydecl from numba.npyufunc.dufunc import DUFunc diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index ed7ccc91a51..2203b15bee7 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -10,8 +10,8 @@ import llvmlite.ir.values as liv import numba -from numba import compiler, cgutils, sigutils, lowering, parfor -from numba.core import types, ir, config +from numba import cgutils, sigutils, lowering, parfor +from numba.core import types, ir, config, compiler from numba.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 034ea14cae0..4245a50c436 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -8,8 +8,8 @@ from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target from numba.targets.cpu import FastMathOptions -from numba import compiler, sigutils -from numba.core import utils, types, serialize +from numba import sigutils +from numba.core import utils, types, serialize, compiler from numba.numpy_support import as_dtype from numba.npyufunc import _internal from numba.npyufunc.sigparse import parse_signature diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index a175447b7f1..00c1333c167 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -10,7 +10,7 @@ from numba import cgutils from numba.pycc import llvm_types as lt -from numba.compiler import compile_extra, Flags +from numba.core.compiler import compile_extra, Flags from numba.core.compiler_lock import global_compiler_lock from numba.targets.registry import cpu_target diff --git a/numba/roc/compiler.py b/numba/roc/compiler.py index 7e1a2748c5f..21629c09d11 100644 --- a/numba/roc/compiler.py +++ b/numba/roc/compiler.py @@ -6,8 +6,7 @@ import numpy as np from numba.core.typing.templates import ConcreteTemplate -from numba import compiler -from numba.core import types, config +from numba.core import types, config, compiler from .hlc import hlc from .hsadrv import devices, driver, enums, drvapi from .hsadrv.error import HsaKernelLaunchError diff --git a/numba/stencil.py b/numba/stencil.py index bcaa9323fe1..4235604ca8f 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -8,8 +8,8 @@ import numpy as np from llvmlite import ir as lir -from numba import compiler, ir_utils, numpy_support -from numba.core import types, typing, utils, ir, typed_passes, config +from numba import ir_utils, numpy_support +from numba.core import types, typing, utils, ir, typed_passes, config, compiler from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) from numba.targets import registry diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index b76d07f4167..ad373d27845 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -732,7 +732,7 @@ def get_stencil_ir(sf, typingctx, args, scope, loc, input_dict, typemap, class DummyPipeline(object): def __init__(self, typingctx, targetctx, args, f_ir): - from numba.compiler import StateDict + from numba.core.compiler import StateDict self.state = StateDict() self.state.typingctx = typingctx self.state.targetctx = targetctx diff --git a/numba/targets/base.py b/numba/targets/base.py index 6fd4a6e94e6..f51a5fe824e 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -24,6 +24,7 @@ RegistryLoader) from numba.cpython import builtins + GENERIC_POINTER = Type.pointer(Type.int(8)) PYOBJECT = GENERIC_POINTER void_ptr = GENERIC_POINTER @@ -819,7 +820,7 @@ def _compile_subroutine_no_cache(self, builder, impl, sig, locals={}, Note this context's flags are not inherited. """ # Compile - from numba import compiler + from numba.core import compiler with global_compiler_lock: codegen = self.codegen() @@ -829,10 +830,10 @@ def _compile_subroutine_no_cache(self, builder, impl, sig, locals={}, flags.set('no_compile') flags.set('no_cpython_wrapper') cres = compiler.compile_internal(self.typing_context, self, - library, - impl, sig.args, - sig.return_type, flags, - locals=locals) + library, + impl, sig.args, + sig.return_type, flags, + locals=locals) # Allow inlining the function inside callers. self.active_code_library.add_linking_library(cres.library) diff --git a/numba/tests/support.py b/numba/tests/support.py index 5ab5fac6ed0..89de4039bf2 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -25,7 +25,7 @@ from numba import numpy_support, testing from numba.core import errors, typing, utils, config -from numba.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS +from numba.core.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS from numba.targets import cpu import numba.unittest_support as unittest from numba.runtime import rtsys diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index e04547905c8..a428c94348d 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -2,7 +2,7 @@ import collections import numpy as np -from numba.compiler import compile_isolated, run_frontend, Flags, StateDict +from numba.core.compiler import compile_isolated, run_frontend, Flags, StateDict from numba import jit, ir_utils, njit from numba.core import types, errors, ir, rewrites from numba.tests.support import TestCase, MemoryLeakMixin, SerialMixin diff --git a/numba/tests/test_annotations.py b/numba/tests/test_annotations.py index 2bf3e520b80..4c4cac5e949 100644 --- a/numba/tests/test_annotations.py +++ b/numba/tests/test_annotations.py @@ -3,7 +3,7 @@ import numba from numba import unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types try: diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 2caa40212ec..5e31e355f2f 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -10,7 +10,7 @@ from numba.core import types, typing, ir, bytecode, postproc from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.parfors.array_analysis import EquivSet, ArrayAnalysis -from numba.compiler import Compiler, Flags, PassManager +from numba.core.compiler import Compiler, Flags, PassManager from numba.targets import cpu, registry from numba.ir_utils import remove_dead from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index c5330231b07..5563b176c64 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -2,7 +2,7 @@ import numba.unittest_support as unittest from numba import jitclass -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.numpy_support import from_dtype from numba import njit, typeof from numba.core import types diff --git a/numba/tests/test_array_constants.py b/numba/tests/test_array_constants.py index 849bf02a06c..f6eae4e3409 100644 --- a/numba/tests/test_array_constants.py +++ b/numba/tests/test_array_constants.py @@ -1,7 +1,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.core.errors import TypingError from numba import jit, typeof from numba.core import types diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index 4f38bcafefc..e16163f933e 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -5,9 +5,9 @@ from numba import njit, vectorize from numba import unittest_support as unittest -from numba import compiler, typeof -from numba.core import utils, types, typing, ir -from numba.compiler import Compiler, Flags +from numba import typeof +from numba.core import utils, types, typing, ir, compiler +from numba.core.compiler import Compiler, Flags from numba.targets import cpu from numba.tests.support import MemoryLeakMixin, TestCase diff --git a/numba/tests/test_array_iterators.py b/numba/tests/test_array_iterators.py index d9fc1d3490d..5915d33784a 100644 --- a/numba/tests/test_array_iterators.py +++ b/numba/tests/test_array_iterators.py @@ -5,7 +5,7 @@ from numba import unittest_support as unittest from numba import jit, typeof from numba.core import types -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin, tag diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 7cfd78402b8..874f2ea51d4 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -4,7 +4,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit, njit, from_dtype, typeof from numba.core.errors import TypingError from numba.core import types, errors diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index 6056e2ce2db..c2436c9c40b 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -7,7 +7,7 @@ from numba import unittest_support as unittest from numba import jit, typeof from numba.core import types -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.core.errors import TypingError, LoweringError from numba.numpy_support import as_dtype from numba.tests.support import (TestCase, CompilationCache, MemoryLeak, diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index b4b66373127..401d4678510 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -4,7 +4,7 @@ from numba import unittest_support as unittest from numba import jit, typeof -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_array_return.py b/numba/tests/test_array_return.py index 0b208ec2272..da48c615c03 100644 --- a/numba/tests/test_array_return.py +++ b/numba/tests/test_array_return.py @@ -1,6 +1,6 @@ import numpy as np -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import typeof from numba import unittest_support as unittest from numba.tests.support import MemoryLeakMixin diff --git a/numba/tests/test_auto_constants.py b/numba/tests/test_auto_constants.py index 05a7a1cd252..52376ac30f2 100644 --- a/numba/tests/test_auto_constants.py +++ b/numba/tests/test_auto_constants.py @@ -4,7 +4,7 @@ import numpy as np from numba import unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated class TestAutoConstants(unittest.TestCase): diff --git a/numba/tests/test_blackscholes.py b/numba/tests/test_blackscholes.py index 88d9826f233..60c96b91d28 100644 --- a/numba/tests/test_blackscholes.py +++ b/numba/tests/test_blackscholes.py @@ -3,7 +3,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, compile_extra, Flags +from numba.core.compiler import compile_isolated, compile_extra, Flags from numba.core import types, typing from numba.tests.support import TestCase diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index 61cd30308ba..81d9eb272cd 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -1,6 +1,6 @@ import numpy as np -from numba.compiler import compile_isolated, DEFAULT_FLAGS +from numba.core.compiler import compile_isolated, DEFAULT_FLAGS from numba.cuda.testing import SerialMixin from numba import typeof, cuda, njit from numba.core.types import float64 diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index 28b996d16c2..59f2528efbd 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -6,7 +6,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit, typeof, njit from numba.core import errors, types, utils, config from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_byteflow.py b/numba/tests/test_byteflow.py index 961b3199e77..646ad5ca3e9 100644 --- a/numba/tests/test_byteflow.py +++ b/numba/tests/test_byteflow.py @@ -2,7 +2,7 @@ Test byteflow.py specific issues """ from numba.tests.support import TestCase -from numba.compiler import run_frontend +from numba.core.compiler import run_frontend class TestByteFlowIssues(TestCase): diff --git a/numba/tests/test_casting.py b/numba/tests/test_casting.py index fae93701a4c..779dd283967 100644 --- a/numba/tests/test_casting.py +++ b/numba/tests/test_casting.py @@ -1,6 +1,6 @@ from numba import unittest_support as unittest import numpy as np -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import njit from numba.core import types import struct diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index 0e1d147f5ea..b59493e8aa2 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -4,7 +4,7 @@ from numba import unittest_support as unittest from numba import jit, cffi_support from numba.core import types, errors -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag import numba.tests.cffi_usecases as mod diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index 51f7bcdcfb4..e201c7e2935 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -4,7 +4,7 @@ import sys from numba import unittest_support as unittest -from numba.compiler import compile_isolated, Flags, utils +from numba.core.compiler import compile_isolated, Flags, utils from numba.core import types from numba.tests.support import TestCase, tag from .complex_usecases import * diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index e66ec44cacd..5976430feda 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -8,12 +8,13 @@ import numpy as np import numpy -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import jit from numba.core import types, utils from numba.core.errors import TypingError, LoweringError from numba.tests.support import tag, _32bit, captured_stdout + PARALLEL_SUPPORTED = not _32bit def comp_list(n): diff --git a/numba/tests/test_conversion.py b/numba/tests/test_conversion.py index 34b2d95f2c8..7987cb95087 100644 --- a/numba/tests/test_conversion.py +++ b/numba/tests/test_conversion.py @@ -6,7 +6,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit, numpy_support from numba.core import types from numba.tests.support import TestCase diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 915d3fb0577..9333c1063fa 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -3,9 +3,8 @@ # SPDX-License-Identifier: BSD-2-Clause # -from numba import compiler from numba.targets import cpu -from numba.core import types, typing, ir, config +from numba.core import types, typing, ir, config, compiler from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index 461f7d6126a..7e174aec565 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -6,7 +6,7 @@ from numba import unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import jit from numba.core import types, errors from numba.core.typing import ctypes_utils diff --git a/numba/tests/test_dataflow.py b/numba/tests/test_dataflow.py index 54f79bdaa0f..0713d7cfa28 100644 --- a/numba/tests/test_dataflow.py +++ b/numba/tests/test_dataflow.py @@ -1,7 +1,7 @@ import warnings import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types, errors from numba.tests.support import (TestCase, CompilationCache, skip_tryexcept_supported) diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 75ecbd1bad3..e33572fc8a3 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -11,11 +11,11 @@ needs_blas) from numba import unittest_support as unittest from numba import jit, jitclass -from numba.core import types -from numba.compiler import compile_isolated, Flags +from numba.core import types, compiler +from numba.core.compiler import compile_isolated, Flags from numba.targets.cpu import ParallelOptions from numba.core.errors import NumbaPerformanceWarning -from numba import compiler, prange +from numba import prange def simple_nopython(somearg): diff --git a/numba/tests/test_del.py b/numba/tests/test_del.py index 0f81f97e5bd..b19ba4988fa 100644 --- a/numba/tests/test_del.py +++ b/numba/tests/test_del.py @@ -1,6 +1,6 @@ import re -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.tests.support import TestCase import numba.unittest_support as unittest from numba import testing diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 46f1e96fa34..55c052b189a 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -19,7 +19,7 @@ from numba import jit, generated_jit, typeof from numba.core import types, errors from numba import _dispatcher -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.core.errors import NumbaWarning from numba.tests.support import (TestCase, temp_directory, import_dynamic, override_env_config, capture_cache_log, diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index 3b3feab0eae..4ff3036b1f7 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -93,8 +93,8 @@ def foo_docstring(): def test_use_of_ir_unknown_loc(self): # for context see # 3390 - import numba - class TestPipeline(numba.compiler.CompilerBase): + from numba.core.compiler import CompilerBase + class TestPipeline(CompilerBase): def define_pipelines(self): name = 'bad_DCE_pipeline' pm = PassManager(name) diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index e9838d911a7..4e7fe9052d6 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -2,7 +2,7 @@ import sys import traceback -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types, errors from numba import unittest_support as unittest diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 091067ae562..89b68503716 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -10,11 +10,11 @@ import numpy as np from numba import unittest_support as unittest -from numba import njit, jit, compiler -from numba.core import types, errors, typing +from numba import njit, jit +from numba.core import types, errors, typing, compiler from numba.core.typed_passes import type_inference_stage from numba.targets.registry import cpu_target -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.tests.support import (TestCase, captured_stdout, tag, temp_directory, override_config) from numba.core.errors import LoweringError @@ -36,6 +36,7 @@ # Pandas-like API implementation from .pdlike_usecase import Index, Series + try: import scipy if LooseVersion(scipy.__version__) < '0.19': diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index cd1eeb227dd..570bd8822ea 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -2,7 +2,7 @@ import numba.unittest_support as unittest from numba.core.controlflow import CFGraph, ControlFlowAnalysis -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types from numba.core.bytecode import FunctionIdentity, ByteCode from numba.tests.support import TestCase diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index 77d62363190..28a022e6246 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -2,7 +2,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types from numba.tests.support import TestCase, MemoryLeakMixin diff --git a/numba/tests/test_gil.py b/numba/tests/test_gil.py index f20c54015af..9d48667b264 100644 --- a/numba/tests/test_gil.py +++ b/numba/tests/test_gil.py @@ -8,7 +8,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import errors from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_heapq.py b/numba/tests/test_heapq.py index 2e2a83ef2f4..479140cc377 100644 --- a/numba/tests/test_heapq.py +++ b/numba/tests/test_heapq.py @@ -4,7 +4,7 @@ import numpy as np from numba import jit -from numba.compiler import Flags +from numba.core.compiler import Flags from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin no_pyobj_flags = Flags() diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index d0d51c634c9..8b0108ad1c8 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -4,7 +4,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import njit, typeof from numba.core import utils, types, errors from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index a1d4568ea30..1d259e138ad 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -3,10 +3,9 @@ from numba.tests.support import (TestCase, override_config, captured_stdout, skip_parfors_unsupported) -import numba from numba import unittest_support as unittest -from numba import jit, njit, compiler -from numba.core import types, ir, postproc +from numba import jit, njit +from numba.core import types, ir, postproc, compiler from numba.ir_utils import guard, find_callname, find_const, get_definition from numba.targets.registry import CPUDispatcher from numba.core.inline_closurecall import inline_closure_call @@ -102,7 +101,7 @@ def gen_pipeline(state, test_pass): pm.add_pass(DumpParforDiagnostics, "dump parfor diagnostics") return pm -class InlineTestPipeline(numba.compiler.CompilerBase): +class InlineTestPipeline(compiler.CompilerBase): """compiler pipeline for testing inlining after optimization """ def define_pipelines(self): @@ -264,7 +263,7 @@ def run_pass(self, state): break return True - class InlineTestPipelinePrune(numba.compiler.CompilerBase): + class InlineTestPipelinePrune(compiler.CompilerBase): def define_pipelines(self): pm = gen_pipeline(self.state, PruningInlineTestPass) diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index 2aa4514f680..186e48a3e88 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -1,7 +1,7 @@ import numba.unittest_support as unittest -from numba import compiler, objmode +from numba import objmode import numpy as np -from numba.core import ir +from numba.core import ir, compiler class TestIR(unittest.TestCase): diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index 75cfdd89777..dcbfca371a4 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -21,14 +21,14 @@ ) from numba.core.datamodel.models import OpaqueModel from numba.targets.cpu import InlineOptions -from numba.compiler import DefaultPassBuilder +from numba.core.compiler import DefaultPassBuilder, CompilerBase from numba.core.typed_passes import DeadCodeElimination, IRLegalization from numba.core.untyped_passes import PreserveIR from itertools import product from numba.tests.support import TestCase, unittest, skip_py38_or_later -class InlineTestPipeline(numba.compiler.CompilerBase): +class InlineTestPipeline(CompilerBase): """ Same as the standard pipeline, but preserves the func_ir into the metadata store""" diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index d5b86eca6df..f1da16a930c 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -1,12 +1,12 @@ import numba from numba.tests.support import TestCase, unittest -from numba import compiler, jitclass +from numba import jitclass from numba.targets.registry import cpu_target -from numba.compiler import CompilerBase, Flags +from numba.core.compiler import CompilerBase, Flags from numba.core.compiler_machinery import PassManager from numba.targets import registry from numba import ir_utils -from numba.core import types, ir, bytecode +from numba.core import types, ir, bytecode, compiler from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index 8061ce8a57f..2d5f6e67a5e 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -2,7 +2,7 @@ from numba import njit import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import numpy_support from numba.core import types, errors from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_jitmethod.py b/numba/tests/test_jitmethod.py index e30000b51a6..d65e8d4584e 100644 --- a/numba/tests/test_jitmethod.py +++ b/numba/tests/test_jitmethod.py @@ -4,7 +4,7 @@ from numba import jit from numba.core import types, config -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.tests.support import override_config diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 0b0ac9a0f26..685c0c7788a 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -6,7 +6,7 @@ import ctypes as ct import numpy as np -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit, typeof, jitclass import numba.unittest_support as unittest from numba import testing diff --git a/numba/tests/test_locals.py b/numba/tests/test_locals.py index d5fa1a517dd..e58718e56d7 100644 --- a/numba/tests/test_locals.py +++ b/numba/tests/test_locals.py @@ -1,5 +1,6 @@ -from numba import compiler, float32 +from numba import float32 from numba import unittest_support as unittest +from numba.core import compiler def foo(): x = 123 diff --git a/numba/tests/test_looplifting.py b/numba/tests/test_looplifting.py index 08eed6b5a71..b7ad053be95 100644 --- a/numba/tests/test_looplifting.py +++ b/numba/tests/test_looplifting.py @@ -3,7 +3,7 @@ from numba.core import types from numba import unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, MemoryLeakMixin diff --git a/numba/tests/test_mandelbrot.py b/numba/tests/test_mandelbrot.py index ac605259ba3..64acb52c775 100644 --- a/numba/tests/test_mandelbrot.py +++ b/numba/tests/test_mandelbrot.py @@ -1,5 +1,5 @@ import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types, utils enable_pyobj_flags = Flags() diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index 493de792ec7..4f6991bf793 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -6,7 +6,7 @@ import numpy as np from numba import unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import numpy_support from numba.core import utils, types from numba.core.config import IS_WIN32, IS_32BITS diff --git a/numba/tests/test_maxmin.py b/numba/tests/test_maxmin.py index b83ca1f1c18..86781271d11 100644 --- a/numba/tests/test_maxmin.py +++ b/numba/tests/test_maxmin.py @@ -1,5 +1,5 @@ from numba import unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.core import types diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 663d9e306e9..d43bfede872 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -7,7 +7,7 @@ from numba.testing import unittest from numba.extending import overload from numba.core.compiler_machinery import PassManager, register_pass, FunctionPass -from numba.compiler import CompilerBase +from numba.core.compiler import CompilerBase from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, InlineClosureLikes, SimplifyCFG, IterLoopCanonicalization, LiteralUnroll) diff --git a/numba/tests/test_nan.py b/numba/tests/test_nan.py index 82112ebfc4e..ed427db500e 100644 --- a/numba/tests/test_nan.py +++ b/numba/tests/test_nan.py @@ -1,5 +1,5 @@ import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types enable_pyobj_flags = Flags() diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 6c209d3ff25..c9d3965fb77 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -8,7 +8,7 @@ import numpy as np from numba import unittest_support as unittest -from numba.compiler import Flags +from numba.core.compiler import Flags from numba import jit, njit, typeof from numba.core import types from numba.numpy_support import numpy_version diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index be2d90e3442..599be60cfb7 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -9,7 +9,7 @@ from numba import unittest_support as unittest from numba import njit, targets from numba.core import typing, types -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.runtime import ( rtsys, nrtopt, diff --git a/numba/tests/test_numberctor.py b/numba/tests/test_numberctor.py index 3a7f5382c7f..0928e8a0a9c 100644 --- a/numba/tests/test_numberctor.py +++ b/numba/tests/test_numberctor.py @@ -1,7 +1,7 @@ import numpy as np from numba import unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import jit from numba.core import types diff --git a/numba/tests/test_numconv.py b/numba/tests/test_numconv.py index e83df2528cc..c1a29b2c47d 100644 --- a/numba/tests/test_numconv.py +++ b/numba/tests/test_numconv.py @@ -1,6 +1,6 @@ import itertools import numba.unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.core import types diff --git a/numba/tests/test_obj_lifetime.py b/numba/tests/test_obj_lifetime.py index c5a43c8968b..594352b7013 100644 --- a/numba/tests/test_obj_lifetime.py +++ b/numba/tests/test_obj_lifetime.py @@ -5,7 +5,7 @@ import numba.unittest_support as unittest from numba.core.controlflow import CFGraph, Loop -from numba.compiler import compile_extra, compile_isolated, Flags +from numba.core.compiler import compile_extra, compile_isolated, Flags from numba.core import types from numba.tests.support import TestCase diff --git a/numba/tests/test_object_mode.py b/numba/tests/test_object_mode.py index 50bff7aacd0..c2431c2beef 100644 --- a/numba/tests/test_object_mode.py +++ b/numba/tests/test_object_mode.py @@ -6,7 +6,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import utils from numba.tests.support import TestCase diff --git a/numba/tests/test_objects.py b/numba/tests/test_objects.py index b9ac335da10..4c09b86cb5f 100644 --- a/numba/tests/test_objects.py +++ b/numba/tests/test_objects.py @@ -4,7 +4,7 @@ import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types from numba.tests.support import TestCase diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 40599e62a8a..fb9fc5cda07 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -7,7 +7,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types, utils, errors, typeinfer from numba.tests.support import TestCase, tag, needs_blas diff --git a/numba/tests/test_optional.py b/numba/tests/test_optional.py index b278b1a8eb5..f06361b2950 100644 --- a/numba/tests/test_optional.py +++ b/numba/tests/test_optional.py @@ -3,7 +3,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import typeof, njit, lowering from numba.core import types from numba.tests.support import TestCase diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 476490e094c..ab6aa3a1726 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -21,16 +21,15 @@ import numba from numba import unittest_support as unittest from numba import njit, prange, stencil -from numba import compiler from numba.targets import cpu -from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config +from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations from numba.ir_utils import (find_callname, guard, build_definitions, get_definition, is_getitem, is_setitem, index_var_of_get_setitem) from numba.unsafe.ndarray import empty_inferred as unsafe_empty -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core.bytecode import ByteCodeIter from numba.tests.support import (TestCase, captured_stdout, MemoryLeakMixin, override_env_config, linux_only, tag, diff --git a/numba/tests/test_pipeline.py b/numba/tests/test_pipeline.py index 516ac78f572..e7091a5f104 100644 --- a/numba/tests/test_pipeline.py +++ b/numba/tests/test_pipeline.py @@ -1,4 +1,4 @@ -from numba.compiler import Compiler +from numba.core.compiler import Compiler from numba import jit, generated_jit, objmode from numba.core import types from numba.core.ir import FunctionIR diff --git a/numba/tests/test_practical_lowering_issues.py b/numba/tests/test_practical_lowering_issues.py index e81459c04d0..4fd6a34612a 100644 --- a/numba/tests/test_practical_lowering_issues.py +++ b/numba/tests/test_practical_lowering_issues.py @@ -5,7 +5,7 @@ import numpy as np from numba import njit from numba.core import types, ir -from numba.compiler import CompilerBase, DefaultPassBuilder +from numba.core.compiler import CompilerBase, DefaultPassBuilder from numba.core.typed_passes import NopythonTypeInference from numba.core.compiler_machinery import register_pass, FunctionPass diff --git a/numba/tests/test_print.py b/numba/tests/test_print.py index 3127bfb3373..cef0289b211 100644 --- a/numba/tests/test_print.py +++ b/numba/tests/test_print.py @@ -3,7 +3,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types, errors, utils from numba.tests.support import captured_stdout, tag, TestCase diff --git a/numba/tests/test_python_int.py b/numba/tests/test_python_int.py index b5b6e13cc77..847d036a593 100644 --- a/numba/tests/test_python_int.py +++ b/numba/tests/test_python_int.py @@ -1,5 +1,5 @@ import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index 408b51fa510..87681e64537 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -13,7 +13,7 @@ import numba.unittest_support as unittest from numba import jit, _helperlib from numba.core import types -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.tests.support import TestCase, compile_function, tag diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index 6585034efaa..af3319de52a 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -4,7 +4,7 @@ import numpy -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import jit, njit from numba.core import types, utils from numba.tests.support import tag diff --git a/numba/tests/test_recarray_usecases.py b/numba/tests/test_recarray_usecases.py index 6266ce007cc..657097d37e9 100644 --- a/numba/tests/test_recarray_usecases.py +++ b/numba/tests/test_recarray_usecases.py @@ -4,7 +4,7 @@ from numba import numpy_support from numba.core import types -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import unittest_support as unittest from numba.tests.support import captured_stdout, tag, TestCase diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 063ea3c87c7..049a6bc11dc 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -5,7 +5,7 @@ from numba import jit, numpy_support from numba.core import types from numba import unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba.core.itanium_mangler import mangle_type from numba.core.config import IS_WIN32 from numba.numpy_support import numpy_version diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 80b4971011b..8bedfd16370 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -4,10 +4,9 @@ # import numba -from numba import compiler -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.targets import cpu -from numba.core import types, typing, ir, config +from numba.core import types, typing, ir, config, compiler from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations from numba.ir_utils import (copy_propagate, apply_copy_propagate, @@ -262,7 +261,7 @@ def run_pass(self, state): parfor_pass.nested_fusion_info) return True - class TestPipeline(numba.compiler.Compiler): + class TestPipeline(compiler.Compiler): """Test pipeline that just converts prange() to parfor and calls remove_dead(). Copy propagation can replace B in the example code which this pipeline avoids. diff --git a/numba/tests/test_return_values.py b/numba/tests/test_return_values.py index 6ec8de0d68c..7fd32a745ec 100644 --- a/numba/tests/test_return_values.py +++ b/numba/tests/test_return_values.py @@ -6,7 +6,7 @@ import math import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types from numba.core.errors import TypingError diff --git a/numba/tests/test_sets.py b/numba/tests/test_sets.py index d72ae5e62ef..b1c67e670f1 100644 --- a/numba/tests/test_sets.py +++ b/numba/tests/test_sets.py @@ -9,7 +9,7 @@ import numpy as np -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types import numba.unittest_support as unittest diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index efc3b04e969..53a0afb803c 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -6,7 +6,7 @@ import numpy as np -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types, utils, errors import numba.unittest_support as unittest diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index e71813a7a50..1a00514890e 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -17,7 +17,7 @@ from numba import unittest_support as unittest from numba import njit, stencil from numba.core import types -from numba.compiler import compile_extra, Flags +from numba.core.compiler import compile_extra, Flags from numba.targets import registry from numba.targets.cpu import ParallelOptions from numba.tests.support import tag, skip_parfors_unsupported, _32bit diff --git a/numba/tests/test_storeslice.py b/numba/tests/test_storeslice.py index d5da886e53d..ddb862ed711 100644 --- a/numba/tests/test_storeslice.py +++ b/numba/tests/test_storeslice.py @@ -1,7 +1,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types, errors from numba.tests.support import TestCase diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index ccb17564451..e92042afc67 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -11,7 +11,7 @@ from numba.core import config from numba import prange, njit, unittest_support as unittest from numba.targets import cpu -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, override_env_config needs_svml = unittest.skipUnless(config.USING_SVML, @@ -367,7 +367,7 @@ def check_no_svml(): from numba import config from numba.targets import cpu from numba.tests.support import override_env_config - from numba.compiler import compile_isolated, Flags + from numba.core.compiler import compile_isolated, Flags # compile for overridden CPU, with and without fastmath with override_env_config('NUMBA_CPU_NAME', 'skylake-avx512'), \ diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index b4deecc2d5d..77a324543e3 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -4,7 +4,7 @@ import numpy as np from numba import unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import njit, jit from numba.core import types, errors, utils from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index 1e01c924d04..95feb6ceda5 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -4,7 +4,7 @@ import numpy as np from numba import unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import jit from numba.core import types, typing, errors, typeinfer, utils from numba.core.typeconv import Conversion diff --git a/numba/tests/test_typingerror.py b/numba/tests/test_typingerror.py index 9ab89fd51c4..b45c2ad989a 100644 --- a/numba/tests/test_typingerror.py +++ b/numba/tests/test_typingerror.py @@ -6,7 +6,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated +from numba.core.compiler import compile_isolated from numba import jit from numba.core import types from numba.core.errors import TypingError diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index d9129aca0b6..75abb93803f 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -11,7 +11,7 @@ import numba.unittest_support as unittest from numba import typeof, numpy_support, njit from numba.core import types, typing, utils -from numba.compiler import compile_isolated, Flags, DEFAULT_FLAGS +from numba.core.compiler import compile_isolated, Flags, DEFAULT_FLAGS from numba.numpy_support import from_dtype from numba import jit, vectorize from numba.core.errors import LoweringError, TypingError diff --git a/numba/tests/test_unpack_sequence.py b/numba/tests/test_unpack_sequence.py index a7fed5032cd..aa6582f291f 100644 --- a/numba/tests/test_unpack_sequence.py +++ b/numba/tests/test_unpack_sequence.py @@ -1,7 +1,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import errors, types from numba import typeof from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_usecases.py b/numba/tests/test_usecases.py index c097ebc260b..4d5311cf71b 100644 --- a/numba/tests/test_usecases.py +++ b/numba/tests/test_usecases.py @@ -2,7 +2,7 @@ import numpy as np import numba.unittest_support as unittest -from numba.compiler import compile_isolated, Flags +from numba.core.compiler import compile_isolated, Flags from numba.core import types, utils from numba.tests import usecases from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index fc85c14cd8d..a212540d695 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -11,7 +11,7 @@ from numba.core import typing, errors from numba.targets.registry import cpu_target from numba.targets import cpu -from numba.compiler import compile_ir, DEFAULT_FLAGS +from numba.core.compiler import compile_ir, DEFAULT_FLAGS from numba import njit, typeof, objmode from numba.extending import overload from numba.tests.support import (MemoryLeak, TestCase, captured_stdout, diff --git a/numba/tests/test_wrapper.py b/numba/tests/test_wrapper.py index 7a5463f54e9..8f8a6580787 100644 --- a/numba/tests/test_wrapper.py +++ b/numba/tests/test_wrapper.py @@ -1,8 +1,7 @@ import numpy as np import numba.unittest_support as unittest -from numba import compiler -from numba.core import types, utils +from numba.core import types, utils, compiler from numba.targets import registry From 4a4f30f2031a9138f8129077bed5a5d7a60a7b97 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 12:17:39 +0000 Subject: [PATCH 385/595] Move numba/lowering.py to numba/cpython --- numba/{ => core}/lowering.py | 0 numba/core/pythonapi.py | 4 ++-- numba/core/typed_passes.py | 3 +-- numba/npyufunc/parfor.py | 4 ++-- numba/pylowering.py | 2 +- numba/targets/npyfuncs.py | 4 ++-- numba/tests/test_optional.py | 4 ++-- 7 files changed, 10 insertions(+), 11 deletions(-) rename numba/{ => core}/lowering.py (100%) diff --git a/numba/lowering.py b/numba/core/lowering.py similarity index 100% rename from numba/lowering.py rename to numba/core/lowering.py diff --git a/numba/core/pythonapi.py b/numba/core/pythonapi.py index 28378e85a0b..d7deabd84fe 100644 --- a/numba/core/pythonapi.py +++ b/numba/core/pythonapi.py @@ -7,8 +7,8 @@ import llvmlite.llvmpy.core as lc import ctypes -from numba import cgutils, lowering, _helperlib -from numba.core import types, utils, config +from numba import cgutils, _helperlib +from numba.core import types, utils, config, lowering PY_UNICODE_1BYTE_KIND = _helperlib.py_unicode_1byte_kind diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index dd56d7b6929..e1c2eb5dd46 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -1,8 +1,7 @@ from contextlib import contextmanager import warnings -from numba import lowering -from numba.core import errors, types, typing, ir, funcdesc, rewrites, typeinfer, config +from numba.core import errors, types, typing, ir, funcdesc, rewrites, typeinfer, config, lowering from numba.parfor import PreParforPass as _parfor_PreParforPass from numba.parfor import ParforPass as _parfor_ParforPass diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 2203b15bee7..cb34970450e 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -10,8 +10,8 @@ import llvmlite.ir.values as liv import numba -from numba import cgutils, sigutils, lowering, parfor -from numba.core import types, ir, config, compiler +from numba import cgutils, sigutils, parfor +from numba.core import types, ir, config, compiler, lowering from numba.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, diff --git a/numba/pylowering.py b/numba/pylowering.py index d4ed77cde10..a0198486619 100644 --- a/numba/pylowering.py +++ b/numba/pylowering.py @@ -12,7 +12,7 @@ from numba import cgutils from numba.core import types, utils, ir, generators from numba.core.errors import ForbiddenConstruct -from numba.lowering import BaseLower +from numba.core.lowering import BaseLower # Issue #475: locals() is unsupported as calling it naively would give diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index 476e20aab77..7e74b8a5266 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -10,8 +10,8 @@ from llvmlite.llvmpy import core as lc from numba.targets.imputils import impl_ret_untracked -from numba import cgutils, lowering -from numba.core import typing, types, errors +from numba import cgutils +from numba.core import typing, types, errors, lowering from numba.targets import npdatetime from numba.cpython import cmathimpl, mathimpl, numbers diff --git a/numba/tests/test_optional.py b/numba/tests/test_optional.py index f06361b2950..ea4f61cb808 100644 --- a/numba/tests/test_optional.py +++ b/numba/tests/test_optional.py @@ -4,8 +4,8 @@ import numba.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags -from numba import typeof, njit, lowering -from numba.core import types +from numba import typeof, njit +from numba.core import types, lowering from numba.tests.support import TestCase From dd5595f094ddc9d0347ede8f0df830af7d04aa92 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 12:19:18 +0000 Subject: [PATCH 386/595] Move numba/pylowering.py to numba/cpython --- numba/core/object_mode_passes.py | 4 ++-- numba/{ => core}/pylowering.py | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{ => core}/pylowering.py (100%) diff --git a/numba/core/object_mode_passes.py b/numba/core/object_mode_passes.py index 9191969bbd0..7a5a41b14a8 100644 --- a/numba/core/object_mode_passes.py +++ b/numba/core/object_mode_passes.py @@ -1,7 +1,7 @@ from contextlib import contextmanager import warnings -from numba import pylowering, transforms -from numba.core import errors, types, typing, funcdesc, config +from numba import transforms +from numba.core import errors, types, typing, funcdesc, config, pylowering from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass from collections import defaultdict diff --git a/numba/pylowering.py b/numba/core/pylowering.py similarity index 100% rename from numba/pylowering.py rename to numba/core/pylowering.py From ba56fced2c41197e3959fbcba89c2b97d38755c2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 12:27:11 +0000 Subject: [PATCH 387/595] Move numba/sigutils.py to numba/cpython --- numba/core/dispatcher.py | 3 +-- numba/{ => core}/sigutils.py | 0 numba/core/withcontexts.py | 4 ++-- numba/cuda/compiler.py | 3 +-- numba/cuda/decorators.py | 3 +-- numba/decorators.py | 3 +-- numba/npyufunc/deviceufunc.py | 3 +-- numba/npyufunc/dufunc.py | 4 ++-- numba/npyufunc/parfor.py | 4 ++-- numba/npyufunc/ufuncbuilder.py | 3 +-- numba/pycc/cc.py | 3 +-- numba/pycc/decorators.py | 3 +-- numba/roc/decorators.py | 3 +-- numba/tests/test_types.py | 13 +++++++------ 14 files changed, 22 insertions(+), 30 deletions(-) rename numba/{ => core}/sigutils.py (100%) diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py index c96a40e0c0a..425ab58a0cf 100644 --- a/numba/core/dispatcher.py +++ b/numba/core/dispatcher.py @@ -12,10 +12,9 @@ from copy import deepcopy from numba import _dispatcher -from numba.core import utils, types, errors, typing, serialize, config, compiler +from numba.core import utils, types, errors, typing, serialize, config, compiler, sigutils from numba.core.compiler_lock import global_compiler_lock from numba.core.typeconv.rules import default_type_manager -from numba import sigutils from numba.core.typing.templates import fold_arguments from numba.core.typing.typeof import Purpose, typeof from numba.core.bytecode import get_code_object diff --git a/numba/sigutils.py b/numba/core/sigutils.py similarity index 100% rename from numba/sigutils.py rename to numba/core/sigutils.py diff --git a/numba/core/withcontexts.py b/numba/core/withcontexts.py index b88428e0683..37c0e2f5531 100644 --- a/numba/core/withcontexts.py +++ b/numba/core/withcontexts.py @@ -1,5 +1,5 @@ -from numba import ir_utils, sigutils -from numba.core import types, errors, ir +from numba import ir_utils +from numba.core import types, errors, ir, sigutils from numba.core.typing.typeof import typeof_impl from numba.transforms import find_region_inout_vars diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index a909a6e8682..98edc28d70e 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -8,9 +8,8 @@ import numpy as np -from numba import sigutils from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate -from numba.core import types, typing, utils, funcdesc, serialize, config, compiler +from numba.core import types, typing, utils, funcdesc, serialize, config, compiler, sigutils from numba.core.compiler_lock import global_compiler_lock from .cudadrv.autotune import AutoTuner diff --git a/numba/cuda/decorators.py b/numba/cuda/decorators.py index 7ea671a53cd..3877db0339c 100644 --- a/numba/cuda/decorators.py +++ b/numba/cuda/decorators.py @@ -1,6 +1,5 @@ from warnings import warn -from numba import sigutils -from numba.core import types, config +from numba.core import types, config, sigutils from .compiler import (compile_kernel, compile_device, declare_device_function, AutoJitCUDAKernel, compile_device_template) from .simulator.kernel import FakeCUDAKernel diff --git a/numba/decorators.py b/numba/decorators.py index eb58e175c05..332c1a650b6 100644 --- a/numba/decorators.py +++ b/numba/decorators.py @@ -8,11 +8,10 @@ import inspect import logging -from numba import sigutils from numba.core.errors import DeprecationError, NumbaDeprecationWarning from numba.targets import registry from numba.stencil import stencil -from numba.core import config +from numba.core import config, sigutils _logger = logging.getLogger(__name__) diff --git a/numba/npyufunc/deviceufunc.py b/numba/npyufunc/deviceufunc.py index ebead63bf23..5eb1375a6f0 100644 --- a/numba/npyufunc/deviceufunc.py +++ b/numba/npyufunc/deviceufunc.py @@ -11,8 +11,7 @@ from numba.utils import longint from numba.npyufunc.ufuncbuilder import _BaseUFuncBuilder, parse_identity -from numba import sigutils -from numba.core import types +from numba.core import types, sigutils from numba.core.typing import signature from numba.npyufunc.sigparse import parse_signature diff --git a/numba/npyufunc/dufunc.py b/numba/npyufunc/dufunc.py index aa5c5c7fb53..5022810887f 100644 --- a/numba/npyufunc/dufunc.py +++ b/numba/npyufunc/dufunc.py @@ -1,5 +1,5 @@ -from numba import jit, typeof, numpy_support, sigutils -from numba.core import types, utils, serialize +from numba import jit, typeof, numpy_support +from numba.core import types, utils, serialize, sigutils from numba.core.typing import npydecl from numba.core.typing.templates import AbstractTemplate, signature from numba.npyufunc import _internal, ufuncbuilder diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index cb34970450e..142d3f23ae1 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -10,8 +10,8 @@ import llvmlite.ir.values as liv import numba -from numba import cgutils, sigutils, parfor -from numba.core import types, ir, config, compiler, lowering +from numba import cgutils, parfor +from numba.core import types, ir, config, compiler, lowering, sigutils from numba.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 4245a50c436..7636daf7cd9 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -8,8 +8,7 @@ from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target from numba.targets.cpu import FastMathOptions -from numba import sigutils -from numba.core import utils, types, serialize, compiler +from numba.core import utils, types, serialize, compiler, sigutils from numba.numpy_support import as_dtype from numba.npyufunc import _internal from numba.npyufunc.sigparse import parse_signature diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index a5566d6de77..25e4f64ff28 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -6,8 +6,7 @@ import sys import tempfile -from numba import sigutils -from numba.core import typing +from numba.core import typing, sigutils from numba.core.compiler_lock import global_compiler_lock from numba.pycc.compiler import ModuleCompiler, ExportEntry from numba.pycc.platform import Toolchain diff --git a/numba/pycc/decorators.py b/numba/pycc/decorators.py index 16e2faea91c..34278903dec 100644 --- a/numba/pycc/decorators.py +++ b/numba/pycc/decorators.py @@ -1,8 +1,7 @@ import re import warnings -from numba import sigutils -from numba.core import typing +from numba.core import typing, sigutils from numba.pycc.compiler import ExportEntry # Registry is okay to be a global because we are using pycc as a standalone diff --git a/numba/roc/decorators.py b/numba/roc/decorators.py index 78a8132042c..05f11ed689c 100644 --- a/numba/roc/decorators.py +++ b/numba/roc/decorators.py @@ -1,5 +1,4 @@ -from numba import sigutils -from numba.core import types +from numba.core import types, sigutils from .compiler import (compile_kernel, compile_device, AutoJitHSAKernel, compile_device_template) diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index bb348b28ed7..1384988b007 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -12,17 +12,12 @@ import shutil import sys import uuid -try: - import cPickle as pickle -except ImportError: - import pickle import weakref import numpy as np from numba import unittest_support as unittest -from numba import sigutils -from numba.core import types, typing, errors +from numba.core import types, typing, errors, sigutils from numba.core.types.abstract import _typecache from numba.core.typing.templates import make_overload_template from numba import jit, njit, numpy_support, typeof @@ -32,6 +27,12 @@ from numba.tests.enum_usecases import Color, Shake, Shape +try: + import cPickle as pickle +except ImportError: + import pickle + + Point = namedtuple('Point', ('x', 'y')) Rect = namedtuple('Rect', ('width', 'height')) From abbc45ee331870e66fb36913f2ad5289d3084786 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 12:28:26 +0000 Subject: [PATCH 388/595] Create numba.stencil --- numba/stencil/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/stencil/__init__.py diff --git a/numba/stencil/__init__.py b/numba/stencil/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 02f2aad5bae1666dd821e4ee4589943210132745 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 12:51:30 +0000 Subject: [PATCH 389/595] remove numba/stencil, move numba/ir_utils to numba/core --- numba/core/analysis.py | 6 +++--- numba/core/inline_closurecall.py | 6 +++--- numba/{ => core}/ir_utils.py | 0 numba/core/lowering.py | 4 ++-- numba/core/typed_passes.py | 2 +- numba/core/untyped_passes.py | 2 +- numba/core/withcontexts.py | 3 +-- numba/npyufunc/parfor.py | 2 +- numba/parfor.py | 6 +++--- numba/parfors/array_analysis.py | 2 +- numba/stencil.py | 4 ++-- numba/stencil/__init__.py | 0 numba/stencilparfor.py | 5 ++--- numba/tests/test_analysis.py | 4 ++-- numba/tests/test_array_analysis.py | 2 +- numba/tests/test_copy_propagate.py | 2 +- numba/tests/test_inlining.py | 2 +- numba/tests/test_ir_inlining.py | 9 ++++----- numba/tests/test_ir_utils.py | 3 +-- numba/tests/test_mixed_tuple_unroller.py | 2 +- numba/tests/test_parfors.py | 2 +- numba/tests/test_remove_dead.py | 7 ++++--- numba/transforms.py | 3 +-- 23 files changed, 37 insertions(+), 41 deletions(-) rename numba/{ => core}/ir_utils.py (100%) delete mode 100644 numba/stencil/__init__.py diff --git a/numba/core/analysis.py b/numba/core/analysis.py index e8a58bda641..49d83c3c098 100644 --- a/numba/core/analysis.py +++ b/numba/core/analysis.py @@ -292,7 +292,7 @@ def dead_branch_prune(func_ir, called_args): func_ir is the IR called_args are the actual arguments with which the function is called """ - from numba.ir_utils import get_definition, guard, find_const, GuardException + from numba.core.ir_utils import get_definition, guard, find_const, GuardException DEBUG = 0 @@ -507,7 +507,7 @@ def rewrite_tuple_len(val, func_ir, called_args): if isinstance(argty, types.BaseTuple): rewrite_statement(func_ir, stmt, argty.count) - from numba.ir_utils import get_definition, guard + from numba.core.ir_utils import get_definition, guard for blk in func_ir.blocks.values(): for stmt in blk.body: if isinstance(stmt, ir.Assign): @@ -535,7 +535,7 @@ def find_literally_calls(func_ir, argtypes): argtypes : Sequence[numba.types.Type] The argument types. """ - from numba import ir_utils + from numba.core import ir_utils marked_args = set() first_loc = {} diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 0fc74de7bff..4d1ace43439 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -1,10 +1,10 @@ import types as pytypes # avoid confusion with numba.types import ctypes import numba.core.analysis -from numba.core import utils, types, typing, errors, ir, rewrites, config -from numba import ir_utils, prange +from numba.core import utils, types, typing, errors, ir, rewrites, config, ir_utils +from numba import prange from numba.parfor import internal_prange -from numba.ir_utils import ( +from numba.core.ir_utils import ( mk_unique_var, next_label, add_offset_to_labels, diff --git a/numba/ir_utils.py b/numba/core/ir_utils.py similarity index 100% rename from numba/ir_utils.py rename to numba/core/ir_utils.py diff --git a/numba/core/lowering.py b/numba/core/lowering.py index 192b3fa786a..6de01db6553 100644 --- a/numba/core/lowering.py +++ b/numba/core/lowering.py @@ -5,8 +5,8 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import _dynfunc, cgutils, ir_utils -from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config +from numba import _dynfunc, cgutils +from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config, ir_utils from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) from numba.targets import removerefctpass diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index e1c2eb5dd46..977487dba85 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -9,7 +9,7 @@ from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass from numba.core.annotations import type_annotations -from numba.ir_utils import (raise_on_unsupported_feature, warn_deprecated, +from numba.core.ir_utils import (raise_on_unsupported_feature, warn_deprecated, check_and_legalize_ir, guard, dead_code_elimination, simplify_CFG, get_definition) diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 4775de4ba74..8f260c5ae64 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -9,7 +9,7 @@ from numba.special import literal_unroll from .analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls, compute_cfg_from_blocks, compute_use_defs from numba.core.inline_closurecall import InlineClosureCallPass, inline_closure_call -from numba.ir_utils import guard, resolve_func_from_module, simplify_CFG, GuardException, convert_code_obj_to_function, mk_unique_var, build_definitions, replace_var_names, get_name_var_table, compile_to_numba_ir, get_definition, find_max_label, rename_labels +from numba.core.ir_utils import guard, resolve_func_from_module, simplify_CFG, GuardException, convert_code_obj_to_function, mk_unique_var, build_definitions, replace_var_names, get_name_var_table, compile_to_numba_ir, get_definition, find_max_label, rename_labels from numba.core import interpreter diff --git a/numba/core/withcontexts.py b/numba/core/withcontexts.py index 37c0e2f5531..20c0d0e9090 100644 --- a/numba/core/withcontexts.py +++ b/numba/core/withcontexts.py @@ -1,5 +1,4 @@ -from numba import ir_utils -from numba.core import types, errors, ir, sigutils +from numba.core import types, errors, ir, sigutils, ir_utils from numba.core.typing.typeof import typeof_impl from numba.transforms import find_region_inout_vars diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 142d3f23ae1..39703e1729c 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -12,7 +12,7 @@ import numba from numba import cgutils, parfor from numba.core import types, ir, config, compiler, lowering, sigutils -from numba.ir_utils import (add_offset_to_labels, replace_var_names, +from numba.core.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, get_definition, guard, find_callname, diff --git a/numba/parfor.py b/numba/parfor.py index 7f28ec24cb5..43069d9528f 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -25,8 +25,8 @@ import operator import numba.core.ir -from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites, typeinfer, config -from numba import ir_utils, prange, pndindex +from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites, typeinfer, config, ir_utils +from numba import prange, pndindex from numba.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate from numba import stencilparfor @@ -34,7 +34,7 @@ from numba.extending import register_jitable -from numba.ir_utils import ( +from numba.core.ir_utils import ( mk_unique_var, next_label, mk_alloc, diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index 9e9670b212e..0bbbf9f6c54 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -8,7 +8,7 @@ import operator from numba import cgutils from numba.core import types, typing, ir, analysis, config -from numba.ir_utils import ( +from numba.core.ir_utils import ( mk_unique_var, replace_vars_inner, find_topo_order, diff --git a/numba/stencil.py b/numba/stencil.py index 4235604ca8f..7a519be32c7 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -8,8 +8,8 @@ import numpy as np from llvmlite import ir as lir -from numba import ir_utils, numpy_support -from numba.core import types, typing, utils, ir, typed_passes, config, compiler +from numba import numpy_support +from numba.core import types, typing, utils, ir, typed_passes, config, compiler, ir_utils from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) from numba.targets import registry diff --git a/numba/stencil/__init__.py b/numba/stencil/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index ad373d27845..ed6e2fe8e72 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -12,12 +12,11 @@ import numpy as np import numba -from numba.core import types, ir, rewrites, config +from numba.core import types, ir, rewrites, config, ir_utils from numba.core.typing.templates import infer_global, AbstractTemplate from numba.core.typing import signature from numba.core import utils, typing -from numba import ir_utils -from numba.ir_utils import (get_call_table, mk_unique_var, +from numba.core.ir_utils import (get_call_table, mk_unique_var, compile_to_numba_ir, replace_arg_nodes, guard, find_callname, require, find_const, GuardException) from numba.core.utils import OPERATORS_TO_BUILTINS diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index a428c94348d..2ab5682c5f1 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -3,8 +3,8 @@ import numpy as np from numba.core.compiler import compile_isolated, run_frontend, Flags, StateDict -from numba import jit, ir_utils, njit -from numba.core import types, errors, ir, rewrites +from numba import jit, njit +from numba.core import types, errors, ir, rewrites, ir_utils from numba.tests.support import TestCase, MemoryLeakMixin, SerialMixin from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 5e31e355f2f..eb45f6d0411 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -12,7 +12,7 @@ from numba.parfors.array_analysis import EquivSet, ArrayAnalysis from numba.core.compiler import Compiler, Flags, PassManager from numba.targets import cpu, registry -from numba.ir_utils import remove_dead +from numba.core.ir_utils import remove_dead from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, RewriteSemanticConstants, GenericRewrites, diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 9333c1063fa..32cf2c7dfdd 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -7,7 +7,7 @@ from numba.core import types, typing, ir, config, compiler from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations -from numba.ir_utils import (copy_propagate, apply_copy_propagate, +from numba.core.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) from numba.core.typed_passes import type_inference_stage from numba import unittest_support as unittest diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 1d259e138ad..f74e984fc75 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -6,7 +6,7 @@ from numba import unittest_support as unittest from numba import jit, njit from numba.core import types, ir, postproc, compiler -from numba.ir_utils import guard, find_callname, find_const, get_definition +from numba.core.ir_utils import guard, find_callname, find_const, get_definition from numba.targets.registry import CPUDispatcher from numba.core.inline_closurecall import inline_closure_call diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index dcbfca371a4..6cb7137567f 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -6,9 +6,8 @@ import numpy as np -import numba -from numba import njit -from numba.core import types, ir +from numba import njit, typeof +from numba.core import types, ir, ir_utils from numba.extending import ( overload, overload_method, @@ -104,7 +103,7 @@ def check(self, test_impl, *args, **kwargs): # make sure IR doesn't have branches fir = j_func.overloads[j_func.signatures[0]].metadata['preserved_ir'] - fir.blocks = numba.ir_utils.simplify_CFG(fir.blocks) + fir.blocks = ir_utils.simplify_CFG(fir.blocks) if self._DEBUG: print("FIR".center(80, "-")) fir.dump() @@ -757,7 +756,7 @@ def test_multiple_overloads_with_different_inline_characteristics(self): # this is the Python equiv of the overloads below def bar(x): - if isinstance(numba.typeof(x), types.Float): + if isinstance(typeof(x), types.Float): return x + 1234 else: return x + 1 diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index f1da16a930c..6625a321d0d 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -5,8 +5,7 @@ from numba.core.compiler import CompilerBase, Flags from numba.core.compiler_machinery import PassManager from numba.targets import registry -from numba import ir_utils -from numba.core import types, ir, bytecode, compiler +from numba.core import types, ir, bytecode, compiler, ir_utils from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index d43bfede872..d1893219e65 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -13,7 +13,7 @@ IterLoopCanonicalization, LiteralUnroll) from numba.core.typed_passes import (NopythonTypeInference, IRLegalization, NoPythonBackend, PartialTypeInference) -from numba.ir_utils import (compute_cfg_from_blocks, flatten_labels) +from numba.core.ir_utils import (compute_cfg_from_blocks, flatten_labels) class TestLiteralTupleInterpretation(MemoryLeakMixin, TestCase): diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index ab6aa3a1726..a85b4a28969 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -25,7 +25,7 @@ from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations -from numba.ir_utils import (find_callname, guard, build_definitions, +from numba.core.ir_utils import (find_callname, guard, build_definitions, get_definition, is_getitem, is_setitem, index_var_of_get_setitem) from numba.unsafe.ndarray import empty_inferred as unsafe_empty diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 8bedfd16370..c76f3e95df9 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -4,12 +4,13 @@ # import numba +from numba.core import ir_utils from numba.core.compiler import compile_isolated, Flags from numba.targets import cpu from numba.core import types, typing, ir, config, compiler from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations -from numba.ir_utils import (copy_propagate, apply_copy_propagate, +from numba.core.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table, remove_dels, remove_dead, remove_call_handlers, alias_func_extensions) from numba.core.typed_passes import type_inference_stage @@ -45,7 +46,7 @@ def dummy_aliased_func(A): return A def alias_ext_dummy_func(lhs_name, args, alias_map, arg_aliases): - numba.ir_utils._add_alias(lhs_name, args[0].name, alias_map, arg_aliases) + ir_utils._add_alias(lhs_name, args[0].name, alias_map, arg_aliases) def findLhsAssign(func_ir, var): for label, block in func_ir.blocks.items(): @@ -214,7 +215,7 @@ def func(A, i): self.run_array_index_test(func) finally: # recover global state - numba.ir_utils.alias_func_extensions = old_ext_handlers + ir_utils.alias_func_extensions = old_ext_handlers @skip_parfors_unsupported def test_alias_parfor_extension(self): diff --git a/numba/transforms.py b/numba/transforms.py index 2f0943322fc..d01747884ac 100644 --- a/numba/transforms.py +++ b/numba/transforms.py @@ -7,8 +7,7 @@ import logging from numba.core.analysis import compute_cfg_from_blocks, find_top_level_loops -from numba import ir_utils -from numba.core import errors, ir +from numba.core import errors, ir, ir_utils from numba.core.analysis import compute_use_defs From 37d492038d6d9142baeab5e3fb646a50996d780d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:02:22 +0000 Subject: [PATCH 390/595] Move numba/cgutils.py to numba/core --- numba/core/callwrapper.py | 3 +-- numba/{ => core}/cgutils.py | 0 numba/core/datamodel/models.py | 4 ++-- numba/core/datamodel/packer.py | 3 +-- numba/core/generators.py | 3 +-- numba/core/ir_utils.py | 3 +-- numba/core/lowering.py | 4 ++-- numba/core/pylowering.py | 3 +-- numba/core/pythonapi.py | 4 ++-- numba/cpython/builtins.py | 3 +-- numba/cpython/charseq.py | 5 ++--- numba/cpython/cmathimpl.py | 3 +-- numba/cpython/iterators.py | 3 +-- numba/cpython/listobj.py | 3 +-- numba/cpython/mathimpl.py | 4 ++-- numba/cpython/numbers.py | 3 +-- numba/cpython/printimpl.py | 3 +-- numba/cpython/randomimpl.py | 4 ++-- numba/cpython/rangeobj.py | 4 ++-- numba/cpython/setobj.py | 3 +-- numba/cpython/slicing.py | 3 +-- numba/cpython/tupleobj.py | 3 +-- numba/cpython/unicode.py | 3 +-- numba/cpython/unicode_support.py | 3 +-- numba/cpython/unsafe/tuple.py | 2 +- numba/cuda/cudaimpl.py | 3 +-- numba/cuda/libdevice.py | 3 +-- numba/cuda/nvvmutils.py | 2 +- numba/cuda/printimpl.py | 3 +-- numba/cuda/target.py | 3 +-- numba/dictobject.py | 3 +-- numba/extending.py | 2 +- numba/jitclass/base.py | 3 +-- numba/jitclass/boxing.py | 3 +-- numba/listobject.py | 3 +-- numba/np/arrayobj.py | 4 ++-- numba/np/linalg.py | 4 +--- numba/npyufunc/parfor.py | 4 ++-- numba/npyufunc/wrappers.py | 3 +-- numba/numpy_support.py | 4 +++- numba/parfors/array_analysis.py | 3 +-- numba/pycc/compiler.py | 2 +- numba/roc/hsaimpl.py | 3 +-- numba/roc/target.py | 3 +-- numba/runtime/context.py | 3 +-- numba/runtime/nrtdynmod.py | 3 +-- numba/runtime/nrtopt.py | 2 +- numba/targets/arraymath.py | 4 ++-- numba/targets/base.py | 3 +-- numba/targets/boxing.py | 4 ++-- numba/targets/callconv.py | 3 +-- numba/targets/codegen.py | 3 +-- numba/targets/cpu.py | 3 +-- numba/targets/gdb_hook.py | 4 ++-- numba/targets/imputils.py | 3 +-- numba/targets/npdatetime.py | 4 ++-- numba/targets/npyfuncs.py | 3 +-- numba/targets/npyimpl.py | 4 ++-- numba/targets/optional.py | 3 +-- numba/tests/pdlike_usecase.py | 3 +-- numba/tests/test_cgutils.py | 3 +-- numba/tests/test_extending_types.py | 3 +-- numba/tests/test_literal_dispatch.py | 4 ++-- numba/tests/test_unicode_names.py | 3 ++- numba/typed/typeddict.py | 4 ++-- numba/typed/typedlist.py | 4 ++-- numba/typedobjectutils.py | 3 +-- numba/unsafe/bytes.py | 3 +-- numba/unsafe/eh.py | 3 +-- numba/unsafe/ndarray.py | 2 +- numba/unsafe/refcount.py | 3 +-- 71 files changed, 90 insertions(+), 134 deletions(-) rename numba/{ => core}/cgutils.py (100%) diff --git a/numba/core/callwrapper.py b/numba/core/callwrapper.py index 733c62d320f..5a443662e3b 100644 --- a/numba/core/callwrapper.py +++ b/numba/core/callwrapper.py @@ -1,8 +1,7 @@ from llvmlite.llvmpy.core import Type, Builder, Constant import llvmlite.llvmpy.core as lc -from numba.core import types, config -from numba import cgutils +from numba.core import types, config, cgutils class _ArgManager(object): diff --git a/numba/cgutils.py b/numba/core/cgutils.py similarity index 100% rename from numba/cgutils.py rename to numba/core/cgutils.py diff --git a/numba/core/datamodel/models.py b/numba/core/datamodel/models.py index 3bf954e35dc..75646474127 100644 --- a/numba/core/datamodel/models.py +++ b/numba/core/datamodel/models.py @@ -2,9 +2,9 @@ from llvmlite import ir -from numba import cgutils, numpy_support +from numba import numpy_support from numba.core.datamodel.registry import register_default -from numba.core import types +from numba.core import types, cgutils class DataModel(object): diff --git a/numba/core/datamodel/packer.py b/numba/core/datamodel/packer.py index 2d959a9f2c2..512637c8b6b 100644 --- a/numba/core/datamodel/packer.py +++ b/numba/core/datamodel/packer.py @@ -1,7 +1,6 @@ from collections import deque -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils diff --git a/numba/core/generators.py b/numba/core/generators.py index 64af0bc2f81..febe5c4bc91 100644 --- a/numba/core/generators.py +++ b/numba/core/generators.py @@ -4,8 +4,7 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import cgutils -from numba.core import types, config +from numba.core import types, config, cgutils from numba.core.funcdesc import FunctionDescriptor diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index 43d30b0adab..f65d1019d1b 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -13,8 +13,7 @@ from llvmlite import ir as lir import numba -from numba.core import types, utils, typing, ir, analysis, postproc, rewrites, config -from numba import cgutils +from numba.core import types, utils, typing, ir, analysis, postproc, rewrites, config, cgutils from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) from numba.targets.imputils import impl_ret_untracked diff --git a/numba/core/lowering.py b/numba/core/lowering.py index 6de01db6553..c8587a783a5 100644 --- a/numba/core/lowering.py +++ b/numba/core/lowering.py @@ -5,8 +5,8 @@ from llvmlite.llvmpy.core import Constant, Type, Builder -from numba import _dynfunc, cgutils -from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config, ir_utils +from numba import _dynfunc +from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config, ir_utils, cgutils from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) from numba.targets import removerefctpass diff --git a/numba/core/pylowering.py b/numba/core/pylowering.py index a0198486619..cbe0d35cdcd 100644 --- a/numba/core/pylowering.py +++ b/numba/core/pylowering.py @@ -9,8 +9,7 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba import cgutils -from numba.core import types, utils, ir, generators +from numba.core import types, utils, ir, generators, cgutils from numba.core.errors import ForbiddenConstruct from numba.core.lowering import BaseLower diff --git a/numba/core/pythonapi.py b/numba/core/pythonapi.py index d7deabd84fe..06ea81daf5f 100644 --- a/numba/core/pythonapi.py +++ b/numba/core/pythonapi.py @@ -7,8 +7,8 @@ import llvmlite.llvmpy.core as lc import ctypes -from numba import cgutils, _helperlib -from numba.core import types, utils, config, lowering +from numba import _helperlib +from numba.core import types, utils, config, lowering, cgutils PY_UNICODE_1BYTE_KIND = _helperlib.py_unicode_1byte_kind diff --git a/numba/cpython/builtins.py b/numba/cpython/builtins.py index 216823d7c50..ab22c38d268 100644 --- a/numba/cpython/builtins.py +++ b/numba/cpython/builtins.py @@ -9,8 +9,7 @@ import llvmlite.llvmpy.core as lc from numba.targets.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, iternext_impl, call_getiter, call_iternext, impl_ret_borrowed, impl_ret_untracked, numba_typeref_ctor -from numba.core import typing, types, utils -from numba import cgutils +from numba.core import typing, types, utils, cgutils from numba.extending import overload, intrinsic from numba.core.typeconv import Conversion from numba.core.errors import TypingError diff --git a/numba/cpython/charseq.py b/numba/cpython/charseq.py index 7dfcb2104e7..c6eba7afb6a 100644 --- a/numba/cpython/charseq.py +++ b/numba/cpython/charseq.py @@ -3,11 +3,10 @@ import numpy as np from llvmlite import ir -from numba.core import types -from numba import cgutils +from numba.core import types, cgutils from numba.extending import (overload, intrinsic, overload_method, lower_cast, register_jitable) -from numba.cgutils import is_nonelike +from numba.core.cgutils import is_nonelike from numba.cpython import unicode # bytes and str arrays items are of type CharSeq and UnicodeCharSeq, diff --git a/numba/cpython/cmathimpl.py b/numba/cpython/cmathimpl.py index 4015a658840..61009c2c683 100644 --- a/numba/cpython/cmathimpl.py +++ b/numba/cpython/cmathimpl.py @@ -10,8 +10,7 @@ from llvmlite.llvmpy.core import Type from numba.targets.imputils import Registry, impl_ret_untracked -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from numba.core.typing import signature from numba.cpython import builtins, mathimpl diff --git a/numba/cpython/iterators.py b/numba/cpython/iterators.py index 74f8d67ba8e..769dcb71da0 100644 --- a/numba/cpython/iterators.py +++ b/numba/cpython/iterators.py @@ -2,8 +2,7 @@ Implementation of various iterable and iterator types. """ -from numba.core import types -from numba import cgutils +from numba.core import types, cgutils from numba.targets.imputils import ( lower_builtin, iternext_impl, call_iternext, call_getiter, impl_ret_borrowed, impl_ret_new_ref, RefType) diff --git a/numba/cpython/listobj.py b/numba/cpython/listobj.py index 1ae623bd39d..6c4f3241c8b 100644 --- a/numba/cpython/listobj.py +++ b/numba/cpython/listobj.py @@ -7,8 +7,7 @@ import operator from llvmlite import ir -from numba import cgutils -from numba.core import types, typing, errors +from numba.core import types, typing, errors, cgutils from numba.targets.imputils import (lower_builtin, lower_cast, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, diff --git a/numba/cpython/mathimpl.py b/numba/cpython/mathimpl.py index 3ded2050acc..a6e4e10c268 100644 --- a/numba/cpython/mathimpl.py +++ b/numba/cpython/mathimpl.py @@ -11,8 +11,8 @@ from llvmlite.llvmpy.core import Type from numba.targets.imputils import Registry, impl_ret_untracked -from numba import typeof, cgutils -from numba.core import types, utils, config +from numba import typeof +from numba.core import types, utils, config, cgutils from numba.extending import overload from numba.core.typing import signature from numba.cpython.unsafe.numbers import trailing_zeros diff --git a/numba/cpython/numbers.py b/numba/cpython/numbers.py index 01b264eecab..4ebdffad113 100644 --- a/numba/cpython/numbers.py +++ b/numba/cpython/numbers.py @@ -13,8 +13,7 @@ lower_constant, impl_ret_borrowed, impl_ret_untracked) from numba.targets import optional -from numba.core import typing, types, utils, errors -from numba import cgutils +from numba.core import typing, types, utils, errors, cgutils from numba.extending import intrinsic, overload_method from numba.cpython.unsafe.numbers import viewer diff --git a/numba/cpython/printimpl.py b/numba/cpython/printimpl.py index 8f2558cfc9f..3d42ba914b0 100644 --- a/numba/cpython/printimpl.py +++ b/numba/cpython/printimpl.py @@ -2,8 +2,7 @@ This file implements print functionality for the CPU. """ from llvmlite.llvmpy.core import Type -from numba.core import types, typing -from numba import cgutils +from numba.core import types, typing, cgutils from numba.targets.imputils import Registry, impl_ret_untracked registry = Registry() diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index 641c8d12e06..97339a591fa 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -15,8 +15,8 @@ from numba.targets.imputils import (Registry, impl_ret_untracked, impl_ret_new_ref) from numba.core.typing import signature -from numba import _helperlib, cgutils -from numba.core import types, utils +from numba import _helperlib +from numba.core import types, utils, cgutils from numba.np import arrayobj POST_PY38 = utils.PYVERSION >= (3, 8) diff --git a/numba/cpython/rangeobj.py b/numba/cpython/rangeobj.py index 537fc401d03..512d7c22ce8 100644 --- a/numba/cpython/rangeobj.py +++ b/numba/cpython/rangeobj.py @@ -6,8 +6,8 @@ import llvmlite.llvmpy.core as lc -from numba import cgutils, prange -from numba.core import types +from numba import prange +from numba.core import types, cgutils from numba.cpython.listobj import ListIterInstance from numba.np.arrayobj import make_array from numba.targets.imputils import (lower_builtin, lower_cast, diff --git a/numba/cpython/setobj.py b/numba/cpython/setobj.py index a4f17d622ee..b0570f26067 100644 --- a/numba/cpython/setobj.py +++ b/numba/cpython/setobj.py @@ -9,8 +9,7 @@ import operator from llvmlite import ir -from numba.core import types, typing -from numba import cgutils +from numba.core import types, typing, cgutils from numba.targets.imputils import (lower_builtin, lower_cast, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, diff --git a/numba/cpython/slicing.py b/numba/cpython/slicing.py index e073e2d51ff..0ab68e38b8a 100644 --- a/numba/cpython/slicing.py +++ b/numba/cpython/slicing.py @@ -6,8 +6,7 @@ from llvmlite import ir -from numba import cgutils -from numba.core import types, typing, utils +from numba.core import types, typing, utils, cgutils from numba.targets.imputils import (lower_builtin, lower_getattr, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) diff --git a/numba/cpython/tupleobj.py b/numba/cpython/tupleobj.py index 32681f4d76e..787968490db 100644 --- a/numba/cpython/tupleobj.py +++ b/numba/cpython/tupleobj.py @@ -10,8 +10,7 @@ lower_cast, lower_constant, iternext_impl, impl_ret_borrowed, impl_ret_untracked, RefType) -from numba.core import typing, types -from numba import cgutils +from numba.core import typing, types, cgutils from numba.extending import overload_method, overload, intrinsic diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index a3977a8f655..30b553004ab 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -19,8 +19,7 @@ from numba.targets.imputils import (lower_constant, lower_cast, lower_builtin, iternext_impl, impl_ret_new_ref, RefType) from numba.core.datamodel import register_default, StructModel -from numba import cgutils -from numba.core import utils, types +from numba.core import utils, types, cgutils from numba.core.pythonapi import ( PY_UNICODE_1BYTE_KIND, PY_UNICODE_2BYTE_KIND, diff --git a/numba/cpython/unicode_support.py b/numba/cpython/unicode_support.py index 48b850cb9fc..ba7f3b35f9a 100644 --- a/numba/cpython/unicode_support.py +++ b/numba/cpython/unicode_support.py @@ -9,8 +9,7 @@ import numpy as np import llvmlite.llvmpy.core as lc -from numba.core import types -from numba import cgutils +from numba.core import types, cgutils from numba.targets.imputils import (impl_ret_untracked) from numba.extending import overload, intrinsic, register_jitable diff --git a/numba/cpython/unsafe/tuple.py b/numba/cpython/unsafe/tuple.py index e57338f3a89..b5e500c10eb 100644 --- a/numba/cpython/unsafe/tuple.py +++ b/numba/cpython/unsafe/tuple.py @@ -3,7 +3,7 @@ operations with tuple and workarounds for limitations enforced in userland. """ -from numba.cgutils import alloca_once +from numba.core.cgutils import alloca_once from numba.extending import intrinsic diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index cd5de9dc58c..a970137c644 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -7,8 +7,7 @@ import llvmlite.binding as ll from numba.targets.imputils import Registry -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from .cudadrv import nvvm from numba.cuda import nvvmutils, stubs diff --git a/numba/cuda/libdevice.py b/numba/cuda/libdevice.py index e283941e76a..84a7792e1d4 100644 --- a/numba/cuda/libdevice.py +++ b/numba/cuda/libdevice.py @@ -1,8 +1,7 @@ import sys import math from llvmlite.llvmpy.core import Type -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from numba.targets.imputils import Registry registry = Registry() diff --git a/numba/cuda/nvvmutils.py b/numba/cuda/nvvmutils.py index 75d0de08d4b..3b78b6cbeb5 100644 --- a/numba/cuda/nvvmutils.py +++ b/numba/cuda/nvvmutils.py @@ -2,7 +2,7 @@ import llvmlite.llvmpy.core as lc from .cudadrv import nvvm from .api import current_context -from numba import cgutils +from numba.core import cgutils def declare_atomic_cas_int32(lmod): diff --git a/numba/cuda/printimpl.py b/numba/cuda/printimpl.py index 6695612695a..4a20834efba 100644 --- a/numba/cuda/printimpl.py +++ b/numba/cuda/printimpl.py @@ -2,8 +2,7 @@ from llvmlite.llvmpy.core import Type, Constant -from numba import cgutils -from numba.core import types, typing +from numba.core import types, typing, cgutils from numba.targets.imputils import Registry from numba.cuda import nvvmutils diff --git a/numba/cuda/target.py b/numba/cuda/target.py index 44c69486e37..48208857528 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -4,8 +4,7 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba.core import typing, types, dispatcher, debuginfo, itanium_mangler -from numba import cgutils +from numba.core import typing, types, dispatcher, debuginfo, itanium_mangler, cgutils from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv diff --git a/numba/dictobject.py b/numba/dictobject.py index 09fbd90b160..151265e1a19 100644 --- a/numba/dictobject.py +++ b/numba/dictobject.py @@ -7,7 +7,6 @@ from llvmlite import ir -from numba import cgutils from numba import _helperlib from numba.extending import ( @@ -19,7 +18,7 @@ lower_builtin, ) from numba.targets.imputils import iternext_impl -from numba.core import types +from numba.core import types, cgutils from numba.core.types import ( DictType, DictItemsIterableType, diff --git a/numba/extending.py b/numba/extending.py index 7dbb303cc97..7a052a0b57b 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -224,7 +224,7 @@ def make_attribute_wrapper(typeclass, struct_attr, python_attr): from numba.core.datamodel import default_manager from numba.core.datamodel.models import StructModel from numba.targets.imputils import impl_ret_borrowed - from numba import cgutils + from numba.core import cgutils if not isinstance(typeclass, type) or not issubclass(typeclass, types.Type): raise TypeError("typeclass should be a Type subclass, got %s" diff --git a/numba/jitclass/base.py b/numba/jitclass/base.py index 4bae51ab706..51d8989f129 100644 --- a/numba/jitclass/base.py +++ b/numba/jitclass/base.py @@ -6,13 +6,12 @@ from llvmlite import ir as llvmir -from numba.core import types, utils, errors +from numba.core import types, utils, errors, cgutils from numba.targets.registry import cpu_target from numba import njit from numba.core.typing import templates from numba.core.datamodel import default_manager, models from numba.targets import imputils -from numba import cgutils from numba.jitclass import _box diff --git a/numba/jitclass/boxing.py b/numba/jitclass/boxing.py index 5b44cd765d9..eb847dc5263 100644 --- a/numba/jitclass/boxing.py +++ b/numba/jitclass/boxing.py @@ -7,8 +7,7 @@ from llvmlite import ir -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from numba.core.pythonapi import box, unbox, NativeValue from numba import njit from numba.jitclass import _box diff --git a/numba/listobject.py b/numba/listobject.py index a50bd197baa..a467eb9674e 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -7,7 +7,6 @@ from llvmlite import ir -from numba import cgutils from numba import _helperlib from numba.extending import ( @@ -20,7 +19,7 @@ lower_builtin, ) from numba.targets.imputils import iternext_impl -from numba.core import types +from numba.core import types, cgutils from numba.core.types import ( ListType, ListTypeIterableType, diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index ab6dbc58ed7..8e6e2e2cde8 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -14,8 +14,8 @@ import numpy as np -from numba import cgutils, extending, pndindex -from numba.core import types, utils, typing, errors +from numba import extending, pndindex +from numba.core import types, utils, typing, errors, cgutils from numba.numpy_support import (as_dtype, carray, farray, is_contiguous, is_fortran) from numba.numpy_support import type_can_asarray, is_nonelike diff --git a/numba/np/linalg.py b/numba/np/linalg.py index 3006dd60094..a1f00ff19c5 100644 --- a/numba/np/linalg.py +++ b/numba/np/linalg.py @@ -10,13 +10,11 @@ import numpy as np import operator -from numba import cgutils - from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) from numba.core.typing import signature from numba.extending import overload, register_jitable -from numba.core import types +from numba.core import types, cgutils from numba.core.errors import TypingError from numba import numpy_support as np_support from .arrayobj import make_array, _empty_nd_impl, array_copy diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 39703e1729c..2a6cb260c55 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -10,8 +10,8 @@ import llvmlite.ir.values as liv import numba -from numba import cgutils, parfor -from numba.core import types, ir, config, compiler, lowering, sigutils +from numba import parfor +from numba.core import types, ir, config, compiler, lowering, sigutils, cgutils from numba.core.ir_utils import (add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, diff --git a/numba/npyufunc/wrappers.py b/numba/npyufunc/wrappers.py index e8ac18eceb1..6c697e67922 100644 --- a/numba/npyufunc/wrappers.py +++ b/numba/npyufunc/wrappers.py @@ -4,8 +4,7 @@ from llvmlite.llvmpy.core import Type, Builder, ICMP_EQ, Constant -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from numba.core.compiler_lock import global_compiler_lock from numba.core.caching import make_library_cache, NullCache diff --git a/numba/numpy_support.py b/numba/numpy_support.py index 4e58e951799..367d15b5705 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -5,8 +5,10 @@ import numpy as np from numba.core import errors, types, utils + + # re-export -from numba.cgutils import is_nonelike # noqa: F401 +from numba.core.cgutils import is_nonelike # noqa: F401 numpy_version = tuple(map(int, np.__version__.split('.')[:2])) diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index 0bbbf9f6c54..f034d274c13 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -6,8 +6,7 @@ import types as pytypes import numpy import operator -from numba import cgutils -from numba.core import types, typing, ir, analysis, config +from numba.core import types, typing, ir, analysis, config, cgutils from numba.core.ir_utils import ( mk_unique_var, replace_vars_inner, diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index 00c1333c167..08b892ef68a 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -8,13 +8,13 @@ from llvmlite.binding import Linkage import llvmlite.llvmpy.core as lc -from numba import cgutils from numba.pycc import llvm_types as lt from numba.core.compiler import compile_extra, Flags from numba.core.compiler_lock import global_compiler_lock from numba.targets.registry import cpu_target from numba.runtime import nrtdynmod +from numba.core import cgutils logger = logging.getLogger(__name__) diff --git a/numba/roc/hsaimpl.py b/numba/roc/hsaimpl.py index 74d867c24e4..97aa28f1576 100644 --- a/numba/roc/hsaimpl.py +++ b/numba/roc/hsaimpl.py @@ -7,8 +7,7 @@ from llvmlite import ir from numba.targets.imputils import Registry -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from numba.core.itanium_mangler import mangle_c, mangle, mangle_type from numba.roc import target from numba.roc import stubs diff --git a/numba/roc/target.py b/numba/roc/target.py index 2f5886e7781..c8439bbf12e 100644 --- a/numba/roc/target.py +++ b/numba/roc/target.py @@ -4,8 +4,7 @@ from llvmlite import ir as llvmir from llvmlite import binding as ll -from numba import cgutils -from numba.core import typing, types, utils, datamodel +from numba.core import typing, types, utils, datamodel, cgutils from numba.core.utils import cached_property from numba.targets.base import BaseContext from numba.targets.callconv import MinimalCallConv diff --git a/numba/runtime/context.py b/numba/runtime/context.py index 5093e5c7a10..02c0f3148db 100644 --- a/numba/runtime/context.py +++ b/numba/runtime/context.py @@ -1,7 +1,6 @@ from llvmlite import ir -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils class NRTContext(object): diff --git a/numba/runtime/nrtdynmod.py b/numba/runtime/nrtdynmod.py index 55f92b9021a..a4a54621995 100644 --- a/numba/runtime/nrtdynmod.py +++ b/numba/runtime/nrtdynmod.py @@ -4,8 +4,7 @@ from numba.core.config import MACHINE_BITS -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from llvmlite import ir, binding # Flag to enable debug print in NRT_incref and NRT_decref diff --git a/numba/runtime/nrtopt.py b/numba/runtime/nrtopt.py index 77f2f8506a1..df137a8c3df 100644 --- a/numba/runtime/nrtopt.py +++ b/numba/runtime/nrtopt.py @@ -4,7 +4,7 @@ import re from collections import defaultdict, deque from llvmlite import binding as ll -from numba import cgutils +from numba.core import cgutils _regex_incref = re.compile(r'\s*(?:tail)?\s*call void @NRT_incref\((.*)\)') _regex_decref = re.compile(r'\s*(?:tail)?\s*call void @NRT_decref\((.*)\)') diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 06ef64a2737..7d2c4c387b5 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -12,8 +12,8 @@ import llvmlite.llvmpy.core as lc -from numba import cgutils, generated_jit -from numba.core import types +from numba import generated_jit +from numba.core import types, cgutils from numba.extending import overload, overload_method, register_jitable from numba.numpy_support import as_dtype, type_can_asarray from numba.numpy_support import numpy_version diff --git a/numba/targets/base.py b/numba/targets/base.py index f51a5fe824e..1d4373338cb 100644 --- a/numba/targets/base.py +++ b/numba/targets/base.py @@ -12,8 +12,7 @@ from llvmlite.llvmpy.core import Type, Constant, LLVMException import llvmlite.binding as ll -from numba.core import types, utils, typing, datamodel, debuginfo, funcdesc, config -from numba import cgutils +from numba.core import types, utils, typing, datamodel, debuginfo, funcdesc, config, cgutils from numba import _dynfunc, _helperlib from numba.core.compiler_lock import global_compiler_lock from numba.core.pythonapi import PythonAPI diff --git a/numba/targets/boxing.py b/numba/targets/boxing.py index 085d936cbe2..c5f62ebaa97 100644 --- a/numba/targets/boxing.py +++ b/numba/targets/boxing.py @@ -4,8 +4,8 @@ from llvmlite import ir -from numba import cgutils, numpy_support -from numba.core import types +from numba import numpy_support +from numba.core import types, cgutils from numba.core.pythonapi import box, unbox, reflect, NativeValue from numba.cpython import setobj, listobj diff --git a/numba/targets/callconv.py b/numba/targets/callconv.py index ab553010ca1..c6510bae439 100644 --- a/numba/targets/callconv.py +++ b/numba/targets/callconv.py @@ -7,8 +7,7 @@ from llvmlite import ir as ir -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from numba.targets.base import PYOBJECT, GENERIC_POINTER diff --git a/numba/targets/codegen.py b/numba/targets/codegen.py index 443d2451bff..e0752be9a4e 100644 --- a/numba/targets/codegen.py +++ b/numba/targets/codegen.py @@ -9,8 +9,7 @@ import llvmlite.binding as ll import llvmlite.ir as llvmir -from numba.core import utils, config -from numba import cgutils +from numba.core import utils, config, cgutils from numba.runtime.nrtopt import remove_redundant_nrt_refct from numba.runtime import rtsys from numba.core.compiler_lock import require_global_compiler_lock diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index aaab1044445..d2d1763bd56 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -7,8 +7,7 @@ from numba import _dynfunc from numba.core.callwrapper import PyCallWrapper from numba.targets.base import BaseContext, PYOBJECT -from numba.core import utils, types, config -from numba import cgutils +from numba.core import utils, types, config, cgutils from numba.core.utils import cached_property from numba.targets import callconv, codegen, externals, intrinsics, dictimpl from numba.targets.options import TargetOptions diff --git a/numba/targets/gdb_hook.py b/numba/targets/gdb_hook.py index 45f3df6e42f..10a10f4a258 100644 --- a/numba/targets/gdb_hook.py +++ b/numba/targets/gdb_hook.py @@ -3,8 +3,8 @@ from llvmlite import ir -from numba.core import types, utils, config -from numba import gdb, gdb_init, gdb_breakpoint, cgutils +from numba.core import types, utils, config, cgutils +from numba import gdb, gdb_init, gdb_breakpoint from numba.extending import overload, intrinsic _path = os.path.dirname(__file__) diff --git a/numba/targets/imputils.py b/numba/targets/imputils.py index 4c6afcea4ef..912c770151a 100644 --- a/numba/targets/imputils.py +++ b/numba/targets/imputils.py @@ -9,8 +9,7 @@ import functools from enum import Enum -from numba.core import typing, types, utils -from numba import cgutils +from numba.core import typing, types, utils, cgutils from numba.core.typing.templates import BaseRegistryLoader diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index d887ba32949..96d65625745 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -8,8 +8,8 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba import cgutils, numpy_support -from numba.core import types +from numba import numpy_support +from numba.core import types, cgutils from numba.targets.imputils import (lower_builtin, lower_constant, impl_ret_untracked) from numba.np import npdatetime diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index 7e74b8a5266..44c023553ef 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -10,8 +10,7 @@ from llvmlite.llvmpy import core as lc from numba.targets.imputils import impl_ret_untracked -from numba import cgutils -from numba.core import typing, types, errors, lowering +from numba.core import typing, types, errors, lowering, cgutils from numba.targets import npdatetime from numba.cpython import cmathimpl, mathimpl, numbers diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index bc06ccd37d3..95b1981c2e9 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -16,8 +16,8 @@ from numba.targets import callconv, ufunc_db from numba.np import arrayobj from numba.targets.imputils import Registry, impl_ret_new_ref, force_error_model -from numba import cgutils, numpy_support -from numba.core import typing, types, utils +from numba import numpy_support +from numba.core import typing, types, utils, cgutils from numba.numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype from numba.core.typing import npydecl from numba.extending import overload, intrinsic diff --git a/numba/targets/optional.py b/numba/targets/optional.py index 15b8ed8b905..3b15d69d9b7 100644 --- a/numba/targets/optional.py +++ b/numba/targets/optional.py @@ -1,7 +1,6 @@ import operator -from numba.core import types, typing -from numba import cgutils +from numba.core import types, typing, cgutils from numba.targets.imputils import (lower_cast, lower_builtin, lower_getattr_generic, impl_ret_untracked, diff --git a/numba/tests/pdlike_usecase.py b/numba/tests/pdlike_usecase.py index c91f0ef02e3..983bc2fd893 100644 --- a/numba/tests/pdlike_usecase.py +++ b/numba/tests/pdlike_usecase.py @@ -4,8 +4,7 @@ import numpy as np -from numba.core import types -from numba import cgutils +from numba.core import types, cgutils from numba.core.datamodel import models from numba.extending import ( typeof_impl, type_callable, register_model, diff --git a/numba/tests/test_cgutils.py b/numba/tests/test_cgutils.py index d2ae1353b85..309e79a7d15 100644 --- a/numba/tests/test_cgutils.py +++ b/numba/tests/test_cgutils.py @@ -7,8 +7,7 @@ import numpy as np import numba.unittest_support as unittest -from numba import cgutils -from numba.core import types, typing +from numba.core import types, typing, cgutils from numba.core.compiler_lock import global_compiler_lock from numba.targets import cpu from numba.tests.support import TestCase diff --git a/numba/tests/test_extending_types.py b/numba/tests/test_extending_types.py index 156da1edf4f..461617d29b5 100644 --- a/numba/tests/test_extending_types.py +++ b/numba/tests/test_extending_types.py @@ -3,8 +3,7 @@ """ from numba import njit -from numba.core import types -from numba import cgutils +from numba.core import types, cgutils from numba.core.errors import TypingError from numba.extending import lower_builtin from numba.extending import models, register_model diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index 589ef33248a..2498487c9f2 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -3,8 +3,8 @@ import numba import numba.unittest_support as unittest from numba.tests.support import TestCase -from numba import njit, cgutils -from numba.core import types, errors +from numba import njit +from numba.core import types, errors, cgutils from numba.core.typing import signature from numba.core.datamodel import models from numba.extending import ( diff --git a/numba/tests/test_unicode_names.py b/numba/tests/test_unicode_names.py index 7e82adef61e..0ed8fb75641 100644 --- a/numba/tests/test_unicode_names.py +++ b/numba/tests/test_unicode_names.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -from numba import njit, cfunc, cgutils +from numba import njit, cfunc from numba.tests.support import TestCase, unittest +from numba.core import cgutils unicode_name1 = u""" def unicode_name1(ಠ_ರೃ, ಠਊಠ): diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index b02c09ee402..ea677f08e58 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -5,8 +5,8 @@ from numba.core.types import DictType, TypeRef from numba.targets.imputils import numba_typeref_ctor -from numba import njit, dictobject, cgutils, typeof -from numba.core import types, errors, config +from numba import njit, dictobject, typeof +from numba.core import types, errors, config, cgutils from numba.extending import ( overload_method, overload, diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index f0d0d4dd523..1a27eb1b3b3 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -14,8 +14,8 @@ from numba.targets.imputils import numba_typeref_ctor from numba import listobject from numba.core.dispatcher import Dispatcher -from numba.core import types, errors, config -from numba import njit, cgutils, typeof +from numba.core import types, errors, config, cgutils +from numba import njit, typeof from numba.extending import ( overload_method, overload, diff --git a/numba/typedobjectutils.py b/numba/typedobjectutils.py index 2ce5cfdbe02..6c3f7ba5e47 100644 --- a/numba/typedobjectutils.py +++ b/numba/typedobjectutils.py @@ -6,8 +6,7 @@ from llvmlite import ir from llvmlite.llvmpy.core import Builder -from numba import cgutils -from numba.core import types +from numba.core import types, cgutils from numba.core import typing from numba.targets.registry import cpu_target from numba.core.typeconv import Conversion diff --git a/numba/unsafe/bytes.py b/numba/unsafe/bytes.py index 7d2c0b3f13a..bc86b90dd82 100644 --- a/numba/unsafe/bytes.py +++ b/numba/unsafe/bytes.py @@ -5,8 +5,7 @@ from numba.extending import intrinsic from llvmlite import ir -from numba.core import types -from numba import cgutils +from numba.core import types, cgutils @intrinsic diff --git a/numba/unsafe/eh.py b/numba/unsafe/eh.py index 3f3b1f4a4bc..0d25fbbb2f1 100644 --- a/numba/unsafe/eh.py +++ b/numba/unsafe/eh.py @@ -2,8 +2,7 @@ Exception handling intrinsics. """ -from numba.core import types, errors -from numba import cgutils +from numba.core import types, errors, cgutils from numba.extending import intrinsic diff --git a/numba/unsafe/ndarray.py b/numba/unsafe/ndarray.py index d1e5cf818bb..98a2b4db699 100644 --- a/numba/unsafe/ndarray.py +++ b/numba/unsafe/ndarray.py @@ -3,7 +3,7 @@ operations with numpy. """ from numba.core import types, typing -from numba.cgutils import unpack_tuple +from numba.core.cgutils import unpack_tuple from numba.extending import intrinsic from numba.targets.imputils import impl_ret_new_ref from numba.core.errors import RequireLiteralValue, TypingError diff --git a/numba/unsafe/refcount.py b/numba/unsafe/refcount.py index b9925948367..4107ca0b33f 100644 --- a/numba/unsafe/refcount.py +++ b/numba/unsafe/refcount.py @@ -3,8 +3,7 @@ """ from llvmlite import ir -from numba.core import types -from numba import cgutils +from numba.core import types, cgutils from numba.extending import intrinsic from numba.runtime.nrtdynmod import _meminfo_struct_type From 60b36542c11bbe2a36133f7605d3414a33a73369 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:05:15 +0000 Subject: [PATCH 391/595] Move numba/targets/callconv.py to numba/core --- numba/{targets => core}/callconv.py | 0 numba/core/compiler.py | 4 ++-- numba/cuda/target.py | 2 +- numba/roc/target.py | 2 +- numba/targets/cpu.py | 4 ++-- numba/targets/imputils.py | 2 +- numba/targets/npyimpl.py | 4 ++-- numba/tests/test_compile_cache.py | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) rename numba/{targets => core}/callconv.py (100%) diff --git a/numba/targets/callconv.py b/numba/core/callconv.py similarity index 100% rename from numba/targets/callconv.py rename to numba/core/callconv.py diff --git a/numba/core/compiler.py b/numba/core/compiler.py index 32993b6a7a9..f561d4ba188 100644 --- a/numba/core/compiler.py +++ b/numba/core/compiler.py @@ -3,8 +3,8 @@ import warnings from numba.core.tracing import event -from numba.core import utils, errors, typing, interpreter, bytecode, postproc, config -from numba.targets import cpu, callconv +from numba.core import utils, errors, typing, interpreter, bytecode, postproc, config, callconv +from numba.targets import cpu from numba.parfor import ParforDiagnostics from numba.core.inline_closurecall import InlineClosureCallPass from numba.core.errors import CompilerError diff --git a/numba/cuda/target.py b/numba/cuda/target.py index 48208857528..8a945ff2216 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -7,7 +7,7 @@ from numba.core import typing, types, dispatcher, debuginfo, itanium_mangler, cgutils from numba.core.utils import cached_property from numba.targets.base import BaseContext -from numba.targets.callconv import MinimalCallConv +from numba.core.callconv import MinimalCallConv from numba.core.typing import cmathdecl from .cudadrv import nvvm diff --git a/numba/roc/target.py b/numba/roc/target.py index c8439bbf12e..666c42feaad 100644 --- a/numba/roc/target.py +++ b/numba/roc/target.py @@ -7,7 +7,7 @@ from numba.core import typing, types, utils, datamodel, cgutils from numba.core.utils import cached_property from numba.targets.base import BaseContext -from numba.targets.callconv import MinimalCallConv +from numba.core.callconv import MinimalCallConv from numba.roc import codegen from .hlc import DATALAYOUT diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index d2d1763bd56..97d856d8b6c 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -7,9 +7,9 @@ from numba import _dynfunc from numba.core.callwrapper import PyCallWrapper from numba.targets.base import BaseContext, PYOBJECT -from numba.core import utils, types, config, cgutils +from numba.core import utils, types, config, cgutils, callconv from numba.core.utils import cached_property -from numba.targets import callconv, codegen, externals, intrinsics, dictimpl +from numba.targets import codegen, externals, intrinsics, dictimpl from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/targets/imputils.py b/numba/targets/imputils.py index 912c770151a..fc047b04028 100644 --- a/numba/targets/imputils.py +++ b/numba/targets/imputils.py @@ -448,7 +448,7 @@ def force_error_model(context, model_name='numpy'): """ Temporarily change the context's error model. """ - from numba.targets import callconv + from numba.core import callconv old_error_model = context.error_model context.error_model = callconv.create_error_model(model_name, context) diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index 95b1981c2e9..486a1ea4875 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -13,11 +13,11 @@ import numpy as np import operator -from numba.targets import callconv, ufunc_db +from numba.targets import ufunc_db from numba.np import arrayobj from numba.targets.imputils import Registry, impl_ret_new_ref, force_error_model from numba import numpy_support -from numba.core import typing, types, utils, cgutils +from numba.core import typing, types, utils, cgutils, callconv from numba.numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype from numba.core.typing import npydecl from numba.extending import overload, intrinsic diff --git a/numba/tests/test_compile_cache.py b/numba/tests/test_compile_cache.py index a002b838241..aedfb600b9f 100644 --- a/numba/tests/test_compile_cache.py +++ b/numba/tests/test_compile_cache.py @@ -3,8 +3,8 @@ import llvmlite.llvmpy.core as lc -from numba.core import types, typing -from numba.targets import callconv, cpu +from numba.core import types, typing, callconv +from numba.targets import cpu class TestCompileCache(unittest.TestCase): From d686fb5276200685545e012559cf633da2857499 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:09:29 +0000 Subject: [PATCH 392/595] Move numba/targets/boxing.py to numba/core --- numba/{targets => core}/boxing.py | 0 numba/core/pythonapi.py | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename numba/{targets => core}/boxing.py (100%) diff --git a/numba/targets/boxing.py b/numba/core/boxing.py similarity index 100% rename from numba/targets/boxing.py rename to numba/core/boxing.py diff --git a/numba/core/pythonapi.py b/numba/core/pythonapi.py index 06ea81daf5f..8a610e555c7 100644 --- a/numba/core/pythonapi.py +++ b/numba/core/pythonapi.py @@ -148,7 +148,7 @@ def __init__(self, context, builder): """ Note: Maybe called multiple times when lowering a function """ - from numba.targets import boxing + from numba.core import boxing self.context = context self.builder = builder @@ -1342,7 +1342,7 @@ def to_native_value(self, typ, obj): Unbox the Python object as the given Numba type. A NativeValue instance is returned. """ - from numba.targets.boxing import unbox_unsupported + from numba.core.boxing import unbox_unsupported impl = _unboxers.lookup(typ.__class__, unbox_unsupported) c = _UnboxContext(self.context, self.builder, self) @@ -1361,7 +1361,7 @@ def from_native_value(self, typ, val, env_manager=None): pointer is returned (NULL if an error occurred). This method steals any native (NRT) reference embedded in *val*. """ - from numba.targets.boxing import box_unsupported + from numba.core.boxing import box_unsupported impl = _boxers.lookup(typ.__class__, box_unsupported) From 3175f77c10f7ba233fdeb64db051d2311dbf562e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:11:57 +0000 Subject: [PATCH 393/595] Move numba/targets/codegen.py to numba/core --- numba/core/caching.py | 2 +- numba/{targets => core}/codegen.py | 0 numba/cuda/codegen.py | 2 +- numba/roc/codegen.py | 2 +- numba/targets/cpu.py | 4 ++-- numba/tests/support.py | 4 ++-- numba/tests/test_codegen.py | 2 +- numba/tests/test_dispatcher.py | 3 +-- 8 files changed, 9 insertions(+), 10 deletions(-) rename numba/{targets => core}/codegen.py (100%) diff --git a/numba/core/caching.py b/numba/core/caching.py index 396ff73f2c8..59c6e4fc5bb 100644 --- a/numba/core/caching.py +++ b/numba/core/caching.py @@ -21,7 +21,7 @@ import numba from numba.core.errors import NumbaWarning from numba.targets.base import BaseContext -from numba.targets.codegen import CodeLibrary +from numba.core.codegen import CodeLibrary from numba.core.compiler import CompileResult from numba.core import config, compiler diff --git a/numba/targets/codegen.py b/numba/core/codegen.py similarity index 100% rename from numba/targets/codegen.py rename to numba/core/codegen.py diff --git a/numba/cuda/codegen.py b/numba/cuda/codegen.py index 5f40a92ee24..e201a2101e4 100644 --- a/numba/cuda/codegen.py +++ b/numba/cuda/codegen.py @@ -1,7 +1,7 @@ from llvmlite import binding as ll from llvmlite.llvmpy import core as lc -from numba.targets.codegen import BaseCPUCodegen, CodeLibrary +from numba.core.codegen import BaseCPUCodegen, CodeLibrary from numba.core import utils from .cudadrv import nvvm diff --git a/numba/roc/codegen.py b/numba/roc/codegen.py index 4de0625a948..8f98cc7669f 100644 --- a/numba/roc/codegen.py +++ b/numba/roc/codegen.py @@ -1,7 +1,7 @@ from llvmlite import binding as ll from llvmlite.llvmpy import core as lc from numba.core import utils -from numba.targets.codegen import BaseCPUCodegen, CodeLibrary +from numba.core.codegen import BaseCPUCodegen, CodeLibrary from .hlc import DATALAYOUT, TRIPLE, hlc diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py index 97d856d8b6c..787438afe40 100644 --- a/numba/targets/cpu.py +++ b/numba/targets/cpu.py @@ -7,9 +7,9 @@ from numba import _dynfunc from numba.core.callwrapper import PyCallWrapper from numba.targets.base import BaseContext, PYOBJECT -from numba.core import utils, types, config, cgutils, callconv +from numba.core import utils, types, config, cgutils, callconv, codegen from numba.core.utils import cached_property -from numba.targets import codegen, externals, intrinsics, dictimpl +from numba.targets import externals, intrinsics, dictimpl from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/tests/support.py b/numba/tests/support.py index 89de4039bf2..ea95f265546 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -705,7 +705,7 @@ def forbid_codegen(): If code generation is invoked, a RuntimeError is raised. """ - from numba.targets import codegen + from numba.core import codegen patchpoints = ['CodeLibrary._finalize_final_module'] old = {} @@ -715,7 +715,7 @@ def fail(*args, **kwargs): # XXX use the mock library instead? for name in patchpoints: parts = name.split('.') - obj = codegen + obj = numba.core.codegen for attrname in parts[:-1]: obj = getattr(obj, attrname) attrname = parts[-1] diff --git a/numba/tests/test_codegen.py b/numba/tests/test_codegen.py index 161fab27c5d..1191bc03856 100644 --- a/numba/tests/test_codegen.py +++ b/numba/tests/test_codegen.py @@ -14,7 +14,7 @@ import llvmlite.binding as ll import numba.unittest_support as unittest -from numba.targets.codegen import JITCPUCodegen +from numba.core.codegen import JITCPUCodegen from numba.core.compiler_lock import global_compiler_lock from numba.tests.support import TestCase diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 55c052b189a..5fc74402a07 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -17,7 +17,7 @@ from numba import unittest_support as unittest from numba import jit, generated_jit, typeof -from numba.core import types, errors +from numba.core import types, errors, codegen from numba import _dispatcher from numba.core.compiler import compile_isolated from numba.core.errors import NumbaWarning @@ -25,7 +25,6 @@ override_env_config, capture_cache_log, captured_stdout) from numba.numpy_support import as_dtype -from numba.targets import codegen from numba.core.caching import _UserWideCacheLocator from numba.core.dispatcher import Dispatcher from numba import parfor From 29cda4ea9c75447111ec2ffdf15a6d03851d4755 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:13:30 +0000 Subject: [PATCH 394/595] Move numba/targets/descriptors.py to numba/core --- numba/{targets => core}/descriptors.py | 0 numba/cuda/descriptor.py | 2 +- numba/cuda/dispatcher.py | 2 +- numba/npyufunc/ufuncbuilder.py | 2 +- numba/roc/descriptor.py | 2 +- numba/targets/registry.py | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename numba/{targets => core}/descriptors.py (100%) diff --git a/numba/targets/descriptors.py b/numba/core/descriptors.py similarity index 100% rename from numba/targets/descriptors.py rename to numba/core/descriptors.py diff --git a/numba/cuda/descriptor.py b/numba/cuda/descriptor.py index 7fdad86d459..96ecbefff27 100644 --- a/numba/cuda/descriptor.py +++ b/numba/cuda/descriptor.py @@ -1,4 +1,4 @@ -from numba.targets.descriptors import TargetDescriptor +from numba.core.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from .target import CUDATargetContext, CUDATypingContext diff --git a/numba/cuda/dispatcher.py b/numba/cuda/dispatcher.py index 89d0100d8aa..32f96d2b8b4 100644 --- a/numba/cuda/dispatcher.py +++ b/numba/cuda/dispatcher.py @@ -1,6 +1,6 @@ import numpy as np -from numba.targets.descriptors import TargetDescriptor +from numba.core.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from numba import cuda from numba.cuda import jit, autojit diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 7636daf7cd9..09fc57ec84c 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -4,7 +4,7 @@ from contextlib import contextmanager from numba.decorators import jit -from numba.targets.descriptors import TargetDescriptor +from numba.core.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target from numba.targets.cpu import FastMathOptions diff --git a/numba/roc/descriptor.py b/numba/roc/descriptor.py index 5a94528596c..835b05c6f4f 100644 --- a/numba/roc/descriptor.py +++ b/numba/roc/descriptor.py @@ -1,4 +1,4 @@ -from numba.targets.descriptors import TargetDescriptor +from numba.core.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from .target import HSATargetContext, HSATypingContext diff --git a/numba/targets/registry.py b/numba/targets/registry.py index ba13efdfa93..57de3974419 100644 --- a/numba/targets/registry.py +++ b/numba/targets/registry.py @@ -1,7 +1,7 @@ import contextlib from numba.targets import cpu -from numba.targets.descriptors import TargetDescriptor +from numba.core.descriptors import TargetDescriptor from numba.core import utils, typing, dispatcher # ----------------------------------------------------------------------------- From f71f7ee8273cfb91fcebddff608eb83713684c78 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:20:04 +0000 Subject: [PATCH 395/595] Move numba/targets/cpu.py to numba/core --- numba/core/compiler.py | 3 +-- numba/{targets => core}/cpu.py | 0 numba/core/ir_utils.py | 2 +- numba/core/untyped_passes.py | 2 +- numba/npyufunc/parfor.py | 2 +- numba/npyufunc/ufuncbuilder.py | 2 +- numba/stencilparfor.py | 2 +- numba/targets/registry.py | 3 +-- numba/tests/support.py | 3 +-- numba/tests/test_array_analysis.py | 4 ++-- numba/tests/test_array_exprs.py | 3 +-- numba/tests/test_cgutils.py | 3 +-- numba/tests/test_compile_cache.py | 3 +-- numba/tests/test_copy_propagate.py | 3 +-- numba/tests/test_debug.py | 2 +- numba/tests/test_ir_inlining.py | 2 +- numba/tests/test_nrt.py | 3 ++- numba/tests/test_parfors.py | 3 +-- numba/tests/test_remove_dead.py | 3 +-- numba/tests/test_stencils.py | 2 +- numba/tests/test_svml.py | 3 +-- numba/tests/test_withlifting.py | 3 +-- 22 files changed, 23 insertions(+), 33 deletions(-) rename numba/{targets => core}/cpu.py (100%) diff --git a/numba/core/compiler.py b/numba/core/compiler.py index f561d4ba188..15b9b7ee956 100644 --- a/numba/core/compiler.py +++ b/numba/core/compiler.py @@ -3,8 +3,7 @@ import warnings from numba.core.tracing import event -from numba.core import utils, errors, typing, interpreter, bytecode, postproc, config, callconv -from numba.targets import cpu +from numba.core import utils, errors, typing, interpreter, bytecode, postproc, config, callconv, cpu from numba.parfor import ParforDiagnostics from numba.core.inline_closurecall import InlineClosureCallPass from numba.core.errors import CompilerError diff --git a/numba/targets/cpu.py b/numba/core/cpu.py similarity index 100% rename from numba/targets/cpu.py rename to numba/core/cpu.py diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index f65d1019d1b..14ccc83d6d3 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -1660,7 +1660,7 @@ def __init__(self, f_ir): # call inline pass to handle cases like stencils and comprehensions swapped = {} # TODO: get this from diagnostics store inline_pass = numba.core.inline_closurecall.InlineClosureCallPass( - ir, numba.targets.cpu.ParallelOptions(False), swapped) + ir, numba.core.cpu.ParallelOptions(False), swapped) inline_pass.run() post_proc = postproc.PostProcessor(ir) post_proc.run() diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 8f260c5ae64..f824a2e93c8 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -308,7 +308,7 @@ def _do_work(self, state, work_list, block, i, expr): from numba.core.inline_closurecall import (inline_closure_call, callee_ir_validator) from numba.core.compiler import run_frontend - from numba.targets.cpu import InlineOptions + from numba.core.cpu import InlineOptions # try and get a definition for the call, this isn't always possible as # it might be a eval(str)/part generated awaiting update etc. (parfors) diff --git a/numba/npyufunc/parfor.py b/numba/npyufunc/parfor.py index 2a6cb260c55..c3ac6d1a9da 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/npyufunc/parfor.py @@ -22,7 +22,7 @@ from numba.core.analysis import (compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks) from numba.core.typing import signature -from numba.targets.cpu import ParallelOptions +from numba.core.cpu import ParallelOptions from numba.parfor import print_wrapped, ensure_parallel_support from numba.core.errors import NumbaParallelSafetyWarning import types as pytypes diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 09fc57ec84c..45ceb797749 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -7,7 +7,7 @@ from numba.core.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target -from numba.targets.cpu import FastMathOptions +from numba.core.cpu import FastMathOptions from numba.core import utils, types, serialize, compiler, sigutils from numba.numpy_support import as_dtype from numba.npyufunc import _internal diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index ed6e2fe8e72..9da544054c4 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -647,7 +647,7 @@ def get_stencil_ir(sf, typingctx, args, scope, loc, input_dict, typemap, calltypes): """get typed IR from stencil bytecode """ - from numba.targets.cpu import CPUContext + from numba.core.cpu import CPUContext from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.typed_passes import type_inference_stage diff --git a/numba/targets/registry.py b/numba/targets/registry.py index 57de3974419..2bd47ebe879 100644 --- a/numba/targets/registry.py +++ b/numba/targets/registry.py @@ -1,8 +1,7 @@ import contextlib -from numba.targets import cpu from numba.core.descriptors import TargetDescriptor -from numba.core import utils, typing, dispatcher +from numba.core import utils, typing, dispatcher, cpu # ----------------------------------------------------------------------------- # Default CPU target descriptors diff --git a/numba/tests/support.py b/numba/tests/support.py index ea95f265546..5d2d4d664a6 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -24,9 +24,8 @@ import numpy as np from numba import numpy_support, testing -from numba.core import errors, typing, utils, config +from numba.core import errors, typing, utils, config, cpu from numba.core.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS -from numba.targets import cpu import numba.unittest_support as unittest from numba.runtime import rtsys diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index eb45f6d0411..1344f2f3ee3 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -7,11 +7,11 @@ from numba import unittest_support as unittest from numba import njit, typeof, jitclass, prange -from numba.core import types, typing, ir, bytecode, postproc +from numba.core import types, typing, ir, bytecode, postproc, cpu from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.parfors.array_analysis import EquivSet, ArrayAnalysis from numba.core.compiler import Compiler, Flags, PassManager -from numba.targets import cpu, registry +from numba.targets import registry from numba.core.ir_utils import remove_dead from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index e16163f933e..12aa0ce424d 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -6,9 +6,8 @@ from numba import njit, vectorize from numba import unittest_support as unittest from numba import typeof -from numba.core import utils, types, typing, ir, compiler +from numba.core import utils, types, typing, ir, compiler, cpu from numba.core.compiler import Compiler, Flags -from numba.targets import cpu from numba.tests.support import MemoryLeakMixin, TestCase diff --git a/numba/tests/test_cgutils.py b/numba/tests/test_cgutils.py index 309e79a7d15..5832f53616e 100644 --- a/numba/tests/test_cgutils.py +++ b/numba/tests/test_cgutils.py @@ -7,9 +7,8 @@ import numpy as np import numba.unittest_support as unittest -from numba.core import types, typing, cgutils +from numba.core import types, typing, cgutils, cpu from numba.core.compiler_lock import global_compiler_lock -from numba.targets import cpu from numba.tests.support import TestCase diff --git a/numba/tests/test_compile_cache.py b/numba/tests/test_compile_cache.py index aedfb600b9f..e0ac1732c9b 100644 --- a/numba/tests/test_compile_cache.py +++ b/numba/tests/test_compile_cache.py @@ -3,8 +3,7 @@ import llvmlite.llvmpy.core as lc -from numba.core import types, typing, callconv -from numba.targets import cpu +from numba.core import types, typing, callconv, cpu class TestCompileCache(unittest.TestCase): diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 32cf2c7dfdd..db366658d2b 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -3,8 +3,7 @@ # SPDX-License-Identifier: BSD-2-Clause # -from numba.targets import cpu -from numba.core import types, typing, ir, config, compiler +from numba.core import types, typing, ir, config, compiler, cpu from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.ir_utils import (copy_propagate, apply_copy_propagate, diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index e33572fc8a3..d4a382b9f68 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -13,7 +13,7 @@ from numba import jit, jitclass from numba.core import types, compiler from numba.core.compiler import compile_isolated, Flags -from numba.targets.cpu import ParallelOptions +from numba.core.cpu import ParallelOptions from numba.core.errors import NumbaPerformanceWarning from numba import prange diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index 6cb7137567f..fff94722963 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -19,7 +19,7 @@ register_jitable, ) from numba.core.datamodel.models import OpaqueModel -from numba.targets.cpu import InlineOptions +from numba.core.cpu import InlineOptions from numba.core.compiler import DefaultPassBuilder, CompilerBase from numba.core.typed_passes import DeadCodeElimination, IRLegalization from numba.core.untyped_passes import PreserveIR diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 599be60cfb7..91994f8e0dd 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -25,6 +25,7 @@ from numba.unsafe.nrt import NRT_get_api from numba.tests.support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic +from numba.core import cpu enable_nrt_flags = Flags() enable_nrt_flags.set("nrt") @@ -80,7 +81,7 @@ def setUp(self): # Reset the Dummy class Dummy.alive = 0 # initialize the NRT (in case the tests are run in isolation) - targets.cpu.CPUContext(typing.Context()) + cpu.CPUContext(typing.Context()) def test_meminfo_refct_1(self): d = Dummy() diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index a85b4a28969..3bef80b1462 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -21,8 +21,7 @@ import numba from numba import unittest_support as unittest from numba import njit, prange, stencil -from numba.targets import cpu -from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler +from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler, cpu from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.ir_utils import (find_callname, guard, build_definitions, diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index c76f3e95df9..2c601b81e6b 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -4,9 +4,8 @@ # import numba -from numba.core import ir_utils +from numba.core import ir_utils, cpu from numba.core.compiler import compile_isolated, Flags -from numba.targets import cpu from numba.core import types, typing, ir, config, compiler from numba.targets.registry import cpu_target from numba.core.annotations import type_annotations diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index 1a00514890e..61777632ca0 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -19,7 +19,7 @@ from numba.core import types from numba.core.compiler import compile_extra, Flags from numba.targets import registry -from numba.targets.cpu import ParallelOptions +from numba.core.cpu import ParallelOptions from numba.tests.support import tag, skip_parfors_unsupported, _32bit from numba.core.errors import LoweringError, TypingError diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index e92042afc67..480cee603f2 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -8,9 +8,8 @@ from itertools import chain, combinations import numba -from numba.core import config +from numba.core import config, cpu from numba import prange, njit, unittest_support as unittest -from numba.targets import cpu from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, override_env_config diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index a212540d695..45904d326fd 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -8,9 +8,8 @@ from numba.core.withcontexts import bypass_context, call_context, objmode_context from numba.core.bytecode import FunctionIdentity, ByteCode from numba.core.interpreter import Interpreter -from numba.core import typing, errors +from numba.core import typing, errors, cpu from numba.targets.registry import cpu_target -from numba.targets import cpu from numba.core.compiler import compile_ir, DEFAULT_FLAGS from numba import njit, typeof, objmode from numba.extending import overload From 905217cfd69fdb431c5c05379be7862c9d58a053 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:22:10 +0000 Subject: [PATCH 396/595] Move numba/targets/cpu_options.py to numba/core --- numba/core/cpu.py | 4 ++-- numba/{targets => core}/cpu_options.py | 0 numba/core/typing/templates.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename numba/{targets => core}/cpu_options.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 787438afe40..da49a69dc33 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -15,8 +15,8 @@ from numba.core.compiler_lock import global_compiler_lock import numba.core.entrypoints from numba.targets import fastmathpass -from numba.targets.cpu_options import (ParallelOptions, FastMathOptions, - InlineOptions) +from numba.core.cpu_options import (ParallelOptions, FastMathOptions, + InlineOptions) from numba.cpython import setobj, listobj diff --git a/numba/targets/cpu_options.py b/numba/core/cpu_options.py similarity index 100% rename from numba/targets/cpu_options.py rename to numba/core/cpu_options.py diff --git a/numba/core/typing/templates.py b/numba/core/typing/templates.py index c6edfb540d6..669b6b47ea8 100644 --- a/numba/core/typing/templates.py +++ b/numba/core/typing/templates.py @@ -13,7 +13,7 @@ import numba from numba.core import types, utils from numba.core.errors import TypingError, InternalError -from numba.targets.cpu_options import InlineOptions +from numba.core.cpu_options import InlineOptions # info store for inliner callback functions e.g. cost model _inline_info = namedtuple('inline_info', From fcd5c74814a8605c45ef0da3ae6d05286779856d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 13:25:44 +0000 Subject: [PATCH 397/595] Move numba/decorators.py to numba/core --- examples/blur_image.py | 2 +- examples/sum.py | 2 +- numba/__init__.py | 3 ++- numba/{ => core}/decorators.py | 0 numba/npyufunc/ufuncbuilder.py | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) rename numba/{ => core}/decorators.py (100%) diff --git a/examples/blur_image.py b/examples/blur_image.py index bd58c45b886..bae625dc5b7 100755 --- a/examples/blur_image.py +++ b/examples/blur_image.py @@ -6,7 +6,7 @@ from numpy import ones import numpy -from numba.decorators import jit +from numba import jit @jit(nopython=True) diff --git a/examples/sum.py b/examples/sum.py index db78c31ee41..edba9560a1a 100755 --- a/examples/sum.py +++ b/examples/sum.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from __future__ import print_function, division, absolute_import from numba import double -from numba.decorators import jit as jit +from numba import jit def sum2d(arr): M, N = arr.shape diff --git a/numba/__init__.py b/numba/__init__.py index 39bf8838136..33f27eb34d7 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -28,7 +28,8 @@ from numba.core.types import * # Re-export decorators -from numba.decorators import cfunc, generated_jit, jit, njit, stencil, jit_module +from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil, + jit_module) # Re-export vectorize decorators and the thread layer querying function from numba.npyufunc import vectorize, guvectorize, threading_layer diff --git a/numba/decorators.py b/numba/core/decorators.py similarity index 100% rename from numba/decorators.py rename to numba/core/decorators.py diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 45ceb797749..7221a1749ac 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -3,7 +3,7 @@ import inspect from contextlib import contextmanager -from numba.decorators import jit +from numba.core.decorators import jit from numba.core.descriptors import TargetDescriptor from numba.targets.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target From 92ed79334d86a7593af5aa8829beecf42e548a3f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 14:22:21 +0000 Subject: [PATCH 398/595] Move numba/jitclass to numba/experimental/jitclass --- examples/binarytree.py | 2 +- examples/jitclass.py | 2 +- examples/linkedlist.py | 2 +- examples/stack.py | 2 +- numba/__init__.py | 6 +++--- numba/experimental/jitclass/__init__.py | 2 ++ numba/{ => experimental}/jitclass/_box.c | 2 +- numba/{ => experimental}/jitclass/base.py | 2 +- numba/{ => experimental}/jitclass/boxing.py | 2 +- numba/{ => experimental}/jitclass/decorators.py | 2 +- numba/jitclass/__init__.py | 2 -- numba/tests/test_array_analysis.py | 3 ++- numba/tests/test_array_attr.py | 2 +- numba/tests/test_debug.py | 3 ++- numba/tests/test_dictobject.py | 3 ++- numba/tests/test_ir_utils.py | 2 +- numba/tests/test_jitclasses.py | 4 ++-- numba/tests/test_lists.py | 3 ++- numba/tests/test_typedlist.py | 3 ++- setup.py | 6 +++--- 20 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 numba/experimental/jitclass/__init__.py rename numba/{ => experimental}/jitclass/_box.c (99%) rename numba/{ => experimental}/jitclass/base.py (99%) rename numba/{ => experimental}/jitclass/boxing.py (99%) rename numba/{ => experimental}/jitclass/decorators.py (89%) delete mode 100644 numba/jitclass/__init__.py diff --git a/examples/binarytree.py b/examples/binarytree.py index 8be2919cb2f..46d1ccd1605 100755 --- a/examples/binarytree.py +++ b/examples/binarytree.py @@ -10,9 +10,9 @@ import random from collections import OrderedDict from numba import njit -from numba import jitclass from numba import int32, deferred_type, optional from numba.runtime import rtsys +from numba.experimental import jitclass node_type = deferred_type() diff --git a/examples/jitclass.py b/examples/jitclass.py index 51d2be21db5..c8d8e7c6663 100755 --- a/examples/jitclass.py +++ b/examples/jitclass.py @@ -6,8 +6,8 @@ """ import numpy as np -from numba import jitclass # import the decorator from numba import int32, float32 # import the types +from numba.experimental import jitclass spec = [ ('value', int32), # a simple scalar field diff --git a/examples/linkedlist.py b/examples/linkedlist.py index 68ec017a5aa..107bfb7cc90 100755 --- a/examples/linkedlist.py +++ b/examples/linkedlist.py @@ -9,9 +9,9 @@ from collections import OrderedDict import numpy as np from numba import njit -from numba import jitclass from numba import int32, deferred_type, optional from numba.runtime import rtsys +from numba.experimental import jitclass node_type = deferred_type() diff --git a/examples/stack.py b/examples/stack.py index 4ed4dbdf7f7..6fafcc618aa 100755 --- a/examples/stack.py +++ b/examples/stack.py @@ -11,9 +11,9 @@ from __future__ import print_function, absolute_import from collections import OrderedDict from numba import njit -from numba import jitclass from numba import deferred_type, intp, optional from numba.runtime import rtsys +from numba.experimental import jitclass linkednode_spec = OrderedDict() diff --git a/numba/__init__.py b/numba/__init__.py index 33f27eb34d7..373421367e7 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -37,8 +37,8 @@ # Re-export Numpy helpers from numba.numpy_support import carray, farray, from_dtype -# Re-export jitclass -from numba.jitclass import jitclass +# Re-export experimental +from numba import experimental # Initialize withcontexts import numba.core.withcontexts @@ -56,7 +56,7 @@ from_dtype guvectorize jit - jitclass + experimental njit stencil jit_module diff --git a/numba/experimental/jitclass/__init__.py b/numba/experimental/jitclass/__init__.py new file mode 100644 index 00000000000..97c1903496b --- /dev/null +++ b/numba/experimental/jitclass/__init__.py @@ -0,0 +1,2 @@ +from numba.experimental.jitclass.decorators import jitclass +from numba.experimental.jitclass import boxing # Has import-time side effect diff --git a/numba/jitclass/_box.c b/numba/experimental/jitclass/_box.c similarity index 99% rename from numba/jitclass/_box.c rename to numba/experimental/jitclass/_box.c index 19ebe004a07..777a826ad4a 100644 --- a/numba/jitclass/_box.c +++ b/numba/experimental/jitclass/_box.c @@ -1,7 +1,7 @@ /* Implements jitclass Box type in python c-api level. */ -#include "../_pymodule.h" +#include "../../_pymodule.h" typedef struct { PyObject_HEAD diff --git a/numba/jitclass/base.py b/numba/experimental/jitclass/base.py similarity index 99% rename from numba/jitclass/base.py rename to numba/experimental/jitclass/base.py index 51d8989f129..98b8a0efb0d 100644 --- a/numba/jitclass/base.py +++ b/numba/experimental/jitclass/base.py @@ -12,7 +12,7 @@ from numba.core.typing import templates from numba.core.datamodel import default_manager, models from numba.targets import imputils -from numba.jitclass import _box +from numba.experimental.jitclass import _box ############################################################################## diff --git a/numba/jitclass/boxing.py b/numba/experimental/jitclass/boxing.py similarity index 99% rename from numba/jitclass/boxing.py rename to numba/experimental/jitclass/boxing.py index eb847dc5263..756ec7f2ef8 100644 --- a/numba/jitclass/boxing.py +++ b/numba/experimental/jitclass/boxing.py @@ -10,7 +10,7 @@ from numba.core import types, cgutils from numba.core.pythonapi import box, unbox, NativeValue from numba import njit -from numba.jitclass import _box +from numba.experimental.jitclass import _box _getter_code_template = """ diff --git a/numba/jitclass/decorators.py b/numba/experimental/jitclass/decorators.py similarity index 89% rename from numba/jitclass/decorators.py rename to numba/experimental/jitclass/decorators.py index 58909d2a5be..8d3d9b6cb07 100644 --- a/numba/jitclass/decorators.py +++ b/numba/experimental/jitclass/decorators.py @@ -1,5 +1,5 @@ from numba.core import types, config -from .base import register_class_type, ClassBuilder +from numba.experimental.jitclass.base import register_class_type, ClassBuilder def jitclass(spec): diff --git a/numba/jitclass/__init__.py b/numba/jitclass/__init__.py deleted file mode 100644 index cf098e7689a..00000000000 --- a/numba/jitclass/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .decorators import jitclass -from numba.jitclass import boxing # Has import-time side effect diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 1344f2f3ee3..0d27ef318c6 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -6,7 +6,7 @@ from io import StringIO from numba import unittest_support as unittest -from numba import njit, typeof, jitclass, prange +from numba import njit, typeof, prange from numba.core import types, typing, ir, bytecode, postproc, cpu from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.parfors.array_analysis import EquivSet, ArrayAnalysis @@ -22,6 +22,7 @@ NopythonRewrites, IRLegalization) from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass +from numba.experimental import jitclass skip_unsupported = skip_parfors_unsupported diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index 5563b176c64..3368a6979f1 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -1,7 +1,6 @@ import numpy as np import numba.unittest_support as unittest -from numba import jitclass from numba.core.compiler import compile_isolated from numba.numpy_support import from_dtype from numba import njit, typeof @@ -9,6 +8,7 @@ from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, tag, skip_parfors_unsupported) from numba.core.errors import TypingError +from numba.experimental import jitclass def array_dtype(a): diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index d4a382b9f68..975ff7b0818 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -10,12 +10,13 @@ captured_stdout, forbid_codegen, skip_parfors_unsupported, needs_blas) from numba import unittest_support as unittest -from numba import jit, jitclass +from numba import jit from numba.core import types, compiler from numba.core.compiler import compile_isolated, Flags from numba.core.cpu import ParallelOptions from numba.core.errors import NumbaPerformanceWarning from numba import prange +from numba.experimental import jitclass def simple_nopython(somearg): diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 5e0574e2f30..09ca4591477 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -11,7 +11,7 @@ import numpy as np -from numba import njit, jitclass +from numba import njit from numba import int32, int64, float32, float64 from numba import dictobject, typeof from numba.typed import Dict @@ -20,6 +20,7 @@ from numba.core import types from numba.tests.support import (TestCase, MemoryLeakMixin, unittest, override_config, forbid_codegen) +from numba.experimental import jitclass class TestDictObject(MemoryLeakMixin, TestCase): diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index 6625a321d0d..2fbe9b9d712 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -1,6 +1,5 @@ import numba from numba.tests.support import TestCase, unittest -from numba import jitclass from numba.targets.registry import cpu_target from numba.core.compiler import CompilerBase, Flags from numba.core.compiler_machinery import PassManager @@ -11,6 +10,7 @@ from numba.core.typed_passes import (NopythonTypeInference, type_inference_stage, DeadCodeElimination) +from numba.experimental import jitclass # global constant for testing find_const GLOBAL_B = 11 diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index bbe3ad0e492..61778d80ad7 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -10,11 +10,11 @@ from numba import njit, typeof from numba.core import types, errors from numba import unittest_support as unittest -from numba import jitclass from numba.tests.support import TestCase, MemoryLeakMixin -from numba.jitclass import _box +from numba.experimental.jitclass import _box from numba.runtime.nrt import MemInfo from numba.core.errors import LoweringError +from numba.experimental import jitclass class TestClass1(object): diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 685c0c7788a..76b31de0aa1 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -7,11 +7,12 @@ import numpy as np from numba.core.compiler import compile_isolated, Flags -from numba import jit, typeof, jitclass +from numba import jit, typeof import numba.unittest_support as unittest from numba import testing from numba.core import types, utils, errors from numba.tests.support import TestCase, MemoryLeakMixin, tag +from numba.experimental import jitclass enable_pyobj_flags = Flags() diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 0bf38245b9d..9681e669170 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -6,13 +6,14 @@ from numba import njit from numba import int32, float32, prange from numba.core import types -from numba import jitclass, typeof +from numba import typeof from numba.typed import List, Dict from numba.core.errors import TypingError from numba.tests.support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen, skip_parfors_unsupported) from numba.unsafe.refcount import get_refcount +from numba.experimental import jitclass # global typed-list for testing purposes diff --git a/setup.py b/setup.py index c2f7bb11ab8..90509935db4 100644 --- a/setup.py +++ b/setup.py @@ -279,9 +279,9 @@ def check_file_at_path(path2file): 'numba/runtime/_nrt_python.c'], **np_compile_args) - ext_jitclass_box = Extension(name='numba.jitclass._box', - sources=['numba/jitclass/_box.c'], - depends=['numba/_pymodule.h'], + ext_jitclass_box = Extension(name='numba.experimental.jitclass._box', + sources=['numba/experimental/jitclass/_box.c'], + depends=['numba/experimental/_pymodule.h'], ) ext_cuda_extras = Extension(name='numba.cuda.cudadrv._extras', From e759034f799c28b5fbad11602d5167db03510208 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 15:11:09 +0000 Subject: [PATCH 399/595] Move numba/targets/base.py to numba/core --- numba/{targets => core}/base.py | 2 +- numba/core/caching.py | 2 +- numba/core/callconv.py | 2 +- numba/core/cpu.py | 2 +- numba/cuda/target.py | 2 +- numba/roc/target.py | 2 +- numba/tests/test_target_overloadselector.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename numba/{targets => core}/base.py (99%) diff --git a/numba/targets/base.py b/numba/core/base.py similarity index 99% rename from numba/targets/base.py rename to numba/core/base.py index 1d4373338cb..e43712b2a3f 100644 --- a/numba/targets/base.py +++ b/numba/core/base.py @@ -18,7 +18,7 @@ from numba.core.pythonapi import PythonAPI from numba.np import arrayobj from numba.targets import imputils -from .imputils import (user_function, user_generator, +from numba.targets.imputils import (user_function, user_generator, builtin_registry, impl_ret_borrowed, RegistryLoader) from numba.cpython import builtins diff --git a/numba/core/caching.py b/numba/core/caching.py index 59c6e4fc5bb..09ed5a6ac98 100644 --- a/numba/core/caching.py +++ b/numba/core/caching.py @@ -20,7 +20,7 @@ import numba from numba.core.errors import NumbaWarning -from numba.targets.base import BaseContext +from numba.core.base import BaseContext from numba.core.codegen import CodeLibrary from numba.core.compiler import CompileResult from numba.core import config, compiler diff --git a/numba/core/callconv.py b/numba/core/callconv.py index c6510bae439..faf1455f111 100644 --- a/numba/core/callconv.py +++ b/numba/core/callconv.py @@ -8,7 +8,7 @@ from llvmlite import ir as ir from numba.core import types, cgutils -from numba.targets.base import PYOBJECT, GENERIC_POINTER +from numba.core.base import PYOBJECT, GENERIC_POINTER TryStatus = namedtuple('TryStatus', ['in_try', 'excinfo']) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index da49a69dc33..22230668271 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -6,7 +6,7 @@ from numba import _dynfunc from numba.core.callwrapper import PyCallWrapper -from numba.targets.base import BaseContext, PYOBJECT +from numba.core.base import BaseContext, PYOBJECT from numba.core import utils, types, config, cgutils, callconv, codegen from numba.core.utils import cached_property from numba.targets import externals, intrinsics, dictimpl diff --git a/numba/cuda/target.py b/numba/cuda/target.py index 8a945ff2216..1ff3af75cb4 100644 --- a/numba/cuda/target.py +++ b/numba/cuda/target.py @@ -6,7 +6,7 @@ from numba.core import typing, types, dispatcher, debuginfo, itanium_mangler, cgutils from numba.core.utils import cached_property -from numba.targets.base import BaseContext +from numba.core.base import BaseContext from numba.core.callconv import MinimalCallConv from numba.core.typing import cmathdecl diff --git a/numba/roc/target.py b/numba/roc/target.py index 666c42feaad..02a0e54ced6 100644 --- a/numba/roc/target.py +++ b/numba/roc/target.py @@ -6,7 +6,7 @@ from numba.core import typing, types, utils, datamodel, cgutils from numba.core.utils import cached_property -from numba.targets.base import BaseContext +from numba.core.base import BaseContext from numba.core.callconv import MinimalCallConv from numba.roc import codegen from .hlc import DATALAYOUT diff --git a/numba/tests/test_target_overloadselector.py b/numba/tests/test_target_overloadselector.py index 44ff57b6f0b..f9e2ccd0209 100644 --- a/numba/tests/test_target_overloadselector.py +++ b/numba/tests/test_target_overloadselector.py @@ -2,7 +2,7 @@ from collections import defaultdict import numba.unittest_support as unittest -from numba.targets.base import OverloadSelector +from numba.core.base import OverloadSelector from numba.targets.registry import cpu_target from numba.targets.imputils import builtin_registry, RegistryLoader from numba.core import types From 6873f9da6955854e6a5640322742a85a471e48d0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 15:15:59 +0000 Subject: [PATCH 400/595] Move numba/targets/optional.py to numba/core --- numba/core/base.py | 3 ++- numba/{targets => core}/optional.py | 0 numba/cpython/numbers.py | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) rename numba/{targets => core}/optional.py (100%) diff --git a/numba/core/base.py b/numba/core/base.py index e43712b2a3f..e6ed2c7704b 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -270,10 +270,11 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, optional, polynomial, + from numba.targets import (arraymath, polynomial, gdb_hook, literal) from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, iterators, numbers, rangeobj) + from numba.core import optional from numba.np import linalg try: diff --git a/numba/targets/optional.py b/numba/core/optional.py similarity index 100% rename from numba/targets/optional.py rename to numba/core/optional.py diff --git a/numba/cpython/numbers.py b/numba/cpython/numbers.py index 4ebdffad113..b053c0a15fd 100644 --- a/numba/cpython/numbers.py +++ b/numba/cpython/numbers.py @@ -12,8 +12,7 @@ lower_getattr_generic, lower_cast, lower_constant, impl_ret_borrowed, impl_ret_untracked) -from numba.targets import optional -from numba.core import typing, types, utils, errors, cgutils +from numba.core import typing, types, utils, errors, cgutils, optional from numba.extending import intrinsic, overload_method from numba.cpython.unsafe.numbers import viewer From e2503e53547ad32aa061b1094f3e40f9bdfb80c0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 15:23:20 +0000 Subject: [PATCH 401/595] Move numba/targets/externals.py to numba/core --- numba/core/cpu.py | 5 +++-- numba/{targets => core}/externals.py | 0 2 files changed, 3 insertions(+), 2 deletions(-) rename numba/{targets => core}/externals.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 22230668271..efc6bb4df24 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -7,9 +7,10 @@ from numba import _dynfunc from numba.core.callwrapper import PyCallWrapper from numba.core.base import BaseContext, PYOBJECT -from numba.core import utils, types, config, cgutils, callconv, codegen +from numba.core import (utils, types, config, cgutils, callconv, codegen, + externals) from numba.core.utils import cached_property -from numba.targets import externals, intrinsics, dictimpl +from numba.targets import intrinsics, dictimpl from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/targets/externals.py b/numba/core/externals.py similarity index 100% rename from numba/targets/externals.py rename to numba/core/externals.py From 85c4eb4371f99d01149c6e025d99b499b2d2b0f4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 15:27:07 +0000 Subject: [PATCH 402/595] Move numba/targets/fastmathpass.py to numba/core --- numba/core/cpu.py | 3 +-- numba/{targets => core}/fastmathpass.py | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename numba/{targets => core}/fastmathpass.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index efc6bb4df24..70440fdded9 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -8,14 +8,13 @@ from numba.core.callwrapper import PyCallWrapper from numba.core.base import BaseContext, PYOBJECT from numba.core import (utils, types, config, cgutils, callconv, codegen, - externals) + externals, fastmathpass) from numba.core.utils import cached_property from numba.targets import intrinsics, dictimpl from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock import numba.core.entrypoints -from numba.targets import fastmathpass from numba.core.cpu_options import (ParallelOptions, FastMathOptions, InlineOptions) from numba.cpython import setobj, listobj diff --git a/numba/targets/fastmathpass.py b/numba/core/fastmathpass.py similarity index 100% rename from numba/targets/fastmathpass.py rename to numba/core/fastmathpass.py From ca063b27f045509e6fe1836564112d98e61a74b5 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 15:28:36 +0000 Subject: [PATCH 403/595] Move numba/targets/intrinsics.py to numba/core --- numba/core/cpu.py | 5 ++--- numba/core/externals.py | 3 +-- numba/{targets => core}/intrinsics.py | 0 3 files changed, 3 insertions(+), 5 deletions(-) rename numba/{targets => core}/intrinsics.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 70440fdded9..37455426bc9 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -7,10 +7,9 @@ from numba import _dynfunc from numba.core.callwrapper import PyCallWrapper from numba.core.base import BaseContext, PYOBJECT -from numba.core import (utils, types, config, cgutils, callconv, codegen, - externals, fastmathpass) +from numba.core import utils, types, config, cgutils, callconv, codegen, externals, fastmathpass, intrinsics from numba.core.utils import cached_property -from numba.targets import intrinsics, dictimpl +from numba.targets import dictimpl from numba.targets.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/core/externals.py b/numba/core/externals.py index e0f77f0abfe..19063c76216 100644 --- a/numba/core/externals.py +++ b/numba/core/externals.py @@ -7,9 +7,8 @@ from llvmlite import ir import llvmlite.binding as ll -from numba.core import utils +from numba.core import utils, intrinsics from numba import _helperlib -from numba.targets import intrinsics def _add_missing_symbol(symbol, addr): diff --git a/numba/targets/intrinsics.py b/numba/core/intrinsics.py similarity index 100% rename from numba/targets/intrinsics.py rename to numba/core/intrinsics.py From e889ddde19616c78e89df879810f2fb69725cbe5 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 15:30:17 +0000 Subject: [PATCH 404/595] Move numba/targets/options.py to numba/core --- numba/core/cpu.py | 2 +- numba/{targets => core}/options.py | 0 numba/cuda/descriptor.py | 2 +- numba/cuda/dispatcher.py | 2 +- numba/npyufunc/ufuncbuilder.py | 2 +- numba/roc/descriptor.py | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename numba/{targets => core}/options.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 37455426bc9..56313ec60e6 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -10,7 +10,7 @@ from numba.core import utils, types, config, cgutils, callconv, codegen, externals, fastmathpass, intrinsics from numba.core.utils import cached_property from numba.targets import dictimpl -from numba.targets.options import TargetOptions +from numba.core.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock import numba.core.entrypoints diff --git a/numba/targets/options.py b/numba/core/options.py similarity index 100% rename from numba/targets/options.py rename to numba/core/options.py diff --git a/numba/cuda/descriptor.py b/numba/cuda/descriptor.py index 96ecbefff27..8dbaa5b5488 100644 --- a/numba/cuda/descriptor.py +++ b/numba/cuda/descriptor.py @@ -1,5 +1,5 @@ from numba.core.descriptors import TargetDescriptor -from numba.targets.options import TargetOptions +from numba.core.options import TargetOptions from .target import CUDATargetContext, CUDATypingContext diff --git a/numba/cuda/dispatcher.py b/numba/cuda/dispatcher.py index 32f96d2b8b4..6379c18288c 100644 --- a/numba/cuda/dispatcher.py +++ b/numba/cuda/dispatcher.py @@ -1,7 +1,7 @@ import numpy as np from numba.core.descriptors import TargetDescriptor -from numba.targets.options import TargetOptions +from numba.core.options import TargetOptions from numba import cuda from numba.cuda import jit, autojit from numba.cuda.cudadrv import devicearray diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/npyufunc/ufuncbuilder.py index 7221a1749ac..79195e8ea4a 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/npyufunc/ufuncbuilder.py @@ -5,7 +5,7 @@ from numba.core.decorators import jit from numba.core.descriptors import TargetDescriptor -from numba.targets.options import TargetOptions +from numba.core.options import TargetOptions from numba.targets.registry import dispatcher_registry, cpu_target from numba.core.cpu import FastMathOptions from numba.core import utils, types, serialize, compiler, sigutils diff --git a/numba/roc/descriptor.py b/numba/roc/descriptor.py index 835b05c6f4f..74586b6550c 100644 --- a/numba/roc/descriptor.py +++ b/numba/roc/descriptor.py @@ -1,5 +1,5 @@ from numba.core.descriptors import TargetDescriptor -from numba.targets.options import TargetOptions +from numba.core.options import TargetOptions from .target import HSATargetContext, HSATypingContext From e0efcb22815a2b97d95ee0cafb6b45c80ce1d931 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 15:48:54 +0000 Subject: [PATCH 405/595] Move numba/targets/imputils.py to numba/core --- numba/core/base.py | 5 ++--- numba/{targets => core}/imputils.py | 0 numba/core/ir_utils.py | 2 +- numba/core/optional.py | 2 +- numba/core/typing/templates.py | 6 +++--- numba/cpython/builtins.py | 2 +- numba/cpython/cmathimpl.py | 2 +- numba/cpython/enumimpl.py | 2 +- numba/cpython/iterators.py | 2 +- numba/cpython/listobj.py | 2 +- numba/cpython/mathimpl.py | 2 +- numba/cpython/numbers.py | 2 +- numba/cpython/printimpl.py | 2 +- numba/cpython/randomimpl.py | 2 +- numba/cpython/rangeobj.py | 2 +- numba/cpython/setobj.py | 2 +- numba/cpython/slicing.py | 2 +- numba/cpython/tupleobj.py | 2 +- numba/cpython/unicode.py | 2 +- numba/cpython/unicode_support.py | 2 +- numba/cuda/cudaimpl.py | 2 +- numba/cuda/libdevice.py | 2 +- numba/cuda/printimpl.py | 2 +- numba/dictobject.py | 4 ++-- numba/experimental/jitclass/base.py | 3 +-- numba/extending.py | 6 ++++-- numba/listobject.py | 4 ++-- numba/np/arrayobj.py | 2 +- numba/np/linalg.py | 2 +- numba/roc/hsaimpl.py | 2 +- numba/roc/mathimpl.py | 2 +- numba/stencil.py | 2 +- numba/targets/arraymath.py | 2 +- numba/targets/cffiimpl.py | 2 +- numba/targets/dictimpl.py | 2 +- numba/targets/npdatetime.py | 2 +- numba/targets/npyfuncs.py | 2 +- numba/targets/npyimpl.py | 2 +- numba/tests/pdlike_usecase.py | 2 +- numba/tests/test_nrt.py | 2 +- numba/tests/test_target_overloadselector.py | 2 +- numba/typed/typeddict.py | 2 +- numba/typed/typedlist.py | 2 +- numba/unsafe/ndarray.py | 2 +- 44 files changed, 51 insertions(+), 51 deletions(-) rename numba/{targets => core}/imputils.py (100%) diff --git a/numba/core/base.py b/numba/core/base.py index e6ed2c7704b..6811151c916 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -12,13 +12,12 @@ from llvmlite.llvmpy.core import Type, Constant, LLVMException import llvmlite.binding as ll -from numba.core import types, utils, typing, datamodel, debuginfo, funcdesc, config, cgutils +from numba.core import types, utils, typing, datamodel, debuginfo, funcdesc, config, cgutils, imputils from numba import _dynfunc, _helperlib from numba.core.compiler_lock import global_compiler_lock from numba.core.pythonapi import PythonAPI from numba.np import arrayobj -from numba.targets import imputils -from numba.targets.imputils import (user_function, user_generator, +from numba.core.imputils import (user_function, user_generator, builtin_registry, impl_ret_borrowed, RegistryLoader) from numba.cpython import builtins diff --git a/numba/targets/imputils.py b/numba/core/imputils.py similarity index 100% rename from numba/targets/imputils.py rename to numba/core/imputils.py diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index 14ccc83d6d3..2180806087d 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -16,7 +16,7 @@ from numba.core import types, utils, typing, ir, analysis, postproc, rewrites, config, cgutils from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) -from numba.targets.imputils import impl_ret_untracked +from numba.core.imputils import impl_ret_untracked from numba.core.analysis import (compute_live_map, compute_use_defs, compute_cfg_from_blocks) from numba.core.errors import (TypingError, UnsupportedError, diff --git a/numba/core/optional.py b/numba/core/optional.py index 3b15d69d9b7..dda2b017f57 100644 --- a/numba/core/optional.py +++ b/numba/core/optional.py @@ -2,7 +2,7 @@ from numba.core import types, typing, cgutils -from numba.targets.imputils import (lower_cast, lower_builtin, +from numba.core.imputils import (lower_cast, lower_builtin, lower_getattr_generic, impl_ret_untracked, lower_setattr_generic) diff --git a/numba/core/typing/templates.py b/numba/core/typing/templates.py index 669b6b47ea8..8674b2fc344 100644 --- a/numba/core/typing/templates.py +++ b/numba/core/typing/templates.py @@ -632,7 +632,7 @@ def generic(self, args, kws): """ Type the intrinsic by the arguments. """ - from numba.targets.imputils import lower_builtin + from numba.core.imputils import lower_builtin cache_key = self.context, args, tuple(kws.items()) try: @@ -727,7 +727,7 @@ def do_class_init(cls): """ Register attribute implementation. """ - from numba.targets.imputils import lower_getattr + from numba.core.imputils import lower_getattr attr = cls._attr @lower_getattr(cls.key, attr) @@ -770,7 +770,7 @@ def do_class_init(cls): """ Register generic method implementation. """ - from numba.targets.imputils import lower_builtin + from numba.core.imputils import lower_builtin attr = cls._attr @lower_builtin((cls.key, attr), cls.key, types.VarArg(types.Any)) diff --git a/numba/cpython/builtins.py b/numba/cpython/builtins.py index ab22c38d268..06b8d1f909d 100644 --- a/numba/cpython/builtins.py +++ b/numba/cpython/builtins.py @@ -8,7 +8,7 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba.targets.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, iternext_impl, call_getiter, call_iternext, impl_ret_borrowed, impl_ret_untracked, numba_typeref_ctor +from numba.core.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, iternext_impl, call_getiter, call_iternext, impl_ret_borrowed, impl_ret_untracked, numba_typeref_ctor from numba.core import typing, types, utils, cgutils from numba.extending import overload, intrinsic from numba.core.typeconv import Conversion diff --git a/numba/cpython/cmathimpl.py b/numba/cpython/cmathimpl.py index 61009c2c683..d6e313b1c78 100644 --- a/numba/cpython/cmathimpl.py +++ b/numba/cpython/cmathimpl.py @@ -9,7 +9,7 @@ import llvmlite.llvmpy.core as lc from llvmlite.llvmpy.core import Type -from numba.targets.imputils import Registry, impl_ret_untracked +from numba.core.imputils import Registry, impl_ret_untracked from numba.core import types, cgutils from numba.core.typing import signature from numba.cpython import builtins, mathimpl diff --git a/numba/cpython/enumimpl.py b/numba/cpython/enumimpl.py index d6787dbd06f..ffff4c752eb 100644 --- a/numba/cpython/enumimpl.py +++ b/numba/cpython/enumimpl.py @@ -3,7 +3,7 @@ """ import operator -from numba.targets.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, impl_ret_untracked +from numba.core.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, impl_ret_untracked from numba.core import types diff --git a/numba/cpython/iterators.py b/numba/cpython/iterators.py index 769dcb71da0..bf9357b9ad1 100644 --- a/numba/cpython/iterators.py +++ b/numba/cpython/iterators.py @@ -3,7 +3,7 @@ """ from numba.core import types, cgutils -from numba.targets.imputils import ( +from numba.core.imputils import ( lower_builtin, iternext_impl, call_iternext, call_getiter, impl_ret_borrowed, impl_ret_new_ref, RefType) diff --git a/numba/cpython/listobj.py b/numba/cpython/listobj.py index 6c4f3241c8b..cc29c953083 100644 --- a/numba/cpython/listobj.py +++ b/numba/cpython/listobj.py @@ -8,7 +8,7 @@ from llvmlite import ir from numba.core import types, typing, errors, cgutils -from numba.targets.imputils import (lower_builtin, lower_cast, +from numba.core.imputils import (lower_builtin, lower_cast, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, RefType) diff --git a/numba/cpython/mathimpl.py b/numba/cpython/mathimpl.py index a6e4e10c268..6d915df3dec 100644 --- a/numba/cpython/mathimpl.py +++ b/numba/cpython/mathimpl.py @@ -10,7 +10,7 @@ import llvmlite.llvmpy.core as lc from llvmlite.llvmpy.core import Type -from numba.targets.imputils import Registry, impl_ret_untracked +from numba.core.imputils import Registry, impl_ret_untracked from numba import typeof from numba.core import types, utils, config, cgutils from numba.extending import overload diff --git a/numba/cpython/numbers.py b/numba/cpython/numbers.py index b053c0a15fd..49c13d9d10b 100644 --- a/numba/cpython/numbers.py +++ b/numba/cpython/numbers.py @@ -8,7 +8,7 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba.targets.imputils import (lower_builtin, lower_getattr, +from numba.core.imputils import (lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, impl_ret_borrowed, impl_ret_untracked) diff --git a/numba/cpython/printimpl.py b/numba/cpython/printimpl.py index 3d42ba914b0..d1678408975 100644 --- a/numba/cpython/printimpl.py +++ b/numba/cpython/printimpl.py @@ -3,7 +3,7 @@ """ from llvmlite.llvmpy.core import Type from numba.core import types, typing, cgutils -from numba.targets.imputils import Registry, impl_ret_untracked +from numba.core.imputils import Registry, impl_ret_untracked registry = Registry() lower = registry.lower diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index 97339a591fa..fbb23325f07 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -12,7 +12,7 @@ from llvmlite import ir from numba.extending import overload, register_jitable -from numba.targets.imputils import (Registry, impl_ret_untracked, +from numba.core.imputils import (Registry, impl_ret_untracked, impl_ret_new_ref) from numba.core.typing import signature from numba import _helperlib diff --git a/numba/cpython/rangeobj.py b/numba/cpython/rangeobj.py index 512d7c22ce8..928e71bea22 100644 --- a/numba/cpython/rangeobj.py +++ b/numba/cpython/rangeobj.py @@ -10,7 +10,7 @@ from numba.core import types, cgutils from numba.cpython.listobj import ListIterInstance from numba.np.arrayobj import make_array -from numba.targets.imputils import (lower_builtin, lower_cast, +from numba.core.imputils import (lower_builtin, lower_cast, iterator_impl, impl_ret_untracked) from numba.core.typing import signature from numba.extending import intrinsic, overload, overload_attribute, register_jitable diff --git a/numba/cpython/setobj.py b/numba/cpython/setobj.py index b0570f26067..6d2e88381c0 100644 --- a/numba/cpython/setobj.py +++ b/numba/cpython/setobj.py @@ -10,7 +10,7 @@ from llvmlite import ir from numba.core import types, typing, cgutils -from numba.targets.imputils import (lower_builtin, lower_cast, +from numba.core.imputils import (lower_builtin, lower_cast, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, for_iter, call_len, RefType) diff --git a/numba/cpython/slicing.py b/numba/cpython/slicing.py index 0ab68e38b8a..6911096338b 100644 --- a/numba/cpython/slicing.py +++ b/numba/cpython/slicing.py @@ -7,7 +7,7 @@ from llvmlite import ir from numba.core import types, typing, utils, cgutils -from numba.targets.imputils import (lower_builtin, lower_getattr, +from numba.core.imputils import (lower_builtin, lower_getattr, iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) diff --git a/numba/cpython/tupleobj.py b/numba/cpython/tupleobj.py index 787968490db..e211b8ed6cd 100644 --- a/numba/cpython/tupleobj.py +++ b/numba/cpython/tupleobj.py @@ -6,7 +6,7 @@ import llvmlite.llvmpy.core as lc import operator -from numba.targets.imputils import (lower_builtin, lower_getattr_generic, +from numba.core.imputils import (lower_builtin, lower_getattr_generic, lower_cast, lower_constant, iternext_impl, impl_ret_borrowed, impl_ret_untracked, RefType) diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index 30b553004ab..5565b8340b5 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -16,7 +16,7 @@ intrinsic, register_jitable, ) -from numba.targets.imputils import (lower_constant, lower_cast, lower_builtin, +from numba.core.imputils import (lower_constant, lower_cast, lower_builtin, iternext_impl, impl_ret_new_ref, RefType) from numba.core.datamodel import register_default, StructModel from numba.core import utils, types, cgutils diff --git a/numba/cpython/unicode_support.py b/numba/cpython/unicode_support.py index ba7f3b35f9a..8ffaad7d0d7 100644 --- a/numba/cpython/unicode_support.py +++ b/numba/cpython/unicode_support.py @@ -10,7 +10,7 @@ import llvmlite.llvmpy.core as lc from numba.core import types, cgutils -from numba.targets.imputils import (impl_ret_untracked) +from numba.core.imputils import (impl_ret_untracked) from numba.extending import overload, intrinsic, register_jitable from numba.core.errors import TypingError diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py index a970137c644..2e421298e35 100644 --- a/numba/cuda/cudaimpl.py +++ b/numba/cuda/cudaimpl.py @@ -6,7 +6,7 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba.targets.imputils import Registry +from numba.core.imputils import Registry from numba.core import types, cgutils from .cudadrv import nvvm from numba.cuda import nvvmutils, stubs diff --git a/numba/cuda/libdevice.py b/numba/cuda/libdevice.py index 84a7792e1d4..9dc0587743c 100644 --- a/numba/cuda/libdevice.py +++ b/numba/cuda/libdevice.py @@ -2,7 +2,7 @@ import math from llvmlite.llvmpy.core import Type from numba.core import types, cgutils -from numba.targets.imputils import Registry +from numba.core.imputils import Registry registry = Registry() lower = registry.lower diff --git a/numba/cuda/printimpl.py b/numba/cuda/printimpl.py index 4a20834efba..03cc9144e5d 100644 --- a/numba/cuda/printimpl.py +++ b/numba/cuda/printimpl.py @@ -3,7 +3,7 @@ from llvmlite.llvmpy.core import Type, Constant from numba.core import types, typing, cgutils -from numba.targets.imputils import Registry +from numba.core.imputils import Registry from numba.cuda import nvvmutils registry = Registry() diff --git a/numba/dictobject.py b/numba/dictobject.py index 151265e1a19..8f0bcc57c0d 100644 --- a/numba/dictobject.py +++ b/numba/dictobject.py @@ -17,7 +17,7 @@ models, lower_builtin, ) -from numba.targets.imputils import iternext_impl +from numba.core.imputils import iternext_impl from numba.core import types, cgutils from numba.core.types import ( DictType, @@ -27,7 +27,7 @@ DictIteratorType, Type, ) -from numba.targets.imputils import impl_ret_borrowed, RefType +from numba.core.imputils import impl_ret_borrowed, RefType from numba.core.errors import TypingError from numba.core import typing from numba.typedobjectutils import (_as_bytes, diff --git a/numba/experimental/jitclass/base.py b/numba/experimental/jitclass/base.py index 98b8a0efb0d..bcc602cf96c 100644 --- a/numba/experimental/jitclass/base.py +++ b/numba/experimental/jitclass/base.py @@ -6,12 +6,11 @@ from llvmlite import ir as llvmir -from numba.core import types, utils, errors, cgutils +from numba.core import types, utils, errors, cgutils, imputils from numba.targets.registry import cpu_target from numba import njit from numba.core.typing import templates from numba.core.datamodel import default_manager, models -from numba.targets import imputils from numba.experimental.jitclass import _box diff --git a/numba/extending.py b/numba/extending.py index 7a052a0b57b..a067c16ac92 100644 --- a/numba/extending.py +++ b/numba/extending.py @@ -10,7 +10,7 @@ # Exported symbols from numba.core.typing.typeof import typeof_impl from numba.core.typing.templates import infer, infer_getattr -from numba.targets.imputils import ( +from numba.core.imputils import ( lower_builtin, lower_getattr, lower_getattr_generic, lower_setattr, lower_setattr_generic, lower_cast) from numba.core.datamodel import models, register_default as register_model @@ -18,6 +18,8 @@ from numba._helperlib import _import_cython_function + + def type_callable(func): """ Decorate a function as implementing typing for the callable *func*. @@ -223,7 +225,7 @@ def make_attribute_wrapper(typeclass, struct_attr, python_attr): from numba.core.typing.templates import AttributeTemplate from numba.core.datamodel import default_manager from numba.core.datamodel.models import StructModel - from numba.targets.imputils import impl_ret_borrowed + from numba.core.imputils import impl_ret_borrowed from numba.core import cgutils if not isinstance(typeclass, type) or not issubclass(typeclass, types.Type): diff --git a/numba/listobject.py b/numba/listobject.py index a467eb9674e..db0e8886d87 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -18,7 +18,7 @@ models, lower_builtin, ) -from numba.targets.imputils import iternext_impl +from numba.core.imputils import iternext_impl from numba.core import types, cgutils from numba.core.types import ( ListType, @@ -27,7 +27,7 @@ Type, NoneType, ) -from numba.targets.imputils import impl_ret_borrowed, RefType +from numba.core.imputils import impl_ret_borrowed, RefType from numba.core.errors import TypingError from numba.core import typing from numba.typedobjectutils import (_as_bytes, diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 8e6e2e2cde8..2118e6db794 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -19,7 +19,7 @@ from numba.numpy_support import (as_dtype, carray, farray, is_contiguous, is_fortran) from numba.numpy_support import type_can_asarray, is_nonelike -from numba.targets.imputils import (lower_builtin, lower_getattr, +from numba.core.imputils import (lower_builtin, lower_getattr, lower_getattr_generic, lower_setattr_generic, lower_cast, lower_constant, diff --git a/numba/np/linalg.py b/numba/np/linalg.py index a1f00ff19c5..0dca84c7fef 100644 --- a/numba/np/linalg.py +++ b/numba/np/linalg.py @@ -10,7 +10,7 @@ import numpy as np import operator -from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, +from numba.core.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) from numba.core.typing import signature from numba.extending import overload, register_jitable diff --git a/numba/roc/hsaimpl.py b/numba/roc/hsaimpl.py index 97aa28f1576..b267723b11b 100644 --- a/numba/roc/hsaimpl.py +++ b/numba/roc/hsaimpl.py @@ -6,7 +6,7 @@ import llvmlite.binding as ll from llvmlite import ir -from numba.targets.imputils import Registry +from numba.core.imputils import Registry from numba.core import types, cgutils from numba.core.itanium_mangler import mangle_c, mangle, mangle_type from numba.roc import target diff --git a/numba/roc/mathimpl.py b/numba/roc/mathimpl.py index 80c898b7ea2..fd89b568670 100644 --- a/numba/roc/mathimpl.py +++ b/numba/roc/mathimpl.py @@ -1,7 +1,7 @@ import math import warnings -from numba.targets.imputils import Registry +from numba.core.imputils import Registry from numba.core import types from numba.core.itanium_mangler import mangle from .hsaimpl import _declare_function diff --git a/numba/stencil.py b/numba/stencil.py index 7a519be32c7..b692a548a05 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -13,7 +13,7 @@ from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) from numba.targets import registry -from numba.targets.imputils import lower_builtin +from numba.core.imputils import lower_builtin from numba.extending import register_jitable import numba diff --git a/numba/targets/arraymath.py b/numba/targets/arraymath.py index 7d2c4c387b5..aac89598465 100644 --- a/numba/targets/arraymath.py +++ b/numba/targets/arraymath.py @@ -18,7 +18,7 @@ from numba.numpy_support import as_dtype, type_can_asarray from numba.numpy_support import numpy_version from numba.numpy_support import is_nonelike -from numba.targets.imputils import (lower_builtin, impl_ret_borrowed, +from numba.core.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) from numba.core.typing import signature from numba.np.arrayobj import make_array, load_item, store_item, _empty_nd_impl diff --git a/numba/targets/cffiimpl.py b/numba/targets/cffiimpl.py index 9548c84a2ab..6215a35476c 100644 --- a/numba/targets/cffiimpl.py +++ b/numba/targets/cffiimpl.py @@ -3,7 +3,7 @@ """ -from numba.targets.imputils import Registry +from numba.core.imputils import Registry from numba.core import types from numba.np import arrayobj diff --git a/numba/targets/dictimpl.py b/numba/targets/dictimpl.py index ad36ed38370..d180439217f 100644 --- a/numba/targets/dictimpl.py +++ b/numba/targets/dictimpl.py @@ -1,7 +1,7 @@ """ This file implements the lowering for `dict()` """ -from numba.targets.imputils import lower_builtin +from numba.core.imputils import lower_builtin @lower_builtin(dict) diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index 96d65625745..1e125a20138 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -10,7 +10,7 @@ from numba import numpy_support from numba.core import types, cgutils -from numba.targets.imputils import (lower_builtin, lower_constant, +from numba.core.imputils import (lower_builtin, lower_constant, impl_ret_untracked) from numba.np import npdatetime diff --git a/numba/targets/npyfuncs.py b/numba/targets/npyfuncs.py index 44c023553ef..f3a0b8e2ed2 100644 --- a/numba/targets/npyfuncs.py +++ b/numba/targets/npyfuncs.py @@ -9,7 +9,7 @@ from llvmlite.llvmpy import core as lc -from numba.targets.imputils import impl_ret_untracked +from numba.core.imputils import impl_ret_untracked from numba.core import typing, types, errors, lowering, cgutils from numba.targets import npdatetime from numba.cpython import cmathimpl, mathimpl, numbers diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index 486a1ea4875..fb0a353474b 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -15,7 +15,7 @@ from numba.targets import ufunc_db from numba.np import arrayobj -from numba.targets.imputils import Registry, impl_ret_new_ref, force_error_model +from numba.core.imputils import Registry, impl_ret_new_ref, force_error_model from numba import numpy_support from numba.core import typing, types, utils, cgutils, callconv from numba.numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype diff --git a/numba/tests/pdlike_usecase.py b/numba/tests/pdlike_usecase.py index 983bc2fd893..67cb3261bba 100644 --- a/numba/tests/pdlike_usecase.py +++ b/numba/tests/pdlike_usecase.py @@ -10,7 +10,7 @@ typeof_impl, type_callable, register_model, lower_builtin, box, unbox, NativeValue, overload, overload_attribute, overload_method, make_attribute_wrapper) -from numba.targets.imputils import impl_ret_borrowed +from numba.core.imputils import impl_ret_borrowed class Index(object): diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 91994f8e0dd..c08cc8ec8f8 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -18,7 +18,7 @@ ) from numba.extending import intrinsic, include_path from numba.core.typing import signature -from numba.targets.imputils import impl_ret_untracked +from numba.core.imputils import impl_ret_untracked from llvmlite import ir import llvmlite.binding as llvm from numba import cffi_support diff --git a/numba/tests/test_target_overloadselector.py b/numba/tests/test_target_overloadselector.py index f9e2ccd0209..baf232a5e1b 100644 --- a/numba/tests/test_target_overloadselector.py +++ b/numba/tests/test_target_overloadselector.py @@ -4,7 +4,7 @@ import numba.unittest_support as unittest from numba.core.base import OverloadSelector from numba.targets.registry import cpu_target -from numba.targets.imputils import builtin_registry, RegistryLoader +from numba.core.imputils import builtin_registry, RegistryLoader from numba.core import types diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index ea677f08e58..b3c01692984 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -4,7 +4,7 @@ from collections.abc import MutableMapping from numba.core.types import DictType, TypeRef -from numba.targets.imputils import numba_typeref_ctor +from numba.core.imputils import numba_typeref_ctor from numba import njit, dictobject, typeof from numba.core import types, errors, config, cgutils from numba.extending import ( diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index 1a27eb1b3b3..ef262163395 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -11,7 +11,7 @@ from collections.abc import MutableSequence from numba.core.types import ListType, TypeRef -from numba.targets.imputils import numba_typeref_ctor +from numba.core.imputils import numba_typeref_ctor from numba import listobject from numba.core.dispatcher import Dispatcher from numba.core import types, errors, config, cgutils diff --git a/numba/unsafe/ndarray.py b/numba/unsafe/ndarray.py index 98a2b4db699..a5a303c9e5a 100644 --- a/numba/unsafe/ndarray.py +++ b/numba/unsafe/ndarray.py @@ -5,7 +5,7 @@ from numba.core import types, typing from numba.core.cgutils import unpack_tuple from numba.extending import intrinsic -from numba.targets.imputils import impl_ret_new_ref +from numba.core.imputils import impl_ret_new_ref from numba.core.errors import RequireLiteralValue, TypingError from numba.cpython.unsafe.tuple import tuple_setitem From 17080a44887bd0051b4c2dbcc313db420c3014b4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:13:33 +0000 Subject: [PATCH 406/595] Move numba/targets/removerefctpass.py to numba/core --- numba/core/lowering.py | 3 +-- numba/{targets => core}/removerefctpass.py | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename numba/{targets => core}/removerefctpass.py (100%) diff --git a/numba/core/lowering.py b/numba/core/lowering.py index c8587a783a5..be08bb87b69 100644 --- a/numba/core/lowering.py +++ b/numba/core/lowering.py @@ -6,10 +6,9 @@ from llvmlite.llvmpy.core import Constant, Type, Builder from numba import _dynfunc -from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config, ir_utils, cgutils +from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config, ir_utils, cgutils, removerefctpass from numba.core.errors import (LoweringError, new_error_context, TypingError, LiteralTypingError) -from numba.targets import removerefctpass from numba.core.funcdesc import default_mangler diff --git a/numba/targets/removerefctpass.py b/numba/core/removerefctpass.py similarity index 100% rename from numba/targets/removerefctpass.py rename to numba/core/removerefctpass.py From 8251a3481dc19ef6d6ddfcef2de3e2bb11578577 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:19:43 +0000 Subject: [PATCH 407/595] Move numba/transforms.py to numba/core --- numba/core/compiler_machinery.py | 3 +-- numba/core/object_mode_passes.py | 3 +-- numba/core/postproc.py | 3 +-- numba/{ => core}/transforms.py | 0 numba/core/untyped_passes.py | 3 +-- numba/core/withcontexts.py | 2 +- numba/tests/test_withlifting.py | 2 +- 7 files changed, 6 insertions(+), 10 deletions(-) rename numba/{ => core}/transforms.py (100%) diff --git a/numba/core/compiler_machinery.py b/numba/core/compiler_machinery.py index f0ee40efe58..83956cc2b9b 100644 --- a/numba/core/compiler_machinery.py +++ b/numba/core/compiler_machinery.py @@ -3,8 +3,7 @@ from collections import namedtuple, OrderedDict import inspect from numba.core.compiler_lock import global_compiler_lock -from numba.core import errors, config -from numba import transforms +from numba.core import errors, config, transforms from numba.core.utils import add_metaclass from numba.core.tracing import event from numba.core.postproc import PostProcessor diff --git a/numba/core/object_mode_passes.py b/numba/core/object_mode_passes.py index 7a5a41b14a8..b60d0c72228 100644 --- a/numba/core/object_mode_passes.py +++ b/numba/core/object_mode_passes.py @@ -1,7 +1,6 @@ from contextlib import contextmanager import warnings -from numba import transforms -from numba.core import errors, types, typing, funcdesc, config, pylowering +from numba.core import errors, types, typing, funcdesc, config, pylowering, transforms from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass from collections import defaultdict diff --git a/numba/core/postproc.py b/numba/core/postproc.py index 423cb82bb2b..c019493afb1 100644 --- a/numba/core/postproc.py +++ b/numba/core/postproc.py @@ -1,5 +1,4 @@ -from numba import transforms -from numba.core import utils, ir, analysis +from numba.core import utils, ir, analysis, transforms class YieldPoint(object): diff --git a/numba/transforms.py b/numba/core/transforms.py similarity index 100% rename from numba/transforms.py rename to numba/core/transforms.py diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index f824a2e93c8..ed3c2522a7c 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -4,8 +4,7 @@ import warnings from numba.core.compiler_machinery import FunctionPass, register_pass -from numba import transforms -from numba.core import errors, types, ir, bytecode, postproc, rewrites, config +from numba.core import errors, types, ir, bytecode, postproc, rewrites, config, transforms from numba.special import literal_unroll from .analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls, compute_cfg_from_blocks, compute_use_defs from numba.core.inline_closurecall import InlineClosureCallPass, inline_closure_call diff --git a/numba/core/withcontexts.py b/numba/core/withcontexts.py index 20c0d0e9090..fb3c783fa5b 100644 --- a/numba/core/withcontexts.py +++ b/numba/core/withcontexts.py @@ -1,6 +1,6 @@ from numba.core import types, errors, ir, sigutils, ir_utils from numba.core.typing.typeof import typeof_impl -from numba.transforms import find_region_inout_vars +from numba.core.transforms import find_region_inout_vars class WithContext(object): diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index 45904d326fd..bf9a0884dc5 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -4,7 +4,7 @@ import numba from numba import unittest_support as unittest -from numba.transforms import find_setupwiths, with_lifting +from numba.core.transforms import find_setupwiths, with_lifting from numba.core.withcontexts import bypass_context, call_context, objmode_context from numba.core.bytecode import FunctionIdentity, ByteCode from numba.core.interpreter import Interpreter From d0c9ec33bc6244a4a12c47e1d13122c63242727d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:20:17 +0000 Subject: [PATCH 408/595] Add numba.core.unsafe submodule --- numba/core/unsafe/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/core/unsafe/__init__.py diff --git a/numba/core/unsafe/__init__.py b/numba/core/unsafe/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From e0399e41c929d3dc21ca35dc40e3346a38813144 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:23:09 +0000 Subject: [PATCH 409/595] Move numba/unsafe/bytes.py to numba/core/unsafe --- numba/{ => core}/unsafe/bytes.py | 0 numba/cpython/hashing.py | 2 +- numba/cpython/unicode.py | 2 +- numba/tests/test_unsafe_intrinsics.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename numba/{ => core}/unsafe/bytes.py (100%) diff --git a/numba/unsafe/bytes.py b/numba/core/unsafe/bytes.py similarity index 100% rename from numba/unsafe/bytes.py rename to numba/core/unsafe/bytes.py diff --git a/numba/cpython/hashing.py b/numba/cpython/hashing.py index 494e97330bd..e547de774f1 100644 --- a/numba/cpython/hashing.py +++ b/numba/cpython/hashing.py @@ -16,7 +16,7 @@ overload, overload_method, intrinsic, register_jitable) from numba.core import errors from numba.core import types, utils -from numba.unsafe.bytes import grab_byte, grab_uint64_t +from numba.core.unsafe.bytes import grab_byte, grab_uint64_t _py38_or_later = utils.PYVERSION >= (3, 8) diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index 5565b8340b5..8df16e0f9e2 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -28,7 +28,7 @@ ) from numba._helperlib import c_helpers from numba.cpython.hashing import _Py_hash_t -from numba.unsafe.bytes import memcpy_region +from numba.core.unsafe.bytes import memcpy_region from numba.core.errors import TypingError from numba.cpython.unicode_support import (_Py_TOUPPER, _Py_TOLOWER, _Py_UCS4, _Py_ISALNUM, diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index 49b9dc0e74e..6adccd7e2fb 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -6,7 +6,7 @@ from numba.core import types from numba.cpython.unsafe.tuple import tuple_setitem from numba.unsafe.ndarray import to_fixed_tuple, empty_inferred -from numba.unsafe.bytes import memcpy_region +from numba.core.unsafe.bytes import memcpy_region from numba.unsafe.refcount import dump_refcount from numba.cpython.unsafe.numbers import trailing_zeros, leading_zeros from numba.core.errors import TypingError From a54465afec28494f7a6b24a444a0cd67afbcb2ce Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:27:16 +0000 Subject: [PATCH 410/595] Move numba/unsafe/eh.py to numba/core/unsafe --- numba/core/interpreter.py | 2 +- numba/core/lowering.py | 2 +- numba/core/typing/context.py | 2 +- numba/{ => core}/unsafe/eh.py | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename numba/{ => core}/unsafe/eh.py (100%) diff --git a/numba/core/interpreter.py b/numba/core/interpreter.py index 8ae8616c3e0..3f2dad08fdd 100644 --- a/numba/core/interpreter.py +++ b/numba/core/interpreter.py @@ -15,7 +15,7 @@ get_function_globals ) from numba.core.byteflow import Flow, AdaptDFA, AdaptCFA -from numba.unsafe import eh +from numba.core.unsafe import eh _logger = logging.getLogger(__name__) diff --git a/numba/core/lowering.py b/numba/core/lowering.py index be08bb87b69..b7b12bbb3bf 100644 --- a/numba/core/lowering.py +++ b/numba/core/lowering.py @@ -306,7 +306,7 @@ class Lower(BaseLower): GeneratorLower = generators.GeneratorLower def pre_block(self, block): - from numba.unsafe import eh + from numba.core.unsafe import eh super(Lower, self).pre_block(block) diff --git a/numba/core/typing/context.py b/numba/core/typing/context.py index 069d71dabe3..29de9d4f04f 100644 --- a/numba/core/typing/context.py +++ b/numba/core/typing/context.py @@ -396,7 +396,7 @@ def _load_builtins(self): # Initialize declarations from numba.core.typing import builtins, arraydecl, npdatetime # noqa: F401 from numba.core.typing import ctypes_utils, bufproto # noqa: F401 - from numba.unsafe import eh # noqa: F401 + from numba.core.unsafe import eh # noqa: F401 self.install_registry(templates.builtin_registry) diff --git a/numba/unsafe/eh.py b/numba/core/unsafe/eh.py similarity index 100% rename from numba/unsafe/eh.py rename to numba/core/unsafe/eh.py From e0aa51e779a9f20c16509a903fa0ec196a08c6ce Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:28:42 +0000 Subject: [PATCH 411/595] Move numba/unsafe/nrt.py to numba/core/unsafe --- numba/{ => core}/unsafe/nrt.py | 0 numba/tests/test_nrt.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => core}/unsafe/nrt.py (100%) diff --git a/numba/unsafe/nrt.py b/numba/core/unsafe/nrt.py similarity index 100% rename from numba/unsafe/nrt.py rename to numba/core/unsafe/nrt.py diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index c08cc8ec8f8..508cbb00425 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -22,7 +22,7 @@ from llvmlite import ir import llvmlite.binding as llvm from numba import cffi_support -from numba.unsafe.nrt import NRT_get_api +from numba.core.unsafe.nrt import NRT_get_api from numba.tests.support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic from numba.core import cpu From d5b89b8644fd407794c7a8544dc50a41140f4108 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:30:35 +0000 Subject: [PATCH 412/595] Move numba/unsafe/refcount.py to numba/core/unsafe --- numba/{ => core}/unsafe/refcount.py | 0 numba/tests/test_typedlist.py | 2 +- numba/tests/test_unsafe_intrinsics.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename numba/{ => core}/unsafe/refcount.py (100%) diff --git a/numba/unsafe/refcount.py b/numba/core/unsafe/refcount.py similarity index 100% rename from numba/unsafe/refcount.py rename to numba/core/unsafe/refcount.py diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 9681e669170..c2040c8ef24 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -12,7 +12,7 @@ from numba.tests.support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen, skip_parfors_unsupported) -from numba.unsafe.refcount import get_refcount +from numba.core.unsafe.refcount import get_refcount from numba.experimental import jitclass diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index 6adccd7e2fb..a128e3fbc06 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -7,7 +7,7 @@ from numba.cpython.unsafe.tuple import tuple_setitem from numba.unsafe.ndarray import to_fixed_tuple, empty_inferred from numba.core.unsafe.bytes import memcpy_region -from numba.unsafe.refcount import dump_refcount +from numba.core.unsafe.refcount import dump_refcount from numba.cpython.unsafe.numbers import trailing_zeros, leading_zeros from numba.core.errors import TypingError From 5dd6f81ea14e81a41350b8ed27ba5a3f68ed199e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:36:35 +0000 Subject: [PATCH 413/595] Move numba/dummyarray.py to numba/misc --- numba/cuda/cudadrv/devicearray.py | 3 ++- numba/{ => misc}/dummyarray.py | 0 numba/roc/hsadrv/devicearray.py | 3 ++- numba/tests/test_dummyarray.py | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) rename numba/{ => misc}/dummyarray.py (100%) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 0744d046211..fc0fe526710 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -16,9 +16,10 @@ import numba from numba.cuda.cudadrv import driver as _driver from numba.cuda.cudadrv import devices -from numba import dummyarray, numpy_support +from numba import numpy_support from numba.core import types from numba.unsafe.ndarray import to_fixed_tuple +from numba.misc import dummyarray try: lru_cache = getattr(functools, 'lru_cache')(None) diff --git a/numba/dummyarray.py b/numba/misc/dummyarray.py similarity index 100% rename from numba/dummyarray.py rename to numba/misc/dummyarray.py diff --git a/numba/roc/hsadrv/devicearray.py b/numba/roc/hsadrv/devicearray.py index 5efcd5a2575..03c5af024bd 100644 --- a/numba/roc/hsadrv/devicearray.py +++ b/numba/roc/hsadrv/devicearray.py @@ -11,9 +11,10 @@ import numpy as np from numba.roc.hsadrv import driver as _driver from numba.roc.hsadrv import devices -from numba import dummyarray, numpy_support +from numba import numpy_support from numba.core import types from .error import HsaContextMismatchError +from numba.misc import dummyarray try: long diff --git a/numba/tests/test_dummyarray.py b/numba/tests/test_dummyarray.py index d504b6c1c75..b06c97816a2 100644 --- a/numba/tests/test_dummyarray.py +++ b/numba/tests/test_dummyarray.py @@ -1,7 +1,7 @@ import numba.unittest_support as unittest import itertools import numpy as np -from numba.dummyarray import Array +from numba.misc.dummyarray import Array class TestSlicing(unittest.TestCase): From 35945518856340add36e4e83f3926106a927d84c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:43:02 +0000 Subject: [PATCH 414/595] Move numba/findlib.py to numba/misc --- numba/cuda/cuda_paths.py | 2 +- numba/cuda/cudadrv/libs.py | 2 +- numba/cuda/tests/cudadrv/test_cuda_libraries.py | 2 +- numba/{ => misc}/findlib.py | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename numba/{ => misc}/findlib.py (100%) diff --git a/numba/cuda/cuda_paths.py b/numba/cuda/cuda_paths.py index a83fd799cea..a8c934eef69 100644 --- a/numba/cuda/cuda_paths.py +++ b/numba/cuda/cuda_paths.py @@ -4,7 +4,7 @@ from collections import defaultdict, namedtuple from numba.core.config import IS_WIN32, IS_OSX -from numba.findlib import find_lib, find_file +from numba.misc.findlib import find_lib, find_file from numba.cuda.envvars import get_numbapro_envvar diff --git a/numba/cuda/cudadrv/libs.py b/numba/cuda/cudadrv/libs.py index a0fcc3ffc9e..b60923b4de1 100644 --- a/numba/cuda/cudadrv/libs.py +++ b/numba/cuda/cudadrv/libs.py @@ -13,7 +13,7 @@ import sys import ctypes -from numba.findlib import find_lib +from numba.misc.findlib import find_lib from numba.cuda.cuda_paths import get_cuda_paths if sys.platform == 'win32': diff --git a/numba/cuda/tests/cudadrv/test_cuda_libraries.py b/numba/cuda/tests/cudadrv/test_cuda_libraries.py index 48e620e1e0e..d13ffde7822 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_libraries.py +++ b/numba/cuda/tests/cudadrv/test_cuda_libraries.py @@ -1,6 +1,6 @@ from numba.cuda.testing import unittest from numba.cuda.testing import skip_on_cudasim, skip_unless_conda_cudatoolkit -from numba.findlib import find_lib +from numba.misc.findlib import find_lib @skip_on_cudasim('Library detection unsupported in the simulator') diff --git a/numba/findlib.py b/numba/misc/findlib.py similarity index 100% rename from numba/findlib.py rename to numba/misc/findlib.py From 156dc38b459197eb40c9077f2d676a3b5d96d781 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:43:51 +0000 Subject: [PATCH 415/595] Fix cuda refactor bug --- numba/npyufunc/deviceufunc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/npyufunc/deviceufunc.py b/numba/npyufunc/deviceufunc.py index 5eb1375a6f0..47a9ec5dcea 100644 --- a/numba/npyufunc/deviceufunc.py +++ b/numba/npyufunc/deviceufunc.py @@ -9,7 +9,7 @@ import numpy as np -from numba.utils import longint +from numba.core.utils import longint from numba.npyufunc.ufuncbuilder import _BaseUFuncBuilder, parse_identity from numba.core import types, sigutils from numba.core.typing import signature From 541669acd88ce547782352f4d93f13ce773751a9 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:44:32 +0000 Subject: [PATCH 416/595] Move numba/help to numba/misc --- docs/source/conf.py | 2 +- numba/{ => misc}/help/__init__.py | 0 numba/{ => misc}/help/inspector.py | 0 numba/tests/test_help.py | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename numba/{ => misc}/help/__init__.py (100%) rename numba/{ => misc}/help/inspector.py (100%) diff --git a/docs/source/conf.py b/docs/source/conf.py index 0fa82debd4b..5a6c97461e7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -301,7 +301,7 @@ def _autogenerate(): from numba.scripts.generate_lower_listing import gen_lower_listing - from numba.help.inspector import write_listings + from numba.misc.help.inspector import write_listings basedir = os.path.dirname(__file__) gen_lower_listing(os.path.join(basedir, diff --git a/numba/help/__init__.py b/numba/misc/help/__init__.py similarity index 100% rename from numba/help/__init__.py rename to numba/misc/help/__init__.py diff --git a/numba/help/inspector.py b/numba/misc/help/inspector.py similarity index 100% rename from numba/help/inspector.py rename to numba/misc/help/inspector.py diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index 9f905f6328e..8db0695538e 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -8,7 +8,7 @@ import builtins from numba.core import types from numba.tests.support import TestCase, temp_directory -from numba.help.inspector import inspect_function, inspect_module +from numba.misc.help.inspector import inspect_function, inspect_module class TestInspector(TestCase): From 1e4d213ba445b7b47978bf4c836d713ffe0c9ec8 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:45:53 +0000 Subject: [PATCH 417/595] Move numba/numba_entry.py to numba/misc --- numba/__main__.py | 2 +- numba/{ => misc}/numba_entry.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => misc}/numba_entry.py (100%) diff --git a/numba/__main__.py b/numba/__main__.py index 89eb31e774f..4e85bf372d8 100644 --- a/numba/__main__.py +++ b/numba/__main__.py @@ -1,6 +1,6 @@ """Expose Numba command via ``python -m numba``.""" import sys -from .numba_entry import main +from numba.misc.numba_entry import main if __name__ == '__main__': sys.exit(main()) diff --git a/numba/numba_entry.py b/numba/misc/numba_entry.py similarity index 100% rename from numba/numba_entry.py rename to numba/misc/numba_entry.py From 62420a43c6b10522d1897150d401f6a80c921e7d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:51:21 +0000 Subject: [PATCH 418/595] Move numba/targets/gdb_hook.py to numba/misc --- numba/core/base.py | 4 ++-- numba/{targets => misc}/cmdlang.gdb | 0 numba/{targets => misc}/gdb_hook.py | 0 numba/tests/test_gdb.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename numba/{targets => misc}/cmdlang.gdb (100%) rename numba/{targets => misc}/gdb_hook.py (100%) diff --git a/numba/core/base.py b/numba/core/base.py index 6811151c916..b8a0dcc7fc3 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -269,11 +269,11 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, polynomial, - gdb_hook, literal) + from numba.targets import (arraymath, polynomial, literal) from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, iterators, numbers, rangeobj) from numba.core import optional + from numba.misc import gdb_hook from numba.np import linalg try: diff --git a/numba/targets/cmdlang.gdb b/numba/misc/cmdlang.gdb similarity index 100% rename from numba/targets/cmdlang.gdb rename to numba/misc/cmdlang.gdb diff --git a/numba/targets/gdb_hook.py b/numba/misc/gdb_hook.py similarity index 100% rename from numba/targets/gdb_hook.py rename to numba/misc/gdb_hook.py diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index a008b319b73..1e52a6e80b3 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -12,7 +12,7 @@ from numba.core import errors from numba import jit from numba import unittest_support as unittest -from numba.targets.gdb_hook import _confirm_gdb +from numba.misc.gdb_hook import _confirm_gdb from numba.tests.support import (TestCase, captured_stdout, tag, skip_parfors_unsupported) From 2b55e078907df67b576824cc90b4baf49e09d9a2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:54:15 +0000 Subject: [PATCH 419/595] Move numba/tests/timsort.py to numba/misc --- numba/{tests => misc}/timsort.py | 0 numba/tests/test_sort.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{tests => misc}/timsort.py (100%) diff --git a/numba/tests/timsort.py b/numba/misc/timsort.py similarity index 100% rename from numba/tests/timsort.py rename to numba/misc/timsort.py diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index 53a0afb803c..33064fb5483 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -15,7 +15,7 @@ from numba.misc.quicksort import make_py_quicksort, make_jit_quicksort from numba.misc.mergesort import make_jit_mergesort -from numba.tests.timsort import make_py_timsort, make_jit_timsort, MergeRun +from numba.misc.timsort import make_py_timsort, make_jit_timsort, MergeRun def make_temp_list(keys, n): From 459bac0389dae1e0565a99ff004bb3fac5c61d4d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 16:57:09 +0000 Subject: [PATCH 420/595] Move numba/targets/literal.py to numba/misc --- numba/core/base.py | 4 ++-- numba/{targets => misc}/literal.py | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{targets => misc}/literal.py (100%) diff --git a/numba/core/base.py b/numba/core/base.py index b8a0dcc7fc3..4fcaba4ce96 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -269,11 +269,11 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, polynomial, literal) + from numba.targets import (arraymath, polynomial) from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, iterators, numbers, rangeobj) from numba.core import optional - from numba.misc import gdb_hook + from numba.misc import gdb_hook, literal from numba.np import linalg try: diff --git a/numba/targets/literal.py b/numba/misc/literal.py similarity index 100% rename from numba/targets/literal.py rename to numba/misc/literal.py From c9cbb9434a1ff072f60f17c60e25110bc813f659 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 17:13:47 +0000 Subject: [PATCH 421/595] Move numba/targets/dictimpl.py to numba/typed --- numba/core/cpu.py | 2 -- numba/tests/support.py | 2 +- numba/{targets => typed}/dictimpl.py | 0 3 files changed, 1 insertion(+), 3 deletions(-) rename numba/{targets => typed}/dictimpl.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 56313ec60e6..609714d6f26 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -9,7 +9,6 @@ from numba.core.base import BaseContext, PYOBJECT from numba.core import utils, types, config, cgutils, callconv, codegen, externals, fastmathpass, intrinsics from numba.core.utils import cached_property -from numba.targets import dictimpl from numba.core.options import TargetOptions from numba.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock @@ -18,7 +17,6 @@ InlineOptions) from numba.cpython import setobj, listobj - # Keep those structures in sync with _dynfunc.c. class ClosureBody(cgutils.Structure): diff --git a/numba/tests/support.py b/numba/tests/support.py index 5d2d4d664a6..5a0c79f451d 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -714,7 +714,7 @@ def fail(*args, **kwargs): # XXX use the mock library instead? for name in patchpoints: parts = name.split('.') - obj = numba.core.codegen + obj = codegen for attrname in parts[:-1]: obj = getattr(obj, attrname) attrname = parts[-1] diff --git a/numba/targets/dictimpl.py b/numba/typed/dictimpl.py similarity index 100% rename from numba/targets/dictimpl.py rename to numba/typed/dictimpl.py From 7c16dd1a6ae99e00202be0860a5fc3181a0a6f8f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 31 Jan 2020 17:15:14 +0000 Subject: [PATCH 422/595] Move numba/targets/polynomial.py to numba/np --- numba/core/base.py | 4 ++-- numba/{targets => np}/polynomial.py | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{targets => np}/polynomial.py (100%) diff --git a/numba/core/base.py b/numba/core/base.py index 4fcaba4ce96..4f68fdd1cde 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -269,12 +269,12 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import (arraymath, polynomial) + from numba.targets import arraymath from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, iterators, numbers, rangeobj) from numba.core import optional from numba.misc import gdb_hook, literal - from numba.np import linalg + from numba.np import linalg, polynomial try: from numba.targets import npdatetime diff --git a/numba/targets/polynomial.py b/numba/np/polynomial.py similarity index 100% rename from numba/targets/polynomial.py rename to numba/np/polynomial.py From c68d1dc0b7c96d105003eb56b59695fa3044a4de Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 10:16:42 +0000 Subject: [PATCH 423/595] Move numba/typedobjectutils.py to numba/typed --- numba/dictobject.py | 2 +- numba/listobject.py | 2 +- numba/tests/test_dictobject.py | 2 +- numba/tests/test_typedobjectutils.py | 2 +- numba/{ => typed}/typedobjectutils.py | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename numba/{ => typed}/typedobjectutils.py (100%) diff --git a/numba/dictobject.py b/numba/dictobject.py index 8f0bcc57c0d..308b8e5c81a 100644 --- a/numba/dictobject.py +++ b/numba/dictobject.py @@ -30,7 +30,7 @@ from numba.core.imputils import impl_ret_borrowed, RefType from numba.core.errors import TypingError from numba.core import typing -from numba.typedobjectutils import (_as_bytes, +from numba.typed.typedobjectutils import (_as_bytes, _cast, _nonoptional, _sentry_safe_cast_default, diff --git a/numba/listobject.py b/numba/listobject.py index db0e8886d87..dfae2ea8566 100644 --- a/numba/listobject.py +++ b/numba/listobject.py @@ -30,7 +30,7 @@ from numba.core.imputils import impl_ret_borrowed, RefType from numba.core.errors import TypingError from numba.core import typing -from numba.typedobjectutils import (_as_bytes, +from numba.typed.typedobjectutils import (_as_bytes, _cast, _nonoptional, _get_incref_decref, diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 09ca4591477..05cdf7b43b9 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -15,7 +15,7 @@ from numba import int32, int64, float32, float64 from numba import dictobject, typeof from numba.typed import Dict -from numba.typedobjectutils import _sentry_safe_cast +from numba.typed.typedobjectutils import _sentry_safe_cast from numba.core.errors import TypingError from numba.core import types from numba.tests.support import (TestCase, MemoryLeakMixin, unittest, override_config, diff --git a/numba/tests/test_typedobjectutils.py b/numba/tests/test_typedobjectutils.py index 2ffd9165f50..f93d6252db8 100644 --- a/numba/tests/test_typedobjectutils.py +++ b/numba/tests/test_typedobjectutils.py @@ -7,7 +7,7 @@ from numba.core import types from numba.tests.support import TestCase -from numba.typedobjectutils import _sentry_safe_cast +from numba.typed.typedobjectutils import _sentry_safe_cast class TestTypedObjectUtils(TestCase): diff --git a/numba/typedobjectutils.py b/numba/typed/typedobjectutils.py similarity index 100% rename from numba/typedobjectutils.py rename to numba/typed/typedobjectutils.py From 8ad951f28fba831ea4dd5494289d8bebff2d5d68 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 10:24:30 +0000 Subject: [PATCH 424/595] Move numba/dictobject.py to numba/typed --- numba/core/cpu.py | 2 +- numba/tests/test_dictobject.py | 4 ++-- numba/{ => typed}/dictobject.py | 0 numba/typed/typeddict.py | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) rename numba/{ => typed}/dictobject.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 609714d6f26..51e23ac4acf 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -128,7 +128,7 @@ def build_set(self, builder, set_type, items): return setobj.build_set(self, builder, set_type, items) def build_map(self, builder, dict_type, item_types, items): - from numba import dictobject + from numba.typed import dictobject return dictobject.build_map(self, builder, dict_type, item_types, items) diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 05cdf7b43b9..b7610a26ee2 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -13,8 +13,8 @@ from numba import njit from numba import int32, int64, float32, float64 -from numba import dictobject, typeof -from numba.typed import Dict +from numba import typeof +from numba.typed import Dict, dictobject from numba.typed.typedobjectutils import _sentry_safe_cast from numba.core.errors import TypingError from numba.core import types diff --git a/numba/dictobject.py b/numba/typed/dictobject.py similarity index 100% rename from numba/dictobject.py rename to numba/typed/dictobject.py diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index b3c01692984..204a05c2d38 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -5,7 +5,7 @@ from numba.core.types import DictType, TypeRef from numba.core.imputils import numba_typeref_ctor -from numba import njit, dictobject, typeof +from numba import njit, typeof from numba.core import types, errors, config, cgutils from numba.extending import ( overload_method, @@ -15,6 +15,7 @@ NativeValue, type_callable, ) +from numba.typed import dictobject @njit From d5ed726efd8abfe55566271a2788fc8e87c66abe Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 10:26:38 +0000 Subject: [PATCH 425/595] Move numba/listobject.py to numba/typed --- numba/tests/test_listobject.py | 2 +- numba/{ => typed}/listobject.py | 0 numba/typed/typedlist.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename numba/{ => typed}/listobject.py (100%) diff --git a/numba/tests/test_listobject.py b/numba/tests/test_listobject.py index f77c8f71846..cad8bf392a6 100644 --- a/numba/tests/test_listobject.py +++ b/numba/tests/test_listobject.py @@ -15,9 +15,9 @@ from numba import int32 from numba.core import types from numba.core.errors import TypingError -from numba import listobject from numba.tests.support import (TestCase, MemoryLeakMixin, override_config, forbid_codegen) +from numba.typed import listobject class TestCreateAppendLength(MemoryLeakMixin, TestCase): diff --git a/numba/listobject.py b/numba/typed/listobject.py similarity index 100% rename from numba/listobject.py rename to numba/typed/listobject.py diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index ef262163395..18d9a37a33c 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -12,7 +12,6 @@ from numba.core.types import ListType, TypeRef from numba.core.imputils import numba_typeref_ctor -from numba import listobject from numba.core.dispatcher import Dispatcher from numba.core import types, errors, config, cgutils from numba import njit, typeof @@ -24,6 +23,7 @@ NativeValue, type_callable, ) +from numba.typed import listobject @njit From 96c31a7c9fa80e10c12a36c6f793a8ac68c9c099 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 10:27:38 +0000 Subject: [PATCH 426/595] Add numba.np.unsafe submodule --- numba/np/unsafe/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/np/unsafe/__init__.py diff --git a/numba/np/unsafe/__init__.py b/numba/np/unsafe/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 4cd21a050256d155e2f7f4026d69004d09e70269 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 10:36:48 +0000 Subject: [PATCH 427/595] Move numba/unsafe/ndarray.py to numba/np/unsafe --- numba/core/inline_closurecall.py | 2 +- numba/cuda/cudadrv/devicearray.py | 2 +- numba/{ => np}/unsafe/ndarray.py | 0 numba/tests/test_parfors.py | 2 +- numba/tests/test_unsafe_intrinsics.py | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename numba/{ => np}/unsafe/ndarray.py (100%) diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 4d1ace43439..ec91460a77c 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -32,7 +32,7 @@ compute_live_variables) from numba.cpython.rangeobj import range_iter_len -from numba.unsafe.ndarray import empty_inferred as unsafe_empty_inferred +from numba.np.unsafe.ndarray import empty_inferred as unsafe_empty_inferred import numpy as np import operator diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index fc0fe526710..06ec8c75baf 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -18,7 +18,7 @@ from numba.cuda.cudadrv import devices from numba import numpy_support from numba.core import types -from numba.unsafe.ndarray import to_fixed_tuple +from numba.np.unsafe.ndarray import to_fixed_tuple from numba.misc import dummyarray try: diff --git a/numba/unsafe/ndarray.py b/numba/np/unsafe/ndarray.py similarity index 100% rename from numba/unsafe/ndarray.py rename to numba/np/unsafe/ndarray.py diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 3bef80b1462..fe6b853c94c 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -27,7 +27,7 @@ from numba.core.ir_utils import (find_callname, guard, build_definitions, get_definition, is_getitem, is_setitem, index_var_of_get_setitem) -from numba.unsafe.ndarray import empty_inferred as unsafe_empty +from numba.np.unsafe.ndarray import empty_inferred as unsafe_empty from numba.core.compiler import compile_isolated, Flags from numba.core.bytecode import ByteCodeIter from numba.tests.support import (TestCase, captured_stdout, MemoryLeakMixin, diff --git a/numba/tests/test_unsafe_intrinsics.py b/numba/tests/test_unsafe_intrinsics.py index a128e3fbc06..07e9e5f6cd3 100644 --- a/numba/tests/test_unsafe_intrinsics.py +++ b/numba/tests/test_unsafe_intrinsics.py @@ -5,7 +5,7 @@ from numba import njit from numba.core import types from numba.cpython.unsafe.tuple import tuple_setitem -from numba.unsafe.ndarray import to_fixed_tuple, empty_inferred +from numba.np.unsafe.ndarray import to_fixed_tuple, empty_inferred from numba.core.unsafe.bytes import memcpy_region from numba.core.unsafe.refcount import dump_refcount from numba.cpython.unsafe.numbers import trailing_zeros, leading_zeros From 39f985a7eccce25b5e45e73a063a697371882915 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 11:16:32 +0000 Subject: [PATCH 428/595] Move numba/unittest_support.py to numba/testing --- numba/core/datamodel/testing.py | 2 +- numba/cuda/testing.py | 2 +- numba/cuda/tests/cudadrv/test_profiler.py | 2 +- numba/cuda/tests/cudapy/test_alignment.py | 2 +- numba/cuda/tests/cudapy/test_array_methods.py | 2 +- numba/cuda/tests/cudapy/test_casting.py | 2 +- numba/cuda/tests/cudapy/test_cuda_autojit.py | 2 +- numba/cuda/tests/cudapy/test_datetime.py | 2 +- numba/cuda/tests/cudapy/test_debug.py | 2 +- numba/cuda/tests/cudapy/test_debuginfo.py | 2 +- numba/cuda/tests/cudapy/test_deprecation.py | 2 +- numba/cuda/tests/cudapy/test_fastmath.py | 2 +- numba/cuda/tests/cudapy/test_forall.py | 2 +- numba/cuda/tests/cudapy/test_gufunc.py | 2 +- numba/cuda/tests/cudapy/test_gufunc_scalar.py | 2 +- .../cuda/tests/cudapy/test_gufunc_scheduling.py | 2 +- numba/cuda/tests/cudapy/test_ipc.py | 2 +- numba/cuda/tests/cudapy/test_multigpu.py | 2 +- numba/cuda/tests/cudapy/test_multiprocessing.py | 2 +- numba/cuda/tests/cudapy/test_multithreads.py | 2 +- numba/cuda/tests/cudapy/test_print.py | 2 +- numba/cuda/tests/cudapy/test_record_dtype.py | 2 +- numba/cuda/tests/cudapy/test_reduction.py | 2 +- .../cudapy/test_retrieve_autoconverted_arrays.py | 2 +- numba/cuda/tests/cudapy/test_serialize.py | 2 +- numba/cuda/tests/cudapy/test_vectorize.py | 2 +- .../cuda/tests/cudapy/test_vectorize_complex.py | 2 +- numba/cuda/tests/cudapy/test_vectorize_decor.py | 2 +- numba/cuda/tests/cudapy/test_vectorize_device.py | 2 +- .../tests/cudapy/test_vectorize_scalar_arg.py | 2 +- numba/cuda/tests/cudasim/test_cudasim_issues.py | 2 +- numba/cuda/tests/nocuda/test_nvvm.py | 2 +- numba/roc/tests/hsadrv/test_async.py | 2 +- numba/roc/tests/hsadrv/test_driver.py | 2 +- numba/roc/tests/hsapy/test_async_kernel.py | 2 +- numba/roc/tests/hsapy/test_atomics.py | 2 +- numba/roc/tests/hsapy/test_autojit.py | 2 +- numba/roc/tests/hsapy/test_barrier.py | 2 +- numba/roc/tests/hsapy/test_compiler.py | 2 +- numba/roc/tests/hsapy/test_decorator.py | 2 +- numba/roc/tests/hsapy/test_gufuncbuilding.py | 2 +- numba/roc/tests/hsapy/test_intrinsics.py | 2 +- numba/roc/tests/hsapy/test_large_code.py | 2 +- numba/roc/tests/hsapy/test_linkage.py | 2 +- numba/roc/tests/hsapy/test_math.py | 2 +- numba/roc/tests/hsapy/test_matmul.py | 2 +- numba/roc/tests/hsapy/test_memory.py | 2 +- numba/roc/tests/hsapy/test_occupancy.py | 2 +- numba/roc/tests/hsapy/test_positioning.py | 2 +- numba/roc/tests/hsapy/test_reduction.py | 2 +- numba/roc/tests/hsapy/test_scan.py | 2 +- numba/roc/tests/hsapy/test_simple.py | 2 +- numba/roc/tests/hsapy/test_ufuncbuilding.py | 2 +- numba/testing/__init__.py | 2 +- numba/testing/loader.py | 2 +- numba/testing/main.py | 2 +- numba/testing/notebook.py | 2 +- numba/{ => testing}/unittest_support.py | 0 numba/tests/__init__.py | 4 +--- numba/tests/npyufunc/__init__.py | 4 +--- numba/tests/npyufunc/test_caching.py | 3 +-- numba/tests/npyufunc/test_dufunc.py | 2 +- numba/tests/npyufunc/test_errors.py | 2 +- numba/tests/npyufunc/test_gufunc.py | 2 +- .../tests/npyufunc/test_parallel_env_variable.py | 2 +- numba/tests/npyufunc/test_parallel_low_work.py | 3 +-- .../tests/npyufunc/test_parallel_ufunc_issues.py | 2 +- numba/tests/npyufunc/test_ufunc.py | 2 +- numba/tests/npyufunc/test_ufuncbuilding.py | 2 +- numba/tests/npyufunc/test_vectorize_decor.py | 2 +- numba/tests/support.py | 2 +- numba/tests/test_annotations.py | 2 +- numba/tests/test_api.py | 2 +- numba/tests/test_array_analysis.py | 2 +- numba/tests/test_array_attr.py | 2 +- numba/tests/test_array_constants.py | 2 +- numba/tests/test_array_exprs.py | 2 +- numba/tests/test_array_iterators.py | 2 +- numba/tests/test_array_manipulation.py | 2 +- numba/tests/test_array_methods.py | 2 +- numba/tests/test_array_reductions.py | 2 +- numba/tests/test_array_return.py | 2 +- numba/tests/test_auto_constants.py | 2 +- numba/tests/test_blackscholes.py | 2 +- numba/tests/test_boundscheck.py | 2 +- numba/tests/test_buffer_protocol.py | 2 +- numba/tests/test_builtins.py | 2 +- numba/tests/test_casting.py | 2 +- numba/tests/test_cffi.py | 2 +- numba/tests/test_cfunc.py | 2 +- numba/tests/test_cgutils.py | 2 +- numba/tests/test_chained_assign.py | 2 +- numba/tests/test_cli.py | 2 +- numba/tests/test_closure.py | 2 +- numba/tests/test_codegen.py | 2 +- numba/tests/test_compile_cache.py | 2 +- numba/tests/test_complex.py | 2 +- numba/tests/test_comprehension.py | 7 ++++--- numba/tests/test_conversion.py | 2 +- numba/tests/test_copy_propagate.py | 2 +- numba/tests/test_ctypes.py | 2 +- numba/tests/test_dataflow.py | 2 +- numba/tests/test_datamodel.py | 2 +- numba/tests/test_debug.py | 2 +- numba/tests/test_debuginfo.py | 2 +- numba/tests/test_del.py | 2 +- numba/tests/test_deprecations.py | 2 +- numba/tests/test_dicts.py | 2 +- numba/tests/test_dispatcher.py | 2 +- numba/tests/test_dummyarray.py | 2 +- numba/tests/test_dyn_array.py | 2 +- numba/tests/test_enums.py | 2 +- numba/tests/test_errorhandling.py | 2 +- numba/tests/test_errormodels.py | 2 +- numba/tests/test_exceptions.py | 2 +- numba/tests/test_extended_arg.py | 2 +- numba/tests/test_extending.py | 4 +++- numba/tests/test_extending_types.py | 2 +- numba/tests/test_fancy_indexing.py | 2 +- numba/tests/test_fastmath.py | 2 +- numba/tests/test_flow_control.py | 2 +- numba/tests/test_func_interface.py | 2 +- numba/tests/test_func_lifetime.py | 2 +- numba/tests/test_gdb.py | 2 +- numba/tests/test_generators.py | 2 +- numba/tests/test_gil.py | 2 +- numba/tests/test_globals.py | 2 +- numba/tests/test_hashing.py | 4 ++-- numba/tests/test_import.py | 2 +- numba/tests/test_indexing.py | 2 +- numba/tests/test_inlining.py | 2 +- numba/tests/test_interproc.py | 2 +- numba/tests/test_intwidth.py | 2 +- numba/tests/test_ir.py | 2 +- numba/tests/test_itanium_mangler.py | 2 +- numba/tests/test_iteration.py | 2 +- numba/tests/test_jit_module.py | 2 +- numba/tests/test_jitclasses.py | 2 +- numba/tests/test_jitmethod.py | 2 +- numba/tests/test_linalg.py | 2 +- numba/tests/test_lists.py | 2 +- numba/tests/test_literal_dispatch.py | 2 +- numba/tests/test_llvm_version_check.py | 2 +- numba/tests/test_locals.py | 2 +- numba/tests/test_looplifting.py | 2 +- .../tests/test_make_function_to_jit_function.py | 2 +- numba/tests/test_mandelbrot.py | 2 +- numba/tests/test_map_filter_reduce.py | 2 +- numba/tests/test_mathlib.py | 2 +- numba/tests/test_maxmin.py | 2 +- numba/tests/test_multi3.py | 2 +- numba/tests/test_nan.py | 2 +- numba/tests/test_nested_calls.py | 2 +- numba/tests/test_np_functions.py | 2 +- numba/tests/test_npdatetime.py | 2 +- numba/tests/test_nrt.py | 2 +- numba/tests/test_nrt_refct.py | 2 +- numba/tests/test_numberctor.py | 2 +- numba/tests/test_numconv.py | 2 +- numba/tests/test_numpy_support.py | 2 +- numba/tests/test_numpyadapt.py | 2 +- numba/tests/test_obj_lifetime.py | 2 +- numba/tests/test_object_mode.py | 2 +- numba/tests/test_objects.py | 2 +- numba/tests/test_operators.py | 2 +- numba/tests/test_optional.py | 2 +- numba/tests/test_overlap.py | 2 +- numba/tests/test_parallel_backend.py | 2 +- numba/tests/test_parfors.py | 2 +- numba/tests/test_polynomial.py | 2 +- numba/tests/test_print.py | 2 +- numba/tests/test_profiler.py | 2 +- numba/tests/test_pycc.py | 16 +++++++++------- numba/tests/test_python_int.py | 2 +- numba/tests/test_random.py | 2 +- numba/tests/test_range.py | 2 +- numba/tests/test_recarray_usecases.py | 2 +- numba/tests/test_record_dtype.py | 2 +- numba/tests/test_recursion.py | 2 +- numba/tests/test_remove_dead.py | 2 +- numba/tests/test_return_values.py | 2 +- numba/tests/test_runtests.py | 2 +- numba/tests/test_serialize.py | 2 +- numba/tests/test_sets.py | 4 ++-- numba/tests/test_slices.py | 2 +- numba/tests/test_sort.py | 2 +- numba/tests/test_stencils.py | 2 +- numba/tests/test_storeslice.py | 2 +- numba/tests/test_support.py | 2 +- numba/tests/test_svml.py | 3 ++- numba/tests/test_target_overloadselector.py | 2 +- numba/tests/test_threadsafety.py | 2 +- numba/tests/test_tracing.py | 2 +- numba/tests/test_tuples.py | 2 +- numba/tests/test_typeconv.py | 2 +- numba/tests/test_typeinfer.py | 2 +- numba/tests/test_typenames.py | 2 +- numba/tests/test_typeof.py | 2 +- numba/tests/test_types.py | 2 +- numba/tests/test_typingerror.py | 2 +- numba/tests/test_ufuncs.py | 2 +- numba/tests/test_unicode.py | 2 +- numba/tests/test_unicode_array.py | 2 +- numba/tests/test_unpack_sequence.py | 2 +- numba/tests/test_usecases.py | 2 +- numba/tests/test_vectorization_type_inference.py | 2 +- numba/tests/test_warnings.py | 2 +- numba/tests/test_withlifting.py | 2 +- numba/tests/test_wrapper.py | 2 +- 209 files changed, 224 insertions(+), 224 deletions(-) rename numba/{ => testing}/unittest_support.py (100%) diff --git a/numba/core/datamodel/testing.py b/numba/core/datamodel/testing.py index 8f5d3484dc5..80c4df8a20c 100644 --- a/numba/core/datamodel/testing.py +++ b/numba/core/datamodel/testing.py @@ -1,8 +1,8 @@ from llvmlite import ir from llvmlite import binding as ll -from numba import unittest_support as unittest from numba.core import datamodel +from numba.testing import unittest_support as unittest class DataModelTester(unittest.TestCase): diff --git a/numba/cuda/testing.py b/numba/cuda/testing.py index 440580cc3b9..f861101aed6 100644 --- a/numba/cuda/testing.py +++ b/numba/cuda/testing.py @@ -1,7 +1,6 @@ import contextlib import sys -from numba import unittest_support as unittest from numba.tests.support import ( captured_stdout, SerialMixin, @@ -9,6 +8,7 @@ ) from numba.cuda.cuda_paths import get_conda_ctk from numba.core import config +from numba.testing import unittest_support as unittest class CUDATestCase(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudadrv/test_profiler.py b/numba/cuda/tests/cudadrv/test_profiler.py index 0c0bf037a6c..2b03477ed01 100644 --- a/numba/cuda/tests/cudadrv/test_profiler.py +++ b/numba/cuda/tests/cudadrv/test_profiler.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.cuda.testing import CUDATestCase from numba import cuda from numba.cuda.testing import skip_on_cudasim diff --git a/numba/cuda/tests/cudapy/test_alignment.py b/numba/cuda/tests/cudapy/test_alignment.py index 877c5f290ea..8589d721e7d 100644 --- a/numba/cuda/tests/cudapy/test_alignment.py +++ b/numba/cuda/tests/cudapy/test_alignment.py @@ -1,7 +1,7 @@ import numpy as np from numba import from_dtype, cuda -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest class TestAlignment(SerialMixin, unittest.TestCase): def test_record_alignment(self): diff --git a/numba/cuda/tests/cudapy/test_array_methods.py b/numba/cuda/tests/cudapy/test_array_methods.py index 88fbe45f16e..0908976af67 100644 --- a/numba/cuda/tests/cudapy/test_array_methods.py +++ b/numba/cuda/tests/cudapy/test_array_methods.py @@ -1,7 +1,7 @@ -from numba import unittest_support as unittest import numpy as np from numba import cuda from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest def reinterpret_array_type(byte_arr, start, stop, output): diff --git a/numba/cuda/tests/cudapy/test_casting.py b/numba/cuda/tests/cudapy/test_casting.py index b6f5e0e51f2..2a0d236df0b 100644 --- a/numba/cuda/tests/cudapy/test_casting.py +++ b/numba/cuda/tests/cudapy/test_casting.py @@ -1,10 +1,10 @@ import struct import numpy as np -from numba import unittest_support as unittest from numba import cuda from numba.core import types from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest def float_to_int(x): diff --git a/numba/cuda/tests/cudapy/test_cuda_autojit.py b/numba/cuda/tests/cudapy/test_cuda_autojit.py index a8df6f2b2d4..770219b53ec 100644 --- a/numba/cuda/tests/cudapy/test_cuda_autojit.py +++ b/numba/cuda/tests/cudapy/test_cuda_autojit.py @@ -1,7 +1,7 @@ -from numba import unittest_support as unittest from numba import cuda import numpy as np from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest class TestCudaAutojit(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_datetime.py b/numba/cuda/tests/cudapy/test_datetime.py index da9f3628de5..c2b1a95b24f 100644 --- a/numba/cuda/tests/cudapy/test_datetime.py +++ b/numba/cuda/tests/cudapy/test_datetime.py @@ -1,10 +1,10 @@ import numpy as np from numba import cuda, vectorize, guvectorize -from numba import unittest_support as unittest from numba.numpy_support import from_dtype from numba.tests.support import TestCase from numba.cuda.testing import SerialMixin, skip_on_cudasim +from numba.testing import unittest_support as unittest class TestCudaDateTime(SerialMixin, TestCase): diff --git a/numba/cuda/tests/cudapy/test_debug.py b/numba/cuda/tests/cudapy/test_debug.py index 5399fa18f2c..a3dd62c9e21 100644 --- a/numba/cuda/tests/cudapy/test_debug.py +++ b/numba/cuda/tests/cudapy/test_debug.py @@ -3,8 +3,8 @@ from numba.cuda.testing import skip_on_cudasim, SerialMixin from numba.tests.support import (override_config, captured_stderr, captured_stdout) -from numba import unittest_support as unittest from numba import cuda, float64 +from numba.testing import unittest_support as unittest def simple_cuda(A, B): diff --git a/numba/cuda/tests/cudapy/test_debuginfo.py b/numba/cuda/tests/cudapy/test_debuginfo.py index 4b09bc5edf5..c3ae6945d40 100644 --- a/numba/cuda/tests/cudapy/test_debuginfo.py +++ b/numba/cuda/tests/cudapy/test_debuginfo.py @@ -1,9 +1,9 @@ from numba.tests.support import override_config, TestCase from numba.cuda.testing import skip_on_cudasim -from numba import unittest_support as unittest from numba import cuda from numba.core import types from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim('Simulator does not produce debug dumps') diff --git a/numba/cuda/tests/cudapy/test_deprecation.py b/numba/cuda/tests/cudapy/test_deprecation.py index 9eff8ce608b..2c2eaf861d0 100644 --- a/numba/cuda/tests/cudapy/test_deprecation.py +++ b/numba/cuda/tests/cudapy/test_deprecation.py @@ -3,10 +3,10 @@ from numba.tests.support import override_config, TestCase from numba.cuda.testing import skip_on_cudasim -from numba import unittest_support as unittest from numba import cuda from numba.core import types from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim("Skipped on simulator") diff --git a/numba/cuda/tests/cudapy/test_fastmath.py b/numba/cuda/tests/cudapy/test_fastmath.py index 11ddd1475d9..dd1c6e2026f 100644 --- a/numba/cuda/tests/cudapy/test_fastmath.py +++ b/numba/cuda/tests/cudapy/test_fastmath.py @@ -1,8 +1,8 @@ import numpy as np -from numba import unittest_support as unittest from numba import cuda, float32 from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest class TestFastMathOption(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_forall.py b/numba/cuda/tests/cudapy/test_forall.py index 5d55fd4bb7c..cb619c6868f 100644 --- a/numba/cuda/tests/cudapy/test_forall.py +++ b/numba/cuda/tests/cudapy/test_forall.py @@ -1,7 +1,7 @@ import numpy as np from numba import cuda -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.cuda.testing import SerialMixin diff --git a/numba/cuda/tests/cudapy/test_gufunc.py b/numba/cuda/tests/cudapy/test_gufunc.py index ceac7f16bff..93028561394 100644 --- a/numba/cuda/tests/cudapy/test_gufunc.py +++ b/numba/cuda/tests/cudapy/test_gufunc.py @@ -4,8 +4,8 @@ from numba import void, float32, float64 from numba import guvectorize from numba import cuda -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_gufunc_scalar.py b/numba/cuda/tests/cudapy/test_gufunc_scalar.py index 07caa2589a3..73e78173a0d 100644 --- a/numba/cuda/tests/cudapy/test_gufunc_scalar.py +++ b/numba/cuda/tests/cudapy/test_gufunc_scalar.py @@ -5,9 +5,9 @@ """ import numpy as np from numba import guvectorize, cuda -from numba import unittest_support as unittest from numba.tests.support import TestCase from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py index 6a5559a3f3a..0ad41d227c9 100644 --- a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +++ b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py @@ -1,5 +1,5 @@ from numba.npyufunc.deviceufunc import GUFuncEngine -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest def template(signature, shapes, expects): diff --git a/numba/cuda/tests/cudapy/test_ipc.py b/numba/cuda/tests/cudapy/test_ipc.py index 39d1d5ff1e2..7af11abd6bc 100644 --- a/numba/cuda/tests/cudapy/test_ipc.py +++ b/numba/cuda/tests/cudapy/test_ipc.py @@ -7,8 +7,8 @@ from numba import cuda from numba.cuda.cudadrv import drvapi, devicearray -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, CUDATestCase +from numba.testing import unittest_support as unittest not_linux = not sys.platform.startswith('linux') diff --git a/numba/cuda/tests/cudapy/test_multigpu.py b/numba/cuda/tests/cudapy/test_multigpu.py index 0ad157e7294..ce68450f87a 100644 --- a/numba/cuda/tests/cudapy/test_multigpu.py +++ b/numba/cuda/tests/cudapy/test_multigpu.py @@ -1,8 +1,8 @@ from numba import cuda import numpy as np -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin import threading +from numba.testing import unittest_support as unittest class TestMultiGPUContext(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_multiprocessing.py b/numba/cuda/tests/cudapy/test_multiprocessing.py index fb21bad7ce7..78270168301 100644 --- a/numba/cuda/tests/cudapy/test_multiprocessing.py +++ b/numba/cuda/tests/cudapy/test_multiprocessing.py @@ -4,8 +4,8 @@ import numpy as np from numba import cuda -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest has_mp_get_context = hasattr(mp, 'get_context') is_unix = os.name == 'posix' diff --git a/numba/cuda/tests/cudapy/test_multithreads.py b/numba/cuda/tests/cudapy/test_multithreads.py index 7337241b259..8b382d3ba15 100644 --- a/numba/cuda/tests/cudapy/test_multithreads.py +++ b/numba/cuda/tests/cudapy/test_multithreads.py @@ -3,8 +3,8 @@ import multiprocessing import numpy as np from numba import cuda -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest try: from concurrent.futures import ThreadPoolExecutor diff --git a/numba/cuda/tests/cudapy/test_print.py b/numba/cuda/tests/cudapy/test_print.py index 891b48a596b..9c2f41e8a3f 100644 --- a/numba/cuda/tests/cudapy/test_print.py +++ b/numba/cuda/tests/cudapy/test_print.py @@ -1,8 +1,8 @@ import numpy as np from numba import cuda -from numba import unittest_support as unittest from numba.cuda.testing import captured_cuda_stdout, SerialMixin +from numba.testing import unittest_support as unittest def cuhello(): diff --git a/numba/cuda/tests/cudapy/test_record_dtype.py b/numba/cuda/tests/cudapy/test_record_dtype.py index 3471b7f4786..9ddb8fd84c9 100644 --- a/numba/cuda/tests/cudapy/test_record_dtype.py +++ b/numba/cuda/tests/cudapy/test_record_dtype.py @@ -3,8 +3,8 @@ import numpy as np from numba import cuda, numpy_support from numba.core import types -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest def set_a(ary, i, v): diff --git a/numba/cuda/tests/cudapy/test_reduction.py b/numba/cuda/tests/cudapy/test_reduction.py index 12337cc228a..9a934010598 100644 --- a/numba/cuda/tests/cudapy/test_reduction.py +++ b/numba/cuda/tests/cudapy/test_reduction.py @@ -1,8 +1,8 @@ import numpy as np from numba import cuda -from numba import unittest_support as unittest from numba.core.config import ENABLE_CUDASIM from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest # Avoid recompilation of the sum_reduce function by keeping it at global scope sum_reduce = cuda.Reduce(lambda a, b: a + b) diff --git a/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py b/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py index f513e6b8072..f0a0a4ccb85 100644 --- a/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +++ b/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py @@ -1,9 +1,9 @@ import numpy as np from numba import cuda -from numba import unittest_support as unittest from numba.cuda.args import wrap_arg from numba.cuda.testing import SerialMixin +from numba.testing import unittest_support as unittest class DefaultIn(object): diff --git a/numba/cuda/tests/cudapy/test_serialize.py b/numba/cuda/tests/cudapy/test_serialize.py index 69b7c57ac7a..52a4fd517ee 100644 --- a/numba/cuda/tests/cudapy/test_serialize.py +++ b/numba/cuda/tests/cudapy/test_serialize.py @@ -2,8 +2,8 @@ import numpy as np from numba import cuda, vectorize, numpy_support from numba.core import types -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim('pickling not supported in CUDASIM') diff --git a/numba/cuda/tests/cudapy/test_vectorize.py b/numba/cuda/tests/cudapy/test_vectorize.py index 5823af409a9..c40f7dea247 100644 --- a/numba/cuda/tests/cudapy/test_vectorize.py +++ b/numba/cuda/tests/cudapy/test_vectorize.py @@ -2,10 +2,10 @@ from numba import vectorize from numba import cuda, int32, float32, float64 -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim from numba.cuda.testing import CUDATestCase from numba.core import config +from numba.testing import unittest_support as unittest sig = [int32(int32, int32), float32(float32, float32), diff --git a/numba/cuda/tests/cudapy/test_vectorize_complex.py b/numba/cuda/tests/cudapy/test_vectorize_complex.py index e06c20888f8..5ec227110d3 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_complex.py +++ b/numba/cuda/tests/cudapy/test_vectorize_complex.py @@ -1,7 +1,7 @@ import numpy as np from numba import vectorize -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_vectorize_decor.py b/numba/cuda/tests/cudapy/test_vectorize_decor.py index 9e0b0ef4fae..d4c24096e79 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_decor.py +++ b/numba/cuda/tests/cudapy/test_vectorize_decor.py @@ -1,10 +1,10 @@ import numpy as np -from numba import unittest_support as unittest from numba import vectorize, cuda from numba.tests.npyufunc.test_vectorize_decor import BaseVectorizeDecor, \ BaseVectorizeNopythonArg, BaseVectorizeUnrecognizedArg from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_vectorize_device.py b/numba/cuda/tests/cudapy/test_vectorize_device.py index dbdbe62374b..7948ffe7617 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_device.py +++ b/numba/cuda/tests/cudapy/test_vectorize_device.py @@ -1,8 +1,8 @@ from numba import vectorize from numba import cuda, float32 import numpy as np -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin +from numba.testing import unittest_support as unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py index c8184561947..496ac22a88b 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +++ b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py @@ -1,9 +1,9 @@ import numpy as np from numba import vectorize from numba import cuda, float64 -from numba import unittest_support as unittest from numba.cuda.testing import skip_on_cudasim, SerialMixin from numba.core import config +from numba.testing import unittest_support as unittest sig = [float64(float64, float64)] diff --git a/numba/cuda/tests/cudasim/test_cudasim_issues.py b/numba/cuda/tests/cudasim/test_cudasim_issues.py index 699c98aa2b0..796759e127d 100644 --- a/numba/cuda/tests/cudasim/test_cudasim_issues.py +++ b/numba/cuda/tests/cudasim/test_cudasim_issues.py @@ -2,10 +2,10 @@ import numpy as np -from numba import unittest_support as unittest from numba import cuda from numba.cuda.testing import SerialMixin, skip_unless_cudasim import numba.cuda.simulator as simulator +from numba.testing import unittest_support as unittest class TestCudaSimIssues(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/nocuda/test_nvvm.py b/numba/cuda/tests/nocuda/test_nvvm.py index e2991204185..7cc464c3260 100644 --- a/numba/cuda/tests/nocuda/test_nvvm.py +++ b/numba/cuda/tests/nocuda/test_nvvm.py @@ -1,8 +1,8 @@ from numba.cuda.compiler import compile_kernel from numba.cuda.cudadrv import nvvm from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba import unittest_support as unittest from numba.core import types, utils +from numba.testing import unittest_support as unittest @skip_on_cudasim('libNVVM not supported in simulator') diff --git a/numba/roc/tests/hsadrv/test_async.py b/numba/roc/tests/hsadrv/test_async.py index b1b33d09c95..2221141ff24 100644 --- a/numba/roc/tests/hsadrv/test_async.py +++ b/numba/roc/tests/hsadrv/test_async.py @@ -1,7 +1,7 @@ import numpy as np from numba import roc -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.roc.hsadrv.driver import dgpu_present diff --git a/numba/roc/tests/hsadrv/test_driver.py b/numba/roc/tests/hsadrv/test_driver.py index d14c4458b34..10d504226eb 100644 --- a/numba/roc/tests/hsadrv/test_driver.py +++ b/numba/roc/tests/hsadrv/test_driver.py @@ -4,7 +4,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.roc.hsadrv.driver import hsa, Queue, Program, Executable,\ BrigModule, Context, dgpu_present diff --git a/numba/roc/tests/hsapy/test_async_kernel.py b/numba/roc/tests/hsapy/test_async_kernel.py index 58e92f2900e..ee532ae0eff 100644 --- a/numba/roc/tests/hsapy/test_async_kernel.py +++ b/numba/roc/tests/hsapy/test_async_kernel.py @@ -7,7 +7,7 @@ import numpy as np from numba import roc -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.roc.hsadrv.driver import dgpu_present logger = logging.getLogger() diff --git a/numba/roc/tests/hsapy/test_atomics.py b/numba/roc/tests/hsapy/test_atomics.py index 117232d0f7a..ee9d2eff282 100644 --- a/numba/roc/tests/hsapy/test_atomics.py +++ b/numba/roc/tests/hsapy/test_atomics.py @@ -2,7 +2,7 @@ import numba from numba import roc -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest def atomic_add(ary): diff --git a/numba/roc/tests/hsapy/test_autojit.py b/numba/roc/tests/hsapy/test_autojit.py index 606dcb46189..0279a218bba 100644 --- a/numba/roc/tests/hsapy/test_autojit.py +++ b/numba/roc/tests/hsapy/test_autojit.py @@ -1,6 +1,6 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import roc diff --git a/numba/roc/tests/hsapy/test_barrier.py b/numba/roc/tests/hsapy/test_barrier.py index 61dff0ed3e9..506845af8c6 100644 --- a/numba/roc/tests/hsapy/test_barrier.py +++ b/numba/roc/tests/hsapy/test_barrier.py @@ -1,7 +1,7 @@ import numpy as np -from numba import unittest_support as unittest from numba import roc, float32 +from numba.testing import unittest_support as unittest class TestBarrier(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_compiler.py b/numba/roc/tests/hsapy/test_compiler.py index 1ad80190cca..527c32f04d1 100644 --- a/numba/roc/tests/hsapy/test_compiler.py +++ b/numba/roc/tests/hsapy/test_compiler.py @@ -2,7 +2,7 @@ import os import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import roc from numba.core import types from numba.roc import compiler diff --git a/numba/roc/tests/hsapy/test_decorator.py b/numba/roc/tests/hsapy/test_decorator.py index f1dc16169a7..a062b8923db 100644 --- a/numba/roc/tests/hsapy/test_decorator.py +++ b/numba/roc/tests/hsapy/test_decorator.py @@ -1,6 +1,6 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import roc diff --git a/numba/roc/tests/hsapy/test_gufuncbuilding.py b/numba/roc/tests/hsapy/test_gufuncbuilding.py index a7c4f4d5542..94a4e905110 100644 --- a/numba/roc/tests/hsapy/test_gufuncbuilding.py +++ b/numba/roc/tests/hsapy/test_gufuncbuilding.py @@ -1,9 +1,9 @@ import numpy as np -from numba import unittest_support as unittest from numba.roc.vectorizers import HsaGUFuncVectorize from numba.roc.dispatch import HSAGenerializedUFunc from numba import guvectorize +from numba.testing import unittest_support as unittest def ufunc_add_core(a, b, c): diff --git a/numba/roc/tests/hsapy/test_intrinsics.py b/numba/roc/tests/hsapy/test_intrinsics.py index 793e4263d5c..385b00a8556 100644 --- a/numba/roc/tests/hsapy/test_intrinsics.py +++ b/numba/roc/tests/hsapy/test_intrinsics.py @@ -1,9 +1,9 @@ import numpy as np -from numba import unittest_support as unittest from numba import roc from numba.core.errors import TypingError import operator as oper +from numba.testing import unittest_support as unittest _WAVESIZE = roc.get_context().agent.wavefront_size diff --git a/numba/roc/tests/hsapy/test_large_code.py b/numba/roc/tests/hsapy/test_large_code.py index 46e98318a57..77dc2e39af9 100644 --- a/numba/roc/tests/hsapy/test_large_code.py +++ b/numba/roc/tests/hsapy/test_large_code.py @@ -5,7 +5,7 @@ import math import numba -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest class TestLargeCode(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_linkage.py b/numba/roc/tests/hsapy/test_linkage.py index 69494dcea99..a211a48038e 100644 --- a/numba/roc/tests/hsapy/test_linkage.py +++ b/numba/roc/tests/hsapy/test_linkage.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import roc diff --git a/numba/roc/tests/hsapy/test_math.py b/numba/roc/tests/hsapy/test_math.py index a30c59f9d08..3e7119dc7c2 100644 --- a/numba/roc/tests/hsapy/test_math.py +++ b/numba/roc/tests/hsapy/test_math.py @@ -1,7 +1,7 @@ import numpy as np import math -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import roc from numba.core import utils diff --git a/numba/roc/tests/hsapy/test_matmul.py b/numba/roc/tests/hsapy/test_matmul.py index 1b42dc266f7..17c72a1e119 100644 --- a/numba/roc/tests/hsapy/test_matmul.py +++ b/numba/roc/tests/hsapy/test_matmul.py @@ -1,9 +1,9 @@ from timeit import default_timer as timer import numpy as np -from numba import unittest_support as unittest from numba import roc, float32 from numba.roc.hsadrv.error import HsaKernelLaunchError +from numba.testing import unittest_support as unittest class TestMatMul(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_memory.py b/numba/roc/tests/hsapy/test_memory.py index 8102da54c2c..f099bfdd099 100644 --- a/numba/roc/tests/hsapy/test_memory.py +++ b/numba/roc/tests/hsapy/test_memory.py @@ -7,7 +7,7 @@ import numpy as np from numba import roc -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.roc.hsadrv.driver import dgpu_present logger = logging.getLogger() diff --git a/numba/roc/tests/hsapy/test_occupancy.py b/numba/roc/tests/hsapy/test_occupancy.py index 66e46217818..8cf84f889cb 100644 --- a/numba/roc/tests/hsapy/test_occupancy.py +++ b/numba/roc/tests/hsapy/test_occupancy.py @@ -1,5 +1,5 @@ -from numba import unittest_support as unittest from numba.roc.gcn_occupancy import get_limiting_factors +from numba.testing import unittest_support as unittest class TestOccupancy(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_positioning.py b/numba/roc/tests/hsapy/test_positioning.py index fae3a6d7d10..46d134a2aac 100644 --- a/numba/roc/tests/hsapy/test_positioning.py +++ b/numba/roc/tests/hsapy/test_positioning.py @@ -1,6 +1,6 @@ import numpy as np from numba import roc -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest class TestPositioning(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_reduction.py b/numba/roc/tests/hsapy/test_reduction.py index 0bbbe836088..e43c365fcb6 100644 --- a/numba/roc/tests/hsapy/test_reduction.py +++ b/numba/roc/tests/hsapy/test_reduction.py @@ -1,7 +1,7 @@ import numpy as np -from numba import unittest_support as unittest from numba import roc, intp +from numba.testing import unittest_support as unittest WAVESIZE = 64 diff --git a/numba/roc/tests/hsapy/test_scan.py b/numba/roc/tests/hsapy/test_scan.py index 289bd19132d..59487fa3857 100644 --- a/numba/roc/tests/hsapy/test_scan.py +++ b/numba/roc/tests/hsapy/test_scan.py @@ -1,7 +1,7 @@ import numpy as np -from numba import unittest_support as unittest from numba import roc, intp, int32 +from numba.testing import unittest_support as unittest @roc.jit(device=True) diff --git a/numba/roc/tests/hsapy/test_simple.py b/numba/roc/tests/hsapy/test_simple.py index f2f470bca66..1a5738937a0 100644 --- a/numba/roc/tests/hsapy/test_simple.py +++ b/numba/roc/tests/hsapy/test_simple.py @@ -1,7 +1,7 @@ import numpy as np from numba import roc from numba.roc.hsadrv.error import HsaKernelLaunchError -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest class TestSimple(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_ufuncbuilding.py b/numba/roc/tests/hsapy/test_ufuncbuilding.py index 64c8a65a456..c8288bddd53 100644 --- a/numba/roc/tests/hsapy/test_ufuncbuilding.py +++ b/numba/roc/tests/hsapy/test_ufuncbuilding.py @@ -1,9 +1,9 @@ import numpy as np -from numba import unittest_support as unittest from numba import vectorize from numba.roc.vectorizers import HsaVectorize from numba.roc.dispatch import HsaUFuncDispatcher +from numba.testing import unittest_support as unittest def ufunc_add_core(a, b): diff --git a/numba/testing/__init__.py b/numba/testing/__init__.py index 6ed3aeb0821..ec307f75c1b 100644 --- a/numba/testing/__init__.py +++ b/numba/testing/__init__.py @@ -6,7 +6,7 @@ from os.path import join, isfile, relpath, normpath, splitext from .main import NumbaTestProgram, SerialSuite, make_tag_decorator -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core import config diff --git a/numba/testing/loader.py b/numba/testing/loader.py index 694be166c8e..3c953f82777 100644 --- a/numba/testing/loader.py +++ b/numba/testing/loader.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from unittest import loader, case from os.path import isdir, isfile, join, dirname, basename diff --git a/numba/testing/main.py b/numba/testing/main.py index 286a725651b..51ff424fa1f 100644 --- a/numba/testing/main.py +++ b/numba/testing/main.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import collections import contextlib diff --git a/numba/testing/notebook.py b/numba/testing/notebook.py index 07e879dd8bc..fb3b75c9482 100644 --- a/numba/testing/notebook.py +++ b/numba/testing/notebook.py @@ -1,4 +1,3 @@ -from numba import unittest_support as unittest from unittest import TestCase from ipykernel.tests import utils @@ -8,6 +7,7 @@ import re import json from copy import copy +from numba.testing import unittest_support as unittest try: # py3 diff --git a/numba/unittest_support.py b/numba/testing/unittest_support.py similarity index 100% rename from numba/unittest_support.py rename to numba/testing/unittest_support.py diff --git a/numba/tests/__init__.py b/numba/tests/__init__.py index 89794cc0c30..51dc0cfaf77 100644 --- a/numba/tests/__init__.py +++ b/numba/tests/__init__.py @@ -1,5 +1,3 @@ -from numba import unittest_support as unittest - import gc from os.path import dirname, join import multiprocessing @@ -8,7 +6,7 @@ import warnings from unittest.suite import TestSuite -from numba.testing import load_testsuite +from numba.testing import load_testsuite, unittest_support as unittest try: diff --git a/numba/tests/npyufunc/__init__.py b/numba/tests/npyufunc/__init__.py index 83bc55d6892..45a2bd85e0d 100644 --- a/numba/tests/npyufunc/__init__.py +++ b/numba/tests/npyufunc/__init__.py @@ -1,9 +1,7 @@ -from numba import unittest_support as unittest - from os.path import dirname from unittest.suite import TestSuite -from numba.testing import load_testsuite +from numba.testing import load_testsuite, unittest_support as unittest def load_tests(loader, tests, pattern): suite = TestSuite() diff --git a/numba/tests/npyufunc/test_caching.py b/numba/tests/npyufunc/test_caching.py index 72790b5c516..865fcc5de92 100644 --- a/numba/tests/npyufunc/test_caching.py +++ b/numba/tests/npyufunc/test_caching.py @@ -5,11 +5,10 @@ import numpy as np -from numba import unittest_support as unittest - from ..support import capture_cache_log from ..test_dispatcher import BaseCacheTest from numba.core import config +from numba.testing import unittest_support as unittest class UfuncCacheTest(BaseCacheTest): diff --git a/numba/tests/npyufunc/test_dufunc.py b/numba/tests/npyufunc/test_dufunc.py index d0ec1475b28..29774a096a1 100644 --- a/numba/tests/npyufunc/test_dufunc.py +++ b/numba/tests/npyufunc/test_dufunc.py @@ -5,7 +5,7 @@ from numba import njit, vectorize from numba.npyufunc import dufunc from ..support import MemoryLeakMixin -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest def pyuadd(a0, a1): diff --git a/numba/tests/npyufunc/test_errors.py b/numba/tests/npyufunc/test_errors.py index f1267623abe..997e66b4f49 100644 --- a/numba/tests/npyufunc/test_errors.py +++ b/numba/tests/npyufunc/test_errors.py @@ -3,10 +3,10 @@ import numpy as np -from numba import unittest_support as unittest from numba import vectorize, guvectorize from ..support import TestCase, CheckWarningsMixin +from numba.testing import unittest_support as unittest def sqrt(val): diff --git a/numba/tests/npyufunc/test_gufunc.py b/numba/tests/npyufunc/test_gufunc.py index 089b410b3bf..e0f3f6b7e69 100644 --- a/numba/tests/npyufunc/test_gufunc.py +++ b/numba/tests/npyufunc/test_gufunc.py @@ -1,10 +1,10 @@ import numpy as np import numpy.core.umath_tests as ut -from numba import unittest_support as unittest from numba import void, float32, jit, guvectorize from numba.npyufunc import GUVectorize from ..support import tag, TestCase +from numba.testing import unittest_support as unittest def matmulcore(A, B, C): diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index 8f3372461db..8ab18a5023f 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -1,7 +1,7 @@ -from numba import unittest_support as unittest from numba.npyufunc.parallel import get_thread_count from os import environ as env from numba.core import config +from numba.testing import unittest_support as unittest class TestParallelEnvVariable(unittest.TestCase): diff --git a/numba/tests/npyufunc/test_parallel_low_work.py b/numba/tests/npyufunc/test_parallel_low_work.py index 9357b42d2c8..8e5b7c1ef2d 100644 --- a/numba/tests/npyufunc/test_parallel_low_work.py +++ b/numba/tests/npyufunc/test_parallel_low_work.py @@ -2,12 +2,11 @@ There was a deadlock problem when work count is smaller than number of threads. """ -from numba import unittest_support as unittest - import numpy as np from numba import float32, float64, int32, uint32 from numba.npyufunc import Vectorize +from numba.testing import unittest_support as unittest def vector_add(a, b): diff --git a/numba/tests/npyufunc/test_parallel_ufunc_issues.py b/numba/tests/npyufunc/test_parallel_ufunc_issues.py index 99acffe0ea2..c519a1348c6 100644 --- a/numba/tests/npyufunc/test_parallel_ufunc_issues.py +++ b/numba/tests/npyufunc/test_parallel_ufunc_issues.py @@ -3,9 +3,9 @@ import numpy as np -from numba import unittest_support as unittest from numba.tests.support import captured_stdout from numba import vectorize, guvectorize +from numba.testing import unittest_support as unittest class TestParUfuncIssues(unittest.TestCase): diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index 1b9d9bb3378..074fc0ff629 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -1,10 +1,10 @@ import numpy as np -from numba import unittest_support as unittest from numba import float32, jit from numba.npyufunc import Vectorize from numba.core.errors import TypingError from ..support import TestCase +from numba.testing import unittest_support as unittest dtype = np.float32 diff --git a/numba/tests/npyufunc/test_ufuncbuilding.py b/numba/tests/npyufunc/test_ufuncbuilding.py index 8cc0baa9391..397ac374c4a 100644 --- a/numba/tests/npyufunc/test_ufuncbuilding.py +++ b/numba/tests/npyufunc/test_ufuncbuilding.py @@ -2,13 +2,13 @@ import numpy as np -from numba import unittest_support as unittest from numba.npyufunc.ufuncbuilder import GUFuncBuilder from numba import vectorize, guvectorize from numba.npyufunc import PyUFunc_One from numba.npyufunc.dufunc import DUFunc as UFuncBuilder from ..support import tag, TestCase from numba.core import config +from numba.testing import unittest_support as unittest def add(a, b): diff --git a/numba/tests/npyufunc/test_vectorize_decor.py b/numba/tests/npyufunc/test_vectorize_decor.py index ad50534af80..ec5953adbb5 100644 --- a/numba/tests/npyufunc/test_vectorize_decor.py +++ b/numba/tests/npyufunc/test_vectorize_decor.py @@ -2,9 +2,9 @@ import numpy as np -from numba import unittest_support as unittest from numba import int32, uint32, float32, float64, jit, vectorize from ..support import tag, CheckWarningsMixin +from numba.testing import unittest_support as unittest pi = math.pi diff --git a/numba/tests/support.py b/numba/tests/support.py index 5a0c79f451d..0e851f50362 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -26,7 +26,7 @@ from numba import numpy_support, testing from numba.core import errors, typing, utils, config, cpu from numba.core.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.runtime import rtsys diff --git a/numba/tests/test_annotations.py b/numba/tests/test_annotations.py index 4c4cac5e949..55b96a082be 100644 --- a/numba/tests/test_annotations.py +++ b/numba/tests/test_annotations.py @@ -2,9 +2,9 @@ from io import StringIO import numba -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types +from numba.testing import unittest_support as unittest try: import jinja2 diff --git a/numba/tests/test_api.py b/numba/tests/test_api.py index 4429ee0b879..e38941214ef 100644 --- a/numba/tests/test_api.py +++ b/numba/tests/test_api.py @@ -1,7 +1,7 @@ import numba -from numba import unittest_support as unittest from numba.tests.support import TestCase +from numba.testing import unittest_support as unittest class TestNumbaModule(TestCase): diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 0d27ef318c6..257ab16d083 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -5,7 +5,6 @@ from collections import namedtuple from io import StringIO -from numba import unittest_support as unittest from numba import njit, typeof, prange from numba.core import types, typing, ir, bytecode, postproc, cpu from numba.tests.support import TestCase, tag, skip_parfors_unsupported @@ -23,6 +22,7 @@ from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass from numba.experimental import jitclass +from numba.testing import unittest_support as unittest skip_unsupported = skip_parfors_unsupported diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index 3368a6979f1..bd361433385 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -1,6 +1,6 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated from numba.numpy_support import from_dtype from numba import njit, typeof diff --git a/numba/tests/test_array_constants.py b/numba/tests/test_array_constants.py index f6eae4e3409..b374656b82d 100644 --- a/numba/tests/test_array_constants.py +++ b/numba/tests/test_array_constants.py @@ -1,6 +1,6 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated from numba.core.errors import TypingError from numba import jit, typeof diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index 12aa0ce424d..ba79cb03999 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -4,11 +4,11 @@ import numpy as np from numba import njit, vectorize -from numba import unittest_support as unittest from numba import typeof from numba.core import utils, types, typing, ir, compiler, cpu from numba.core.compiler import Compiler, Flags from numba.tests.support import MemoryLeakMixin, TestCase +from numba.testing import unittest_support as unittest class Namespace(dict): diff --git a/numba/tests/test_array_iterators.py b/numba/tests/test_array_iterators.py index 5915d33784a..47069b4adcc 100644 --- a/numba/tests/test_array_iterators.py +++ b/numba/tests/test_array_iterators.py @@ -2,11 +2,11 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit, typeof from numba.core import types from numba.core.compiler import compile_isolated from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin, tag +from numba.testing import unittest_support as unittest def array_iter(arr): diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 874f2ea51d4..70444286824 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -3,7 +3,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit, njit, from_dtype, typeof from numba.core.errors import TypingError diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index c2436c9c40b..e34bf3d2dbd 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -4,7 +4,6 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit, typeof from numba.core import types from numba.core.compiler import compile_isolated @@ -12,6 +11,7 @@ from numba.numpy_support import as_dtype from numba.tests.support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, tag, needs_blas) +from numba.testing import unittest_support as unittest def np_around_array(arr, decimals, out): diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index 401d4678510..04f8c17c911 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -2,10 +2,10 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit, typeof from numba.core.compiler import compile_isolated from numba.tests.support import TestCase, MemoryLeakMixin, tag +from numba.testing import unittest_support as unittest def array_all(arr): diff --git a/numba/tests/test_array_return.py b/numba/tests/test_array_return.py index da48c615c03..d87e4901d10 100644 --- a/numba/tests/test_array_return.py +++ b/numba/tests/test_array_return.py @@ -2,8 +2,8 @@ from numba.core.compiler import compile_isolated from numba import typeof -from numba import unittest_support as unittest from numba.tests.support import MemoryLeakMixin +from numba.testing import unittest_support as unittest def array_return(a, i): diff --git a/numba/tests/test_auto_constants.py b/numba/tests/test_auto_constants.py index 52376ac30f2..71b008e6541 100644 --- a/numba/tests/test_auto_constants.py +++ b/numba/tests/test_auto_constants.py @@ -3,8 +3,8 @@ import numpy as np -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated +from numba.testing import unittest_support as unittest class TestAutoConstants(unittest.TestCase): diff --git a/numba/tests/test_blackscholes.py b/numba/tests/test_blackscholes.py index 60c96b91d28..7e888ffc17c 100644 --- a/numba/tests/test_blackscholes.py +++ b/numba/tests/test_blackscholes.py @@ -2,7 +2,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, compile_extra, Flags from numba.core import types, typing from numba.tests.support import TestCase diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index 81d9eb272cd..f5b846bdd28 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -4,9 +4,9 @@ from numba.cuda.testing import SerialMixin from numba import typeof, cuda, njit from numba.core.types import float64 -from numba import unittest_support as unittest from numba.tests.support import MemoryLeakMixin, override_env_config from numba.core import config +from numba.testing import unittest_support as unittest BOUNDSCHECK_FLAGS = DEFAULT_FLAGS.copy() BOUNDSCHECK_FLAGS.set('boundscheck', True) diff --git a/numba/tests/test_buffer_protocol.py b/numba/tests/test_buffer_protocol.py index 01731daf902..d9c6c05a7ed 100644 --- a/numba/tests/test_buffer_protocol.py +++ b/numba/tests/test_buffer_protocol.py @@ -2,9 +2,9 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit from numba.tests.support import TestCase, compile_function, MemoryLeakMixin +from numba.testing import unittest_support as unittest @jit(nopython=True) diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index 59f2528efbd..147e2249a81 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -5,7 +5,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit, typeof, njit from numba.core import errors, types, utils, config diff --git a/numba/tests/test_casting.py b/numba/tests/test_casting.py index 779dd283967..c6f6f511f9b 100644 --- a/numba/tests/test_casting.py +++ b/numba/tests/test_casting.py @@ -1,9 +1,9 @@ -from numba import unittest_support as unittest import numpy as np from numba.core.compiler import compile_isolated from numba import njit from numba.core import types import struct +from numba.testing import unittest_support as unittest def float_to_int(x): diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index b59493e8aa2..a5059e75d1c 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -1,13 +1,13 @@ import array import numpy as np -from numba import unittest_support as unittest from numba import jit, cffi_support from numba.core import types, errors from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag import numba.tests.cffi_usecases as mod +from numba.testing import unittest_support as unittest enable_pyobj_flags = Flags() diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index 78ac85d2948..13849019da6 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -11,12 +11,12 @@ import numpy as np -from numba import unittest_support as unittest from numba import cfunc, carray, farray, njit from numba.core import types, typing, utils from numba import cffi_support, numpy_support from numba.tests.support import TestCase, tag, captured_stderr from numba.tests.test_dispatcher import BaseCacheTest +from numba.testing import unittest_support as unittest skip_cffi_unsupported = unittest.skipUnless( cffi_support.SUPPORTED, diff --git a/numba/tests/test_cgutils.py b/numba/tests/test_cgutils.py index 5832f53616e..d333193589f 100644 --- a/numba/tests/test_cgutils.py +++ b/numba/tests/test_cgutils.py @@ -6,7 +6,7 @@ import llvmlite.llvmpy.core as lc import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core import types, typing, cgutils, cpu from numba.core.compiler_lock import global_compiler_lock from numba.tests.support import TestCase diff --git a/numba/tests/test_chained_assign.py b/numba/tests/test_chained_assign.py index eee9327a222..6d2e63373df 100644 --- a/numba/tests/test_chained_assign.py +++ b/numba/tests/test_chained_assign.py @@ -1,5 +1,5 @@ from numba import jit -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import numpy as np import copy from numba.tests.support import MemoryLeakMixin diff --git a/numba/tests/test_cli.py b/numba/tests/test_cli.py index c9a2de1d441..000d852e53e 100644 --- a/numba/tests/test_cli.py +++ b/numba/tests/test_cli.py @@ -5,7 +5,7 @@ import sys import threading -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import TestCase diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index 4d740a0bff0..c681dd82f50 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -2,7 +2,7 @@ import numpy as np import numpy -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import njit, jit, testing from numba.core.errors import TypingError, UnsupportedError from numba.tests.support import TestCase diff --git a/numba/tests/test_codegen.py b/numba/tests/test_codegen.py index 1191bc03856..734f863cf01 100644 --- a/numba/tests/test_codegen.py +++ b/numba/tests/test_codegen.py @@ -13,7 +13,7 @@ import llvmlite.binding as ll -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.codegen import JITCPUCodegen from numba.core.compiler_lock import global_compiler_lock from numba.tests.support import TestCase diff --git a/numba/tests/test_compile_cache.py b/numba/tests/test_compile_cache.py index e0ac1732c9b..95e029f9ed8 100644 --- a/numba/tests/test_compile_cache.py +++ b/numba/tests/test_compile_cache.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from contextlib import contextmanager import llvmlite.llvmpy.core as lc diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index e201c7e2935..b1181f44a26 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -3,11 +3,11 @@ import math import sys -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated, Flags, utils from numba.core import types from numba.tests.support import TestCase, tag from .complex_usecases import * +from numba.testing import unittest_support as unittest enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index 5976430feda..812b0a2d95f 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -1,10 +1,8 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import TestCase import sys import operator - -# deliberately imported twice for different use cases import numpy as np import numpy @@ -15,6 +13,9 @@ from numba.tests.support import tag, _32bit, captured_stdout +# deliberately imported twice for different use cases + + PARALLEL_SUPPORTED = not _32bit def comp_list(n): diff --git a/numba/tests/test_conversion.py b/numba/tests/test_conversion.py index 7987cb95087..0da2afe1f6d 100644 --- a/numba/tests/test_conversion.py +++ b/numba/tests/test_conversion.py @@ -5,7 +5,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit, numpy_support from numba.core import types diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index db366658d2b..fd08a5ecffc 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -9,7 +9,7 @@ from numba.core.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) from numba.core.typed_passes import type_inference_stage -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest def test_will_propagate(b, z, w): x = 3 diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index 7e174aec565..e4920dd3ea8 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -5,13 +5,13 @@ import numpy as np -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated from numba import jit from numba.core import types, errors from numba.core.typing import ctypes_utils from numba.tests.support import MemoryLeakMixin, tag, TestCase from numba.tests.ctypes_usecases import * +from numba.testing import unittest_support as unittest class TestCTypesTypes(TestCase): diff --git a/numba/tests/test_dataflow.py b/numba/tests/test_dataflow.py index 0713d7cfa28..b908ab6952b 100644 --- a/numba/tests/test_dataflow.py +++ b/numba/tests/test_dataflow.py @@ -1,6 +1,6 @@ import warnings -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, errors from numba.tests.support import (TestCase, CompilationCache, diff --git a/numba/tests/test_datamodel.py b/numba/tests/test_datamodel.py index 60278e20815..acb7adee3ce 100644 --- a/numba/tests/test_datamodel.py +++ b/numba/tests/test_datamodel.py @@ -1,8 +1,8 @@ from llvmlite import ir, binding as ll from numba.core import types, datamodel -from numba import unittest_support as unittest from numba.core.datamodel.testing import test_factory +from numba.testing import unittest_support as unittest class TestBool(test_factory()): diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 975ff7b0818..06d9ed3a03f 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -9,7 +9,6 @@ from numba.tests.support import (TestCase, override_config, override_env_config, captured_stdout, forbid_codegen, skip_parfors_unsupported, needs_blas) -from numba import unittest_support as unittest from numba import jit from numba.core import types, compiler from numba.core.compiler import compile_isolated, Flags @@ -17,6 +16,7 @@ from numba.core.errors import NumbaPerformanceWarning from numba import prange from numba.experimental import jitclass +from numba.testing import unittest_support as unittest def simple_nopython(somearg): diff --git a/numba/tests/test_debuginfo.py b/numba/tests/test_debuginfo.py index 0a408fca340..7882407d299 100644 --- a/numba/tests/test_debuginfo.py +++ b/numba/tests/test_debuginfo.py @@ -1,9 +1,9 @@ import re from numba.tests.support import TestCase, override_config -from numba import unittest_support as unittest from numba import jit from numba.core import types +from numba.testing import unittest_support as unittest class TestDebugInfo(TestCase): diff --git a/numba/tests/test_del.py b/numba/tests/test_del.py index b19ba4988fa..f0f47f10f16 100644 --- a/numba/tests/test_del.py +++ b/numba/tests/test_del.py @@ -2,7 +2,7 @@ from numba.core.compiler import compile_isolated from numba.tests.support import TestCase -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import testing diff --git a/numba/tests/test_deprecations.py b/numba/tests/test_deprecations.py index a1d48e41899..1a4b49f9f01 100644 --- a/numba/tests/test_deprecations.py +++ b/numba/tests/test_deprecations.py @@ -2,7 +2,7 @@ from numba import jit from numba.core.errors import (NumbaDeprecationWarning, NumbaPendingDeprecationWarning, NumbaWarning) -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest class TestDeprecation(unittest.TestCase): diff --git a/numba/tests/test_dicts.py b/numba/tests/test_dicts.py index 814090b3b5a..b05d612fda8 100644 --- a/numba/tests/test_dicts.py +++ b/numba/tests/test_dicts.py @@ -1,6 +1,6 @@ from numba import njit from numba.core.errors import TypingError -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import TestCase, force_pyobj_flags diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 5fc74402a07..9fa462c9aef 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -15,7 +15,6 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit, generated_jit, typeof from numba.core import types, errors, codegen from numba import _dispatcher @@ -31,6 +30,7 @@ from numba.tests.support import skip_parfors_unsupported, needs_lapack import llvmlite.binding as ll +from numba.testing import unittest_support as unittest try: import jinja2 diff --git a/numba/tests/test_dummyarray.py b/numba/tests/test_dummyarray.py index b06c97816a2..72dfa12673e 100644 --- a/numba/tests/test_dummyarray.py +++ b/numba/tests/test_dummyarray.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import itertools import numpy as np from numba.misc.dummyarray import Array diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 1247c450d20..93fcd32b69f 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -5,11 +5,11 @@ import threading import gc -from numba import unittest_support as unittest from numba.core.errors import TypingError from numba import njit from numba.core import types, utils, config from numba.tests.support import MemoryLeakMixin, TestCase, tag +from numba.testing import unittest_support as unittest nrtjit = njit(_nrt=True, nogil=True) diff --git a/numba/tests/test_enums.py b/numba/tests/test_enums.py index dbc4f5ad9a7..697f9f86b3b 100644 --- a/numba/tests/test_enums.py +++ b/numba/tests/test_enums.py @@ -4,7 +4,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import jit, vectorize from numba.tests.support import TestCase diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index 4ff3036b1f7..c977a925ae5 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -3,7 +3,6 @@ """ from numba import jit, njit, typed, int64 -from numba import unittest_support as unittest from numba.core import errors, utils import numpy as np @@ -18,6 +17,7 @@ from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass from numba.tests.support import skip_parfors_unsupported +from numba.testing import unittest_support as unittest # used in TestMiscErrorHandling::test_handling_of_write_to_*_global _global_list = [1, 2, 3, 4] diff --git a/numba/tests/test_errormodels.py b/numba/tests/test_errormodels.py index a6dc276c427..9c1b72c0df0 100644 --- a/numba/tests/test_errormodels.py +++ b/numba/tests/test_errormodels.py @@ -3,7 +3,7 @@ """ from numba import jit -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest class TestErrorModel(unittest.TestCase): diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index 4e7fe9052d6..7546db065f0 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -5,8 +5,8 @@ from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types, errors -from numba import unittest_support as unittest from numba.tests.support import TestCase +from numba.testing import unittest_support as unittest force_pyobj_flags = Flags() force_pyobj_flags.set("force_pyobject") diff --git a/numba/tests/test_extended_arg.py b/numba/tests/test_extended_arg.py index 046698b9c6c..52d5e0494e9 100644 --- a/numba/tests/test_extended_arg.py +++ b/numba/tests/test_extended_arg.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import dis import struct diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 89b68503716..51d4438dc9a 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -9,7 +9,6 @@ import numpy as np -from numba import unittest_support as unittest from numba import njit, jit from numba.core import types, errors, typing, compiler from numba.core.typed_passes import type_inference_stage @@ -18,6 +17,7 @@ from numba.tests.support import (TestCase, captured_stdout, tag, temp_directory, override_config) from numba.core.errors import LoweringError +from numba.testing import unittest_support as unittest from numba.extending import (typeof_impl, type_callable, lower_builtin, lower_cast, @@ -37,6 +37,8 @@ from .pdlike_usecase import Index, Series + + try: import scipy if LooseVersion(scipy.__version__) < '0.19': diff --git a/numba/tests/test_extending_types.py b/numba/tests/test_extending_types.py index 461617d29b5..e8f38aa6f21 100644 --- a/numba/tests/test_extending_types.py +++ b/numba/tests/test_extending_types.py @@ -12,7 +12,7 @@ from numba.extending import overload from numba.extending import typeof_impl -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest class TestExtTypDummy(unittest.TestCase): diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index 23a70a37e64..ada77de6146 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -2,7 +2,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import jit, typeof from numba.core import types from numba.core.errors import TypingError diff --git a/numba/tests/test_fastmath.py b/numba/tests/test_fastmath.py index 495abb0004c..777bbeeaed5 100644 --- a/numba/tests/test_fastmath.py +++ b/numba/tests/test_fastmath.py @@ -1,9 +1,9 @@ import math import numpy as np -from numba import unittest_support as unittest from numba.tests.support import captured_stdout, override_config from numba import njit, vectorize, guvectorize +from numba.testing import unittest_support as unittest class TestFastMath(unittest.TestCase): diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index 570bd8822ea..3178ddcc5ac 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -1,6 +1,6 @@ import itertools -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.controlflow import CFGraph, ControlFlowAnalysis from numba.core.compiler import compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_func_interface.py b/numba/tests/test_func_interface.py index 816b0837566..51a26278155 100644 --- a/numba/tests/test_func_interface.py +++ b/numba/tests/test_func_interface.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import jit diff --git a/numba/tests/test_func_lifetime.py b/numba/tests/test_func_lifetime.py index 3960044037b..04b5ab34df1 100644 --- a/numba/tests/test_func_lifetime.py +++ b/numba/tests/test_func_lifetime.py @@ -1,10 +1,10 @@ import gc import weakref -from numba import unittest_support as unittest from numba import jit from numba.core import types from numba.tests.support import TestCase +from numba.testing import unittest_support as unittest class Dummy(object): diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index 1e52a6e80b3..a33764b6694 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -11,10 +11,10 @@ from numba import njit, gdb, gdb_init, gdb_breakpoint, prange from numba.core import errors from numba import jit -from numba import unittest_support as unittest from numba.misc.gdb_hook import _confirm_gdb from numba.tests.support import (TestCase, captured_stdout, tag, skip_parfors_unsupported) +from numba.testing import unittest_support as unittest _platform = sys.platform diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index 28a022e6246..8b3e48c88b7 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -1,7 +1,7 @@ import sys import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types diff --git a/numba/tests/test_gil.py b/numba/tests/test_gil.py index 9d48667b264..214b9d97957 100644 --- a/numba/tests/test_gil.py +++ b/numba/tests/test_gil.py @@ -7,7 +7,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import errors diff --git a/numba/tests/test_globals.py b/numba/tests/test_globals.py index 76fc18f3461..9b42c896a66 100644 --- a/numba/tests/test_globals.py +++ b/numba/tests/test_globals.py @@ -1,7 +1,7 @@ import numpy as np from numba import jit -from numba import unittest_support as unittest from numba.tests import usecases +from numba.testing import unittest_support as unittest X = np.arange(10) diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index f8a277a3108..c7795fc52f9 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -3,7 +3,7 @@ Test hashing of various supported types. """ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import sys from collections import defaultdict @@ -12,7 +12,7 @@ from numba import jit from numba.core import types, utils -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import TestCase, tag, CompilationCache from numba.cpython.unicode import compile_time_get_string_data diff --git a/numba/tests/test_import.py b/numba/tests/test_import.py index c59e84171b4..6a0fe1286d3 100644 --- a/numba/tests/test_import.py +++ b/numba/tests/test_import.py @@ -1,8 +1,8 @@ import subprocess import sys -from numba import unittest_support as unittest from numba.tests.support import TestCase +from numba.testing import unittest_support as unittest class TestNumbaImport(TestCase): diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index 8b0108ad1c8..a9dcd1feba8 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -3,7 +3,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import njit, typeof from numba.core import utils, types, errors diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index f74e984fc75..39d110d897e 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -3,7 +3,6 @@ from numba.tests.support import (TestCase, override_config, captured_stdout, skip_parfors_unsupported) -from numba import unittest_support as unittest from numba import jit, njit from numba.core import types, ir, postproc, compiler from numba.core.ir_utils import guard, find_callname, find_const, get_definition @@ -21,6 +20,7 @@ IRLegalization, NoPythonBackend) from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass +from numba.testing import unittest_support as unittest @jit((types.int32,), nopython=True) def inner(a): diff --git a/numba/tests/test_interproc.py b/numba/tests/test_interproc.py index 048cecd5303..714d6124c71 100644 --- a/numba/tests/test_interproc.py +++ b/numba/tests/test_interproc.py @@ -1,7 +1,7 @@ import gc from numba import jit, int32 -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest def foo(a, b): diff --git a/numba/tests/test_intwidth.py b/numba/tests/test_intwidth.py index 2ce4cfc517f..18481951091 100644 --- a/numba/tests/test_intwidth.py +++ b/numba/tests/test_intwidth.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import math import sys diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index 186e48a3e88..0cb665e092d 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import objmode import numpy as np from numba.core import ir, compiler diff --git a/numba/tests/test_itanium_mangler.py b/numba/tests/test_itanium_mangler.py index 54bb0f827d0..8c0810ad3dd 100644 --- a/numba/tests/test_itanium_mangler.py +++ b/numba/tests/test_itanium_mangler.py @@ -2,10 +2,10 @@ import re -from numba import unittest_support as unittest from numba import int32, int64, uint32, uint64, float32, float64 from numba.core.types import range_iter32_type from numba.core import itanium_mangler +from numba.testing import unittest_support as unittest class TestItaniumManager(unittest.TestCase): diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index 2d5f6e67a5e..a69c1ff3c6d 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -1,7 +1,7 @@ import numpy as np from numba import njit -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import numpy_support from numba.core import types, errors diff --git a/numba/tests/test_jit_module.py b/numba/tests/test_jit_module.py index 2275769a942..3a73140c6f1 100644 --- a/numba/tests/test_jit_module.py +++ b/numba/tests/test_jit_module.py @@ -9,7 +9,7 @@ import logging from io import StringIO -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import temp_directory, SerialMixin from numba.core import dispatcher diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index 61778d80ad7..df5dd59dbd0 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -9,12 +9,12 @@ optional) from numba import njit, typeof from numba.core import types, errors -from numba import unittest_support as unittest from numba.tests.support import TestCase, MemoryLeakMixin from numba.experimental.jitclass import _box from numba.runtime.nrt import MemInfo from numba.core.errors import LoweringError from numba.experimental import jitclass +from numba.testing import unittest_support as unittest class TestClass1(object): diff --git a/numba/tests/test_jitmethod.py b/numba/tests/test_jitmethod.py index d65e8d4584e..5b334923005 100644 --- a/numba/tests/test_jitmethod.py +++ b/numba/tests/test_jitmethod.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import numpy as np diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index 7b2fd8145d5..fd522c088bf 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -8,11 +8,11 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit from numba.core import errors from numba.tests.support import TestCase, tag, needs_lapack, needs_blas, _is_armv7l from .matmul_usecase import matmul_usecase +from numba.testing import unittest_support as unittest def dot2(a, b): diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 76b31de0aa1..43730c52c9d 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -8,7 +8,7 @@ from numba.core.compiler import compile_isolated, Flags from numba import jit, typeof -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import testing from numba.core import types, utils, errors from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index 2498487c9f2..f77dddcad12 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -1,7 +1,7 @@ import numpy as np import numba -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import TestCase from numba import njit from numba.core import types, errors, cgutils diff --git a/numba/tests/test_llvm_version_check.py b/numba/tests/test_llvm_version_check.py index 984f94af42a..917c0fef1d2 100644 --- a/numba/tests/test_llvm_version_check.py +++ b/numba/tests/test_llvm_version_check.py @@ -1,7 +1,7 @@ import imp import sys -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest class TestLlvmVersion(unittest.TestCase): diff --git a/numba/tests/test_locals.py b/numba/tests/test_locals.py index e58718e56d7..8b59c678a4d 100644 --- a/numba/tests/test_locals.py +++ b/numba/tests/test_locals.py @@ -1,6 +1,6 @@ from numba import float32 -from numba import unittest_support as unittest from numba.core import compiler +from numba.testing import unittest_support as unittest def foo(): x = 123 diff --git a/numba/tests/test_looplifting.py b/numba/tests/test_looplifting.py index b7ad053be95..91662154eeb 100644 --- a/numba/tests/test_looplifting.py +++ b/numba/tests/test_looplifting.py @@ -2,9 +2,9 @@ import numpy as np from numba.core import types -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, MemoryLeakMixin +from numba.testing import unittest_support as unittest looplift_flags = Flags() diff --git a/numba/tests/test_make_function_to_jit_function.py b/numba/tests/test_make_function_to_jit_function.py index ce31d58b109..cb23544c3b1 100644 --- a/numba/tests/test_make_function_to_jit_function.py +++ b/numba/tests/test_make_function_to_jit_function.py @@ -3,7 +3,7 @@ from numba.extending import overload import numpy as np -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest @njit diff --git a/numba/tests/test_mandelbrot.py b/numba/tests/test_mandelbrot.py index 64acb52c775..02c790b9097 100644 --- a/numba/tests/test_mandelbrot.py +++ b/numba/tests/test_mandelbrot.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, utils diff --git a/numba/tests/test_map_filter_reduce.py b/numba/tests/test_map_filter_reduce.py index 531ee3113c8..4e498e104c5 100644 --- a/numba/tests/test_map_filter_reduce.py +++ b/numba/tests/test_map_filter_reduce.py @@ -1,7 +1,7 @@ from numba import njit -from numba import unittest_support as unittest from functools import reduce +from numba.testing import unittest_support as unittest class TestMap(unittest.TestCase): diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index 4f6991bf793..697d892375e 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -5,12 +5,12 @@ import numpy as np -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import numpy_support from numba.core import utils, types from numba.core.config import IS_WIN32, IS_32BITS from numba.tests.support import TestCase, CompilationCache, tag +from numba.testing import unittest_support as unittest enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_maxmin.py b/numba/tests/test_maxmin.py index 86781271d11..48c3d63248b 100644 --- a/numba/tests/test_maxmin.py +++ b/numba/tests/test_maxmin.py @@ -1,6 +1,6 @@ -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated from numba.core import types +from numba.testing import unittest_support as unittest def domax3(a, b, c): diff --git a/numba/tests/test_multi3.py b/numba/tests/test_multi3.py index b6cd87835e9..e235dc70c4c 100644 --- a/numba/tests/test_multi3.py +++ b/numba/tests/test_multi3.py @@ -4,7 +4,7 @@ from numba import njit from numba.core import types -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest class TestMulti3(unittest.TestCase): """ diff --git a/numba/tests/test_nan.py b/numba/tests/test_nan.py index ed427db500e..6bcadad4451 100644 --- a/numba/tests/test_nan.py +++ b/numba/tests/test_nan.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_nested_calls.py b/numba/tests/test_nested_calls.py index 6a5dd5df4ba..84c5fc05992 100644 --- a/numba/tests/test_nested_calls.py +++ b/numba/tests/test_nested_calls.py @@ -7,8 +7,8 @@ from numba import int32, int64 from numba import jit, generated_jit from numba.core import types -from numba import unittest_support as unittest from numba.tests.support import TestCase, tag +from numba.testing import unittest_support as unittest @jit(nopython=True) diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index c9d3965fb77..7b38044079b 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -7,7 +7,6 @@ import numpy as np -from numba import unittest_support as unittest from numba.core.compiler import Flags from numba import jit, njit, typeof from numba.core import types @@ -18,6 +17,7 @@ from numba.targets.arraymath import cross2d from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, needs_blas) +from numba.testing import unittest_support as unittest no_pyobj_flags = Flags() diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index f73a86dc9b4..453e610173d 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -11,7 +11,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import jit, vectorize, numpy_support from numba.numpy_support import numpy_version from numba.core import types, config diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 508cbb00425..e07dcbd9c89 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -6,7 +6,6 @@ import numpy as np -from numba import unittest_support as unittest from numba import njit, targets from numba.core import typing, types from numba.core.compiler import compile_isolated, Flags @@ -26,6 +25,7 @@ from numba.tests.support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic from numba.core import cpu +from numba.testing import unittest_support as unittest enable_nrt_flags = Flags() enable_nrt_flags.set("nrt") diff --git a/numba/tests/test_nrt_refct.py b/numba/tests/test_nrt_refct.py index 5a2333adc1c..7bc404bc917 100644 --- a/numba/tests/test_nrt_refct.py +++ b/numba/tests/test_nrt_refct.py @@ -7,7 +7,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import njit from numba.runtime import rtsys from numba.tests.support import TestCase diff --git a/numba/tests/test_numberctor.py b/numba/tests/test_numberctor.py index 0928e8a0a9c..f4dce69cb44 100644 --- a/numba/tests/test_numberctor.py +++ b/numba/tests/test_numberctor.py @@ -1,11 +1,11 @@ import numpy as np -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated from numba import jit from numba.core import types from numba.tests.support import TestCase, tag +from numba.testing import unittest_support as unittest def dobool(a): diff --git a/numba/tests/test_numconv.py b/numba/tests/test_numconv.py index c1a29b2c47d..8cdb5ee1a92 100644 --- a/numba/tests/test_numconv.py +++ b/numba/tests/test_numconv.py @@ -1,5 +1,5 @@ import itertools -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated from numba.core import types diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index b07e4d71ffc..249b130ad2b 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -8,7 +8,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import numpy_support from numba.core import types from numba.tests.support import TestCase diff --git a/numba/tests/test_numpyadapt.py b/numba/tests/test_numpyadapt.py index 82bdc2175b9..1ab20e155ab 100644 --- a/numba/tests/test_numpyadapt.py +++ b/numba/tests/test_numpyadapt.py @@ -2,7 +2,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import _helperlib diff --git a/numba/tests/test_obj_lifetime.py b/numba/tests/test_obj_lifetime.py index 594352b7013..dc2f9cb70f0 100644 --- a/numba/tests/test_obj_lifetime.py +++ b/numba/tests/test_obj_lifetime.py @@ -3,7 +3,7 @@ import weakref import gc -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.controlflow import CFGraph, Loop from numba.core.compiler import compile_extra, compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_object_mode.py b/numba/tests/test_object_mode.py index c2431c2beef..140192362e2 100644 --- a/numba/tests/test_object_mode.py +++ b/numba/tests/test_object_mode.py @@ -5,7 +5,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import utils diff --git a/numba/tests/test_objects.py b/numba/tests/test_objects.py index 4c09b86cb5f..7372e4fa48c 100644 --- a/numba/tests/test_objects.py +++ b/numba/tests/test_objects.py @@ -3,7 +3,7 @@ """ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types from numba.tests.support import TestCase diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index fb9fc5cda07..23e2f8a3f67 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -6,7 +6,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types, utils, errors, typeinfer diff --git a/numba/tests/test_optional.py b/numba/tests/test_optional.py index ea4f61cb808..f92dd4b04eb 100644 --- a/numba/tests/test_optional.py +++ b/numba/tests/test_optional.py @@ -2,7 +2,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import typeof, njit from numba.core import types, lowering diff --git a/numba/tests/test_overlap.py b/numba/tests/test_overlap.py index db6224aa3cd..e1a13d0a862 100644 --- a/numba/tests/test_overlap.py +++ b/numba/tests/test_overlap.py @@ -1,9 +1,9 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit from numba.core import types from numba.tests.support import TestCase, tag +from numba.testing import unittest_support as unittest # Array overlaps involving a displacement diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index cc6fee65c88..962c521d6d1 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -13,7 +13,6 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize from numba.tests.support import (temp_directory, override_config, TestCase, tag, @@ -22,6 +21,7 @@ import queue as t_queue from numba.testing.main import _TIMEOUT as _RUNNER_TIMEOUT from numba.core import config +from numba.testing import unittest_support as unittest _TEST_TIMEOUT = _RUNNER_TIMEOUT - 60. diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index fe6b853c94c..f79e6cee4d9 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -19,7 +19,6 @@ from collections import defaultdict import numba -from numba import unittest_support as unittest from numba import njit, prange, stencil from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler, cpu from numba.targets.registry import cpu_target @@ -35,6 +34,7 @@ skip_parfors_unsupported, _32bit, needs_blas, needs_lapack) import cmath +from numba.testing import unittest_support as unittest test_disabled = unittest.skipIf(True, 'Test disabled') diff --git a/numba/tests/test_polynomial.py b/numba/tests/test_polynomial.py index 9f85c4f04c1..65f4bd24302 100644 --- a/numba/tests/test_polynomial.py +++ b/numba/tests/test_polynomial.py @@ -3,9 +3,9 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit from numba.tests.support import TestCase, tag, needs_lapack +from numba.testing import unittest_support as unittest def roots_fn(p): diff --git a/numba/tests/test_print.py b/numba/tests/test_print.py index cef0289b211..6d6aa897d84 100644 --- a/numba/tests/test_print.py +++ b/numba/tests/test_print.py @@ -2,7 +2,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types, errors, utils diff --git a/numba/tests/test_profiler.py b/numba/tests/test_profiler.py index 2a52784f5cc..897a871fe15 100644 --- a/numba/tests/test_profiler.py +++ b/numba/tests/test_profiler.py @@ -7,8 +7,8 @@ import numpy as np from numba import jit -from numba import unittest_support as unittest from numba.tests.support import needs_blas +from numba.testing import unittest_support as unittest def dot(a, b): diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index 14806c8cb47..44764089d83 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -9,20 +9,24 @@ from ctypes import * import numpy as np -try: - import setuptools -except ImportError: - setuptools = None import llvmlite.binding as ll -from numba import unittest_support as unittest from numba.core import utils from numba.pycc import main from numba.pycc.decorators import clear_export_registry from numba.pycc.platform import find_shared_ending, find_pyext_ending from numba.pycc.platform import _external_compiler_ok +from numba.tests.support import TestCase, tag, import_dynamic, temp_directory, has_blas +from numba.testing import unittest_support as unittest + + +try: + import setuptools +except ImportError: + setuptools = None + # if suitable compilers are not present then skip. _skip_reason = 'AOT compatible compilers missing' _skip_missing_compilers = unittest.skipIf(not _external_compiler_ok, @@ -31,8 +35,6 @@ _windows_only = unittest.skipIf(not sys.platform.startswith('win'), _skip_reason) -from numba.tests.support import TestCase, tag, import_dynamic, temp_directory, has_blas - base_path = os.path.dirname(os.path.abspath(__file__)) diff --git a/numba/tests/test_python_int.py b/numba/tests/test_python_int.py index 847d036a593..2f85305e696 100644 --- a/numba/tests/test_python_int.py +++ b/numba/tests/test_python_int.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index 87681e64537..b76d7cf3e39 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -10,7 +10,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import jit, _helperlib from numba.core import types from numba.core.compiler import compile_isolated diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index af3319de52a..6ea118013e5 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import sys diff --git a/numba/tests/test_recarray_usecases.py b/numba/tests/test_recarray_usecases.py index 657097d37e9..93505c24189 100644 --- a/numba/tests/test_recarray_usecases.py +++ b/numba/tests/test_recarray_usecases.py @@ -5,8 +5,8 @@ from numba import numpy_support from numba.core import types from numba.core.compiler import compile_isolated -from numba import unittest_support as unittest from numba.tests.support import captured_stdout, tag, TestCase +from numba.testing import unittest_support as unittest def usecase1(arr1, arr2): diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 049a6bc11dc..a443f58cff3 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -4,11 +4,11 @@ import ctypes from numba import jit, numpy_support from numba.core import types -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated from numba.core.itanium_mangler import mangle_type from numba.core.config import IS_WIN32 from numba.numpy_support import numpy_version +from numba.testing import unittest_support as unittest def get_a(ary, i): diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index be47504425c..9655566d485 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -2,9 +2,9 @@ import warnings from numba import jit -from numba import unittest_support as unittest from numba.core.errors import TypingError, NumbaWarning from numba.tests.support import TestCase +from numba.testing import unittest_support as unittest class TestSelfRecursion(TestCase): diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 2c601b81e6b..4592b1fce4c 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -23,9 +23,9 @@ NopythonRewrites, PreParforPass, ParforPass, DumpParforDiagnostics, NativeLowering, IRLegalization, NoPythonBackend) -from numba import unittest_support as unittest import numpy as np from numba.tests.support import skip_parfors_unsupported, needs_blas +from numba.testing import unittest_support as unittest def test_will_propagate(b, z, w): diff --git a/numba/tests/test_return_values.py b/numba/tests/test_return_values.py index 7fd32a745ec..322374c9776 100644 --- a/numba/tests/test_return_values.py +++ b/numba/tests/test_return_values.py @@ -5,7 +5,7 @@ import math -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types from numba.core.errors import TypingError diff --git a/numba/tests/test_runtests.py b/numba/tests/test_runtests.py index db3a4e42a9c..db344b9f1c9 100755 --- a/numba/tests/test_runtests.py +++ b/numba/tests/test_runtests.py @@ -1,8 +1,8 @@ import sys import subprocess -from numba import unittest_support as unittest from numba import cuda +from numba.testing import unittest_support as unittest class TestCase(unittest.TestCase): diff --git a/numba/tests/test_serialize.py b/numba/tests/test_serialize.py index 2d69daf67b5..597d7da2e75 100644 --- a/numba/tests/test_serialize.py +++ b/numba/tests/test_serialize.py @@ -4,11 +4,11 @@ import subprocess import sys -from numba import unittest_support as unittest from numba.core.errors import TypingError from numba.targets import registry from numba.tests.support import TestCase, tag from .serialize_usecases import * +from numba.testing import unittest_support as unittest class TestDispatcherPickling(TestCase): diff --git a/numba/tests/test_sets.py b/numba/tests/test_sets.py index b1c67e670f1..53c4008db1d 100644 --- a/numba/tests/test_sets.py +++ b/numba/tests/test_sets.py @@ -1,4 +1,4 @@ -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from collections import namedtuple import contextlib @@ -12,7 +12,7 @@ from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import (TestCase, enable_pyobj_flags, MemoryLeakMixin, tag, compile_function) diff --git a/numba/tests/test_slices.py b/numba/tests/test_slices.py index f3346ace859..e0346ebf202 100644 --- a/numba/tests/test_slices.py +++ b/numba/tests/test_slices.py @@ -5,10 +5,10 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit, typeof, TypingError from numba.core import utils from numba.tests.support import TestCase, MemoryLeakMixin +from numba.testing import unittest_support as unittest def slice_passing(sl): diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index 33064fb5483..b9044251907 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -9,7 +9,7 @@ from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types, utils, errors -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import testing from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index 61777632ca0..d8e1e85bb6b 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -14,7 +14,6 @@ from copy import deepcopy import numba -from numba import unittest_support as unittest from numba import njit, stencil from numba.core import types from numba.core.compiler import compile_extra, Flags @@ -22,6 +21,7 @@ from numba.core.cpu import ParallelOptions from numba.tests.support import tag, skip_parfors_unsupported, _32bit from numba.core.errors import LoweringError, TypingError +from numba.testing import unittest_support as unittest skip_unsupported = skip_parfors_unsupported diff --git a/numba/tests/test_storeslice.py b/numba/tests/test_storeslice.py index ddb862ed711..47bcabb9c22 100644 --- a/numba/tests/test_storeslice.py +++ b/numba/tests/test_storeslice.py @@ -1,6 +1,6 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, errors from numba.tests.support import TestCase diff --git a/numba/tests/test_support.py b/numba/tests/test_support.py index 94c165054cb..850c5dc2daf 100644 --- a/numba/tests/test_support.py +++ b/numba/tests/test_support.py @@ -4,9 +4,9 @@ from numba import jit from numba.core import utils -from numba import unittest_support as unittest from numba.tests.support import TestCase, forbid_codegen from .enum_usecases import * +from numba.testing import unittest_support as unittest DBL_EPSILON = 2**-52 FLT_EPSILON = 2**-23 diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 480cee603f2..a95a2a4cfb8 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -9,9 +9,10 @@ import numba from numba.core import config, cpu -from numba import prange, njit, unittest_support as unittest +from numba import prange, njit from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, override_env_config +from numba.testing import unittest_support as unittest needs_svml = unittest.skipUnless(config.USING_SVML, "SVML tests need SVML to be present") diff --git a/numba/tests/test_target_overloadselector.py b/numba/tests/test_target_overloadselector.py index baf232a5e1b..79c67df8a3e 100644 --- a/numba/tests/test_target_overloadselector.py +++ b/numba/tests/test_target_overloadselector.py @@ -1,7 +1,7 @@ from itertools import product, permutations from collections import defaultdict -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.base import OverloadSelector from numba.targets.registry import cpu_target from numba.core.imputils import builtin_registry, RegistryLoader diff --git a/numba/tests/test_threadsafety.py b/numba/tests/test_threadsafety.py index 941d1d74cd0..131f82719f9 100644 --- a/numba/tests/test_threadsafety.py +++ b/numba/tests/test_threadsafety.py @@ -7,11 +7,11 @@ import numpy as np -from numba import unittest_support as unittest from numba import jit, vectorize, guvectorize from numba.tests.support import temp_directory, override_config from numba.core import config +from numba.testing import unittest_support as unittest def foo(n, v): diff --git a/numba/tests/test_tracing.py b/numba/tests/test_tracing.py index 9e3b222135d..7e134dc3082 100644 --- a/numba/tests/test_tracing.py +++ b/numba/tests/test_tracing.py @@ -1,7 +1,7 @@ from io import StringIO import logging -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core import tracing logger = logging.getLogger('trace') diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index 77a324543e3..c29166097f3 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -3,11 +3,11 @@ import numpy as np -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated from numba import njit, jit from numba.core import types, errors, utils from numba.tests.support import TestCase, MemoryLeakMixin, tag +from numba.testing import unittest_support as unittest Rect = collections.namedtuple('Rect', ('width', 'height')) diff --git a/numba/tests/test_typeconv.py b/numba/tests/test_typeconv.py index 5345dccc15d..402c5856dc6 100644 --- a/numba/tests/test_typeconv.py +++ b/numba/tests/test_typeconv.py @@ -1,10 +1,10 @@ import itertools -from numba import unittest_support as unittest from numba.core import types from numba.core.typeconv.typeconv import TypeManager, TypeCastingRules from numba.core.typeconv import rules from numba.core.typeconv import castgraph, Conversion +from numba.testing import unittest_support as unittest class CompatibilityTestMixin(unittest.TestCase): diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index 95feb6ceda5..597b1c73fd6 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -3,7 +3,6 @@ import numpy as np -from numba import unittest_support as unittest from numba.core.compiler import compile_isolated from numba import jit from numba.core import types, typing, errors, typeinfer, utils @@ -11,6 +10,7 @@ from numba.tests.support import TestCase, tag from numba.tests.test_typeconv import CompatibilityTestMixin +from numba.testing import unittest_support as unittest i8 = types.int8 diff --git a/numba/tests/test_typenames.py b/numba/tests/test_typenames.py index 4258df81b36..1167ee2664f 100644 --- a/numba/tests/test_typenames.py +++ b/numba/tests/test_typenames.py @@ -1,7 +1,7 @@ import numpy as np from numba.core import types -from numba import unittest_support as unittest +from numba.testing import unittest_support as unittest class TestTypeNames(unittest.TestCase): diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 25a173f0dd9..30bf979b4db 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -8,7 +8,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import cffi_support, numpy_support from numba.core import types from numba.special import typeof diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 1384988b007..70336d4dd21 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -16,7 +16,6 @@ import numpy as np -from numba import unittest_support as unittest from numba.core import types, typing, errors, sigutils from numba.core.types.abstract import _typecache from numba.core.typing.templates import make_overload_template @@ -25,6 +24,7 @@ NativeValue, typeof_impl) from numba.tests.support import TestCase, temp_directory from numba.tests.enum_usecases import Color, Shake, Shape +from numba.testing import unittest_support as unittest try: diff --git a/numba/tests/test_typingerror.py b/numba/tests/test_typingerror.py index b45c2ad989a..66576bcc5fc 100644 --- a/numba/tests/test_typingerror.py +++ b/numba/tests/test_typingerror.py @@ -5,7 +5,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated from numba import jit from numba.core import types diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index 75abb93803f..872700f4090 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -8,7 +8,7 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import typeof, numpy_support, njit from numba.core import types, typing, utils from numba.core.compiler import compile_isolated, Flags, DEFAULT_FLAGS diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 890f918588b..b582279a158 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -4,7 +4,7 @@ from numba import njit from numba.core import types, utils -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.tests.support import (TestCase, no_pyobj_flags, MemoryLeakMixin) from numba.core.errors import TypingError diff --git a/numba/tests/test_unicode_array.py b/numba/tests/test_unicode_array.py index 47be52267d1..04603d285bc 100644 --- a/numba/tests/test_unicode_array.py +++ b/numba/tests/test_unicode_array.py @@ -1,7 +1,7 @@ import platform import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import jit, from_dtype from numba.core import types, utils from numba.typed import Dict diff --git a/numba/tests/test_unpack_sequence.py b/numba/tests/test_unpack_sequence.py index aa6582f291f..08c86268180 100644 --- a/numba/tests/test_unpack_sequence.py +++ b/numba/tests/test_unpack_sequence.py @@ -1,6 +1,6 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import errors, types from numba import typeof diff --git a/numba/tests/test_usecases.py b/numba/tests/test_usecases.py index 4d5311cf71b..4776117a7ea 100644 --- a/numba/tests/test_usecases.py +++ b/numba/tests/test_usecases.py @@ -1,7 +1,7 @@ import itertools import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, utils from numba.tests import usecases diff --git a/numba/tests/test_vectorization_type_inference.py b/numba/tests/test_vectorization_type_inference.py index 7d347630847..c1ba840c4a0 100644 --- a/numba/tests/test_vectorization_type_inference.py +++ b/numba/tests/test_vectorization_type_inference.py @@ -1,5 +1,5 @@ from numba import vectorize, jit, bool_, double, int_, float_, typeof, int8 -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest import numpy as np diff --git a/numba/tests/test_warnings.py b/numba/tests/test_warnings.py index c0131c01942..e8809b9d08d 100644 --- a/numba/tests/test_warnings.py +++ b/numba/tests/test_warnings.py @@ -4,7 +4,7 @@ import warnings import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba import jit from numba.core.errors import NumbaWarning, deprecated, NumbaDeprecationWarning from numba.core import errors diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index bf9a0884dc5..2b20dee72a5 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -3,7 +3,6 @@ import numpy as np import numba -from numba import unittest_support as unittest from numba.core.transforms import find_setupwiths, with_lifting from numba.core.withcontexts import bypass_context, call_context, objmode_context from numba.core.bytecode import FunctionIdentity, ByteCode @@ -15,6 +14,7 @@ from numba.extending import overload from numba.tests.support import (MemoryLeak, TestCase, captured_stdout, skip_unless_scipy) +from numba.testing import unittest_support as unittest def get_func_ir(func): diff --git a/numba/tests/test_wrapper.py b/numba/tests/test_wrapper.py index 8f8a6580787..5916a13dce3 100644 --- a/numba/tests/test_wrapper.py +++ b/numba/tests/test_wrapper.py @@ -1,6 +1,6 @@ import numpy as np -import numba.unittest_support as unittest +import numba.testing.unittest_support as unittest from numba.core import types, utils, compiler from numba.targets import registry From ddcf72fa6286e8baadc5b480956fab13a30b9fdf Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 11:25:55 +0000 Subject: [PATCH 429/595] Create numba.np.ufunc --- numba/np/ufunc/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/np/ufunc/__init__.py diff --git a/numba/np/ufunc/__init__.py b/numba/np/ufunc/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 49e15ceb8532feafe4201aabc6bfab5b9704bb54 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 12:22:04 +0000 Subject: [PATCH 430/595] Move numba/npyufunc to numba/np/ufunc --- numba/__init__.py | 2 +- numba/core/typed_passes.py | 2 +- numba/cuda/dispatcher.py | 2 +- .../tests/cudapy/test_gufunc_scheduling.py | 2 +- numba/cuda/vectorizers.py | 2 +- numba/misc/numba_entry.py | 6 +-- numba/np/ufunc/__init__.py | 37 +++++++++++++ numba/{npyufunc => np/ufunc}/_internal.c | 0 numba/{npyufunc => np/ufunc}/_internal.h | 2 +- numba/{npyufunc => np/ufunc}/_ufunc.c | 0 numba/{npyufunc => np/ufunc}/array_exprs.py | 4 +- numba/{npyufunc => np/ufunc}/decorators.py | 7 +-- numba/{npyufunc => np/ufunc}/deviceufunc.py | 4 +- numba/{npyufunc => np/ufunc}/dufunc.py | 7 +-- .../ufunc}/gufunc_scheduler.cpp | 0 .../{npyufunc => np/ufunc}/gufunc_scheduler.h | 0 numba/{npyufunc => np/ufunc}/omppool.cpp | 2 +- numba/{npyufunc => np/ufunc}/parallel.py | 10 ++-- numba/{npyufunc => np/ufunc}/parfor.py | 22 +++----- numba/{npyufunc => np/ufunc}/sigparse.py | 1 - numba/{npyufunc => np/ufunc}/tbbpool.cpp | 2 +- numba/{npyufunc => np/ufunc}/ufuncbuilder.py | 6 +-- numba/{npyufunc => np/ufunc}/workqueue.c | 4 +- numba/{npyufunc => np/ufunc}/workqueue.h | 0 numba/{npyufunc => np/ufunc}/wrappers.py | 0 numba/npyufunc/__init__.py | 37 ------------- numba/roc/dispatch.py | 2 +- numba/roc/initialize.py | 6 +-- numba/roc/vectorizers.py | 2 +- numba/tests/npyufunc/test_dufunc.py | 2 +- numba/tests/npyufunc/test_gufunc.py | 2 +- .../npyufunc/test_parallel_env_variable.py | 2 +- .../tests/npyufunc/test_parallel_low_work.py | 2 +- numba/tests/npyufunc/test_ufunc.py | 2 +- numba/tests/npyufunc/test_ufuncbuilding.py | 6 +-- numba/tests/test_parallel_backend.py | 6 +-- numba/tests/test_svml.py | 2 +- setup.py | 54 +++++++++---------- 38 files changed, 120 insertions(+), 129 deletions(-) rename numba/{npyufunc => np/ufunc}/_internal.c (100%) rename numba/{npyufunc => np/ufunc}/_internal.h (92%) rename numba/{npyufunc => np/ufunc}/_ufunc.c (100%) rename numba/{npyufunc => np/ufunc}/array_exprs.py (99%) rename numba/{npyufunc => np/ufunc}/decorators.py (96%) rename numba/{npyufunc => np/ufunc}/deviceufunc.py (99%) rename numba/{npyufunc => np/ufunc}/dufunc.py (98%) rename numba/{npyufunc => np/ufunc}/gufunc_scheduler.cpp (100%) rename numba/{npyufunc => np/ufunc}/gufunc_scheduler.h (100%) rename numba/{npyufunc => np/ufunc}/omppool.cpp (99%) rename numba/{npyufunc => np/ufunc}/parallel.py (98%) rename numba/{npyufunc => np/ufunc}/parfor.py (98%) rename numba/{npyufunc => np/ufunc}/sigparse.py (98%) rename numba/{npyufunc => np/ufunc}/tbbpool.cpp (99%) rename numba/{npyufunc => np/ufunc}/ufuncbuilder.py (98%) rename numba/{npyufunc => np/ufunc}/workqueue.c (99%) rename numba/{npyufunc => np/ufunc}/workqueue.h (100%) rename numba/{npyufunc => np/ufunc}/wrappers.py (100%) delete mode 100644 numba/npyufunc/__init__.py diff --git a/numba/__init__.py b/numba/__init__.py index 373421367e7..2550bcaf0a9 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -32,7 +32,7 @@ jit_module) # Re-export vectorize decorators and the thread layer querying function -from numba.npyufunc import vectorize, guvectorize, threading_layer +from numba.np.ufunc import vectorize, guvectorize, threading_layer # Re-export Numpy helpers from numba.numpy_support import carray, farray, from_dtype diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index 977487dba85..be8c47f7431 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -237,7 +237,7 @@ def _reload_parfors(): """Reloader for cached parfors """ # Re-initialize the parallel backend when load from cache. - from numba.npyufunc.parallel import _launch_threads + from numba.np.ufunc.parallel import _launch_threads _launch_threads() diff --git a/numba/cuda/dispatcher.py b/numba/cuda/dispatcher.py index 6379c18288c..412e0e3ead0 100644 --- a/numba/cuda/dispatcher.py +++ b/numba/cuda/dispatcher.py @@ -6,7 +6,7 @@ from numba.cuda import jit, autojit from numba.cuda.cudadrv import devicearray from .descriptor import CUDATargetDesc -from numba.npyufunc.deviceufunc import (UFuncMechanism, GenerializedUFunc, +from numba.np.ufunc.deviceufunc import (UFuncMechanism, GenerializedUFunc, GUFuncCallSteps) diff --git a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py index 0ad41d227c9..bcd7ebd0b62 100644 --- a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +++ b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py @@ -1,4 +1,4 @@ -from numba.npyufunc.deviceufunc import GUFuncEngine +from numba.np.ufunc.deviceufunc import GUFuncEngine from numba.testing import unittest_support as unittest diff --git a/numba/cuda/vectorizers.py b/numba/cuda/vectorizers.py index c808e3cd6ab..660a90d0837 100644 --- a/numba/cuda/vectorizers.py +++ b/numba/cuda/vectorizers.py @@ -1,6 +1,6 @@ from numba import cuda -from numba.npyufunc import deviceufunc from numba.cuda import dispatcher +from numba.np.ufunc import deviceufunc vectorizer_stager_source = ''' def __vectorized_{name}({args}, __out__): diff --git a/numba/misc/numba_entry.py b/numba/misc/numba_entry.py index 005b9b62412..cdd06297a44 100644 --- a/numba/misc/numba_entry.py +++ b/numba/misc/numba_entry.py @@ -267,7 +267,7 @@ def parse_error(e, backend): return "Unknown import problem." try: - from numba.npyufunc import tbbpool + from numba.np.ufunc import tbbpool print(fmt % ("TBB Threading layer available", True)) except ImportError as e: # might be a missing symbol due to e.g. tbb libraries missing @@ -276,7 +276,7 @@ def parse_error(e, backend): parse_error(e, 'tbbpool'))) try: - from numba.npyufunc import omppool + from numba.np.ufunc import omppool print(fmt % ("OpenMP Threading layer available", True)) except ImportError as e: print(fmt % ("OpenMP Threading layer available", False)) @@ -284,7 +284,7 @@ def parse_error(e, backend): parse_error(e, 'omppool'))) try: - from numba.npyufunc import workqueue + from numba.np.ufunc import workqueue print(fmt % ("Workqueue Threading layer available", True)) except ImportError as e: print(fmt % ("Workqueue Threading layer available", False)) diff --git a/numba/np/ufunc/__init__.py b/numba/np/ufunc/__init__.py index e69de29bb2d..bc85fa47062 100644 --- a/numba/np/ufunc/__init__.py +++ b/numba/np/ufunc/__init__.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize +from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One +from numba.np.ufunc import _internal, array_exprs, parfor +from numba.np.ufunc.parallel import threading_layer +if hasattr(_internal, 'PyUFunc_ReorderableNone'): + PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone +del _internal, array_exprs + + +def _init(): + + def init_cuda_vectorize(): + from numba.cuda.vectorizers import CUDAVectorize + return CUDAVectorize + + def init_cuda_guvectorize(): + from numba.cuda.vectorizers import CUDAGUFuncVectorize + return CUDAGUFuncVectorize + + Vectorize.target_registry.ondemand['cuda'] = init_cuda_vectorize + GUVectorize.target_registry.ondemand['cuda'] = init_cuda_guvectorize + + def init_roc_vectorize(): + from numba.roc.vectorizers import HsaVectorize + return HsaVectorize + + def init_roc_guvectorize(): + from numba.roc.vectorizers import HsaGUFuncVectorize + return HsaGUFuncVectorize + + Vectorize.target_registry.ondemand['roc'] = init_roc_vectorize + GUVectorize.target_registry.ondemand['roc'] = init_roc_guvectorize + +_init() +del _init diff --git a/numba/npyufunc/_internal.c b/numba/np/ufunc/_internal.c similarity index 100% rename from numba/npyufunc/_internal.c rename to numba/np/ufunc/_internal.c diff --git a/numba/npyufunc/_internal.h b/numba/np/ufunc/_internal.h similarity index 92% rename from numba/npyufunc/_internal.h rename to numba/np/ufunc/_internal.h index 3527d155477..2abb358731c 100644 --- a/numba/npyufunc/_internal.h +++ b/numba/np/ufunc/_internal.h @@ -3,7 +3,7 @@ #ifndef NUMBA_UFUNC_INTERNAL_H_ #define NUMBA_UFUNC_INTERNAL_H_ -#include "../_pymodule.h" +#include "../../_pymodule.h" #include #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION diff --git a/numba/npyufunc/_ufunc.c b/numba/np/ufunc/_ufunc.c similarity index 100% rename from numba/npyufunc/_ufunc.c rename to numba/np/ufunc/_ufunc.c diff --git a/numba/npyufunc/array_exprs.py b/numba/np/ufunc/array_exprs.py similarity index 99% rename from numba/npyufunc/array_exprs.py rename to numba/np/ufunc/array_exprs.py index 367cf392279..884d34adaad 100644 --- a/numba/npyufunc/array_exprs.py +++ b/numba/np/ufunc/array_exprs.py @@ -8,7 +8,7 @@ from numba.core import types, utils, ir, rewrites, compiler from numba.core.typing import npydecl -from numba.npyufunc.dufunc import DUFunc +from numba.np.ufunc.dufunc import DUFunc def _is_ufunc(func): @@ -386,7 +386,7 @@ def _lower_array_expr(lowerer, expr): caching=False) # Create kernel subclass calling our native function - from ..targets import npyimpl + from numba.targets import npyimpl class ExprKernel(npyimpl._Kernel): def generate(self, *args): diff --git a/numba/npyufunc/decorators.py b/numba/np/ufunc/decorators.py similarity index 96% rename from numba/npyufunc/decorators.py rename to numba/np/ufunc/decorators.py index e6a783c1630..dce299b2926 100644 --- a/numba/npyufunc/decorators.py +++ b/numba/np/ufunc/decorators.py @@ -1,10 +1,11 @@ import inspect -from numba.npyufunc import _internal, dufunc -from .ufuncbuilder import GUFuncBuilder -from .parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder +from numba.np.ufunc import _internal +from numba.np.ufunc.ufuncbuilder import GUFuncBuilder +from numba.np.ufunc.parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder from numba.targets.registry import TargetRegistry +from numba.np.ufunc import dufunc class _BaseVectorize(object): diff --git a/numba/npyufunc/deviceufunc.py b/numba/np/ufunc/deviceufunc.py similarity index 99% rename from numba/npyufunc/deviceufunc.py rename to numba/np/ufunc/deviceufunc.py index 47a9ec5dcea..d34f4c37171 100644 --- a/numba/npyufunc/deviceufunc.py +++ b/numba/np/ufunc/deviceufunc.py @@ -10,10 +10,10 @@ import numpy as np from numba.core.utils import longint -from numba.npyufunc.ufuncbuilder import _BaseUFuncBuilder, parse_identity +from numba.np.ufunc.ufuncbuilder import _BaseUFuncBuilder, parse_identity from numba.core import types, sigutils from numba.core.typing import signature -from numba.npyufunc.sigparse import parse_signature +from numba.np.ufunc.sigparse import parse_signature def _broadcast_axis(a, b): diff --git a/numba/npyufunc/dufunc.py b/numba/np/ufunc/dufunc.py similarity index 98% rename from numba/npyufunc/dufunc.py rename to numba/np/ufunc/dufunc.py index 5022810887f..fed94efcb12 100644 --- a/numba/npyufunc/dufunc.py +++ b/numba/np/ufunc/dufunc.py @@ -2,13 +2,14 @@ from numba.core import types, utils, serialize, sigutils from numba.core.typing import npydecl from numba.core.typing.templates import AbstractTemplate, signature -from numba.npyufunc import _internal, ufuncbuilder +from numba.np.ufunc import _internal from numba.core.dispatcher import Dispatcher from numba.parfors import array_analysis +from numba.np.ufunc import ufuncbuilder def make_dufunc_kernel(_dufunc): - from ..targets import npyimpl + from numba.targets import npyimpl class DUFuncKernel(npyimpl._Kernel): """ @@ -57,7 +58,7 @@ def __init__(self, dufunc): self.libs = [] def __call__(self, context, builder, sig, args): - from ..targets import npyimpl + from numba.targets import npyimpl explicit_output = len(args) > self.kernel.dufunc.ufunc.nin return npyimpl.numpy_ufunc_kernel(context, builder, sig, args, self.kernel, diff --git a/numba/npyufunc/gufunc_scheduler.cpp b/numba/np/ufunc/gufunc_scheduler.cpp similarity index 100% rename from numba/npyufunc/gufunc_scheduler.cpp rename to numba/np/ufunc/gufunc_scheduler.cpp diff --git a/numba/npyufunc/gufunc_scheduler.h b/numba/np/ufunc/gufunc_scheduler.h similarity index 100% rename from numba/npyufunc/gufunc_scheduler.h rename to numba/np/ufunc/gufunc_scheduler.h diff --git a/numba/npyufunc/omppool.cpp b/numba/np/ufunc/omppool.cpp similarity index 99% rename from numba/npyufunc/omppool.cpp rename to numba/np/ufunc/omppool.cpp index 32293fd94df..c2c62f62284 100644 --- a/numba/npyufunc/omppool.cpp +++ b/numba/np/ufunc/omppool.cpp @@ -2,7 +2,7 @@ Threading layer on top of OpenMP. */ -#include "../_pymodule.h" +#include "../../_pymodule.h" #ifdef _POSIX_C_SOURCE #undef _POSIX_C_SOURCE #endif diff --git a/numba/npyufunc/parallel.py b/numba/np/ufunc/parallel.py similarity index 98% rename from numba/npyufunc/parallel.py rename to numba/np/ufunc/parallel.py index eeb5e47839c..8191df4dd98 100644 --- a/numba/npyufunc/parallel.py +++ b/numba/np/ufunc/parallel.py @@ -22,10 +22,10 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba.npyufunc import ufuncbuilder from numba.numpy_support import as_dtype from numba.core import types, config -from numba.npyufunc.wrappers import _wrapper_info +from numba.np.ufunc.wrappers import _wrapper_info +from numba.np.ufunc import ufuncbuilder def get_thread_count(): @@ -329,18 +329,18 @@ def select_known_backend(backend): lib = None if backend.startswith("tbb"): try: - from numba.npyufunc import tbbpool as lib + from numba.np.ufunc import tbbpool as lib except ImportError: pass elif backend.startswith("omp"): # TODO: Check that if MKL is present that it is a version # that understands GNU OMP might be present try: - from numba.npyufunc import omppool as lib + from numba.np.ufunc import omppool as lib except ImportError: pass elif backend.startswith("workqueue"): - from numba.npyufunc import workqueue as lib + from numba.np.ufunc import workqueue as lib else: msg = "Unknown value specified for threading layer: %s" raise ValueError(msg % backend) diff --git a/numba/npyufunc/parfor.py b/numba/np/ufunc/parfor.py similarity index 98% rename from numba/npyufunc/parfor.py rename to numba/np/ufunc/parfor.py index c3ac6d1a9da..2402b005fb8 100644 --- a/numba/npyufunc/parfor.py +++ b/numba/np/ufunc/parfor.py @@ -5,6 +5,9 @@ import os import sys import numpy as np +import types as pytypes +import operator +import warnings import llvmlite.llvmpy.core as lc import llvmlite.ir.values as liv @@ -12,23 +15,12 @@ import numba from numba import parfor from numba.core import types, ir, config, compiler, lowering, sigutils, cgutils -from numba.core.ir_utils import (add_offset_to_labels, replace_var_names, - remove_dels, legalize_names, mk_unique_var, - rename_labels, get_name_var_table, visit_vars_inner, - get_definition, guard, find_callname, - get_call_table, is_pure, get_np_ufunc_typ, - get_unused_var_name, find_potential_aliases, - is_const_call) -from numba.core.analysis import (compute_use_defs, compute_live_map, - compute_dead_maps, compute_cfg_from_blocks) +from numba.core.ir_utils import add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, get_definition, guard, find_callname, get_call_table, is_pure, get_np_ufunc_typ, get_unused_var_name, find_potential_aliases, is_const_call +from numba.core.analysis import compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks from numba.core.typing import signature from numba.core.cpu import ParallelOptions from numba.parfor import print_wrapped, ensure_parallel_support from numba.core.errors import NumbaParallelSafetyWarning -import types as pytypes -import operator - -import warnings def _lower_parfor_parallel(lowerer, parfor): @@ -44,7 +36,7 @@ def _lower_parfor_parallel(lowerer, parfor): the reduction function across the reduction arrays to produce the final reduction values. """ - from .parallel import get_thread_count + from numba.np.ufunc.parallel import get_thread_count ensure_parallel_support() typingctx = lowerer.context.typing_context @@ -1213,7 +1205,7 @@ def call_parallel_gufunc(lowerer, cres, gu_signature, outer_sig, expr_args, expr context = lowerer.context builder = lowerer.builder - from .parallel import (build_gufunc_wrapper, + from numba.np.ufunc.parallel import (build_gufunc_wrapper, get_thread_count, _launch_threads) diff --git a/numba/npyufunc/sigparse.py b/numba/np/ufunc/sigparse.py similarity index 98% rename from numba/npyufunc/sigparse.py rename to numba/np/ufunc/sigparse.py index 0d18d1349a3..67ca346c903 100644 --- a/numba/npyufunc/sigparse.py +++ b/numba/np/ufunc/sigparse.py @@ -1,6 +1,5 @@ import tokenize import string -from numba.core import utils def parse_signature(sig): diff --git a/numba/npyufunc/tbbpool.cpp b/numba/np/ufunc/tbbpool.cpp similarity index 99% rename from numba/npyufunc/tbbpool.cpp rename to numba/np/ufunc/tbbpool.cpp index d976c8f8974..640c5739cd4 100644 --- a/numba/npyufunc/tbbpool.cpp +++ b/numba/np/ufunc/tbbpool.cpp @@ -4,7 +4,7 @@ Implement parallel vectorize workqueue on top of Intel TBB. #define TBB_PREVIEW_WAITING_FOR_WORKERS 1 /* tbb.h redefines these */ -#include "../_pymodule.h" +#include "../../_pymodule.h" #ifdef _POSIX_C_SOURCE #undef _POSIX_C_SOURCE #endif diff --git a/numba/npyufunc/ufuncbuilder.py b/numba/np/ufunc/ufuncbuilder.py similarity index 98% rename from numba/npyufunc/ufuncbuilder.py rename to numba/np/ufunc/ufuncbuilder.py index 79195e8ea4a..c877a53f26f 100644 --- a/numba/npyufunc/ufuncbuilder.py +++ b/numba/np/ufunc/ufuncbuilder.py @@ -10,9 +10,9 @@ from numba.core.cpu import FastMathOptions from numba.core import utils, types, serialize, compiler, sigutils from numba.numpy_support import as_dtype -from numba.npyufunc import _internal -from numba.npyufunc.sigparse import parse_signature -from numba.npyufunc.wrappers import build_ufunc_wrapper, build_gufunc_wrapper +from numba.np.ufunc import _internal +from numba.np.ufunc.sigparse import parse_signature +from numba.np.ufunc.wrappers import build_ufunc_wrapper, build_gufunc_wrapper from numba.core.caching import FunctionCache, NullCache from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/npyufunc/workqueue.c b/numba/np/ufunc/workqueue.c similarity index 99% rename from numba/npyufunc/workqueue.c rename to numba/np/ufunc/workqueue.c index 17c29d22f87..82956cc1bf9 100644 --- a/numba/npyufunc/workqueue.c +++ b/numba/np/ufunc/workqueue.c @@ -6,9 +6,9 @@ They wait and spin on a task queue for jobs. **WARNING** This module is not thread-safe. Adding task to queue is not protected from -race condition. +race conditions. */ -#include "../_pymodule.h" +#include "../../_pymodule.h" #ifdef _POSIX_C_SOURCE #undef _POSIX_C_SOURCE #endif diff --git a/numba/npyufunc/workqueue.h b/numba/np/ufunc/workqueue.h similarity index 100% rename from numba/npyufunc/workqueue.h rename to numba/np/ufunc/workqueue.h diff --git a/numba/npyufunc/wrappers.py b/numba/np/ufunc/wrappers.py similarity index 100% rename from numba/npyufunc/wrappers.py rename to numba/np/ufunc/wrappers.py diff --git a/numba/npyufunc/__init__.py b/numba/npyufunc/__init__.py deleted file mode 100644 index ff2e5cd43d5..00000000000 --- a/numba/npyufunc/__init__.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- - -from .decorators import Vectorize, GUVectorize, vectorize, guvectorize -from ._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One -from numba.npyufunc import _internal, array_exprs, parfor -from .parallel import threading_layer -if hasattr(_internal, 'PyUFunc_ReorderableNone'): - PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone -del _internal, array_exprs - - -def _init(): - - def init_cuda_vectorize(): - from numba.cuda.vectorizers import CUDAVectorize - return CUDAVectorize - - def init_cuda_guvectorize(): - from numba.cuda.vectorizers import CUDAGUFuncVectorize - return CUDAGUFuncVectorize - - Vectorize.target_registry.ondemand['cuda'] = init_cuda_vectorize - GUVectorize.target_registry.ondemand['cuda'] = init_cuda_guvectorize - - def init_roc_vectorize(): - from numba.roc.vectorizers import HsaVectorize - return HsaVectorize - - def init_roc_guvectorize(): - from numba.roc.vectorizers import HsaGUFuncVectorize - return HsaGUFuncVectorize - - Vectorize.target_registry.ondemand['roc'] = init_roc_vectorize - GUVectorize.target_registry.ondemand['roc'] = init_roc_guvectorize - -_init() -del _init diff --git a/numba/roc/dispatch.py b/numba/roc/dispatch.py index 88b5108e24c..b6f1374019c 100644 --- a/numba/roc/dispatch.py +++ b/numba/roc/dispatch.py @@ -1,6 +1,6 @@ import numpy as np -from numba.npyufunc.deviceufunc import (UFuncMechanism, GenerializedUFunc, +from numba.np.ufunc.deviceufunc import (UFuncMechanism, GenerializedUFunc, GUFuncCallSteps) from numba.roc.hsadrv.driver import dgpu_present import numba.roc.hsadrv.devicearray as devicearray diff --git a/numba/roc/initialize.py b/numba/roc/initialize.py index 589ca0a4a3d..6abc9d2470c 100644 --- a/numba/roc/initialize.py +++ b/numba/roc/initialize.py @@ -1,8 +1,6 @@ #### Additional initialization code ###### - - def _initialize_ufunc(): - from numba.npyufunc import Vectorize + from numba.np.ufunc import Vectorize def init_vectorize(): from numba.roc.vectorizers import HsaVectorize @@ -13,7 +11,7 @@ def init_vectorize(): def _initialize_gufunc(): - from numba.npyufunc import GUVectorize + from numba.np.ufunc import GUVectorize def init_guvectorize(): from numba.roc.vectorizers import HsaGUFuncVectorize diff --git a/numba/roc/vectorizers.py b/numba/roc/vectorizers.py index 19f11e4d315..ec9d143617b 100644 --- a/numba/roc/vectorizers.py +++ b/numba/roc/vectorizers.py @@ -1,7 +1,7 @@ from numba import roc -from numba.npyufunc import deviceufunc from numba.roc import dispatch +from numba.np.ufunc import deviceufunc vectorizer_stager_source = ''' def __vectorized_{name}({args}, __out__): diff --git a/numba/tests/npyufunc/test_dufunc.py b/numba/tests/npyufunc/test_dufunc.py index 29774a096a1..75ec91ec228 100644 --- a/numba/tests/npyufunc/test_dufunc.py +++ b/numba/tests/npyufunc/test_dufunc.py @@ -3,9 +3,9 @@ import numpy as np from numba import njit, vectorize -from numba.npyufunc import dufunc from ..support import MemoryLeakMixin from numba.testing import unittest_support as unittest +from numba.np.ufunc import dufunc def pyuadd(a0, a1): diff --git a/numba/tests/npyufunc/test_gufunc.py b/numba/tests/npyufunc/test_gufunc.py index e0f3f6b7e69..b4105c23ae3 100644 --- a/numba/tests/npyufunc/test_gufunc.py +++ b/numba/tests/npyufunc/test_gufunc.py @@ -2,7 +2,7 @@ import numpy.core.umath_tests as ut from numba import void, float32, jit, guvectorize -from numba.npyufunc import GUVectorize +from numba.np.ufunc import GUVectorize from ..support import tag, TestCase from numba.testing import unittest_support as unittest diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index 8ab18a5023f..bd0a1697f64 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -1,4 +1,4 @@ -from numba.npyufunc.parallel import get_thread_count +from numba.np.ufunc.parallel import get_thread_count from os import environ as env from numba.core import config from numba.testing import unittest_support as unittest diff --git a/numba/tests/npyufunc/test_parallel_low_work.py b/numba/tests/npyufunc/test_parallel_low_work.py index 8e5b7c1ef2d..0c744eb5ba2 100644 --- a/numba/tests/npyufunc/test_parallel_low_work.py +++ b/numba/tests/npyufunc/test_parallel_low_work.py @@ -5,7 +5,7 @@ import numpy as np from numba import float32, float64, int32, uint32 -from numba.npyufunc import Vectorize +from numba.np.ufunc import Vectorize from numba.testing import unittest_support as unittest diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index 074fc0ff629..0382938da10 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -1,7 +1,7 @@ import numpy as np from numba import float32, jit -from numba.npyufunc import Vectorize +from numba.np.ufunc import Vectorize from numba.core.errors import TypingError from ..support import TestCase from numba.testing import unittest_support as unittest diff --git a/numba/tests/npyufunc/test_ufuncbuilding.py b/numba/tests/npyufunc/test_ufuncbuilding.py index 397ac374c4a..581e7d16afe 100644 --- a/numba/tests/npyufunc/test_ufuncbuilding.py +++ b/numba/tests/npyufunc/test_ufuncbuilding.py @@ -2,10 +2,10 @@ import numpy as np -from numba.npyufunc.ufuncbuilder import GUFuncBuilder +from numba.np.ufunc.ufuncbuilder import GUFuncBuilder from numba import vectorize, guvectorize -from numba.npyufunc import PyUFunc_One -from numba.npyufunc.dufunc import DUFunc as UFuncBuilder +from numba.np.ufunc import PyUFunc_One +from numba.np.ufunc.dufunc import DUFunc as UFuncBuilder from ..support import tag, TestCase from numba.core import config from numba.testing import unittest_support as unittest diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 962c521d6d1..8c6c0a9bd6b 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -29,13 +29,13 @@ # Check which backends are available # TODO: Put this in a subprocess so the address space is kept clean try: - from numba.npyufunc import tbbpool # noqa: F401 + from numba.np.ufunc import tbbpool # noqa: F401 _HAVE_TBB_POOL = True except ImportError: _HAVE_TBB_POOL = False try: - from numba.npyufunc import omppool + from numba.np.ufunc import omppool _HAVE_OMP_POOL = True except ImportError: _HAVE_OMP_POOL = False @@ -564,7 +564,7 @@ class TestForkSafetyIssues(ThreadLayerTestHelper): def test_check_threading_layer_is_gnu(self): runme = """if 1: - from numba.npyufunc import omppool + from numba.np.ufunc import omppool assert omppool.openmp_vendor == 'GNU' """ cmdline = [sys.executable, '-c', runme] diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index a95a2a4cfb8..2089b95ee88 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -365,7 +365,7 @@ def check_no_svml(): # then to override using `numba.config` import numba from numba import config - from numba.targets import cpu + from numba.core import cpu from numba.tests.support import override_env_config from numba.core.compiler import compile_isolated, Flags diff --git a/setup.py b/setup.py index 90509935db4..f08d7c95f7b 100644 --- a/setup.py +++ b/setup.py @@ -142,14 +142,14 @@ def get_ext_modules(): depends=["numba/_pymodule.h"], ) - ext_npyufunc_ufunc = Extension(name="numba.npyufunc._internal", - sources=["numba/npyufunc/_internal.c"], - depends=["numba/npyufunc/_ufunc.c", - "numba/npyufunc/_internal.h", - "numba/_pymodule.h"], - **np_compile_args) + ext_np_ufunc = Extension(name="numba.np.ufunc._internal", + sources=["numba/np/ufunc/_internal.c"], + depends=["numba/np/ufunc/_ufunc.c", + "numba/np/ufunc/_internal.h", + "numba/_pymodule.h"], + **np_compile_args) - ext_npyufunc_workqueue_impls = [] + ext_np_ufunc_backends = [] def check_file_at_path(path2file): """ @@ -213,13 +213,13 @@ def check_file_at_path(path2file): if tbb_root: print("Using Intel TBB from:", tbb_root) - ext_npyufunc_tbb_workqueue = Extension( - name='numba.npyufunc.tbbpool', + ext_np_ufunc_tbb_backend = Extension( + name='numba.np.ufunc.tbbpool', sources=[ - 'numba/npyufunc/tbbpool.cpp', - 'numba/npyufunc/gufunc_scheduler.cpp', + 'numba/np/ufunc/tbbpool.cpp', + 'numba/np/ufunc/gufunc_scheduler.cpp', ], - depends=['numba/npyufunc/workqueue.h'], + depends=['numba/np/ufunc/workqueue.h'], include_dirs=[os.path.join(tbb_root, 'include')], extra_compile_args=cpp11flags, libraries=['tbb'], # TODO: if --debug or -g, use 'tbb_debug' @@ -232,7 +232,7 @@ def check_file_at_path(path2file): os.path.join(tbb_root, 'lib', 'intel64', 'vc_mt'), ], ) - ext_npyufunc_workqueue_impls.append(ext_npyufunc_tbb_workqueue) + ext_np_ufunc_backends.append(ext_np_ufunc_tbb_backend) else: print("TBB not found") @@ -243,29 +243,29 @@ def check_file_at_path(path2file): elif have_openmp: print("Using OpenMP from:", have_openmp) # OpenMP backed work queue - ext_npyufunc_omppool = Extension( - name='numba.npyufunc.omppool', + ext_np_ufunc_omppool_backend = Extension( + name='numba.np.ufunc.omppool', sources=[ - 'numba/npyufunc/omppool.cpp', - 'numba/npyufunc/gufunc_scheduler.cpp', + 'numba/np/ufunc/omppool.cpp', + 'numba/np/ufunc/gufunc_scheduler.cpp', ], - depends=['numba/npyufunc/workqueue.h'], + depends=['numba/np/ufunc/workqueue.h'], extra_compile_args=ompcompileflags + cpp11flags, extra_link_args=omplinkflags, ) - ext_npyufunc_workqueue_impls.append(ext_npyufunc_omppool) + ext_np_ufunc_backends.append(ext_np_ufunc_omppool_backend) else: print("OpenMP not found") # Build the Numba workqueue implementation irrespective of whether the TBB # version is built. Users can select a backend via env vars. - ext_npyufunc_workqueue = Extension( - name='numba.npyufunc.workqueue', - sources=['numba/npyufunc/workqueue.c', - 'numba/npyufunc/gufunc_scheduler.cpp'], - depends=['numba/npyufunc/workqueue.h']) - ext_npyufunc_workqueue_impls.append(ext_npyufunc_workqueue) + ext_np_ufunc_workqueue_backend = Extension( + name='numba.np.ufunc.workqueue', + sources=['numba/np/ufunc/workqueue.c', + 'numba/np/ufunc/gufunc_scheduler.cpp'], + depends=['numba/np/ufunc/workqueue.h']) + ext_np_ufunc_backends.append(ext_np_ufunc_workqueue_backend) ext_mviewbuf = Extension(name='numba.mviewbuf', extra_link_args=install_name_tool_fixer, @@ -290,10 +290,10 @@ def check_file_at_path(path2file): include_dirs=["numba"]) ext_modules = [ext_dynfunc, ext_dispatcher, ext_helperlib, ext_typeconv, - ext_npyufunc_ufunc, ext_mviewbuf, ext_nrt_python, + ext_np_ufunc, ext_mviewbuf, ext_nrt_python, ext_jitclass_box, ext_cuda_extras] - ext_modules += ext_npyufunc_workqueue_impls + ext_modules += ext_np_ufunc_backends return ext_modules From 2e3792319bf28dff4e64b429e8b30350e6d50596 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 12:23:20 +0000 Subject: [PATCH 431/595] Move numba/servicelib to numba/roc --- numba/roc/hsadrv/devices.py | 2 +- numba/{ => roc}/servicelib/__init__.py | 0 numba/{ => roc}/servicelib/service.py | 0 numba/{ => roc}/servicelib/threadlocal.py | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename numba/{ => roc}/servicelib/__init__.py (100%) rename numba/{ => roc}/servicelib/service.py (100%) rename numba/{ => roc}/servicelib/threadlocal.py (100%) diff --git a/numba/roc/hsadrv/devices.py b/numba/roc/hsadrv/devices.py index cabb3cc8a1b..5096181762e 100644 --- a/numba/roc/hsadrv/devices.py +++ b/numba/roc/hsadrv/devices.py @@ -2,8 +2,8 @@ Expose each GPU device directly """ import functools -from numba import servicelib from .driver import hsa as driver, Context as _Context +from numba.roc import servicelib class _culist(object): diff --git a/numba/servicelib/__init__.py b/numba/roc/servicelib/__init__.py similarity index 100% rename from numba/servicelib/__init__.py rename to numba/roc/servicelib/__init__.py diff --git a/numba/servicelib/service.py b/numba/roc/servicelib/service.py similarity index 100% rename from numba/servicelib/service.py rename to numba/roc/servicelib/service.py diff --git a/numba/servicelib/threadlocal.py b/numba/roc/servicelib/threadlocal.py similarity index 100% rename from numba/servicelib/threadlocal.py rename to numba/roc/servicelib/threadlocal.py From 6e96be721aa0279679ffadb22927397e22e02fa7 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 12:29:02 +0000 Subject: [PATCH 432/595] Move numba/targets/arraymath.py to numba/np --- numba/core/base.py | 3 +-- numba/{targets => np}/arraymath.py | 0 numba/numpy_extensions.py | 2 +- numba/tests/test_np_functions.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) rename numba/{targets => np}/arraymath.py (100%) diff --git a/numba/core/base.py b/numba/core/base.py index 4f68fdd1cde..c31d4df88c8 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -269,12 +269,11 @@ def refresh(self): Useful for third-party extensions. """ # Populate built-in registry - from numba.targets import arraymath from numba.cpython import (slicing, tupleobj, enumimpl, hashing, heapq, iterators, numbers, rangeobj) from numba.core import optional from numba.misc import gdb_hook, literal - from numba.np import linalg, polynomial + from numba.np import linalg, polynomial, arraymath try: from numba.targets import npdatetime diff --git a/numba/targets/arraymath.py b/numba/np/arraymath.py similarity index 100% rename from numba/targets/arraymath.py rename to numba/np/arraymath.py diff --git a/numba/numpy_extensions.py b/numba/numpy_extensions.py index 0224923c86e..e0051a1fc18 100644 --- a/numba/numpy_extensions.py +++ b/numba/numpy_extensions.py @@ -2,7 +2,7 @@ NumPy extensions. """ -from numba.targets.arraymath import cross2d +from numba.np.arraymath import cross2d __all__ = [ diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 7b38044079b..a2b5cc31d89 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -14,7 +14,7 @@ from numba.core.errors import TypingError from numba.core.config import IS_WIN32, IS_32BITS from numba.core.utils import pysignature -from numba.targets.arraymath import cross2d +from numba.np.arraymath import cross2d from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, needs_blas) from numba.testing import unittest_support as unittest From 626c9c782196c2315dbc2094f26443e7c82196cf Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 12:32:00 +0000 Subject: [PATCH 433/595] Move numba/targets/cffiimpl.py to numba/misc --- numba/core/cpu.py | 3 ++- numba/{targets => misc}/cffiimpl.py | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename numba/{targets => misc}/cffiimpl.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 51e23ac4acf..dfdfd5d7cde 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -60,8 +60,9 @@ def init(self): def load_additional_registries(self): # Add target specific implementations - from numba.targets import (cffiimpl, npyimpl) + from numba.targets import npyimpl from numba.cpython import cmathimpl, mathimpl, printimpl, randomimpl + from numba.misc import cffiimpl self.install_registry(cmathimpl.registry) self.install_registry(cffiimpl.registry) self.install_registry(mathimpl.registry) diff --git a/numba/targets/cffiimpl.py b/numba/misc/cffiimpl.py similarity index 100% rename from numba/targets/cffiimpl.py rename to numba/misc/cffiimpl.py From de554a431b01c994ba55de57ded2adb9637184ff Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 12:39:42 +0000 Subject: [PATCH 434/595] Move numba/targets/npyfuncs.py to numba/np --- numba/{targets => np}/npyfuncs.py | 0 numba/targets/ufunc_db.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{targets => np}/npyfuncs.py (100%) diff --git a/numba/targets/npyfuncs.py b/numba/np/npyfuncs.py similarity index 100% rename from numba/targets/npyfuncs.py rename to numba/np/npyfuncs.py diff --git a/numba/targets/ufunc_db.py b/numba/targets/ufunc_db.py index 2d42b94d825..6f0245c414c 100644 --- a/numba/targets/ufunc_db.py +++ b/numba/targets/ufunc_db.py @@ -47,7 +47,7 @@ def _fill_ufunc_db(ufunc_db): # some of these imports would cause a problem of circular # imports if done at global scope when importing the numba # module. - from numba.targets import npyfuncs + from numba.np import npyfuncs from numba.cpython import cmathimpl, mathimpl, numbers from numba.numpy_support import numpy_version From 181fe79774843ba5c079629e84b98822bc711e88 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 12:41:41 +0000 Subject: [PATCH 435/595] Move numba/targets/ufunc_db.py to numba/np --- numba/{targets => np}/ufunc_db.py | 0 numba/numpy_support.py | 2 +- numba/targets/npyimpl.py | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) rename numba/{targets => np}/ufunc_db.py (100%) diff --git a/numba/targets/ufunc_db.py b/numba/np/ufunc_db.py similarity index 100% rename from numba/targets/ufunc_db.py rename to numba/np/ufunc_db.py diff --git a/numba/numpy_support.py b/numba/numpy_support.py index 367d15b5705..741cb50d4e1 100644 --- a/numba/numpy_support.py +++ b/numba/numpy_support.py @@ -278,7 +278,7 @@ def supported_ufunc_loop(ufunc, loop): legacy and when implementing new ufuncs the ufunc_db should be preferred, as it allows for a more fine-grained incremental support. """ - from .targets import ufunc_db + from numba.np import ufunc_db loop_sig = loop.ufunc_sig try: # check if the loop has a codegen description in the diff --git a/numba/targets/npyimpl.py b/numba/targets/npyimpl.py index fb0a353474b..06193a5e236 100644 --- a/numba/targets/npyimpl.py +++ b/numba/targets/npyimpl.py @@ -13,8 +13,7 @@ import numpy as np import operator -from numba.targets import ufunc_db -from numba.np import arrayobj +from numba.np import arrayobj, ufunc_db from numba.core.imputils import Registry, impl_ret_new_ref, force_error_model from numba import numpy_support from numba.core import typing, types, utils, cgutils, callconv From 6b8fdd975a1cbd33697d145351dcf54ffbbd7887 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 12:47:27 +0000 Subject: [PATCH 436/595] Move numba/targets/npyimpl.py to numba/np --- numba/core/cpu.py | 2 +- numba/{targets => np}/npyimpl.py | 0 numba/np/ufunc/array_exprs.py | 2 +- numba/np/ufunc/dufunc.py | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename numba/{targets => np}/npyimpl.py (100%) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index dfdfd5d7cde..9601f5d00a0 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -60,7 +60,7 @@ def init(self): def load_additional_registries(self): # Add target specific implementations - from numba.targets import npyimpl + from numba.np import npyimpl from numba.cpython import cmathimpl, mathimpl, printimpl, randomimpl from numba.misc import cffiimpl self.install_registry(cmathimpl.registry) diff --git a/numba/targets/npyimpl.py b/numba/np/npyimpl.py similarity index 100% rename from numba/targets/npyimpl.py rename to numba/np/npyimpl.py diff --git a/numba/np/ufunc/array_exprs.py b/numba/np/ufunc/array_exprs.py index 884d34adaad..1762f280b57 100644 --- a/numba/np/ufunc/array_exprs.py +++ b/numba/np/ufunc/array_exprs.py @@ -386,7 +386,7 @@ def _lower_array_expr(lowerer, expr): caching=False) # Create kernel subclass calling our native function - from numba.targets import npyimpl + from numba.np import npyimpl class ExprKernel(npyimpl._Kernel): def generate(self, *args): diff --git a/numba/np/ufunc/dufunc.py b/numba/np/ufunc/dufunc.py index fed94efcb12..8552d155edd 100644 --- a/numba/np/ufunc/dufunc.py +++ b/numba/np/ufunc/dufunc.py @@ -9,7 +9,7 @@ def make_dufunc_kernel(_dufunc): - from numba.targets import npyimpl + from numba.np import npyimpl class DUFuncKernel(npyimpl._Kernel): """ @@ -58,7 +58,7 @@ def __init__(self, dufunc): self.libs = [] def __call__(self, context, builder, sig, args): - from numba.targets import npyimpl + from numba.np import npyimpl explicit_output = len(args) > self.kernel.dufunc.ufunc.nin return npyimpl.numpy_ufunc_kernel(context, builder, sig, args, self.kernel, From 221164e89fa698e089aafff1a68fd74b874da9de Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 13:00:48 +0000 Subject: [PATCH 437/595] Move numba/numpy_support.py to numba/np --- numba/__init__.py | 4 ++-- numba/core/boxing.py | 2 +- numba/core/datamodel/models.py | 2 +- numba/core/types/abstract.py | 2 +- numba/core/types/npytypes.py | 2 +- numba/core/typing/cffi_utils.py | 2 +- numba/core/typing/npydecl.py | 2 +- numba/core/typing/randomdecl.py | 2 +- numba/core/typing/typeof.py | 2 +- numba/cuda/cudadrv/devicearray.py | 2 +- numba/cuda/kernels/reduction.py | 2 +- numba/cuda/kernels/transpose.py | 2 +- numba/cuda/simulator/cudadrv/devicearray.py | 2 +- numba/cuda/simulator/kernelapi.py | 2 +- numba/cuda/tests/cudadrv/test_cuda_devicerecord.py | 3 ++- numba/cuda/tests/cudapy/test_complex.py | 3 ++- numba/cuda/tests/cudapy/test_datetime.py | 2 +- numba/cuda/tests/cudapy/test_record_dtype.py | 3 ++- numba/cuda/tests/cudapy/test_serialize.py | 3 ++- numba/cuda/tests/cudapy/test_sm.py | 2 +- numba/np/arraymath.py | 6 +++--- numba/np/arrayobj.py | 4 ++-- numba/np/linalg.py | 2 +- numba/np/npyimpl.py | 5 ++--- numba/{ => np}/numpy_support.py | 0 numba/np/polynomial.py | 2 +- numba/np/ufunc/dufunc.py | 3 ++- numba/np/ufunc/parallel.py | 2 +- numba/np/ufunc/ufuncbuilder.py | 2 +- numba/np/ufunc_db.py | 2 +- numba/parfor.py | 2 +- numba/roc/hsadrv/devicearray.py | 2 +- numba/stencil.py | 2 +- numba/targets/npdatetime.py | 3 +-- numba/tests/support.py | 3 ++- numba/tests/test_array_attr.py | 2 +- numba/tests/test_array_methods.py | 2 +- numba/tests/test_cfunc.py | 3 ++- numba/tests/test_conversion.py | 3 ++- numba/tests/test_dispatcher.py | 2 +- numba/tests/test_iteration.py | 2 +- numba/tests/test_mathlib.py | 2 +- numba/tests/test_np_functions.py | 2 +- numba/tests/test_npdatetime.py | 6 +++--- numba/tests/test_numpy_support.py | 2 +- numba/tests/test_recarray_usecases.py | 2 +- numba/tests/test_record_dtype.py | 5 +++-- numba/tests/test_typeof.py | 3 ++- numba/tests/test_types.py | 3 ++- numba/tests/test_ufuncs.py | 5 +++-- 50 files changed, 70 insertions(+), 60 deletions(-) rename numba/{ => np}/numpy_support.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index 2550bcaf0a9..35d3ad15aff 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -35,7 +35,7 @@ from numba.np.ufunc import vectorize, guvectorize, threading_layer # Re-export Numpy helpers -from numba.numpy_support import carray, farray, from_dtype +from numba.np.numpy_support import carray, farray, from_dtype # Re-export experimental from numba import experimental @@ -113,7 +113,7 @@ def _ensure_critical_deps(): """ Make sure Python, NumPy and SciPy have supported versions. """ - from numba.numpy_support import numpy_version + from numba.np.numpy_support import numpy_version from numba.core.utils import PYVERSION if PYVERSION < (3, 6): diff --git a/numba/core/boxing.py b/numba/core/boxing.py index c5f62ebaa97..89737893f8f 100644 --- a/numba/core/boxing.py +++ b/numba/core/boxing.py @@ -4,11 +4,11 @@ from llvmlite import ir -from numba import numpy_support from numba.core import types, cgutils from numba.core.pythonapi import box, unbox, reflect, NativeValue from numba.cpython import setobj, listobj +from numba.np import numpy_support # # Scalar types diff --git a/numba/core/datamodel/models.py b/numba/core/datamodel/models.py index 75646474127..4dd2b040663 100644 --- a/numba/core/datamodel/models.py +++ b/numba/core/datamodel/models.py @@ -2,9 +2,9 @@ from llvmlite import ir -from numba import numpy_support from numba.core.datamodel.registry import register_default from numba.core import types, cgutils +from numba.np import numpy_support class DataModel(object): diff --git a/numba/core/types/abstract.py b/numba/core/types/abstract.py index 0dc3d9c4d55..bb46b32c7ac 100644 --- a/numba/core/types/abstract.py +++ b/numba/core/types/abstract.py @@ -245,7 +245,7 @@ def unify(self, typingctx, other): """ Unify the two number types using Numpy's rules. """ - from numba import numpy_support + from numba.np import numpy_support if isinstance(other, Number): # XXX: this can produce unsafe conversions, # e.g. would unify {int64, uint64} to float64 diff --git a/numba/core/types/npytypes.py b/numba/core/types/npytypes.py index 61cc1694982..5160a6c40de 100644 --- a/numba/core/types/npytypes.py +++ b/numba/core/types/npytypes.py @@ -199,7 +199,7 @@ def members(self): @property def dtype(self): - from numba.numpy_support import as_struct_dtype + from numba.np.numpy_support import as_struct_dtype return as_struct_dtype(self) diff --git a/numba/core/typing/cffi_utils.py b/numba/core/typing/cffi_utils.py index 58a6d3f1494..022e7642daf 100644 --- a/numba/core/typing/cffi_utils.py +++ b/numba/core/typing/cffi_utils.py @@ -10,9 +10,9 @@ import numpy as np from numba.core import types -from numba import numpy_support from numba.core.errors import TypingError from numba.core.typing import templates +from numba.np import numpy_support try: import cffi diff --git a/numba/core/typing/npydecl.py b/numba/core/typing/npydecl.py index eebe8e682e2..9d12923199d 100644 --- a/numba/core/typing/npydecl.py +++ b/numba/core/typing/npydecl.py @@ -7,7 +7,7 @@ from numba.core.typing.templates import (AttributeTemplate, AbstractTemplate, CallableTemplate, Registry, signature) -from numba.numpy_support import (ufunc_find_matching_loop, +from numba.np.numpy_support import (ufunc_find_matching_loop, supported_ufunc_loop, as_dtype, from_dtype, as_dtype, resolve_output_type, carray, farray) diff --git a/numba/core/typing/randomdecl.py b/numba/core/typing/randomdecl.py index 996d1acf34a..7eeaa7567f4 100644 --- a/numba/core/typing/randomdecl.py +++ b/numba/core/typing/randomdecl.py @@ -5,7 +5,7 @@ from numba.core import types from .templates import (ConcreteTemplate, AbstractTemplate, AttributeTemplate, CallableTemplate, Registry, signature) -from numba.numpy_support import numpy_version +from numba.np.numpy_support import numpy_version registry = Registry() diff --git a/numba/core/typing/typeof.py b/numba/core/typing/typeof.py index 6b92bb2dfc1..ae38ca9fa2e 100644 --- a/numba/core/typing/typeof.py +++ b/numba/core/typing/typeof.py @@ -5,8 +5,8 @@ import numpy as np -from numba import numpy_support from numba.core import types, utils, errors +from numba.np import numpy_support # terminal color markup _termcolor = errors.termcolor() diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 06ec8c75baf..cc956d35915 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -16,10 +16,10 @@ import numba from numba.cuda.cudadrv import driver as _driver from numba.cuda.cudadrv import devices -from numba import numpy_support from numba.core import types from numba.np.unsafe.ndarray import to_fixed_tuple from numba.misc import dummyarray +from numba.np import numpy_support try: lru_cache = getattr(functools, 'lru_cache')(None) diff --git a/numba/cuda/kernels/reduction.py b/numba/cuda/kernels/reduction.py index 6b9ef1a59da..cb9342e0eeb 100644 --- a/numba/cuda/kernels/reduction.py +++ b/numba/cuda/kernels/reduction.py @@ -2,7 +2,7 @@ A library written in CUDA Python for generating reduction kernels """ -from numba.numpy_support import from_dtype +from numba.np.numpy_support import from_dtype _WARPSIZE = 32 diff --git a/numba/cuda/kernels/transpose.py b/numba/cuda/kernels/transpose.py index 4dd50b988e7..4ae75f391a1 100644 --- a/numba/cuda/kernels/transpose.py +++ b/numba/cuda/kernels/transpose.py @@ -1,7 +1,7 @@ from numba import cuda from numba.cuda.cudadrv.driver import driver -from numba import numpy_support as nps import math +from numba.np import numpy_support as nps def transpose(a, b=None): """Compute the transpose of 'a' and store it into 'b', if given, diff --git a/numba/cuda/simulator/cudadrv/devicearray.py b/numba/cuda/simulator/cudadrv/devicearray.py index 1b4c1556e66..d96296c7530 100644 --- a/numba/cuda/simulator/cudadrv/devicearray.py +++ b/numba/cuda/simulator/cudadrv/devicearray.py @@ -7,8 +7,8 @@ import numpy as np -from numba import numpy_support from numba.core import types +from numba.np import numpy_support DeviceRecord = None from_record_like = None diff --git a/numba/cuda/simulator/kernelapi.py b/numba/cuda/simulator/kernelapi.py index daa93b2cf3e..e5c2c95819b 100644 --- a/numba/cuda/simulator/kernelapi.py +++ b/numba/cuda/simulator/kernelapi.py @@ -10,7 +10,7 @@ import numpy as np -from numba import numpy_support +from numba.np import numpy_support class Dim3(object): diff --git a/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py b/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py index 7ac81beff5c..41fd8ec2a74 100644 --- a/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +++ b/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py @@ -2,10 +2,11 @@ import ctypes from numba.cuda.cudadrv.devicearray import (DeviceRecord, from_record_like, auto_device) -from numba import cuda, numpy_support +from numba import cuda from numba.cuda.testing import unittest, SerialMixin from numba.cuda.testing import skip_on_cudasim import numpy as np +from numba.np import numpy_support @skip_on_cudasim('Device Record API unsupported in the simulator') class TestCudaDeviceRecord(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_complex.py b/numba/cuda/tests/cudapy/test_complex.py index b1e35c7b645..b2523dfaf7e 100644 --- a/numba/cuda/tests/cudapy/test_complex.py +++ b/numba/cuda/tests/cudapy/test_complex.py @@ -9,9 +9,10 @@ from numba.cuda.testing import unittest, SerialMixin from numba.core import types, utils -from numba import cuda, numpy_support +from numba import cuda from numba.tests.support import TestCase, compile_function from numba.tests.complex_usecases import * +from numba.np import numpy_support def compile_scalar_func(pyfunc, argtypes, restype): diff --git a/numba/cuda/tests/cudapy/test_datetime.py b/numba/cuda/tests/cudapy/test_datetime.py index c2b1a95b24f..5d29ee45799 100644 --- a/numba/cuda/tests/cudapy/test_datetime.py +++ b/numba/cuda/tests/cudapy/test_datetime.py @@ -1,7 +1,7 @@ import numpy as np from numba import cuda, vectorize, guvectorize -from numba.numpy_support import from_dtype +from numba.np.numpy_support import from_dtype from numba.tests.support import TestCase from numba.cuda.testing import SerialMixin, skip_on_cudasim from numba.testing import unittest_support as unittest diff --git a/numba/cuda/tests/cudapy/test_record_dtype.py b/numba/cuda/tests/cudapy/test_record_dtype.py index 9ddb8fd84c9..10315e88c19 100644 --- a/numba/cuda/tests/cudapy/test_record_dtype.py +++ b/numba/cuda/tests/cudapy/test_record_dtype.py @@ -1,10 +1,11 @@ import sys import numpy as np -from numba import cuda, numpy_support +from numba import cuda from numba.core import types from numba.cuda.testing import skip_on_cudasim, SerialMixin from numba.testing import unittest_support as unittest +from numba.np import numpy_support def set_a(ary, i, v): diff --git a/numba/cuda/tests/cudapy/test_serialize.py b/numba/cuda/tests/cudapy/test_serialize.py index 52a4fd517ee..615f80cb446 100644 --- a/numba/cuda/tests/cudapy/test_serialize.py +++ b/numba/cuda/tests/cudapy/test_serialize.py @@ -1,9 +1,10 @@ import pickle import numpy as np -from numba import cuda, vectorize, numpy_support +from numba import cuda, vectorize from numba.core import types from numba.cuda.testing import skip_on_cudasim, SerialMixin from numba.testing import unittest_support as unittest +from numba.np import numpy_support @skip_on_cudasim('pickling not supported in CUDASIM') diff --git a/numba/cuda/tests/cudapy/test_sm.py b/numba/cuda/tests/cudapy/test_sm.py index 4e6e1ea8fa1..d6201c0c3f6 100644 --- a/numba/cuda/tests/cudapy/test_sm.py +++ b/numba/cuda/tests/cudapy/test_sm.py @@ -1,9 +1,9 @@ from numba import cuda, int32, float64 -from numba import numpy_support as nps from numba.cuda.testing import unittest, SerialMixin import numpy as np +from numba.np import numpy_support as nps recordwith2darray = np.dtype([('i', np.int32), diff --git a/numba/np/arraymath.py b/numba/np/arraymath.py index aac89598465..057f3504812 100644 --- a/numba/np/arraymath.py +++ b/numba/np/arraymath.py @@ -15,9 +15,9 @@ from numba import generated_jit from numba.core import types, cgutils from numba.extending import overload, overload_method, register_jitable -from numba.numpy_support import as_dtype, type_can_asarray -from numba.numpy_support import numpy_version -from numba.numpy_support import is_nonelike +from numba.np.numpy_support import as_dtype, type_can_asarray +from numba.np.numpy_support import numpy_version +from numba.np.numpy_support import is_nonelike from numba.core.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) from numba.core.typing import signature diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 2118e6db794..2e9f81c8bf9 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -16,9 +16,9 @@ from numba import extending, pndindex from numba.core import types, utils, typing, errors, cgutils -from numba.numpy_support import (as_dtype, carray, farray, is_contiguous, +from numba.np.numpy_support import (as_dtype, carray, farray, is_contiguous, is_fortran) -from numba.numpy_support import type_can_asarray, is_nonelike +from numba.np.numpy_support import type_can_asarray, is_nonelike from numba.core.imputils import (lower_builtin, lower_getattr, lower_getattr_generic, lower_setattr_generic, diff --git a/numba/np/linalg.py b/numba/np/linalg.py index 0dca84c7fef..7ee2b85f385 100644 --- a/numba/np/linalg.py +++ b/numba/np/linalg.py @@ -16,8 +16,8 @@ from numba.extending import overload, register_jitable from numba.core import types, cgutils from numba.core.errors import TypingError -from numba import numpy_support as np_support from .arrayobj import make_array, _empty_nd_impl, array_copy +from numba.np import numpy_support as np_support ll_char = ir.IntType(8) ll_char_p = ll_char.as_pointer() diff --git a/numba/np/npyimpl.py b/numba/np/npyimpl.py index 06193a5e236..cb0a92b09e0 100644 --- a/numba/np/npyimpl.py +++ b/numba/np/npyimpl.py @@ -13,11 +13,10 @@ import numpy as np import operator -from numba.np import arrayobj, ufunc_db +from numba.np import arrayobj, ufunc_db, numpy_support from numba.core.imputils import Registry, impl_ret_new_ref, force_error_model -from numba import numpy_support from numba.core import typing, types, utils, cgutils, callconv -from numba.numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype +from numba.np.numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype from numba.core.typing import npydecl from numba.extending import overload, intrinsic diff --git a/numba/numpy_support.py b/numba/np/numpy_support.py similarity index 100% rename from numba/numpy_support.py rename to numba/np/numpy_support.py diff --git a/numba/np/polynomial.py b/numba/np/polynomial.py index 2f5d7714fb0..cdbefe0e6e4 100644 --- a/numba/np/polynomial.py +++ b/numba/np/polynomial.py @@ -8,7 +8,7 @@ from numba import jit from numba.core import types from numba.extending import overload -from numba import numpy_support as np_support +from numba.np import numpy_support as np_support @overload(np.roots) diff --git a/numba/np/ufunc/dufunc.py b/numba/np/ufunc/dufunc.py index 8552d155edd..63eaf83e9d2 100644 --- a/numba/np/ufunc/dufunc.py +++ b/numba/np/ufunc/dufunc.py @@ -1,4 +1,4 @@ -from numba import jit, typeof, numpy_support +from numba import jit, typeof from numba.core import types, utils, serialize, sigutils from numba.core.typing import npydecl from numba.core.typing.templates import AbstractTemplate, signature @@ -6,6 +6,7 @@ from numba.core.dispatcher import Dispatcher from numba.parfors import array_analysis from numba.np.ufunc import ufuncbuilder +from numba.np import numpy_support def make_dufunc_kernel(_dufunc): diff --git a/numba/np/ufunc/parallel.py b/numba/np/ufunc/parallel.py index 8191df4dd98..098062dc6a3 100644 --- a/numba/np/ufunc/parallel.py +++ b/numba/np/ufunc/parallel.py @@ -22,7 +22,7 @@ import llvmlite.llvmpy.core as lc import llvmlite.binding as ll -from numba.numpy_support import as_dtype +from numba.np.numpy_support import as_dtype from numba.core import types, config from numba.np.ufunc.wrappers import _wrapper_info from numba.np.ufunc import ufuncbuilder diff --git a/numba/np/ufunc/ufuncbuilder.py b/numba/np/ufunc/ufuncbuilder.py index c877a53f26f..7e991803920 100644 --- a/numba/np/ufunc/ufuncbuilder.py +++ b/numba/np/ufunc/ufuncbuilder.py @@ -9,7 +9,7 @@ from numba.targets.registry import dispatcher_registry, cpu_target from numba.core.cpu import FastMathOptions from numba.core import utils, types, serialize, compiler, sigutils -from numba.numpy_support import as_dtype +from numba.np.numpy_support import as_dtype from numba.np.ufunc import _internal from numba.np.ufunc.sigparse import parse_signature from numba.np.ufunc.wrappers import build_ufunc_wrapper, build_gufunc_wrapper diff --git a/numba/np/ufunc_db.py b/numba/np/ufunc_db.py index 6f0245c414c..cc12453e024 100644 --- a/numba/np/ufunc_db.py +++ b/numba/np/ufunc_db.py @@ -49,7 +49,7 @@ def _fill_ufunc_db(ufunc_db): # module. from numba.np import npyfuncs from numba.cpython import cmathimpl, mathimpl, numbers - from numba.numpy_support import numpy_version + from numba.np.numpy_support import numpy_version ufunc_db[np.negative] = { '?->?': numbers.int_invert_impl, diff --git a/numba/parfor.py b/numba/parfor.py index 43069d9528f..11dbdaa4a13 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -27,7 +27,7 @@ import numba.core.ir from numba.core import types, typing, utils, errors, ir, analysis, postproc, rewrites, typeinfer, config, ir_utils from numba import prange, pndindex -from numba.numpy_support import as_dtype +from numba.np.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate from numba import stencilparfor from numba.stencilparfor import StencilPass diff --git a/numba/roc/hsadrv/devicearray.py b/numba/roc/hsadrv/devicearray.py index 03c5af024bd..7cd6388d359 100644 --- a/numba/roc/hsadrv/devicearray.py +++ b/numba/roc/hsadrv/devicearray.py @@ -11,10 +11,10 @@ import numpy as np from numba.roc.hsadrv import driver as _driver from numba.roc.hsadrv import devices -from numba import numpy_support from numba.core import types from .error import HsaContextMismatchError from numba.misc import dummyarray +from numba.np import numpy_support try: long diff --git a/numba/stencil.py b/numba/stencil.py index b692a548a05..098a52596c9 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -8,7 +8,6 @@ import numpy as np from llvmlite import ir as lir -from numba import numpy_support from numba.core import types, typing, utils, ir, typed_passes, config, compiler, ir_utils from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) @@ -18,6 +17,7 @@ import numba import operator +from numba.np import numpy_support class StencilFuncLowerer(object): '''Callable class responsible for lowering calls to a specific StencilFunc. diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index 1e125a20138..bb082b68831 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -8,11 +8,10 @@ from llvmlite.llvmpy.core import Type, Constant import llvmlite.llvmpy.core as lc -from numba import numpy_support from numba.core import types, cgutils from numba.core.imputils import (lower_builtin, lower_constant, impl_ret_untracked) -from numba.np import npdatetime +from numba.np import npdatetime, numpy_support # datetime64 and timedelta64 use the same internal representation DATETIME64 = TIMEDELTA64 = Type.int(64) diff --git a/numba/tests/support.py b/numba/tests/support.py index 0e851f50362..272cdcb7544 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -23,11 +23,12 @@ import numpy as np -from numba import numpy_support, testing +from numba import testing from numba.core import errors, typing, utils, config, cpu from numba.core.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS import numba.testing.unittest_support as unittest from numba.runtime import rtsys +from numba.np import numpy_support try: diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index bd361433385..eddc3e39723 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -2,7 +2,7 @@ import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated -from numba.numpy_support import from_dtype +from numba.np.numpy_support import from_dtype from numba import njit, typeof from numba.core import types from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index e34bf3d2dbd..95dc22cecbd 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -8,7 +8,7 @@ from numba.core import types from numba.core.compiler import compile_isolated from numba.core.errors import TypingError, LoweringError -from numba.numpy_support import as_dtype +from numba.np.numpy_support import as_dtype from numba.tests.support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, tag, needs_blas) from numba.testing import unittest_support as unittest diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index 13849019da6..6d6e5aef9db 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -13,10 +13,11 @@ from numba import cfunc, carray, farray, njit from numba.core import types, typing, utils -from numba import cffi_support, numpy_support +from numba import cffi_support from numba.tests.support import TestCase, tag, captured_stderr from numba.tests.test_dispatcher import BaseCacheTest from numba.testing import unittest_support as unittest +from numba.np import numpy_support skip_cffi_unsupported = unittest.skipUnless( cffi_support.SUPPORTED, diff --git a/numba/tests/test_conversion.py b/numba/tests/test_conversion.py index 0da2afe1f6d..bb97673c9ba 100644 --- a/numba/tests/test_conversion.py +++ b/numba/tests/test_conversion.py @@ -7,9 +7,10 @@ import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags -from numba import jit, numpy_support +from numba import jit from numba.core import types from numba.tests.support import TestCase +from numba.np import numpy_support def identity(x): diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 9fa462c9aef..4a0eaa5de36 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -23,7 +23,7 @@ from numba.tests.support import (TestCase, temp_directory, import_dynamic, override_env_config, capture_cache_log, captured_stdout) -from numba.numpy_support import as_dtype +from numba.np.numpy_support import as_dtype from numba.core.caching import _UserWideCacheLocator from numba.core.dispatcher import Dispatcher from numba import parfor diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index a69c1ff3c6d..8097ee40dc9 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -3,9 +3,9 @@ from numba import njit import numba.testing.unittest_support as unittest from numba.core.compiler import compile_isolated, Flags -from numba import numpy_support from numba.core import types, errors from numba.tests.support import TestCase, MemoryLeakMixin, tag +from numba.np import numpy_support enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index 697d892375e..c3728bea36d 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -6,11 +6,11 @@ import numpy as np from numba.core.compiler import compile_isolated, Flags -from numba import numpy_support from numba.core import utils, types from numba.core.config import IS_WIN32, IS_32BITS from numba.tests.support import TestCase, CompilationCache, tag from numba.testing import unittest_support as unittest +from numba.np import numpy_support enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index a2b5cc31d89..5ae51ebc1d7 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -10,7 +10,7 @@ from numba.core.compiler import Flags from numba import jit, njit, typeof from numba.core import types -from numba.numpy_support import numpy_version +from numba.np.numpy_support import numpy_version from numba.core.errors import TypingError from numba.core.config import IS_WIN32, IS_32BITS from numba.core.utils import pysignature diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 453e610173d..3820c674c80 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -12,12 +12,12 @@ import numpy as np import numba.testing.unittest_support as unittest -from numba import jit, vectorize, numpy_support -from numba.numpy_support import numpy_version +from numba import jit, vectorize +from numba.np.numpy_support import numpy_version from numba.core import types, config from numba.core.errors import TypingError from numba.tests.support import TestCase, tag -from numba.np import npdatetime +from numba.np import npdatetime, numpy_support def value_unit(val): diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index 249b130ad2b..53f2d41d6a7 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -9,10 +9,10 @@ import numpy as np import numba.testing.unittest_support as unittest -from numba import numpy_support from numba.core import types from numba.tests.support import TestCase from numba.tests.enum_usecases import Shake, RequestError +from numba.np import numpy_support class TestFromDtype(TestCase): diff --git a/numba/tests/test_recarray_usecases.py b/numba/tests/test_recarray_usecases.py index 93505c24189..0e0c7c34d51 100644 --- a/numba/tests/test_recarray_usecases.py +++ b/numba/tests/test_recarray_usecases.py @@ -2,11 +2,11 @@ import numpy as np -from numba import numpy_support from numba.core import types from numba.core.compiler import compile_isolated from numba.tests.support import captured_stdout, tag, TestCase from numba.testing import unittest_support as unittest +from numba.np import numpy_support def usecase1(arr1, arr2): diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index a443f58cff3..27bdfb1b09f 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -2,13 +2,14 @@ import numpy as np import ctypes -from numba import jit, numpy_support +from numba import jit from numba.core import types from numba.core.compiler import compile_isolated from numba.core.itanium_mangler import mangle_type from numba.core.config import IS_WIN32 -from numba.numpy_support import numpy_version +from numba.np.numpy_support import numpy_version from numba.testing import unittest_support as unittest +from numba.np import numpy_support def get_a(ary, i): diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 30bf979b4db..df1256b107c 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -9,7 +9,7 @@ import numpy as np import numba.testing.unittest_support as unittest -from numba import cffi_support, numpy_support +from numba import cffi_support from numba.core import types from numba.special import typeof from numba.core.dispatcher import OmittedArg @@ -19,6 +19,7 @@ from numba.tests.test_numpy_support import ValueTypingTestBase from numba.tests.ctypes_usecases import * from numba.tests.enum_usecases import * +from numba.np import numpy_support recordtype = np.dtype([('a', np.float64), diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 70336d4dd21..a1968e87f68 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -19,12 +19,13 @@ from numba.core import types, typing, errors, sigutils from numba.core.types.abstract import _typecache from numba.core.typing.templates import make_overload_template -from numba import jit, njit, numpy_support, typeof +from numba import jit, njit, typeof from numba.extending import (overload, register_model, models, unbox, NativeValue, typeof_impl) from numba.tests.support import TestCase, temp_directory from numba.tests.enum_usecases import Color, Shake, Shape from numba.testing import unittest_support as unittest +from numba.np import numpy_support try: diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index 872700f4090..aed430f8302 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -9,14 +9,15 @@ import numpy as np import numba.testing.unittest_support as unittest -from numba import typeof, numpy_support, njit +from numba import typeof, njit from numba.core import types, typing, utils from numba.core.compiler import compile_isolated, Flags, DEFAULT_FLAGS -from numba.numpy_support import from_dtype +from numba.np.numpy_support import from_dtype from numba import jit, vectorize from numba.core.errors import LoweringError, TypingError from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin, tag from numba.core.typing.npydecl import supported_ufuncs, all_ufuncs +from numba.np import numpy_support is32bits = tuple.__itemsize__ == 4 iswindows = sys.platform.startswith('win32') From a095803eccbf2575eab67ca6b2fd016a70dfa3ce Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 13:18:31 +0000 Subject: [PATCH 438/595] Move numba/np/npdatetime.py to numba/np/npdatetime_helpers.py --- numba/core/types/scalars.py | 4 +-- numba/core/typing/npdatetime.py | 30 +++++++++++-------- .../{npdatetime.py => npdatetime_helpers.py} | 0 numba/targets/npdatetime.py | 20 ++++++------- numba/tests/test_npdatetime.py | 20 ++++++------- 5 files changed, 39 insertions(+), 35 deletions(-) rename numba/np/{npdatetime.py => npdatetime_helpers.py} (100%) diff --git a/numba/core/types/scalars.py b/numba/core/types/scalars.py index 57241446f78..29b898ca7d3 100644 --- a/numba/core/types/scalars.py +++ b/numba/core/types/scalars.py @@ -6,7 +6,7 @@ from functools import total_ordering from numba.core import utils from numba.core.typeconv import Conversion -from numba.np import npdatetime +from numba.np import npdatetime_helpers class Boolean(Hashable): @@ -140,7 +140,7 @@ class _NPDatetimeBase(Type): def __init__(self, unit, *args, **kws): name = '%s[%s]' % (self.type_name, unit) self.unit = unit - self.unit_code = npdatetime.DATETIME_UNITS[self.unit] + self.unit_code = npdatetime_helpers.DATETIME_UNITS[self.unit] super(_NPDatetimeBase, self).__init__(name, *args, **kws) def __lt__(self, other): diff --git a/numba/core/typing/npdatetime.py b/numba/core/typing/npdatetime.py index 7450c0f899d..a51cc4cd010 100644 --- a/numba/core/typing/npdatetime.py +++ b/numba/core/typing/npdatetime.py @@ -10,7 +10,7 @@ from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, AbstractTemplate, infer_global, infer, infer_getattr, signature) -from numba.np import npdatetime +from numba.np import npdatetime_helpers # timedelta64-only operations @@ -36,9 +36,9 @@ def generic(self, args, kws): left, right = args if not all(isinstance(tp, types.NPTimedelta) for tp in args): return - if npdatetime.can_cast_timedelta_units(left.unit, right.unit): + if npdatetime_helpers.can_cast_timedelta_units(left.unit, right.unit): return signature(right, left, right) - elif npdatetime.can_cast_timedelta_units(right.unit, left.unit): + elif npdatetime_helpers.can_cast_timedelta_units(right.unit, left.unit): return signature(left, left, right) @@ -59,8 +59,8 @@ def generic(self, args, kws): left, right = args if not all(isinstance(tp, types.NPTimedelta) for tp in args): return - if (npdatetime.can_cast_timedelta_units(left.unit, right.unit) or - npdatetime.can_cast_timedelta_units(right.unit, left.unit)): + if (npdatetime_helpers.can_cast_timedelta_units(left.unit, right.unit) or + npdatetime_helpers.can_cast_timedelta_units(right.unit, left.unit)): return signature(types.boolean, left, right) @@ -100,8 +100,8 @@ def generic(self, args, kws): if not isinstance(left, types.NPTimedelta): return if isinstance(right, types.NPTimedelta): - if (npdatetime.can_cast_timedelta_units(left.unit, right.unit) - or npdatetime.can_cast_timedelta_units(right.unit, left.unit)): + if (npdatetime_helpers.can_cast_timedelta_units(left.unit, right.unit) + or npdatetime_helpers.can_cast_timedelta_units(right.unit, left.unit)): return signature(types.float64, left, right) elif isinstance(right, (types.Float)): return signature(left, left, right) @@ -195,7 +195,8 @@ def generic(self, args, kws): else: return if isinstance(dt, types.NPDatetime): - unit = npdatetime.combine_datetime_timedelta_units(dt.unit, td.unit) + unit = npdatetime_helpers.combine_datetime_timedelta_units(dt.unit, + td.unit) if unit is not None: return signature(types.NPDatetime(unit), left, right) @@ -209,8 +210,10 @@ def generic(self, args, kws): # Guard against unary - return dt, td = args - if isinstance(dt, types.NPDatetime) and isinstance(td, types.NPTimedelta): - unit = npdatetime.combine_datetime_timedelta_units(dt.unit, td.unit) + if isinstance(dt, types.NPDatetime) and isinstance(td, + types.NPTimedelta): + unit = npdatetime_helpers.combine_datetime_timedelta_units(dt.unit, + td.unit) if unit is not None: return signature(types.NPDatetime(unit), dt, td) @@ -223,9 +226,10 @@ def generic(self, args, kws): # Guard against unary - return left, right = args - if isinstance(left, types.NPDatetime) and isinstance(right, types.NPDatetime): - # All units compatible! Yoohoo! - unit = npdatetime.get_best_unit(left.unit, right.unit) + if isinstance(left, types.NPDatetime) and isinstance(right, + types.NPDatetime): + # All units compatible... + unit = npdatetime_helpers.get_best_unit(left.unit, right.unit) return signature(types.NPTimedelta(unit), left, right) diff --git a/numba/np/npdatetime.py b/numba/np/npdatetime_helpers.py similarity index 100% rename from numba/np/npdatetime.py rename to numba/np/npdatetime_helpers.py diff --git a/numba/targets/npdatetime.py b/numba/targets/npdatetime.py index bb082b68831..5e85c63034f 100644 --- a/numba/targets/npdatetime.py +++ b/numba/targets/npdatetime.py @@ -11,11 +11,11 @@ from numba.core import types, cgutils from numba.core.imputils import (lower_builtin, lower_constant, impl_ret_untracked) -from numba.np import npdatetime, numpy_support +from numba.np import npdatetime_helpers, numpy_support # datetime64 and timedelta64 use the same internal representation DATETIME64 = TIMEDELTA64 = Type.int(64) -NAT = Constant.int(TIMEDELTA64, npdatetime.NAT) +NAT = Constant.int(TIMEDELTA64, npdatetime_helpers.NAT) TIMEDELTA_BINOP_SIG = (types.NPTimedelta,) * 2 @@ -46,7 +46,7 @@ def scale_timedelta(context, builder, val, srcty, destty): Scale the timedelta64 *val* from *srcty* to *destty* (both numba.types.NPTimedelta instances) """ - factor = npdatetime.get_timedelta_conversion_factor( + factor = npdatetime_helpers.get_timedelta_conversion_factor( srcty.unit, destty.unit) if factor is None: # This can happen when using explicit output in a ufunc. @@ -60,11 +60,11 @@ def normalize_timedeltas(context, builder, left, right, leftty, rightty): Scale either *left* or *right* to the other's unit, in order to have homogeneous units. """ - factor = npdatetime.get_timedelta_conversion_factor( + factor = npdatetime_helpers.get_timedelta_conversion_factor( leftty.unit, rightty.unit) if factor is not None: return scale_by_constant(builder, left, factor), right - factor = npdatetime.get_timedelta_conversion_factor( + factor = npdatetime_helpers.get_timedelta_conversion_factor( rightty.unit, leftty.unit) if factor is not None: return left, scale_by_constant(builder, right, factor) @@ -518,8 +518,8 @@ def year_to_days(builder, year_val): def reduce_datetime_for_unit(builder, dt_val, src_unit, dest_unit): - dest_unit_code = npdatetime.DATETIME_UNITS[dest_unit] - src_unit_code = npdatetime.DATETIME_UNITS[src_unit] + dest_unit_code = npdatetime_helpers.DATETIME_UNITS[dest_unit] + src_unit_code = npdatetime_helpers.DATETIME_UNITS[src_unit] if dest_unit_code < 2 or src_unit_code >= 2: return dt_val, src_unit # Need to compute the day ordinal for *dt_val* @@ -570,7 +570,7 @@ def convert_datetime_for_arith(builder, dt_val, src_unit, dest_unit): dt_val, dt_unit = reduce_datetime_for_unit( builder, dt_val, src_unit, dest_unit) # Then multiply by the remaining constant factor. - dt_factor = npdatetime.get_timedelta_conversion_factor(dt_unit, dest_unit) + dt_factor = npdatetime_helpers.get_timedelta_conversion_factor(dt_unit, dest_unit) if dt_factor is None: # This can happen when using explicit output in a ufunc. raise NotImplementedError("cannot convert datetime64 from %r to %r" @@ -585,7 +585,7 @@ def impl(context, builder, dt_arg, dt_unit, with cgutils.if_likely(builder, are_not_nat(builder, [dt_arg, td_arg])): dt_arg = convert_datetime_for_arith(builder, dt_arg, dt_unit, ret_unit) - td_factor = npdatetime.get_timedelta_conversion_factor( + td_factor = npdatetime_helpers.get_timedelta_conversion_factor( td_unit, ret_unit) td_arg = scale_by_constant(builder, td_arg, td_factor) ret_val = getattr(builder, ll_op_name)(dt_arg, td_arg) @@ -665,7 +665,7 @@ def impl(context, builder, sig, args): ta, tb = sig.args unit_a = ta.unit unit_b = tb.unit - ret_unit = npdatetime.get_best_unit(unit_a, unit_b) + ret_unit = npdatetime_helpers.get_best_unit(unit_a, unit_b) ret = alloc_boolean_result(builder) with builder.if_else(are_not_nat(builder, [va, vb])) as (then, otherwise): with then: diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 3820c674c80..69a71536db9 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -17,7 +17,7 @@ from numba.core import types, config from numba.core.errors import TypingError from numba.tests.support import TestCase, tag -from numba.np import npdatetime, numpy_support +from numba.np import npdatetime_helpers, numpy_support def value_unit(val): @@ -82,11 +82,11 @@ def add_constant(x): class TestModuleHelpers(TestCase): """ - Test the various helpers in numba.npdatetime. + Test the various helpers in numba.npdatetime_helpers. """ def test_can_cast_timedelta(self): - f = npdatetime.can_cast_timedelta_units + f = npdatetime_helpers.can_cast_timedelta_units for a, b in itertools.product(date_units, time_units): self.assertFalse(f(a, b), (a, b)) self.assertFalse(f(b, a), (a, b)) @@ -108,7 +108,7 @@ def check_units_group(group): check_units_group(time_units) def test_timedelta_conversion(self): - f = npdatetime.get_timedelta_conversion_factor + f = npdatetime_helpers.get_timedelta_conversion_factor for unit in all_units + ('',): self.assertEqual(f(unit, unit), 1) for unit in all_units: @@ -133,7 +133,7 @@ def check_units_group(group): self.assertEqual(f('W', 'us'), 24 * 7 * 3600 * 1000 * 1000) def test_datetime_timedelta_scaling(self): - f = npdatetime.get_datetime_timedelta_conversion + f = npdatetime_helpers.get_datetime_timedelta_conversion def check_error(dt_unit, td_unit): with self.assertRaises(RuntimeError): f(dt_unit, td_unit) @@ -172,7 +172,7 @@ def check_error(dt_unit, td_unit): self.assertEqual(f('M', 's'), ('s', (97 + 400 * 365) * 24 * 3600, 400 * 12)) def test_combine_datetime_timedelta_units(self): - f = npdatetime.combine_datetime_timedelta_units + f = npdatetime_helpers.combine_datetime_timedelta_units for unit in all_units: self.assertEqual(f(unit, unit), unit) self.assertEqual(f('', unit), unit) @@ -184,7 +184,7 @@ def test_combine_datetime_timedelta_units(self): self.assertEqual(f(dt_unit, td_unit), td_unit) def test_same_kind(self): - f = npdatetime.same_kind + f = npdatetime_helpers.same_kind for u in all_units: self.assertTrue(f(u, u)) A = ('Y', 'M', 'W', 'D') @@ -639,7 +639,7 @@ def check(a, b, expected=None): with self.silence_numpy_warnings(): dts = self.datetime_samples() for a, b in itertools.product(dts, dts): - if (not npdatetime.same_kind(value_unit(a), value_unit(b))): + if (not npdatetime_helpers.same_kind(value_unit(a), value_unit(b))): continue self.assertPreciseEqual(sub(a, b), a - b, (a, b)) @@ -740,8 +740,8 @@ def check_lt(a, b, expected): for unit in units: # Force conversion b = a.astype('M8[%s]' % unit) - if (not npdatetime.same_kind(value_unit(a), - value_unit(b))): + if (not npdatetime_helpers.same_kind(value_unit(a), + value_unit(b))): continue check_eq(a, b, True) check_lt(a, b + np.timedelta64(1, unit), True) From ca92994faa7c7e4bca8d1908cc2e6e2506749727 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 13:27:07 +0000 Subject: [PATCH 439/595] Move numba/targets/npdatetime.py to numba/np/ --- numba/core/base.py | 2 +- numba/{targets => np}/npdatetime.py | 0 numba/np/npyfuncs.py | 2 +- numba/np/ufunc_db.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename numba/{targets => np}/npdatetime.py (100%) diff --git a/numba/core/base.py b/numba/core/base.py index c31d4df88c8..cef3d781406 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -276,7 +276,7 @@ def refresh(self): from numba.np import linalg, polynomial, arraymath try: - from numba.targets import npdatetime + from numba.np import npdatetime except NotImplementedError: pass self.install_registry(builtin_registry) diff --git a/numba/targets/npdatetime.py b/numba/np/npdatetime.py similarity index 100% rename from numba/targets/npdatetime.py rename to numba/np/npdatetime.py diff --git a/numba/np/npyfuncs.py b/numba/np/npyfuncs.py index f3a0b8e2ed2..c3e3e35597e 100644 --- a/numba/np/npyfuncs.py +++ b/numba/np/npyfuncs.py @@ -11,7 +11,7 @@ from numba.core.imputils import impl_ret_untracked from numba.core import typing, types, errors, lowering, cgutils -from numba.targets import npdatetime +from numba.np import npdatetime from numba.cpython import cmathimpl, mathimpl, numbers # some NumPy constants. Note that we could generate some of them using diff --git a/numba/np/ufunc_db.py b/numba/np/ufunc_db.py index cc12453e024..cc54bef423b 100644 --- a/numba/np/ufunc_db.py +++ b/numba/np/ufunc_db.py @@ -988,7 +988,7 @@ def _fill_ufunc_db(ufunc_db): } # Inject datetime64 support - from numba.targets import npdatetime + from numba.np import npdatetime ufunc_db[np.negative].update({ 'm->m': npdatetime.timedelta_neg_impl, }) From 044212ad90f19e9110ea86a9020f84155d1563d6 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 14:24:45 +0000 Subject: [PATCH 440/595] Move numba/targets/registry.py to numba/core/ --- numba/core/ccallback.py | 3 +-- numba/core/compiler.py | 2 +- numba/core/decorators.py | 3 +-- numba/core/inline_closurecall.py | 2 +- numba/core/ir_utils.py | 2 +- numba/{targets => core}/registry.py | 0 numba/core/types/npytypes.py | 2 +- numba/cuda/cudadrv/ndarray.py | 2 +- numba/cuda/initialize.py | 2 +- numba/experimental/jitclass/base.py | 2 +- numba/misc/help/inspector.py | 2 +- numba/np/ufunc/decorators.py | 2 +- numba/np/ufunc/ufuncbuilder.py | 2 +- numba/pycc/compiler.py | 2 +- numba/scripts/generate_lower_listing.py | 2 +- numba/stencil.py | 6 ++++-- numba/stencilparfor.py | 2 +- numba/tests/support.py | 2 +- numba/tests/test_array_analysis.py | 3 +-- numba/tests/test_copy_propagate.py | 2 +- numba/tests/test_extending.py | 3 ++- numba/tests/test_inlining.py | 2 +- numba/tests/test_ir_utils.py | 5 ++--- numba/tests/test_parfors.py | 2 +- numba/tests/test_remove_dead.py | 2 +- numba/tests/test_serialize.py | 2 +- numba/tests/test_stencils.py | 3 +-- numba/tests/test_target_overloadselector.py | 2 +- numba/tests/test_withlifting.py | 2 +- numba/tests/test_wrapper.py | 3 +-- numba/typed/typedobjectutils.py | 2 +- 31 files changed, 35 insertions(+), 38 deletions(-) rename numba/{targets => core}/registry.py (100%) diff --git a/numba/core/ccallback.py b/numba/core/ccallback.py index 6379c179510..c5c1ffc0393 100644 --- a/numba/core/ccallback.py +++ b/numba/core/ccallback.py @@ -7,10 +7,9 @@ from llvmlite import ir -from numba.core import utils, compiler +from numba.core import utils, compiler, registry from numba.core.caching import NullCache, FunctionCache from numba.core.dispatcher import _FunctionCompiler -from numba.targets import registry from numba.core.typing import signature from numba.core.typing.ctypes_utils import to_ctypes from numba.core.compiler_lock import global_compiler_lock diff --git a/numba/core/compiler.py b/numba/core/compiler.py index 15b9b7ee956..b62097fda61 100644 --- a/numba/core/compiler.py +++ b/numba/core/compiler.py @@ -171,7 +171,7 @@ def compile_isolated(func, args, return_type=None, flags=DEFAULT_FLAGS, context). Good for testing. """ - from numba.targets.registry import cpu_target + from numba.core.registry import cpu_target typingctx = typing.Context() targetctx = cpu.CPUContext(typingctx) # Register the contexts in case for nested @jit or @overload calls diff --git a/numba/core/decorators.py b/numba/core/decorators.py index 332c1a650b6..643e6c8af4b 100644 --- a/numba/core/decorators.py +++ b/numba/core/decorators.py @@ -9,9 +9,8 @@ import logging from numba.core.errors import DeprecationError, NumbaDeprecationWarning -from numba.targets import registry from numba.stencil import stencil -from numba.core import config, sigutils +from numba.core import config, sigutils, registry _logger = logging.getLogger(__name__) diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index ec91460a77c..591f6ce5be6 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -241,7 +241,7 @@ def check_reduce_func(func_ir, func_var): analysis") if isinstance(reduce_func, (ir.FreeVar, ir.Global)): if not isinstance(reduce_func.value, - numba.targets.registry.CPUDispatcher): + numba.core.registry.CPUDispatcher): raise ValueError("Invalid reduction function") # pull out the python function for inlining reduce_func = reduce_func.value.py_func diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index 2180806087d..5f20cb8133e 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -666,7 +666,7 @@ def has_no_side_effect(rhs, lives, call_table): (call_list[0]._name == 'empty_inferred' or call_list[0]._name == 'unsafe_empty_inferred')): return True - from numba.targets.registry import CPUDispatcher + from numba.core.registry import CPUDispatcher from numba.np.linalg import dot_3_mv_check_args if isinstance(call_list[0], CPUDispatcher): py_func = call_list[0].py_func diff --git a/numba/targets/registry.py b/numba/core/registry.py similarity index 100% rename from numba/targets/registry.py rename to numba/core/registry.py diff --git a/numba/core/types/npytypes.py b/numba/core/types/npytypes.py index 5160a6c40de..c7c312adce3 100644 --- a/numba/core/types/npytypes.py +++ b/numba/core/types/npytypes.py @@ -78,7 +78,7 @@ def make_c_struct(cls, name_types): Note: only scalar types are supported currently. """ - from numba.targets.registry import cpu_target + from numba.core.registry import cpu_target ctx = cpu_target.target_context offset = 0 diff --git a/numba/cuda/cudadrv/ndarray.py b/numba/cuda/cudadrv/ndarray.py index 63964e57ceb..bca40dfd977 100644 --- a/numba/cuda/cudadrv/ndarray.py +++ b/numba/cuda/cudadrv/ndarray.py @@ -1,5 +1,5 @@ from numba.cuda.cudadrv import devices, driver -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target def _calc_array_sizeof(ndim): diff --git a/numba/cuda/initialize.py b/numba/cuda/initialize.py index cd0523d35de..cda9d5eb409 100644 --- a/numba/cuda/initialize.py +++ b/numba/cuda/initialize.py @@ -3,6 +3,6 @@ def init_jit(): return CUDADispatcher def initialize_all(): - from numba.targets.registry import dispatcher_registry + from numba.core.registry import dispatcher_registry dispatcher_registry.ondemand['gpu'] = init_jit dispatcher_registry.ondemand['cuda'] = init_jit diff --git a/numba/experimental/jitclass/base.py b/numba/experimental/jitclass/base.py index bcc602cf96c..262c35d56dd 100644 --- a/numba/experimental/jitclass/base.py +++ b/numba/experimental/jitclass/base.py @@ -7,7 +7,7 @@ from llvmlite import ir as llvmir from numba.core import types, utils, errors, cgutils, imputils -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba import njit from numba.core.typing import templates from numba.core.datamodel import default_manager, models diff --git a/numba/misc/help/inspector.py b/numba/misc/help/inspector.py index 1acb930562a..fea8f70a7c2 100644 --- a/numba/misc/help/inspector.py +++ b/numba/misc/help/inspector.py @@ -12,7 +12,7 @@ from numba.core import errors from numba._version import get_versions -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.tests.support import captured_stdout diff --git a/numba/np/ufunc/decorators.py b/numba/np/ufunc/decorators.py index dce299b2926..48a77239dad 100644 --- a/numba/np/ufunc/decorators.py +++ b/numba/np/ufunc/decorators.py @@ -4,7 +4,7 @@ from numba.np.ufunc.ufuncbuilder import GUFuncBuilder from numba.np.ufunc.parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder -from numba.targets.registry import TargetRegistry +from numba.core.registry import TargetRegistry from numba.np.ufunc import dufunc diff --git a/numba/np/ufunc/ufuncbuilder.py b/numba/np/ufunc/ufuncbuilder.py index 7e991803920..0471d95faf8 100644 --- a/numba/np/ufunc/ufuncbuilder.py +++ b/numba/np/ufunc/ufuncbuilder.py @@ -6,7 +6,7 @@ from numba.core.decorators import jit from numba.core.descriptors import TargetDescriptor from numba.core.options import TargetOptions -from numba.targets.registry import dispatcher_registry, cpu_target +from numba.core.registry import dispatcher_registry, cpu_target from numba.core.cpu import FastMathOptions from numba.core import utils, types, serialize, compiler, sigutils from numba.np.numpy_support import as_dtype diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index 08b892ef68a..4b2ec495625 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -12,7 +12,7 @@ from numba.core.compiler import compile_extra, Flags from numba.core.compiler_lock import global_compiler_lock -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.runtime import nrtdynmod from numba.core import cgutils diff --git a/numba/scripts/generate_lower_listing.py b/numba/scripts/generate_lower_listing.py index 3a99c1b63eb..1a93e7a3d0f 100644 --- a/numba/scripts/generate_lower_listing.py +++ b/numba/scripts/generate_lower_listing.py @@ -16,7 +16,7 @@ from functools import partial import numba -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target def git_hash(): diff --git a/numba/stencil.py b/numba/stencil.py index 098a52596c9..9db186b5b92 100644 --- a/numba/stencil.py +++ b/numba/stencil.py @@ -8,10 +8,9 @@ import numpy as np from llvmlite import ir as lir -from numba.core import types, typing, utils, ir, typed_passes, config, compiler, ir_utils +from numba.core import types, typing, utils, ir, config, ir_utils, registry from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) -from numba.targets import registry from numba.core.imputils import lower_builtin from numba.extending import register_jitable import numba @@ -331,6 +330,7 @@ def get_return_type(self, argtys): raise ValueError("The first argument to a stencil kernel must " "be the primary input array.") + from numba.core import typed_passes typemap, return_type, calltypes = typed_passes.type_inference_stage( self._typingctx, self.kernel_ir, @@ -637,6 +637,7 @@ def _stencil_wrapper(self, result, sigret, return_type, typemap, calltypes, *arg pysig = utils.pysignature(stencil_func) sigret.pysig = pysig # Get the IR for the newly created stencil function. + from numba.core import compiler stencil_ir = compiler.run_frontend(stencil_func) ir_utils.remove_dels(stencil_ir.blocks) @@ -787,6 +788,7 @@ def _stencil(mode, options): raise ValueError("Unsupported mode style " + mode) def decorated(func): + from numba.core import compiler kernel_ir = compiler.run_frontend(func) return StencilFunc(kernel_ir, mode, options) diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index 9da544054c4..c58a502bf33 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -648,7 +648,7 @@ def get_stencil_ir(sf, typingctx, args, scope, loc, input_dict, typemap, """get typed IR from stencil bytecode """ from numba.core.cpu import CPUContext - from numba.targets.registry import cpu_target + from numba.core.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.typed_passes import type_inference_stage diff --git a/numba/tests/support.py b/numba/tests/support.py index 272cdcb7544..376226eae7e 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -108,7 +108,7 @@ def compile(self, func, args, return_type=None, flags=DEFAULT_FLAGS): Compile the function or retrieve an already compiled result from the cache. """ - from numba.targets.registry import cpu_target + from numba.core.registry import cpu_target cache_key = (func, args, return_type, flags) try: diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 257ab16d083..f5ac5db7d37 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -6,11 +6,10 @@ from io import StringIO from numba import njit, typeof, prange -from numba.core import types, typing, ir, bytecode, postproc, cpu +from numba.core import types, typing, ir, bytecode, postproc, cpu, registry from numba.tests.support import TestCase, tag, skip_parfors_unsupported from numba.parfors.array_analysis import EquivSet, ArrayAnalysis from numba.core.compiler import Compiler, Flags, PassManager -from numba.targets import registry from numba.core.ir_utils import remove_dead from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing, DeadBranchPrune, diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index fd08a5ecffc..90fdf838429 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -4,7 +4,7 @@ # from numba.core import types, typing, ir, config, compiler, cpu -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 51d4438dc9a..1bdb2a44ca8 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -12,7 +12,7 @@ from numba import njit, jit from numba.core import types, errors, typing, compiler from numba.core.typed_passes import type_inference_stage -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.compiler import compile_isolated from numba.tests.support import (TestCase, captured_stdout, tag, temp_directory, override_config) @@ -33,6 +33,7 @@ from numba.core.typing.templates import ( ConcreteTemplate, signature, infer, infer_global, AbstractTemplate) + # Pandas-like API implementation from .pdlike_usecase import Index, Series diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 39d110d897e..2333eb3d799 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -6,7 +6,7 @@ from numba import jit, njit from numba.core import types, ir, postproc, compiler from numba.core.ir_utils import guard, find_callname, find_const, get_definition -from numba.targets.registry import CPUDispatcher +from numba.core.registry import CPUDispatcher from numba.core.inline_closurecall import inline_closure_call from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index 2fbe9b9d712..7f1ee34524f 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -1,10 +1,9 @@ import numba from numba.tests.support import TestCase, unittest -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.compiler import CompilerBase, Flags from numba.core.compiler_machinery import PassManager -from numba.targets import registry -from numba.core import types, ir, bytecode, compiler, ir_utils +from numba.core import types, ir, bytecode, compiler, ir_utils, registry from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, IRProcessing,) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index f79e6cee4d9..80de481a926 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -21,7 +21,7 @@ import numba from numba import njit, prange, stencil from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler, cpu -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.ir_utils import (find_callname, guard, build_definitions, get_definition, is_getitem, is_setitem, diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index 4592b1fce4c..a2cf5c167ff 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -7,7 +7,7 @@ from numba.core import ir_utils, cpu from numba.core.compiler import compile_isolated, Flags from numba.core import types, typing, ir, config, compiler -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table, remove_dels, remove_dead, diff --git a/numba/tests/test_serialize.py b/numba/tests/test_serialize.py index 597d7da2e75..4439852c4e5 100644 --- a/numba/tests/test_serialize.py +++ b/numba/tests/test_serialize.py @@ -5,10 +5,10 @@ import sys from numba.core.errors import TypingError -from numba.targets import registry from numba.tests.support import TestCase, tag from .serialize_usecases import * from numba.testing import unittest_support as unittest +from numba.core import registry class TestDispatcherPickling(TestCase): diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index d8e1e85bb6b..3eccf5cb5de 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -15,9 +15,8 @@ import numba from numba import njit, stencil -from numba.core import types +from numba.core import types, registry from numba.core.compiler import compile_extra, Flags -from numba.targets import registry from numba.core.cpu import ParallelOptions from numba.tests.support import tag, skip_parfors_unsupported, _32bit from numba.core.errors import LoweringError, TypingError diff --git a/numba/tests/test_target_overloadselector.py b/numba/tests/test_target_overloadselector.py index 79c67df8a3e..13d89fb2c50 100644 --- a/numba/tests/test_target_overloadselector.py +++ b/numba/tests/test_target_overloadselector.py @@ -3,7 +3,7 @@ import numba.testing.unittest_support as unittest from numba.core.base import OverloadSelector -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.imputils import builtin_registry, RegistryLoader from numba.core import types diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index 2b20dee72a5..5cae7160a0f 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -8,7 +8,7 @@ from numba.core.bytecode import FunctionIdentity, ByteCode from numba.core.interpreter import Interpreter from numba.core import typing, errors, cpu -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.compiler import compile_ir, DEFAULT_FLAGS from numba import njit, typeof, objmode from numba.extending import overload diff --git a/numba/tests/test_wrapper.py b/numba/tests/test_wrapper.py index 5916a13dce3..73aae932e53 100644 --- a/numba/tests/test_wrapper.py +++ b/numba/tests/test_wrapper.py @@ -1,8 +1,7 @@ import numpy as np import numba.testing.unittest_support as unittest -from numba.core import types, utils, compiler -from numba.targets import registry +from numba.core import types, utils, compiler, registry def overhead(x): diff --git a/numba/typed/typedobjectutils.py b/numba/typed/typedobjectutils.py index 6c3f7ba5e47..e338d89d829 100644 --- a/numba/typed/typedobjectutils.py +++ b/numba/typed/typedobjectutils.py @@ -8,7 +8,7 @@ from numba.core import types, cgutils from numba.core import typing -from numba.targets.registry import cpu_target +from numba.core.registry import cpu_target from numba.core.typeconv import Conversion from numba.extending import intrinsic from numba.core.errors import TypingError, NumbaTypeSafetyWarning From 64f7bf1fcb69025f981222bbe321fa3935792a0e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 14:31:42 +0000 Subject: [PATCH 441/595] Remove numba.unsafe --- numba/unsafe/__init__.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 numba/unsafe/__init__.py diff --git a/numba/unsafe/__init__.py b/numba/unsafe/__init__.py deleted file mode 100644 index 7215f2b761a..00000000000 --- a/numba/unsafe/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -""" -This subpackage is intended for low-level extension developers and compiler -developers. Regular user SHOULD NOT use code in this module. - -This contains compilable utility functions that can interact directly with -the compiler to implement low-level internal code. -""" From 2586892aa5f7ffd9ade0891b1e1ef6c8bce9896c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 14:32:19 +0000 Subject: [PATCH 442/595] Remove numba.targets --- numba/targets/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 numba/targets/__init__.py diff --git a/numba/targets/__init__.py b/numba/targets/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 From e38cbbb56bcc8e8c582a7d76e8eed7f0a9641e0f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 14:56:28 +0000 Subject: [PATCH 443/595] Move numba/stencil.py to numba/stencils --- numba/__init__.py | 1 - numba/core/decorators.py | 2 +- numba/core/inline_closurecall.py | 2 +- numba/parfors/array_analysis.py | 2 +- numba/stencilparfor.py | 2 +- numba/{ => stencils}/stencil.py | 0 numba/tests/test_array_analysis.py | 2 +- numba/tests/test_parfors.py | 2 +- 8 files changed, 6 insertions(+), 7 deletions(-) rename numba/{ => stencils}/stencil.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index 35d3ad15aff..a7f68451b12 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -65,7 +65,6 @@ gdb gdb_breakpoint gdb_init - stencil vectorize objmode literal_unroll diff --git a/numba/core/decorators.py b/numba/core/decorators.py index 643e6c8af4b..5ea8bbbbb60 100644 --- a/numba/core/decorators.py +++ b/numba/core/decorators.py @@ -9,7 +9,7 @@ import logging from numba.core.errors import DeprecationError, NumbaDeprecationWarning -from numba.stencil import stencil +from numba.stencils.stencil import stencil from numba.core import config, sigutils, registry diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 591f6ce5be6..98063854c89 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -152,7 +152,7 @@ def reduce_func(f, A, v=None): return True def _inline_stencil(self, instr, call_name, func_def): - from numba.stencil import StencilFunc + from numba.stencils.stencil import StencilFunc lhs = instr.target expr = instr.value # We keep the escaping variables of the stencil kernel diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index f034d274c13..c89f596e58a 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -1722,7 +1722,7 @@ def _analyze_op_build_tuple(self, scope, equiv_set, expr): def _analyze_op_call(self, scope, equiv_set, expr): - from numba.stencil import StencilFunc + from numba.stencils.stencil import StencilFunc callee = expr.func callee_def = get_definition(self.func_ir, callee) diff --git a/numba/stencilparfor.py b/numba/stencilparfor.py index c58a502bf33..5bad2159745 100644 --- a/numba/stencilparfor.py +++ b/numba/stencilparfor.py @@ -40,7 +40,7 @@ def __init__(self, func_ir, typemap, calltypes, array_analysis, typingctx, flags def run(self): """ Finds all calls to StencilFuncs in the IR and converts them to parfor. """ - from numba.stencil import StencilFunc + from numba.stencils.stencil import StencilFunc # Get all the calls in the function IR. call_table, _ = get_call_table(self.func_ir.blocks) diff --git a/numba/stencil.py b/numba/stencils/stencil.py similarity index 100% rename from numba/stencil.py rename to numba/stencils/stencil.py diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index f5ac5db7d37..7ab93186b5d 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -452,7 +452,7 @@ def test_assert_2(A, B): def test_stencilcall(self): - from numba import stencil + from numba.stencils.stencil import stencil @stencil def kernel_1(a): return 0.25 * (a[0,1] + a[1,0] + a[0,-1] + a[-1,0]) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 80de481a926..142c20ff480 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -19,7 +19,7 @@ from collections import defaultdict import numba -from numba import njit, prange, stencil +from numba import njit, prange from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler, cpu from numba.core.registry import cpu_target from numba.core.annotations import type_annotations From f18f4067d92b9878ec13d464fecd84c970e11561 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 14:57:51 +0000 Subject: [PATCH 444/595] Move numba/stencilparfor.py to numba/stencils --- numba/parfor.py | 4 ++-- numba/{ => stencils}/stencilparfor.py | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename numba/{ => stencils}/stencilparfor.py (100%) diff --git a/numba/parfor.py b/numba/parfor.py index 11dbdaa4a13..caeeffb1013 100644 --- a/numba/parfor.py +++ b/numba/parfor.py @@ -29,8 +29,7 @@ from numba import prange, pndindex from numba.np.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate -from numba import stencilparfor -from numba.stencilparfor import StencilPass +from numba.stencils.stencilparfor import StencilPass from numba.extending import register_jitable @@ -93,6 +92,7 @@ import numpy as np from numba.parfors import array_analysis import numba.cpython.builtins +from numba.stencils import stencilparfor # circular dependency: import numba.npyufunc.dufunc.DUFunc # wrapped pretty print diff --git a/numba/stencilparfor.py b/numba/stencils/stencilparfor.py similarity index 100% rename from numba/stencilparfor.py rename to numba/stencils/stencilparfor.py From 4c07c6ef4c428dee089ab48a325f2f644aee8f8f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 3 Feb 2020 15:21:31 +0000 Subject: [PATCH 445/595] Move numba/special.py to numba/misc --- numba/__init__.py | 2 +- numba/core/analysis.py | 2 +- numba/core/inline_closurecall.py | 3 ++- numba/core/ir_utils.py | 3 ++- numba/core/typeinfer.py | 2 +- numba/core/untyped_passes.py | 2 +- numba/misc/literal.py | 2 +- numba/{ => misc}/special.py | 0 numba/tests/test_literal_dispatch.py | 2 +- numba/tests/test_typeof.py | 2 +- 10 files changed, 11 insertions(+), 9 deletions(-) rename numba/{ => misc}/special.py (100%) diff --git a/numba/__init__.py b/numba/__init__.py index a7f68451b12..0add9918895 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -16,7 +16,7 @@ from numba.core import types, errors # Re-export typeof -from .special import ( +from numba.misc.special import ( typeof, prange, pndindex, gdb, gdb_breakpoint, gdb_init, literally, literal_unroll ) diff --git a/numba/core/analysis.py b/numba/core/analysis.py index 49d83c3c098..5a87caa413f 100644 --- a/numba/core/analysis.py +++ b/numba/core/analysis.py @@ -6,8 +6,8 @@ from collections import namedtuple, defaultdict from .controlflow import CFGraph -from numba import special from numba.core import types, errors, ir, consts +from numba.misc import special # # Analysis related to variable lifetime diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 98063854c89..7e7a630943e 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -35,6 +35,7 @@ from numba.np.unsafe.ndarray import empty_inferred as unsafe_empty_inferred import numpy as np import operator +import numba.misc.special """ Variable enable_inline_arraycall is only used for testing purpose. @@ -616,7 +617,7 @@ def _find_iter_range(func_ir, range_iter_var, swapped): func_def = get_definition(func_ir, func_var) debug_print("func_var = ", func_var, " func_def = ", func_def) require(isinstance(func_def, ir.Global) and - (func_def.value == range or func_def.value == numba.special.prange)) + (func_def.value == range or func_def.value == numba.misc.special.prange)) nargs = len(range_def.args) swapping = [('"array comprehension"', 'closure of'), range_def.func.loc] if nargs == 1: diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index 5f20cb8133e..cf1b182a157 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -648,6 +648,7 @@ def has_no_side_effect(rhs, lives, call_table): would prevent re-ordering. """ from numba.parfors import array_analysis + from numba.misc.special import prange if isinstance(rhs, ir.Expr) and rhs.op == 'call': func_name = rhs.func.name if func_name not in call_table or call_table[func_name] == []: @@ -659,7 +660,7 @@ def has_no_side_effect(rhs, lives, call_table): call_list == ['log', numpy] or call_list == ['dtype', numpy] or call_list == [array_analysis.wrap_index] or - call_list == [numba.special.prange] or + call_list == [prange] or call_list == [numba.parfor.internal_prange]): return True elif (isinstance(call_list[0], numba.extending._Intrinsic) and diff --git a/numba/core/typeinfer.py b/numba/core/typeinfer.py index 5c6549caf4c..9d77ac9d5a1 100644 --- a/numba/core/typeinfer.py +++ b/numba/core/typeinfer.py @@ -1455,7 +1455,7 @@ def typeof_global(self, inst, target, gvar): # if the untyped global is a numba internal function then add # to the error message asking if it's been imported. - from numba import special + from numba.misc import special if nm in special.__all__: tmp = ("\n'%s' looks like a Numba internal function, has " "it been imported (i.e. 'from numba import %s')?\n" % diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index ed3c2522a7c..87e4e9eda13 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -5,7 +5,7 @@ from numba.core.compiler_machinery import FunctionPass, register_pass from numba.core import errors, types, ir, bytecode, postproc, rewrites, config, transforms -from numba.special import literal_unroll +from numba.misc.special import literal_unroll from .analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls, compute_cfg_from_blocks, compute_use_defs from numba.core.inline_closurecall import InlineClosureCallPass, inline_closure_call from numba.core.ir_utils import guard, resolve_func_from_module, simplify_CFG, GuardException, convert_code_obj_to_function, mk_unique_var, build_definitions, replace_var_names, get_name_var_table, compile_to_numba_ir, get_definition, find_max_label, rename_labels diff --git a/numba/misc/literal.py b/numba/misc/literal.py index 5b33472b179..879af238012 100644 --- a/numba/misc/literal.py +++ b/numba/misc/literal.py @@ -1,6 +1,6 @@ from numba.extending import overload from numba.core import types -from numba.special import literally, literal_unroll +from numba.misc.special import literally, literal_unroll from numba.core.errors import TypingError diff --git a/numba/special.py b/numba/misc/special.py similarity index 100% rename from numba/special.py rename to numba/misc/special.py diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index f77dddcad12..38b74982ff2 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -10,7 +10,7 @@ from numba.extending import ( overload, SentryLiteralArgs, overload_method, register_model, intrinsic, ) -from numba.special import literally +from numba.misc.special import literally class TestLiteralDispatch(TestCase): diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index df1256b107c..6a0517a28a5 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -11,7 +11,7 @@ import numba.testing.unittest_support as unittest from numba import cffi_support from numba.core import types -from numba.special import typeof +from numba.misc.special import typeof from numba.core.dispatcher import OmittedArg from numba._dispatcher import compute_fingerprint From 0408399d7a9ee88c1f51ec8c70dbfe1e1f43c485 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 11:29:53 +0000 Subject: [PATCH 446/595] Move numba/parfor.py to numba/parfors --- numba/core/compiler.py | 2 +- numba/core/inline_closurecall.py | 2 +- numba/core/ir_utils.py | 4 +- numba/core/typed_passes.py | 6 +-- numba/core/typing/builtins.py | 14 +++--- numba/cpython/rangeobj.py | 2 +- numba/np/ufunc/parfor.py | 18 ++++---- numba/{ => parfors}/parfor.py | 79 +++++++++++++++----------------- numba/stencils/stencilparfor.py | 6 +-- numba/tests/test_dispatcher.py | 2 +- numba/tests/test_parfors.py | 28 +++++------ numba/tests/test_remove_dead.py | 7 +-- 12 files changed, 84 insertions(+), 86 deletions(-) rename numba/{ => parfors}/parfor.py (98%) diff --git a/numba/core/compiler.py b/numba/core/compiler.py index b62097fda61..75ca744a9f6 100644 --- a/numba/core/compiler.py +++ b/numba/core/compiler.py @@ -4,7 +4,7 @@ from numba.core.tracing import event from numba.core import utils, errors, typing, interpreter, bytecode, postproc, config, callconv, cpu -from numba.parfor import ParforDiagnostics +from numba.parfors.parfor import ParforDiagnostics from numba.core.inline_closurecall import InlineClosureCallPass from numba.core.errors import CompilerError diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 7e7a630943e..5faf7ca5ea4 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -3,7 +3,7 @@ import numba.core.analysis from numba.core import utils, types, typing, errors, ir, rewrites, config, ir_utils from numba import prange -from numba.parfor import internal_prange +from numba.parfors.parfor import internal_prange from numba.core.ir_utils import ( mk_unique_var, next_label, diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index cf1b182a157..4e8edd108f9 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -647,7 +647,7 @@ def has_no_side_effect(rhs, lives, call_table): """ Returns True if this expression has no side effects that would prevent re-ordering. """ - from numba.parfors import array_analysis + from numba.parfors import array_analysis, parfor from numba.misc.special import prange if isinstance(rhs, ir.Expr) and rhs.op == 'call': func_name = rhs.func.name @@ -661,7 +661,7 @@ def has_no_side_effect(rhs, lives, call_table): call_list == ['dtype', numpy] or call_list == [array_analysis.wrap_index] or call_list == [prange] or - call_list == [numba.parfor.internal_prange]): + call_list == [parfor.internal_prange]): return True elif (isinstance(call_list[0], numba.extending._Intrinsic) and (call_list[0]._name == 'empty_inferred' or diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index be8c47f7431..b4a6d231522 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -3,9 +3,9 @@ from numba.core import errors, types, typing, ir, funcdesc, rewrites, typeinfer, config, lowering -from numba.parfor import PreParforPass as _parfor_PreParforPass -from numba.parfor import ParforPass as _parfor_ParforPass -from numba.parfor import Parfor +from numba.parfors.parfor import PreParforPass as _parfor_PreParforPass +from numba.parfors.parfor import ParforPass as _parfor_ParforPass +from numba.parfors.parfor import Parfor from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass from numba.core.annotations import type_annotations diff --git a/numba/core/typing/builtins.py b/numba/core/typing/builtins.py index 74ca102e2db..22d39d506a4 100644 --- a/numba/core/typing/builtins.py +++ b/numba/core/typing/builtins.py @@ -5,7 +5,7 @@ from numba.core import types, errors from numba import prange -from numba.parfor import internal_prange +from numba.parfors.parfor import internal_prange from numba.core.utils import RANGE_ITER_OBJECTS from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, @@ -13,6 +13,12 @@ infer_getattr, signature, bound_function, make_callable_template) +from numba.cpython.builtins import get_type_min_value, get_type_max_value + +from numba.extending import ( + typeof_impl, type_callable, models, register_model, make_attribute_wrapper, + ) + @infer_global(print) class Print(AbstractTemplate): @@ -1010,8 +1016,6 @@ def generic_resolve(self, deferred, attr): #------------------------------------------------------------------------------ -from numba.cpython.builtins import get_type_min_value, get_type_max_value - @infer_global(get_type_min_value) @infer_global(get_type_max_value) class MinValInfer(AbstractTemplate): @@ -1024,10 +1028,6 @@ def generic(self, args, kws): #------------------------------------------------------------------------------ -from numba.extending import ( - typeof_impl, type_callable, models, register_model, make_attribute_wrapper, - ) - class IndexValue(object): """ diff --git a/numba/cpython/rangeobj.py b/numba/cpython/rangeobj.py index 928e71bea22..acf590d92fe 100644 --- a/numba/cpython/rangeobj.py +++ b/numba/cpython/rangeobj.py @@ -14,7 +14,7 @@ iterator_impl, impl_ret_untracked) from numba.core.typing import signature from numba.extending import intrinsic, overload, overload_attribute, register_jitable -from numba.parfor import internal_prange +from numba.parfors.parfor import internal_prange def make_range_iterator(typ): """ diff --git a/numba/np/ufunc/parfor.py b/numba/np/ufunc/parfor.py index 2402b005fb8..df71ddb8ba6 100644 --- a/numba/np/ufunc/parfor.py +++ b/numba/np/ufunc/parfor.py @@ -13,13 +13,13 @@ import llvmlite.ir.values as liv import numba -from numba import parfor +from numba.parfors import parfor from numba.core import types, ir, config, compiler, lowering, sigutils, cgutils from numba.core.ir_utils import add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, get_definition, guard, find_callname, get_call_table, is_pure, get_np_ufunc_typ, get_unused_var_name, find_potential_aliases, is_const_call from numba.core.analysis import compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks from numba.core.typing import signature from numba.core.cpu import ParallelOptions -from numba.parfor import print_wrapped, ensure_parallel_support +from numba.parfors.parfor import print_wrapped, ensure_parallel_support from numba.core.errors import NumbaParallelSafetyWarning @@ -72,7 +72,7 @@ def _lower_parfor_parallel(lowerer, parfor): alias_map = {} arg_aliases = {} - numba.parfor.find_potential_aliases_parfor(parfor, parfor.params, typemap, + numba.parfors.parfor.find_potential_aliases_parfor(parfor, parfor.params, typemap, lowerer.func_ir, alias_map, arg_aliases) if config.DEBUG_ARRAY_OPT: print("alias_map", alias_map) @@ -82,9 +82,9 @@ def _lower_parfor_parallel(lowerer, parfor): # since Jumps are modified so CFG of loop_body dict will become invalid assert parfor.params != None - parfor_output_arrays = numba.parfor.get_parfor_outputs( + parfor_output_arrays = numba.parfors.parfor.get_parfor_outputs( parfor, parfor.params) - parfor_redvars, parfor_reddict = numba.parfor.get_parfor_reductions( + parfor_redvars, parfor_reddict = numba.parfors.parfor.get_parfor_reductions( lowerer.func_ir, parfor, parfor.params, lowerer.fndesc.calltypes) # init reduction array allocation here. @@ -224,11 +224,11 @@ def _lower_parfor_parallel(lowerer, parfor): # index variables should have the same type, check rest of indices for l in parfor.loop_nests[1:]: assert typemap[l.index_variable.name] == index_var_typ - numba.parfor.sequential_parfor_lowering = True + numba.parfors.parfor.sequential_parfor_lowering = True func, func_args, func_sig, redargstartdim, func_arg_types = _create_gufunc_for_parfor_body( lowerer, parfor, typemap, typingctx, targetctx, flags, {}, bool(alias_map), index_var_typ, parfor.races) - numba.parfor.sequential_parfor_lowering = False + numba.parfors.parfor.sequential_parfor_lowering = False # get the shape signature func_args = ['sched'] + func_args @@ -801,10 +801,10 @@ def _create_gufunc_for_parfor_body( # Get all the parfor params. parfor_params = parfor.params # Get just the outputs of the parfor. - parfor_outputs = numba.parfor.get_parfor_outputs(parfor, parfor_params) + parfor_outputs = numba.parfors.parfor.get_parfor_outputs(parfor, parfor_params) # Get all parfor reduction vars, and operators. typemap = lowerer.fndesc.typemap - parfor_redvars, parfor_reddict = numba.parfor.get_parfor_reductions( + parfor_redvars, parfor_reddict = numba.parfors.parfor.get_parfor_reductions( lowerer.func_ir, parfor, parfor_params, lowerer.fndesc.calltypes) # Compute just the parfor inputs as a set difference. parfor_inputs = sorted( diff --git a/numba/parfor.py b/numba/parfors/parfor.py similarity index 98% rename from numba/parfor.py rename to numba/parfors/parfor.py index caeeffb1013..ad42afbb492 100644 --- a/numba/parfor.py +++ b/numba/parfors/parfor.py @@ -129,15 +129,15 @@ def min_1(in_arr): return in_arr[()] elif arg.ndim == 1: def min_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() min_checker(len(in_arr)) val = numba.cpython.builtins.get_type_max_value(in_arr.dtype) - for i in numba.parfor.internal_prange(len(in_arr)): + for i in numba.parfors.parfor.internal_prange(len(in_arr)): val = min(val, in_arr[i]) return val else: def min_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() min_checker(len(in_arr)) val = numba.cpython.builtins.get_type_max_value(in_arr.dtype) for i in numba.pndindex(in_arr.shape): @@ -151,15 +151,15 @@ def max_1(in_arr): return in_arr[()] elif arg.ndim == 1: def max_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() max_checker(len(in_arr)) val = numba.cpython.builtins.get_type_min_value(in_arr.dtype) - for i in numba.parfor.internal_prange(len(in_arr)): + for i in numba.parfors.parfor.internal_prange(len(in_arr)): val = max(val, in_arr[i]) return val else: def max_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() max_checker(len(in_arr)) val = numba.cpython.builtins.get_type_min_value(in_arr.dtype) for i in numba.pndindex(in_arr.shape): @@ -168,40 +168,40 @@ def max_1(in_arr): return max_1 def argmin_parallel_impl(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() argmin_checker(len(in_arr)) A = in_arr.ravel() init_val = numba.cpython.builtins.get_type_max_value(A.dtype) ival = typing.builtins.IndexValue(0, init_val) - for i in numba.parfor.internal_prange(len(A)): + for i in numba.parfors.parfor.internal_prange(len(A)): curr_ival = typing.builtins.IndexValue(i, A[i]) ival = min(ival, curr_ival) return ival.index def argmax_parallel_impl(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() argmax_checker(len(in_arr)) A = in_arr.ravel() init_val = numba.cpython.builtins.get_type_min_value(A.dtype) ival = typing.builtins.IndexValue(0, init_val) - for i in numba.parfor.internal_prange(len(A)): + for i in numba.parfors.parfor.internal_prange(len(A)): curr_ival = typing.builtins.IndexValue(i, A[i]) ival = max(ival, curr_ival) return ival.index def dotvv_parallel_impl(a, b): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() l = a.shape[0] m = b.shape[0] # TODO: investigate assert_equiv #assert_equiv("sizes of l, m do not match", l, m) s = 0 - for i in numba.parfor.internal_prange(l): + for i in numba.parfors.parfor.internal_prange(l): s += a[i] * b[i] return s def dotvm_parallel_impl(a, b): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() l = a.shape m, n = b.shape # TODO: investigate assert_equiv @@ -213,18 +213,18 @@ def dotvm_parallel_impl(a, b): # for j in range(m): # s += a[j] * b[j, i] # c[i] = s - for i in numba.parfor.internal_prange(m): + for i in numba.parfors.parfor.internal_prange(m): c += a[i] * b[i, :] return c def dotmv_parallel_impl(a, b): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() m, n = a.shape l = b.shape # TODO: investigate assert_equiv #assert_equiv("sizes of n, l do not match", n, l) c = np.empty(m, a.dtype) - for i in numba.parfor.internal_prange(m): + for i in numba.parfors.parfor.internal_prange(m): s = 0 for j in range(n): s += a[i, j] * b[j] @@ -251,14 +251,14 @@ def sum_1(in_arr): return in_arr[()] elif arg.ndim == 1: def sum_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() val = zero - for i in numba.parfor.internal_prange(len(in_arr)): + for i in numba.parfors.parfor.internal_prange(len(in_arr)): val += in_arr[i] return val else: def sum_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() val = zero for i in numba.pndindex(in_arr.shape): val += in_arr[i] @@ -273,14 +273,14 @@ def prod_1(in_arr): return in_arr[()] elif arg.ndim == 1: def prod_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() val = one - for i in numba.parfor.internal_prange(len(in_arr)): + for i in numba.parfors.parfor.internal_prange(len(in_arr)): val *= in_arr[i] return val else: def prod_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() val = one for i in numba.pndindex(in_arr.shape): val *= in_arr[i] @@ -297,14 +297,14 @@ def mean_1(in_arr): return in_arr[()] elif arg.ndim == 1: def mean_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() val = zero - for i in numba.parfor.internal_prange(len(in_arr)): + for i in numba.parfors.parfor.internal_prange(len(in_arr)): val += in_arr[i] return val/len(in_arr) else: def mean_1(in_arr): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() val = zero for i in numba.pndindex(in_arr.shape): val += in_arr[i] @@ -320,9 +320,9 @@ def var_1(in_arr): # Compute the mean m = in_arr.mean() # Compute the sum of square diffs - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() ssd = 0 - for i in numba.parfor.internal_prange(len(in_arr)): + for i in numba.parfors.parfor.internal_prange(len(in_arr)): val = in_arr[i] - m ssd += np.real(val * np.conj(val)) return ssd / len(in_arr) @@ -331,7 +331,7 @@ def var_1(in_arr): # Compute the mean m = in_arr.mean() # Compute the sum of square diffs - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() ssd = 0 for i in numba.pndindex(in_arr.shape): val = in_arr[i] - m @@ -358,23 +358,23 @@ def arange_3(start, stop, step): if any(isinstance(a, types.Complex) for a in args): def arange_4(start, stop, step, dtype): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() nitems_c = (stop - start) / step nitems_r = math.ceil(nitems_c.real) nitems_i = math.ceil(nitems_c.imag) nitems = int(max(min(nitems_i, nitems_r), 0)) arr = np.empty(nitems, dtype) - for i in numba.parfor.internal_prange(nitems): + for i in numba.parfors.parfor.internal_prange(nitems): arr[i] = start + i * step return arr else: def arange_4(start, stop, step, dtype): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() nitems_r = math.ceil((stop - start) / step) nitems = int(max(nitems_r, 0)) arr = np.empty(nitems, dtype) val = start - for i in numba.parfor.internal_prange(nitems): + for i in numba.parfors.parfor.internal_prange(nitems): arr[i] = start + i * step return arr @@ -396,12 +396,12 @@ def linspace_2(start, stop): return np.linspace(start, stop, 50) def linspace_3(start, stop, num): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() arr = np.empty(num, dtype) div = num - 1 delta = stop - start arr[0] = start - for i in numba.parfor.internal_prange(num): + for i in numba.parfors.parfor.internal_prange(num): arr[i] = start + delta * (i / div) return arr @@ -436,13 +436,13 @@ def fill_parallel_impl(return_type, arr, val): """ if arr.ndim == 1: def fill_1(in_arr, val): - numba.parfor.init_prange() - for i in numba.parfor.internal_prange(len(in_arr)): + numba.parfors.parfor.init_prange() + for i in numba.parfors.parfor.internal_prange(len(in_arr)): in_arr[i] = val return None else: def fill_1(in_arr, val): - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() for i in numba.pndindex(in_arr.shape): in_arr[i] = val return None @@ -1600,10 +1600,7 @@ def run(self): self.options.fusion, self.nested_fusion_info) for p in parfors: - numba.parfor.get_parfor_reductions(self.func_ir, - p, - p.params, - self.calltypes) + get_parfor_reductions(self.func_ir, p, p.params, self.calltypes) if config.DEBUG_ARRAY_OPT_STATS: name = self.func_ir.func_id.func_qualname n_parfors = len(parfor_ids) diff --git a/numba/stencils/stencilparfor.py b/numba/stencils/stencilparfor.py index 5bad2159745..6fffd25cd20 100644 --- a/numba/stencils/stencilparfor.py +++ b/numba/stencils/stencilparfor.py @@ -11,7 +11,7 @@ import numpy as np -import numba +import numba.parfors.parfor from numba.core import types, ir, rewrites, config, ir_utils from numba.core.typing.templates import infer_global, AbstractTemplate from numba.core.typing import signature @@ -187,7 +187,7 @@ def _mk_stencil_parfor(self, label, in_args, out_arr, stencil_ir, start_ind = self._get_stencil_start_ind( start_lengths[i], gen_nodes, scope, loc) # start from stencil size to avoid invalid array access - loopnests.append(numba.parfor.LoopNest(parfor_vars[i], + loopnests.append(numba.parfors.parfor.LoopNest(parfor_vars[i], start_ind, last_ind, 1)) # We have to guarantee that the exit block has maximum label and that @@ -354,7 +354,7 @@ def _mk_stencil_parfor(self, label, in_args, out_arr, stencil_ir, ir_utils.dump_blocks(stencil_blocks) pattern = ('stencil', [start_lengths, end_lengths]) - parfor = numba.parfor.Parfor(loopnests, init_block, stencil_blocks, + parfor = numba.parfors.parfor.Parfor(loopnests, init_block, stencil_blocks, loc, parfor_ind_var, equiv_set, pattern, self.flags) gen_nodes.append(parfor) gen_nodes.append(ir.Assign(out_arr, target, loc)) diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 4a0eaa5de36..5170f3104a5 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -26,11 +26,11 @@ from numba.np.numpy_support import as_dtype from numba.core.caching import _UserWideCacheLocator from numba.core.dispatcher import Dispatcher -from numba import parfor from numba.tests.support import skip_parfors_unsupported, needs_lapack import llvmlite.binding as ll from numba.testing import unittest_support as unittest +from numba.parfors import parfor try: import jinja2 diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 142c20ff480..e3b644a484c 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -18,7 +18,7 @@ import operator from collections import defaultdict -import numba +import numba.parfors.parfor from numba import njit, prange from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler, cpu from numba.core.registry import cpu_target @@ -324,9 +324,9 @@ def get_optimized_numba_ir(test_func, args, **kws): return_type=tp.state.return_type, html_output=config.HTML) - diagnostics = numba.parfor.ParforDiagnostics() + diagnostics = numba.parfors.parfor.ParforDiagnostics() - preparfor_pass = numba.parfor.PreParforPass( + preparfor_pass = numba.parfors.parfor.PreParforPass( tp.state.func_ir, tp.state.typemap, tp.state.calltypes, tp.state.typingctx, options, swapped=diagnostics.replaced_fns) @@ -335,7 +335,7 @@ def get_optimized_numba_ir(test_func, args, **kws): rewrites.rewrite_registry.apply('after-inference', tp.state) flags = compiler.Flags() - parfor_pass = numba.parfor.ParforPass( + parfor_pass = numba.parfors.parfor.ParforPass( tp.state.func_ir, tp.state.typemap, tp.state.calltypes, tp.state.return_type, tp.state.typingctx, options, flags, diagnostics=diagnostics) @@ -350,7 +350,7 @@ def countParfors(test_func, args, **kws): for label, block in test_ir.blocks.items(): for i, inst in enumerate(block.body): - if isinstance(inst, numba.parfor.Parfor): + if isinstance(inst, numba.parfors.parfor.Parfor): ret_count += 1 return ret_count @@ -368,7 +368,7 @@ def get_init_block_size(test_func, args, **kws): for label, block in blocks.items(): for i, inst in enumerate(block.body): - if isinstance(inst, numba.parfor.Parfor): + if isinstance(inst, numba.parfors.parfor.Parfor): ret_count += len(inst.init_block.body) return ret_count @@ -379,7 +379,7 @@ def _count_arrays_inner(blocks, typemap): for label, block in blocks.items(): for i, inst in enumerate(block.body): - if isinstance(inst, numba.parfor.Parfor): + if isinstance(inst, numba.parfors.parfor.Parfor): parfor_blocks = inst.loop_body.copy() parfor_blocks[0] = inst.init_block ret_count += _count_arrays_inner(parfor_blocks, typemap) @@ -403,7 +403,7 @@ def countArrayAllocs(test_func, args, **kws): def _count_array_allocs_inner(func_ir, block): ret_count = 0 for inst in block.body: - if isinstance(inst, numba.parfor.Parfor): + if isinstance(inst, numba.parfors.parfor.Parfor): ret_count += _count_array_allocs_inner(func_ir, inst.init_block) for b in inst.loop_body.values(): ret_count += _count_array_allocs_inner(func_ir, b) @@ -429,7 +429,7 @@ def _count_non_parfor_array_accesses_inner(f_ir, blocks, typemap, parfor_indices for label, block in blocks.items(): for stmt in block.body: - if isinstance(stmt, numba.parfor.Parfor): + if isinstance(stmt, numba.parfors.parfor.Parfor): parfor_indices.add(stmt.index_var.name) parfor_blocks = stmt.loop_body.copy() parfor_blocks[0] = stmt.init_block @@ -1188,7 +1188,7 @@ def test_impl(A, b): parfor_found = False parfor = None for stmt in block.body: - if isinstance(stmt, numba.parfor.Parfor): + if isinstance(stmt, numba.parfors.parfor.Parfor): parfor_found = True parfor = stmt @@ -3063,13 +3063,13 @@ def test_impl(A): A = np.array([np.inf, 0.0]) cfunc = njit(parallel=True)(test_impl) # save global state - old_seq_flag = numba.parfor.sequential_parfor_lowering + old_seq_flag = numba.parfors.parfor.sequential_parfor_lowering try: - numba.parfor.sequential_parfor_lowering = True + numba.parfors.parfor.sequential_parfor_lowering = True np.testing.assert_array_equal(test_impl(A), cfunc(A)) finally: # recover global state - numba.parfor.sequential_parfor_lowering = old_seq_flag + numba.parfors.parfor.sequential_parfor_lowering = old_seq_flag @skip_parfors_unsupported def test_init_block_dce(self): @@ -3077,7 +3077,7 @@ def test_init_block_dce(self): def test_impl(): res = 0 arr = [1,2,3,4,5] - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() dummy = arr for i in numba.prange(5): res += arr[i] diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index a2cf5c167ff..b1a8c9d309d 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -4,6 +4,7 @@ # import numba +import numba.parfors.parfor from numba.core import ir_utils, cpu from numba.core.compiler import compile_isolated, Flags from numba.core import types, typing, ir, config, compiler @@ -223,7 +224,7 @@ def test_alias_parfor_extension(self): """ def func(): n = 11 - numba.parfor.init_prange() + numba.parfors.parfor.init_prange() A = np.empty(n) B = A # create alias to A for i in numba.prange(n): @@ -239,7 +240,7 @@ def __init__(self): FunctionPass.__init__(self) def run_pass(self, state): - parfor_pass = numba.parfor.ParforPass( + parfor_pass = numba.parfors.parfor.ParforPass( state.func_ir, state.type_annotation.typemap, state.type_annotation.calltypes, @@ -256,7 +257,7 @@ def run_pass(self, state): state.func_ir.arg_names, state.func_ir, state.type_annotation.typemap) - numba.parfor.get_parfor_params(state.func_ir.blocks, + numba.parfors.parfor.get_parfor_params(state.func_ir.blocks, parfor_pass.options.fusion, parfor_pass.nested_fusion_info) return True From 7627849cfb16d3abb54c1c6a9f454cce324b244e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 12:19:04 +0000 Subject: [PATCH 447/595] Rename numba.np.ufunc.parfor -> numba.np.ufunc.parfor_lowering --- numba/np/ufunc/__init__.py | 2 +- numba/np/ufunc/{parfor.py => parfor_lowering.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/np/ufunc/{parfor.py => parfor_lowering.py} (100%) diff --git a/numba/np/ufunc/__init__.py b/numba/np/ufunc/__init__.py index bc85fa47062..bc6f3a6017f 100644 --- a/numba/np/ufunc/__init__.py +++ b/numba/np/ufunc/__init__.py @@ -2,7 +2,7 @@ from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One -from numba.np.ufunc import _internal, array_exprs, parfor +from numba.np.ufunc import _internal, array_exprs, parfor_lowering from numba.np.ufunc.parallel import threading_layer if hasattr(_internal, 'PyUFunc_ReorderableNone'): PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone diff --git a/numba/np/ufunc/parfor.py b/numba/np/ufunc/parfor_lowering.py similarity index 100% rename from numba/np/ufunc/parfor.py rename to numba/np/ufunc/parfor_lowering.py From 8cca6d900216d4bf225e7ce9820e350a686a5d21 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 12:34:56 +0000 Subject: [PATCH 448/595] Move numba/np/ufunc/parfor_lowering.py to numba/parfors --- numba/np/ufunc/__init__.py | 3 ++- numba/parfors/__init__.py | 1 + numba/{np/ufunc => parfors}/parfor_lowering.py | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) rename numba/{np/ufunc => parfors}/parfor_lowering.py (99%) diff --git a/numba/np/ufunc/__init__.py b/numba/np/ufunc/__init__.py index bc6f3a6017f..2f01bc6de0f 100644 --- a/numba/np/ufunc/__init__.py +++ b/numba/np/ufunc/__init__.py @@ -2,8 +2,9 @@ from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One -from numba.np.ufunc import _internal, array_exprs, parfor_lowering +from numba.np.ufunc import _internal, array_exprs from numba.np.ufunc.parallel import threading_layer + if hasattr(_internal, 'PyUFunc_ReorderableNone'): PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone del _internal, array_exprs diff --git a/numba/parfors/__init__.py b/numba/parfors/__init__.py index e69de29bb2d..f2acbe33969 100644 --- a/numba/parfors/__init__.py +++ b/numba/parfors/__init__.py @@ -0,0 +1 @@ +from numba.parfors import parfor_lowering diff --git a/numba/np/ufunc/parfor_lowering.py b/numba/parfors/parfor_lowering.py similarity index 99% rename from numba/np/ufunc/parfor_lowering.py rename to numba/parfors/parfor_lowering.py index df71ddb8ba6..38aea5cf9ab 100644 --- a/numba/np/ufunc/parfor_lowering.py +++ b/numba/parfors/parfor_lowering.py @@ -18,7 +18,6 @@ from numba.core.ir_utils import add_offset_to_labels, replace_var_names, remove_dels, legalize_names, mk_unique_var, rename_labels, get_name_var_table, visit_vars_inner, get_definition, guard, find_callname, get_call_table, is_pure, get_np_ufunc_typ, get_unused_var_name, find_potential_aliases, is_const_call from numba.core.analysis import compute_use_defs, compute_live_map, compute_dead_maps, compute_cfg_from_blocks from numba.core.typing import signature -from numba.core.cpu import ParallelOptions from numba.parfors.parfor import print_wrapped, ensure_parallel_support from numba.core.errors import NumbaParallelSafetyWarning From 2111cd4381e3d1ff1d00946f5218485f7631bc54 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 12:40:15 +0000 Subject: [PATCH 449/595] Remove numba.macro --- numba/cuda/stubs.py | 40 ++++++++++++++++++++-------------------- numba/macro.py | 8 -------- numba/roc/stubs.py | 6 +++--- 3 files changed, 23 insertions(+), 31 deletions(-) delete mode 100644 numba/macro.py diff --git a/numba/cuda/stubs.py b/numba/cuda/stubs.py index 300b61c7cd8..48d79928f7b 100644 --- a/numba/cuda/stubs.py +++ b/numba/cuda/stubs.py @@ -4,7 +4,7 @@ import operator import numpy import llvmlite.llvmpy.core as lc -from numba import macro +from numba.core.rewrites.macros import Macro from numba.core import types, typing, ir from .cudadrv import nvvm @@ -37,9 +37,9 @@ class threadIdx(Stub): ''' _description_ = '' - x = macro.Macro('tid.x', SREG_SIGNATURE) - y = macro.Macro('tid.y', SREG_SIGNATURE) - z = macro.Macro('tid.z', SREG_SIGNATURE) + x = Macro('tid.x', SREG_SIGNATURE) + y = Macro('tid.y', SREG_SIGNATURE) + z = Macro('tid.z', SREG_SIGNATURE) class blockIdx(Stub): @@ -51,9 +51,9 @@ class blockIdx(Stub): ''' _description_ = '' - x = macro.Macro('ctaid.x', SREG_SIGNATURE) - y = macro.Macro('ctaid.y', SREG_SIGNATURE) - z = macro.Macro('ctaid.z', SREG_SIGNATURE) + x = Macro('ctaid.x', SREG_SIGNATURE) + y = Macro('ctaid.y', SREG_SIGNATURE) + z = Macro('ctaid.z', SREG_SIGNATURE) class blockDim(Stub): @@ -62,9 +62,9 @@ class blockDim(Stub): kernel. This value is the same for all threads in a given kernel, even if they belong to different blocks (i.e. each block is "full"). ''' - x = macro.Macro('ntid.x', SREG_SIGNATURE) - y = macro.Macro('ntid.y', SREG_SIGNATURE) - z = macro.Macro('ntid.z', SREG_SIGNATURE) + x = Macro('ntid.x', SREG_SIGNATURE) + y = Macro('ntid.y', SREG_SIGNATURE) + z = Macro('ntid.z', SREG_SIGNATURE) class gridDim(Stub): @@ -73,13 +73,13 @@ class gridDim(Stub): ``y``, and ``z``. ''' _description_ = '' - x = macro.Macro('nctaid.x', SREG_SIGNATURE) - y = macro.Macro('nctaid.y', SREG_SIGNATURE) - z = macro.Macro('nctaid.z', SREG_SIGNATURE) + x = Macro('nctaid.x', SREG_SIGNATURE) + y = Macro('nctaid.y', SREG_SIGNATURE) + z = Macro('nctaid.z', SREG_SIGNATURE) -warpsize = macro.Macro('warpsize', SREG_SIGNATURE) -laneid = macro.Macro('laneid', SREG_SIGNATURE) +warpsize = Macro('warpsize', SREG_SIGNATURE) +laneid = Macro('laneid', SREG_SIGNATURE) #------------------------------------------------------------------------------- # Grid Macro @@ -121,7 +121,7 @@ def grid_expand(ndim): return ir.Intrinsic(fname, typing.signature(restype, types.intp), args=[ndim]) -grid = macro.Macro('ptx.grid', grid_expand, callable=True) +grid = Macro('ptx.grid', grid_expand, callable=True) #------------------------------------------------------------------------------- # Gridsize Macro @@ -155,7 +155,7 @@ def gridsize_expand(ndim): args=[ndim]) -gridsize = macro.Macro('ptx.gridsize', gridsize_expand, callable=True) +gridsize = Macro('ptx.gridsize', gridsize_expand, callable=True) #------------------------------------------------------------------------------- # syncthreads @@ -306,7 +306,7 @@ class shared(Stub): """ _description_ = '' - array = macro.Macro('shared.array', shared_array, callable=True, + array = Macro('shared.array', shared_array, callable=True, argnames=['shape', 'dtype']) ''' Allocate a shared array of the given *shape* and *type*. *shape* is either @@ -338,7 +338,7 @@ class local(Stub): ''' _description_ = '' - array = macro.Macro('local.array', local_array, callable=True, + array = Macro('local.array', local_array, callable=True, argnames=['shape', 'dtype']) ''' Allocate a local array of the given *shape* and *type*. The array is private @@ -367,7 +367,7 @@ class const(Stub): ''' _description_ = '' - array_like = macro.Macro('const.array_like', const_array_like, + array_like = Macro('const.array_like', const_array_like, callable=True, argnames=['ary']) ''' Create a const array from *ary*. The resulting const array will have the diff --git a/numba/macro.py b/numba/macro.py deleted file mode 100644 index ff125aa0c78..00000000000 --- a/numba/macro.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -Macro handling. - -Macros are expanded on block-by-block -""" - -# Expose the Macro object from the corresponding IR rewrite pass -from numba.core.rewrites.macros import Macro diff --git a/numba/roc/stubs.py b/numba/roc/stubs.py index d02e1a79d1f..a1b46d1efa5 100644 --- a/numba/roc/stubs.py +++ b/numba/roc/stubs.py @@ -1,4 +1,4 @@ -from numba import macro +from numba.core.rewrites.macros import Macro from numba.core import types, typing, ir _stub_error = NotImplementedError("This is a stub.") @@ -140,8 +140,8 @@ class shared(Stub): """ _description_ = '' - array = macro.Macro('shared.array', shared_array, callable=True, - argnames=['shape', 'dtype']) + array = Macro('shared.array', shared_array, callable=True, + argnames=['shape', 'dtype']) def _legalize_shape(shape): From 0127843dbc299b39a6f3edcf7e5ae959fe2e0d0d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 12:45:36 +0000 Subject: [PATCH 450/595] Remove numba.cffi_utils --- numba/cffi_support.py | 5 ----- numba/tests/cffi_usecases.py | 2 +- numba/tests/test_cffi.py | 3 ++- numba/tests/test_cfunc.py | 2 +- numba/tests/test_nrt.py | 4 ++-- numba/tests/test_typeof.py | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) delete mode 100644 numba/cffi_support.py diff --git a/numba/cffi_support.py b/numba/cffi_support.py deleted file mode 100644 index f78cff04e2a..00000000000 --- a/numba/cffi_support.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Alias to numba.core.typing.cffi_utils for backward compatibility -""" -from numba.core.typing.cffi_utils import * diff --git a/numba/tests/cffi_usecases.py b/numba/tests/cffi_usecases.py index fc5a8685f7e..59b7c91e05b 100644 --- a/numba/tests/cffi_usecases.py +++ b/numba/tests/cffi_usecases.py @@ -2,7 +2,7 @@ import numpy as np -from numba import cffi_support +import numba.core.typing.cffi_utils as cffi_support from numba.tests.support import import_dynamic, temp_directory from numba.core.types import complex128 diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index a5059e75d1c..c9ae8a2eed1 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -1,7 +1,8 @@ import array import numpy as np -from numba import jit, cffi_support +from numba import jit +import numba.core.typing.cffi_utils as cffi_support from numba.core import types, errors from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index 6d6e5aef9db..6795f3769e8 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -13,7 +13,7 @@ from numba import cfunc, carray, farray, njit from numba.core import types, typing, utils -from numba import cffi_support +import numba.core.typing.cffi_utils as cffi_support from numba.tests.support import TestCase, tag, captured_stderr from numba.tests.test_dispatcher import BaseCacheTest from numba.testing import unittest_support as unittest diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index e07dcbd9c89..8765247073a 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -6,7 +6,7 @@ import numpy as np -from numba import njit, targets +from numba import njit from numba.core import typing, types from numba.core.compiler import compile_isolated, Flags from numba.runtime import ( @@ -20,7 +20,7 @@ from numba.core.imputils import impl_ret_untracked from llvmlite import ir import llvmlite.binding as llvm -from numba import cffi_support +import numba.core.typing.cffi_utils as cffi_support from numba.core.unsafe.nrt import NRT_get_api from numba.tests.support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 6a0517a28a5..1761270c2b6 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -9,7 +9,7 @@ import numpy as np import numba.testing.unittest_support as unittest -from numba import cffi_support +import numba.core.typing.cffi_utils as cffi_support from numba.core import types from numba.misc.special import typeof from numba.core.dispatcher import OmittedArg From 4489dd337034d93ba59c9668fd7f0862f866d0a4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 13:08:06 +0000 Subject: [PATCH 451/595] Move numba.extending to numba.core.extending and then re-export --- numba/{ => core}/extending.py | 0 numba/core/ir_utils.py | 5 +++-- numba/core/typing/builtins.py | 2 +- numba/core/unsafe/bytes.py | 2 +- numba/core/unsafe/eh.py | 2 +- numba/core/unsafe/nrt.py | 2 +- numba/core/unsafe/refcount.py | 2 +- numba/cpython/builtins.py | 2 +- numba/cpython/charseq.py | 2 +- numba/cpython/hashing.py | 2 +- numba/cpython/heapq.py | 2 +- numba/cpython/listobj.py | 2 +- numba/cpython/mathimpl.py | 2 +- numba/cpython/numbers.py | 2 +- numba/cpython/randomimpl.py | 2 +- numba/cpython/rangeobj.py | 2 +- numba/cpython/tupleobj.py | 2 +- numba/cpython/unicode.py | 2 +- numba/cpython/unicode_support.py | 2 +- numba/cpython/unsafe/numbers.py | 2 +- numba/cpython/unsafe/tuple.py | 2 +- numba/misc/gdb_hook.py | 2 +- numba/misc/literal.py | 2 +- numba/misc/quicksort.py | 2 +- numba/np/arraymath.py | 4 ++-- numba/np/arrayobj.py | 6 +++--- numba/np/linalg.py | 2 +- numba/np/npyimpl.py | 2 +- numba/np/polynomial.py | 2 +- numba/np/unsafe/ndarray.py | 2 +- numba/parfors/array_analysis.py | 2 +- numba/parfors/parfor.py | 4 ++-- numba/stencils/stencil.py | 2 +- numba/tests/inlining_usecases.py | 2 +- numba/tests/pdlike_usecase.py | 2 +- numba/tests/test_extending.py | 4 +--- numba/tests/test_extending_types.py | 12 ++++++------ numba/tests/test_ir_inlining.py | 2 +- numba/tests/test_literal_dispatch.py | 2 +- numba/tests/test_make_function_to_jit_function.py | 2 +- numba/tests/test_mixed_tuple_unroller.py | 2 +- numba/tests/test_nrt.py | 2 +- numba/tests/test_types.py | 2 +- numba/tests/test_withlifting.py | 2 +- numba/typed/dictobject.py | 2 +- numba/typed/listobject.py | 2 +- numba/typed/typeddict.py | 2 +- numba/typed/typedlist.py | 2 +- numba/typed/typedobjectutils.py | 2 +- 49 files changed, 59 insertions(+), 60 deletions(-) rename numba/{ => core}/extending.py (100%) diff --git a/numba/extending.py b/numba/core/extending.py similarity index 100% rename from numba/extending.py rename to numba/core/extending.py diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index 4e8edd108f9..31b3de51d9b 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -13,6 +13,7 @@ from llvmlite import ir as lir import numba +from numba.core.extending import _Intrinsic from numba.core import types, utils, typing, ir, analysis, postproc, rewrites, config, cgutils from numba.core.typing.templates import (signature, infer_global, AbstractTemplate) @@ -663,7 +664,7 @@ def has_no_side_effect(rhs, lives, call_table): call_list == [prange] or call_list == [parfor.internal_prange]): return True - elif (isinstance(call_list[0], numba.extending._Intrinsic) and + elif (isinstance(call_list[0], _Intrinsic) and (call_list[0]._name == 'empty_inferred' or call_list[0]._name == 'unsafe_empty_inferred')): return True @@ -1505,7 +1506,7 @@ def find_callname(func_ir, expr, typemap=None, definition_finder=get_definition) # get the underlying definition of Intrinsic object to be able to # find the module effectively. # Otherwise, it will return numba.extending - if isinstance(def_val, numba.extending._Intrinsic): + if isinstance(def_val, _Intrinsic): def_val = def_val._defn if hasattr(def_val, '__module__'): mod_name = def_val.__module__ diff --git a/numba/core/typing/builtins.py b/numba/core/typing/builtins.py index 22d39d506a4..fd44ae46154 100644 --- a/numba/core/typing/builtins.py +++ b/numba/core/typing/builtins.py @@ -15,7 +15,7 @@ from numba.cpython.builtins import get_type_min_value, get_type_max_value -from numba.extending import ( +from numba.core.extending import ( typeof_impl, type_callable, models, register_model, make_attribute_wrapper, ) diff --git a/numba/core/unsafe/bytes.py b/numba/core/unsafe/bytes.py index bc86b90dd82..3c99be1bd55 100644 --- a/numba/core/unsafe/bytes.py +++ b/numba/core/unsafe/bytes.py @@ -3,7 +3,7 @@ operations with bytes and workarounds for limitations enforced in userland. """ -from numba.extending import intrinsic +from numba.core.extending import intrinsic from llvmlite import ir from numba.core import types, cgutils diff --git a/numba/core/unsafe/eh.py b/numba/core/unsafe/eh.py index 0d25fbbb2f1..56132d50f04 100644 --- a/numba/core/unsafe/eh.py +++ b/numba/core/unsafe/eh.py @@ -3,7 +3,7 @@ """ from numba.core import types, errors, cgutils -from numba.extending import intrinsic +from numba.core.extending import intrinsic @intrinsic diff --git a/numba/core/unsafe/nrt.py b/numba/core/unsafe/nrt.py index dfc1638a84c..673f0130faf 100644 --- a/numba/core/unsafe/nrt.py +++ b/numba/core/unsafe/nrt.py @@ -4,7 +4,7 @@ from numba.core import types from numba.core.typing import signature -from numba.extending import intrinsic +from numba.core.extending import intrinsic @intrinsic diff --git a/numba/core/unsafe/refcount.py b/numba/core/unsafe/refcount.py index 4107ca0b33f..4c6aaee853d 100644 --- a/numba/core/unsafe/refcount.py +++ b/numba/core/unsafe/refcount.py @@ -4,7 +4,7 @@ from llvmlite import ir from numba.core import types, cgutils -from numba.extending import intrinsic +from numba.core.extending import intrinsic from numba.runtime.nrtdynmod import _meminfo_struct_type diff --git a/numba/cpython/builtins.py b/numba/cpython/builtins.py index 06b8d1f909d..f4b46e67ff7 100644 --- a/numba/cpython/builtins.py +++ b/numba/cpython/builtins.py @@ -10,7 +10,7 @@ from numba.core.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, iternext_impl, call_getiter, call_iternext, impl_ret_borrowed, impl_ret_untracked, numba_typeref_ctor from numba.core import typing, types, utils, cgutils -from numba.extending import overload, intrinsic +from numba.core.extending import overload, intrinsic from numba.core.typeconv import Conversion from numba.core.errors import TypingError diff --git a/numba/cpython/charseq.py b/numba/cpython/charseq.py index c6eba7afb6a..a1f3df493a4 100644 --- a/numba/cpython/charseq.py +++ b/numba/cpython/charseq.py @@ -4,7 +4,7 @@ from llvmlite import ir from numba.core import types, cgutils -from numba.extending import (overload, intrinsic, overload_method, lower_cast, +from numba.core.extending import (overload, intrinsic, overload_method, lower_cast, register_jitable) from numba.core.cgutils import is_nonelike from numba.cpython import unicode diff --git a/numba/cpython/hashing.py b/numba/cpython/hashing.py index e547de774f1..5119e8a3263 100644 --- a/numba/cpython/hashing.py +++ b/numba/cpython/hashing.py @@ -12,7 +12,7 @@ import llvmlite.llvmpy.core as lc from llvmlite import ir -from numba.extending import ( +from numba.core.extending import ( overload, overload_method, intrinsic, register_jitable) from numba.core import errors from numba.core import types, utils diff --git a/numba/cpython/heapq.py b/numba/cpython/heapq.py index 0ce2a3280f3..23a80e26904 100644 --- a/numba/cpython/heapq.py +++ b/numba/cpython/heapq.py @@ -5,7 +5,7 @@ from numba.core import types from numba.core.errors import TypingError -from numba.extending import overload, register_jitable +from numba.core.extending import overload, register_jitable @register_jitable diff --git a/numba/cpython/listobj.py b/numba/cpython/listobj.py index cc29c953083..c771ae855e3 100644 --- a/numba/cpython/listobj.py +++ b/numba/cpython/listobj.py @@ -12,7 +12,7 @@ iternext_impl, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked, RefType) -from numba.extending import overload_method, overload +from numba.core.extending import overload_method, overload from numba.core.utils import cached_property from numba.misc import quicksort from numba.cpython import slicing diff --git a/numba/cpython/mathimpl.py b/numba/cpython/mathimpl.py index 6d915df3dec..e79d7cf3956 100644 --- a/numba/cpython/mathimpl.py +++ b/numba/cpython/mathimpl.py @@ -13,7 +13,7 @@ from numba.core.imputils import Registry, impl_ret_untracked from numba import typeof from numba.core import types, utils, config, cgutils -from numba.extending import overload +from numba.core.extending import overload from numba.core.typing import signature from numba.cpython.unsafe.numbers import trailing_zeros diff --git a/numba/cpython/numbers.py b/numba/cpython/numbers.py index 49c13d9d10b..d733836fe05 100644 --- a/numba/cpython/numbers.py +++ b/numba/cpython/numbers.py @@ -13,7 +13,7 @@ lower_constant, impl_ret_borrowed, impl_ret_untracked) from numba.core import typing, types, utils, errors, cgutils, optional -from numba.extending import intrinsic, overload_method +from numba.core.extending import intrinsic, overload_method from numba.cpython.unsafe.numbers import viewer def _int_arith_flags(rettype): diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index fbb23325f07..450301ed0ad 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -11,7 +11,7 @@ from llvmlite import ir -from numba.extending import overload, register_jitable +from numba.core.extending import overload, register_jitable from numba.core.imputils import (Registry, impl_ret_untracked, impl_ret_new_ref) from numba.core.typing import signature diff --git a/numba/cpython/rangeobj.py b/numba/cpython/rangeobj.py index acf590d92fe..0f61a4ff3f0 100644 --- a/numba/cpython/rangeobj.py +++ b/numba/cpython/rangeobj.py @@ -13,7 +13,7 @@ from numba.core.imputils import (lower_builtin, lower_cast, iterator_impl, impl_ret_untracked) from numba.core.typing import signature -from numba.extending import intrinsic, overload, overload_attribute, register_jitable +from numba.core.extending import intrinsic, overload, overload_attribute, register_jitable from numba.parfors.parfor import internal_prange def make_range_iterator(typ): diff --git a/numba/cpython/tupleobj.py b/numba/cpython/tupleobj.py index e211b8ed6cd..d61503048c5 100644 --- a/numba/cpython/tupleobj.py +++ b/numba/cpython/tupleobj.py @@ -11,7 +11,7 @@ impl_ret_borrowed, impl_ret_untracked, RefType) from numba.core import typing, types, cgutils -from numba.extending import overload_method, overload, intrinsic +from numba.core.extending import overload_method, overload, intrinsic @lower_builtin(types.NamedTupleClass, types.VarArg(types.Any)) diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index 8df16e0f9e2..3dc3bf2095c 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -4,7 +4,7 @@ import numpy as np from llvmlite.ir import IntType, Constant -from numba.extending import ( +from numba.core.extending import ( models, register_model, make_attribute_wrapper, diff --git a/numba/cpython/unicode_support.py b/numba/cpython/unicode_support.py index 8ffaad7d0d7..b36ea6f1a21 100644 --- a/numba/cpython/unicode_support.py +++ b/numba/cpython/unicode_support.py @@ -12,7 +12,7 @@ from numba.core import types, cgutils from numba.core.imputils import (impl_ret_untracked) -from numba.extending import overload, intrinsic, register_jitable +from numba.core.extending import overload, intrinsic, register_jitable from numba.core.errors import TypingError # This is equivalent to the struct `_PyUnicode_TypeRecord defined in CPython's diff --git a/numba/cpython/unsafe/numbers.py b/numba/cpython/unsafe/numbers.py index 50a95be26ec..8f945c93ccd 100644 --- a/numba/cpython/unsafe/numbers.py +++ b/numba/cpython/unsafe/numbers.py @@ -1,7 +1,7 @@ """ This module provides the unsafe things for targets/numbers.py """ from numba.core import types -from numba.extending import intrinsic +from numba.core.extending import intrinsic from llvmlite import ir diff --git a/numba/cpython/unsafe/tuple.py b/numba/cpython/unsafe/tuple.py index b5e500c10eb..39f0d28b771 100644 --- a/numba/cpython/unsafe/tuple.py +++ b/numba/cpython/unsafe/tuple.py @@ -4,7 +4,7 @@ """ from numba.core.cgutils import alloca_once -from numba.extending import intrinsic +from numba.core.extending import intrinsic @intrinsic diff --git a/numba/misc/gdb_hook.py b/numba/misc/gdb_hook.py index 10a10f4a258..8613e957d50 100644 --- a/numba/misc/gdb_hook.py +++ b/numba/misc/gdb_hook.py @@ -5,7 +5,7 @@ from numba.core import types, utils, config, cgutils from numba import gdb, gdb_init, gdb_breakpoint -from numba.extending import overload, intrinsic +from numba.core.extending import overload, intrinsic _path = os.path.dirname(__file__) diff --git a/numba/misc/literal.py b/numba/misc/literal.py index 879af238012..d5c9cf1e771 100644 --- a/numba/misc/literal.py +++ b/numba/misc/literal.py @@ -1,4 +1,4 @@ -from numba.extending import overload +from numba.core.extending import overload from numba.core import types from numba.misc.special import literally, literal_unroll from numba.core.errors import TypingError diff --git a/numba/misc/quicksort.py b/numba/misc/quicksort.py index 9b4c986220c..e94507d1811 100644 --- a/numba/misc/quicksort.py +++ b/numba/misc/quicksort.py @@ -239,6 +239,6 @@ def make_py_quicksort(*args, **kwargs): return make_quicksort_impl((lambda f: f), *args, **kwargs) def make_jit_quicksort(*args, **kwargs): - from numba.extending import register_jitable + from numba.core.extending import register_jitable return make_quicksort_impl((lambda f: register_jitable(f)), *args, **kwargs) diff --git a/numba/np/arraymath.py b/numba/np/arraymath.py index 057f3504812..def65643c7e 100644 --- a/numba/np/arraymath.py +++ b/numba/np/arraymath.py @@ -14,7 +14,7 @@ from numba import generated_jit from numba.core import types, cgutils -from numba.extending import overload, overload_method, register_jitable +from numba.core.extending import overload, overload_method, register_jitable from numba.np.numpy_support import as_dtype, type_can_asarray from numba.np.numpy_support import numpy_version from numba.np.numpy_support import is_nonelike @@ -24,7 +24,7 @@ from numba.np.arrayobj import make_array, load_item, store_item, _empty_nd_impl from numba.np.linalg import ensure_blas -from numba.extending import intrinsic +from numba.core.extending import intrinsic from numba.core.errors import RequireLiteralValue, TypingError diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 2e9f81c8bf9..f44ec3067fe 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -14,8 +14,8 @@ import numpy as np -from numba import extending, pndindex -from numba.core import types, utils, typing, errors, cgutils +from numba import pndindex +from numba.core import types, utils, typing, errors, cgutils, extending from numba.np.numpy_support import (as_dtype, carray, farray, is_contiguous, is_fortran) from numba.np.numpy_support import type_can_asarray, is_nonelike @@ -27,7 +27,7 @@ impl_ret_new_ref, impl_ret_untracked, RefType) from numba.core.typing import signature -from numba.extending import register_jitable, overload, overload_method +from numba.core.extending import register_jitable, overload, overload_method from numba.misc import quicksort, mergesort from numba.cpython import slicing diff --git a/numba/np/linalg.py b/numba/np/linalg.py index 7ee2b85f385..23747162c97 100644 --- a/numba/np/linalg.py +++ b/numba/np/linalg.py @@ -13,7 +13,7 @@ from numba.core.imputils import (lower_builtin, impl_ret_borrowed, impl_ret_new_ref, impl_ret_untracked) from numba.core.typing import signature -from numba.extending import overload, register_jitable +from numba.core.extending import overload, register_jitable from numba.core import types, cgutils from numba.core.errors import TypingError from .arrayobj import make_array, _empty_nd_impl, array_copy diff --git a/numba/np/npyimpl.py b/numba/np/npyimpl.py index cb0a92b09e0..9e4473096fa 100644 --- a/numba/np/npyimpl.py +++ b/numba/np/npyimpl.py @@ -18,7 +18,7 @@ from numba.core import typing, types, utils, cgutils, callconv from numba.np.numpy_support import ufunc_find_matching_loop, select_array_wrapper, from_dtype from numba.core.typing import npydecl -from numba.extending import overload, intrinsic +from numba.core.extending import overload, intrinsic from numba.core import errors from numba.cpython import builtins diff --git a/numba/np/polynomial.py b/numba/np/polynomial.py index cdbefe0e6e4..c501b0408cd 100644 --- a/numba/np/polynomial.py +++ b/numba/np/polynomial.py @@ -7,7 +7,7 @@ from numba import jit from numba.core import types -from numba.extending import overload +from numba.core.extending import overload from numba.np import numpy_support as np_support diff --git a/numba/np/unsafe/ndarray.py b/numba/np/unsafe/ndarray.py index a5a303c9e5a..95085a30075 100644 --- a/numba/np/unsafe/ndarray.py +++ b/numba/np/unsafe/ndarray.py @@ -4,7 +4,7 @@ """ from numba.core import types, typing from numba.core.cgutils import unpack_tuple -from numba.extending import intrinsic +from numba.core.extending import intrinsic from numba.core.imputils import impl_ret_new_ref from numba.core.errors import RequireLiteralValue, TypingError diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index c89f596e58a..5e41ffcdd31 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -25,7 +25,7 @@ from numba.core.typing import npydecl, signature import collections import copy -from numba.extending import intrinsic +from numba.core.extending import intrinsic import llvmlite.llvmpy.core as lc import llvmlite diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index ad42afbb492..28951a7f280 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -30,7 +30,7 @@ from numba.np.numpy_support import as_dtype from numba.core.typing.templates import infer_global, AbstractTemplate from numba.stencils.stencilparfor import StencilPass -from numba.extending import register_jitable +from numba.core.extending import register_jitable from numba.core.ir_utils import ( @@ -86,7 +86,7 @@ from numba.parfors.array_analysis import (random_int_args, random_1arg_size, random_2arg_sizelast, random_3arg_sizelast, random_calls, assert_equiv) -from numba.extending import overload +from numba.core.extending import overload import copy import numpy import numpy as np diff --git a/numba/stencils/stencil.py b/numba/stencils/stencil.py index 9db186b5b92..cffef15f73f 100644 --- a/numba/stencils/stencil.py +++ b/numba/stencils/stencil.py @@ -12,7 +12,7 @@ from numba.core.typing.templates import (CallableTemplate, signature, infer_global, AbstractTemplate) from numba.core.imputils import lower_builtin -from numba.extending import register_jitable +from numba.core.extending import register_jitable import numba import operator diff --git a/numba/tests/inlining_usecases.py b/numba/tests/inlining_usecases.py index 94c20c2da94..bda5225f85b 100644 --- a/numba/tests/inlining_usecases.py +++ b/numba/tests/inlining_usecases.py @@ -1,6 +1,6 @@ """ Test cases for inlining IR from another module """ from numba import njit -from numba.extending import overload +from numba.core.extending import overload _GLOBAL1 = 100 diff --git a/numba/tests/pdlike_usecase.py b/numba/tests/pdlike_usecase.py index 67cb3261bba..75ac00b6ffa 100644 --- a/numba/tests/pdlike_usecase.py +++ b/numba/tests/pdlike_usecase.py @@ -6,7 +6,7 @@ from numba.core import types, cgutils from numba.core.datamodel import models -from numba.extending import ( +from numba.core.extending import ( typeof_impl, type_callable, register_model, lower_builtin, box, unbox, NativeValue, overload, overload_attribute, overload_method, make_attribute_wrapper) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 1bdb2a44ca8..98103d29c9d 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -38,8 +38,6 @@ from .pdlike_usecase import Index, Series - - try: import scipy if LooseVersion(scipy.__version__) < '0.19': @@ -59,7 +57,7 @@ class MyDummy(object): class MyDummyType(types.Opaque): def can_convert_to(self, context, toty): if isinstance(toty, types.Number): - from numba.typeconv import Conversion + from numba.core.typeconv import Conversion return Conversion.safe mydummy_type = MyDummyType('mydummy') diff --git a/numba/tests/test_extending_types.py b/numba/tests/test_extending_types.py index e8f38aa6f21..2fcedc6c62e 100644 --- a/numba/tests/test_extending_types.py +++ b/numba/tests/test_extending_types.py @@ -5,12 +5,12 @@ from numba import njit from numba.core import types, cgutils from numba.core.errors import TypingError -from numba.extending import lower_builtin -from numba.extending import models, register_model -from numba.extending import make_attribute_wrapper -from numba.extending import type_callable -from numba.extending import overload -from numba.extending import typeof_impl +from numba.core.extending import lower_builtin +from numba.core.extending import models, register_model +from numba.core.extending import make_attribute_wrapper +from numba.core.extending import type_callable +from numba.core.extending import overload +from numba.core.extending import typeof_impl from numba.testing import unittest_support as unittest diff --git a/numba/tests/test_ir_inlining.py b/numba/tests/test_ir_inlining.py index fff94722963..53ffd4fd82a 100644 --- a/numba/tests/test_ir_inlining.py +++ b/numba/tests/test_ir_inlining.py @@ -8,7 +8,7 @@ from numba import njit, typeof from numba.core import types, ir, ir_utils -from numba.extending import ( +from numba.core.extending import ( overload, overload_method, overload_attribute, diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index 38b74982ff2..6374e19fc36 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -7,7 +7,7 @@ from numba.core import types, errors, cgutils from numba.core.typing import signature from numba.core.datamodel import models -from numba.extending import ( +from numba.core.extending import ( overload, SentryLiteralArgs, overload_method, register_model, intrinsic, ) from numba.misc.special import literally diff --git a/numba/tests/test_make_function_to_jit_function.py b/numba/tests/test_make_function_to_jit_function.py index cb23544c3b1..0af505e2d8e 100644 --- a/numba/tests/test_make_function_to_jit_function.py +++ b/numba/tests/test_make_function_to_jit_function.py @@ -1,6 +1,6 @@ from numba import njit from numba.core import errors -from numba.extending import overload +from numba.core.extending import overload import numpy as np from numba.testing import unittest_support as unittest diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index d1893219e65..58c10c8b781 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -5,7 +5,7 @@ from numba import njit, typed, literal_unroll, prange from numba.core import types, errors, ir from numba.testing import unittest -from numba.extending import overload +from numba.core.extending import overload from numba.core.compiler_machinery import PassManager, register_pass, FunctionPass from numba.core.compiler import CompilerBase from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 8765247073a..c25001cb1ec 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -15,7 +15,7 @@ _nrt_python, nrt, ) -from numba.extending import intrinsic, include_path +from numba.core.extending import intrinsic, include_path from numba.core.typing import signature from numba.core.imputils import impl_ret_untracked from llvmlite import ir diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index a1968e87f68..3e17b09ce83 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -20,7 +20,7 @@ from numba.core.types.abstract import _typecache from numba.core.typing.templates import make_overload_template from numba import jit, njit, typeof -from numba.extending import (overload, register_model, models, unbox, +from numba.core.extending import (overload, register_model, models, unbox, NativeValue, typeof_impl) from numba.tests.support import TestCase, temp_directory from numba.tests.enum_usecases import Color, Shake, Shape diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index 5cae7160a0f..a2f8e70dd0f 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -11,7 +11,7 @@ from numba.core.registry import cpu_target from numba.core.compiler import compile_ir, DEFAULT_FLAGS from numba import njit, typeof, objmode -from numba.extending import overload +from numba.core.extending import overload from numba.tests.support import (MemoryLeak, TestCase, captured_stdout, skip_unless_scipy) from numba.testing import unittest_support as unittest diff --git a/numba/typed/dictobject.py b/numba/typed/dictobject.py index 308b8e5c81a..d55c535364f 100644 --- a/numba/typed/dictobject.py +++ b/numba/typed/dictobject.py @@ -9,7 +9,7 @@ from numba import _helperlib -from numba.extending import ( +from numba.core.extending import ( overload, overload_method, intrinsic, diff --git a/numba/typed/listobject.py b/numba/typed/listobject.py index dfae2ea8566..c45433c8776 100644 --- a/numba/typed/listobject.py +++ b/numba/typed/listobject.py @@ -9,7 +9,7 @@ from numba import _helperlib -from numba.extending import ( +from numba.core.extending import ( overload, overload_method, register_jitable, diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index 204a05c2d38..801f4589cc8 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -7,7 +7,7 @@ from numba.core.imputils import numba_typeref_ctor from numba import njit, typeof from numba.core import types, errors, config, cgutils -from numba.extending import ( +from numba.core.extending import ( overload_method, overload, box, diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index 18d9a37a33c..747311055aa 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -15,7 +15,7 @@ from numba.core.dispatcher import Dispatcher from numba.core import types, errors, config, cgutils from numba import njit, typeof -from numba.extending import ( +from numba.core.extending import ( overload_method, overload, box, diff --git a/numba/typed/typedobjectutils.py b/numba/typed/typedobjectutils.py index e338d89d829..fd8959ded89 100644 --- a/numba/typed/typedobjectutils.py +++ b/numba/typed/typedobjectutils.py @@ -10,7 +10,7 @@ from numba.core import typing from numba.core.registry import cpu_target from numba.core.typeconv import Conversion -from numba.extending import intrinsic +from numba.core.extending import intrinsic from numba.core.errors import TypingError, NumbaTypeSafetyWarning From d04926d072cb6e0975aef16ba029ac162b83854d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 13:17:21 +0000 Subject: [PATCH 452/595] Move numba.numpy_extensions to numba.np.extensions --- docs/source/reference/numpysupported.rst | 2 +- numba/{numpy_extensions.py => np/extensions.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename numba/{numpy_extensions.py => np/extensions.py} (100%) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index 4e90f58fd14..520aa6cf60b 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -339,7 +339,7 @@ The following top-level functions are supported: arrays should have ``shape[-1] == 3``) * If ``shape[-1] == 2`` for both inputs, please replace your - :func:`numpy.cross` call with :func:`numba.numpy_extensions.cross2d`. + :func:`numpy.cross` call with :func:`numba.np.extensions.cross2d`. * :func:`numpy.delete` (only the 2 first arguments) * :func:`numpy.diag` diff --git a/numba/numpy_extensions.py b/numba/np/extensions.py similarity index 100% rename from numba/numpy_extensions.py rename to numba/np/extensions.py From 35bd51d9f91bae53b5335fac1d8ceff7bf289910 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 14:10:22 +0000 Subject: [PATCH 453/595] Add back in extension API --- numba/extending.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 numba/extending.py diff --git a/numba/extending.py b/numba/extending.py new file mode 100644 index 00000000000..e771ed61e3e --- /dev/null +++ b/numba/extending.py @@ -0,0 +1,3 @@ +# Re-export symbols +from numba.core.extending import * +from numba.core.extending import _Intrinsic \ No newline at end of file From 27209920996a7f7e4210a298e507d0ce25e21913 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 14:27:01 +0000 Subject: [PATCH 454/595] Fix up numba_entry --- bin/numba | 2 +- numba/core/__init__.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 numba/core/__init__.py diff --git a/bin/numba b/bin/numba index 0e54a0a6066..32e7180df65 100755 --- a/bin/numba +++ b/bin/numba @@ -2,7 +2,7 @@ # -*- coding: UTF-8 -*- from __future__ import print_function, division, absolute_import -from numba.numba_entry import main +from numba.misc.numba_entry import main if __name__ == "__main__": main() diff --git a/numba/core/__init__.py b/numba/core/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 9d8dfec52ab61d8857495ac62b0f7684d1ce5745 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 14:40:34 +0000 Subject: [PATCH 455/595] Add missing experimental/__init__.py --- numba/experimental/__init__.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 numba/experimental/__init__.py diff --git a/numba/experimental/__init__.py b/numba/experimental/__init__.py new file mode 100644 index 00000000000..3bc3359e90e --- /dev/null +++ b/numba/experimental/__init__.py @@ -0,0 +1 @@ +from .jitclass import jitclass \ No newline at end of file From f14e87c3d5a45fcaa970892aacd7139a324ada1e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 15:32:57 +0000 Subject: [PATCH 456/595] Remove now-dead unittest_support file --- numba/core/datamodel/testing.py | 2 +- numba/cuda/testing.py | 2 +- numba/cuda/tests/cudadrv/test_profiler.py | 2 +- numba/cuda/tests/cudapy/test_alignment.py | 2 +- numba/cuda/tests/cudapy/test_array_methods.py | 2 +- numba/cuda/tests/cudapy/test_casting.py | 2 +- numba/cuda/tests/cudapy/test_cuda_autojit.py | 2 +- numba/cuda/tests/cudapy/test_datetime.py | 2 +- numba/cuda/tests/cudapy/test_debug.py | 2 +- numba/cuda/tests/cudapy/test_debuginfo.py | 2 +- numba/cuda/tests/cudapy/test_deprecation.py | 2 +- numba/cuda/tests/cudapy/test_fastmath.py | 2 +- numba/cuda/tests/cudapy/test_forall.py | 2 +- numba/cuda/tests/cudapy/test_gufunc.py | 2 +- numba/cuda/tests/cudapy/test_gufunc_scalar.py | 2 +- numba/cuda/tests/cudapy/test_gufunc_scheduling.py | 2 +- numba/cuda/tests/cudapy/test_ipc.py | 2 +- numba/cuda/tests/cudapy/test_multigpu.py | 2 +- numba/cuda/tests/cudapy/test_multiprocessing.py | 2 +- numba/cuda/tests/cudapy/test_multithreads.py | 2 +- numba/cuda/tests/cudapy/test_print.py | 2 +- numba/cuda/tests/cudapy/test_record_dtype.py | 2 +- numba/cuda/tests/cudapy/test_reduction.py | 2 +- .../tests/cudapy/test_retrieve_autoconverted_arrays.py | 2 +- numba/cuda/tests/cudapy/test_serialize.py | 2 +- numba/cuda/tests/cudapy/test_vectorize.py | 2 +- numba/cuda/tests/cudapy/test_vectorize_complex.py | 2 +- numba/cuda/tests/cudapy/test_vectorize_decor.py | 2 +- numba/cuda/tests/cudapy/test_vectorize_device.py | 2 +- numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py | 2 +- numba/cuda/tests/cudasim/test_cudasim_issues.py | 2 +- numba/cuda/tests/nocuda/test_nvvm.py | 2 +- numba/roc/tests/hsadrv/test_async.py | 2 +- numba/roc/tests/hsadrv/test_driver.py | 2 +- numba/roc/tests/hsapy/test_async_kernel.py | 2 +- numba/roc/tests/hsapy/test_atomics.py | 2 +- numba/roc/tests/hsapy/test_autojit.py | 2 +- numba/roc/tests/hsapy/test_barrier.py | 2 +- numba/roc/tests/hsapy/test_compiler.py | 2 +- numba/roc/tests/hsapy/test_decorator.py | 2 +- numba/roc/tests/hsapy/test_gufuncbuilding.py | 2 +- numba/roc/tests/hsapy/test_intrinsics.py | 2 +- numba/roc/tests/hsapy/test_large_code.py | 2 +- numba/roc/tests/hsapy/test_linkage.py | 2 +- numba/roc/tests/hsapy/test_math.py | 2 +- numba/roc/tests/hsapy/test_matmul.py | 2 +- numba/roc/tests/hsapy/test_memory.py | 2 +- numba/roc/tests/hsapy/test_occupancy.py | 2 +- numba/roc/tests/hsapy/test_positioning.py | 2 +- numba/roc/tests/hsapy/test_reduction.py | 2 +- numba/roc/tests/hsapy/test_scan.py | 2 +- numba/roc/tests/hsapy/test_simple.py | 2 +- numba/roc/tests/hsapy/test_ufuncbuilding.py | 2 +- numba/testing/__init__.py | 2 +- numba/testing/loader.py | 1 - numba/testing/main.py | 3 +-- numba/testing/notebook.py | 2 +- numba/testing/unittest_support.py | 7 ------- numba/tests/__init__.py | 3 ++- numba/tests/npyufunc/__init__.py | 3 ++- numba/tests/npyufunc/test_caching.py | 2 +- numba/tests/npyufunc/test_dufunc.py | 2 +- numba/tests/npyufunc/test_errors.py | 2 +- numba/tests/npyufunc/test_gufunc.py | 2 +- numba/tests/npyufunc/test_parallel_env_variable.py | 2 +- numba/tests/npyufunc/test_parallel_low_work.py | 2 +- numba/tests/npyufunc/test_parallel_ufunc_issues.py | 2 +- numba/tests/npyufunc/test_ufunc.py | 2 +- numba/tests/npyufunc/test_ufuncbuilding.py | 2 +- numba/tests/npyufunc/test_vectorize_decor.py | 2 +- numba/tests/support.py | 2 +- numba/tests/test_annotations.py | 2 +- numba/tests/test_api.py | 2 +- numba/tests/test_array_analysis.py | 2 +- numba/tests/test_array_attr.py | 2 +- numba/tests/test_array_constants.py | 2 +- numba/tests/test_array_exprs.py | 2 +- numba/tests/test_array_iterators.py | 2 +- numba/tests/test_array_manipulation.py | 2 +- numba/tests/test_array_methods.py | 2 +- numba/tests/test_array_reductions.py | 2 +- numba/tests/test_array_return.py | 2 +- numba/tests/test_auto_constants.py | 2 +- numba/tests/test_blackscholes.py | 2 +- numba/tests/test_boundscheck.py | 2 +- numba/tests/test_buffer_protocol.py | 2 +- numba/tests/test_builtins.py | 2 +- numba/tests/test_casting.py | 2 +- numba/tests/test_cffi.py | 2 +- numba/tests/test_cfunc.py | 2 +- numba/tests/test_cgutils.py | 2 +- numba/tests/test_chained_assign.py | 2 +- numba/tests/test_cli.py | 2 +- numba/tests/test_closure.py | 2 +- numba/tests/test_codegen.py | 2 +- numba/tests/test_compile_cache.py | 2 +- numba/tests/test_complex.py | 2 +- numba/tests/test_comprehension.py | 2 +- numba/tests/test_conversion.py | 2 +- numba/tests/test_copy_propagate.py | 2 +- numba/tests/test_ctypes.py | 2 +- numba/tests/test_dataflow.py | 2 +- numba/tests/test_datamodel.py | 2 +- numba/tests/test_debug.py | 2 +- numba/tests/test_debuginfo.py | 2 +- numba/tests/test_del.py | 2 +- numba/tests/test_deprecations.py | 2 +- numba/tests/test_dicts.py | 2 +- numba/tests/test_dispatcher.py | 2 +- numba/tests/test_dummyarray.py | 2 +- numba/tests/test_dyn_array.py | 2 +- numba/tests/test_enums.py | 2 +- numba/tests/test_errorhandling.py | 2 +- numba/tests/test_errormodels.py | 2 +- numba/tests/test_exceptions.py | 2 +- numba/tests/test_extended_arg.py | 2 +- numba/tests/test_extending.py | 2 +- numba/tests/test_extending_types.py | 2 +- numba/tests/test_fancy_indexing.py | 2 +- numba/tests/test_fastmath.py | 2 +- numba/tests/test_flow_control.py | 2 +- numba/tests/test_func_interface.py | 2 +- numba/tests/test_func_lifetime.py | 2 +- numba/tests/test_gdb.py | 2 +- numba/tests/test_generators.py | 2 +- numba/tests/test_gil.py | 2 +- numba/tests/test_globals.py | 2 +- numba/tests/test_hashing.py | 4 ++-- numba/tests/test_import.py | 2 +- numba/tests/test_indexing.py | 2 +- numba/tests/test_inlining.py | 2 +- numba/tests/test_interproc.py | 2 +- numba/tests/test_intwidth.py | 2 +- numba/tests/test_ir.py | 2 +- numba/tests/test_itanium_mangler.py | 2 +- numba/tests/test_iteration.py | 2 +- numba/tests/test_jit_module.py | 2 +- numba/tests/test_jitclasses.py | 2 +- numba/tests/test_jitmethod.py | 2 +- numba/tests/test_linalg.py | 2 +- numba/tests/test_lists.py | 2 +- numba/tests/test_literal_dispatch.py | 2 +- numba/tests/test_llvm_version_check.py | 2 +- numba/tests/test_locals.py | 2 +- numba/tests/test_looplifting.py | 2 +- numba/tests/test_make_function_to_jit_function.py | 2 +- numba/tests/test_mandelbrot.py | 2 +- numba/tests/test_map_filter_reduce.py | 2 +- numba/tests/test_mathlib.py | 2 +- numba/tests/test_maxmin.py | 2 +- numba/tests/test_multi3.py | 2 +- numba/tests/test_nan.py | 2 +- numba/tests/test_nested_calls.py | 2 +- numba/tests/test_np_functions.py | 2 +- numba/tests/test_npdatetime.py | 2 +- numba/tests/test_nrt.py | 2 +- numba/tests/test_nrt_refct.py | 2 +- numba/tests/test_numberctor.py | 2 +- numba/tests/test_numconv.py | 2 +- numba/tests/test_numpy_support.py | 2 +- numba/tests/test_numpyadapt.py | 2 +- numba/tests/test_obj_lifetime.py | 2 +- numba/tests/test_object_mode.py | 2 +- numba/tests/test_objects.py | 2 +- numba/tests/test_operators.py | 2 +- numba/tests/test_optional.py | 2 +- numba/tests/test_overlap.py | 2 +- numba/tests/test_parallel_backend.py | 2 +- numba/tests/test_parfors.py | 2 +- numba/tests/test_polynomial.py | 2 +- numba/tests/test_print.py | 2 +- numba/tests/test_profiler.py | 2 +- numba/tests/test_pycc.py | 2 +- numba/tests/test_python_int.py | 2 +- numba/tests/test_random.py | 2 +- numba/tests/test_range.py | 2 +- numba/tests/test_recarray_usecases.py | 2 +- numba/tests/test_record_dtype.py | 2 +- numba/tests/test_recursion.py | 2 +- numba/tests/test_remove_dead.py | 2 +- numba/tests/test_return_values.py | 2 +- numba/tests/test_runtests.py | 2 +- numba/tests/test_serialize.py | 2 +- numba/tests/test_sets.py | 4 ++-- numba/tests/test_slices.py | 2 +- numba/tests/test_sort.py | 2 +- numba/tests/test_stencils.py | 2 +- numba/tests/test_storeslice.py | 2 +- numba/tests/test_support.py | 2 +- numba/tests/test_svml.py | 2 +- numba/tests/test_target_overloadselector.py | 2 +- numba/tests/test_threadsafety.py | 2 +- numba/tests/test_tracing.py | 2 +- numba/tests/test_tuples.py | 2 +- numba/tests/test_typeconv.py | 2 +- numba/tests/test_typeinfer.py | 2 +- numba/tests/test_typenames.py | 2 +- numba/tests/test_typeof.py | 2 +- numba/tests/test_types.py | 2 +- numba/tests/test_typingerror.py | 2 +- numba/tests/test_ufuncs.py | 2 +- numba/tests/test_unicode.py | 2 +- numba/tests/test_unicode_array.py | 2 +- numba/tests/test_unpack_sequence.py | 2 +- numba/tests/test_usecases.py | 2 +- numba/tests/test_vectorization_type_inference.py | 2 +- numba/tests/test_warnings.py | 2 +- numba/tests/test_withlifting.py | 2 +- numba/tests/test_wrapper.py | 2 +- 209 files changed, 211 insertions(+), 218 deletions(-) delete mode 100644 numba/testing/unittest_support.py diff --git a/numba/core/datamodel/testing.py b/numba/core/datamodel/testing.py index 80c4df8a20c..e2e8a2818b6 100644 --- a/numba/core/datamodel/testing.py +++ b/numba/core/datamodel/testing.py @@ -2,7 +2,7 @@ from llvmlite import binding as ll from numba.core import datamodel -from numba.testing import unittest_support as unittest +import unittest class DataModelTester(unittest.TestCase): diff --git a/numba/cuda/testing.py b/numba/cuda/testing.py index f861101aed6..16372d2e403 100644 --- a/numba/cuda/testing.py +++ b/numba/cuda/testing.py @@ -8,7 +8,7 @@ ) from numba.cuda.cuda_paths import get_conda_ctk from numba.core import config -from numba.testing import unittest_support as unittest +import unittest class CUDATestCase(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudadrv/test_profiler.py b/numba/cuda/tests/cudadrv/test_profiler.py index 2b03477ed01..d96d7875989 100644 --- a/numba/cuda/tests/cudadrv/test_profiler.py +++ b/numba/cuda/tests/cudadrv/test_profiler.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba.cuda.testing import CUDATestCase from numba import cuda from numba.cuda.testing import skip_on_cudasim diff --git a/numba/cuda/tests/cudapy/test_alignment.py b/numba/cuda/tests/cudapy/test_alignment.py index 8589d721e7d..f7a9cc81541 100644 --- a/numba/cuda/tests/cudapy/test_alignment.py +++ b/numba/cuda/tests/cudapy/test_alignment.py @@ -1,7 +1,7 @@ import numpy as np from numba import from_dtype, cuda from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest class TestAlignment(SerialMixin, unittest.TestCase): def test_record_alignment(self): diff --git a/numba/cuda/tests/cudapy/test_array_methods.py b/numba/cuda/tests/cudapy/test_array_methods.py index 0908976af67..4122ddec86f 100644 --- a/numba/cuda/tests/cudapy/test_array_methods.py +++ b/numba/cuda/tests/cudapy/test_array_methods.py @@ -1,7 +1,7 @@ import numpy as np from numba import cuda from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest def reinterpret_array_type(byte_arr, start, stop, output): diff --git a/numba/cuda/tests/cudapy/test_casting.py b/numba/cuda/tests/cudapy/test_casting.py index 2a0d236df0b..fd2c7ce6c86 100644 --- a/numba/cuda/tests/cudapy/test_casting.py +++ b/numba/cuda/tests/cudapy/test_casting.py @@ -4,7 +4,7 @@ from numba import cuda from numba.core import types from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest def float_to_int(x): diff --git a/numba/cuda/tests/cudapy/test_cuda_autojit.py b/numba/cuda/tests/cudapy/test_cuda_autojit.py index 770219b53ec..601ea129858 100644 --- a/numba/cuda/tests/cudapy/test_cuda_autojit.py +++ b/numba/cuda/tests/cudapy/test_cuda_autojit.py @@ -1,7 +1,7 @@ from numba import cuda import numpy as np from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest class TestCudaAutojit(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_datetime.py b/numba/cuda/tests/cudapy/test_datetime.py index 5d29ee45799..6c2b39509d6 100644 --- a/numba/cuda/tests/cudapy/test_datetime.py +++ b/numba/cuda/tests/cudapy/test_datetime.py @@ -4,7 +4,7 @@ from numba.np.numpy_support import from_dtype from numba.tests.support import TestCase from numba.cuda.testing import SerialMixin, skip_on_cudasim -from numba.testing import unittest_support as unittest +import unittest class TestCudaDateTime(SerialMixin, TestCase): diff --git a/numba/cuda/tests/cudapy/test_debug.py b/numba/cuda/tests/cudapy/test_debug.py index a3dd62c9e21..5d28a0069f8 100644 --- a/numba/cuda/tests/cudapy/test_debug.py +++ b/numba/cuda/tests/cudapy/test_debug.py @@ -4,7 +4,7 @@ from numba.tests.support import (override_config, captured_stderr, captured_stdout) from numba import cuda, float64 -from numba.testing import unittest_support as unittest +import unittest def simple_cuda(A, B): diff --git a/numba/cuda/tests/cudapy/test_debuginfo.py b/numba/cuda/tests/cudapy/test_debuginfo.py index c3ae6945d40..9e0ae782453 100644 --- a/numba/cuda/tests/cudapy/test_debuginfo.py +++ b/numba/cuda/tests/cudapy/test_debuginfo.py @@ -3,7 +3,7 @@ from numba import cuda from numba.core import types from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim('Simulator does not produce debug dumps') diff --git a/numba/cuda/tests/cudapy/test_deprecation.py b/numba/cuda/tests/cudapy/test_deprecation.py index 2c2eaf861d0..790716691a1 100644 --- a/numba/cuda/tests/cudapy/test_deprecation.py +++ b/numba/cuda/tests/cudapy/test_deprecation.py @@ -6,7 +6,7 @@ from numba import cuda from numba.core import types from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim("Skipped on simulator") diff --git a/numba/cuda/tests/cudapy/test_fastmath.py b/numba/cuda/tests/cudapy/test_fastmath.py index dd1c6e2026f..e5388b47bb4 100644 --- a/numba/cuda/tests/cudapy/test_fastmath.py +++ b/numba/cuda/tests/cudapy/test_fastmath.py @@ -2,7 +2,7 @@ from numba import cuda, float32 from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest class TestFastMathOption(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_forall.py b/numba/cuda/tests/cudapy/test_forall.py index cb619c6868f..1670f150ba2 100644 --- a/numba/cuda/tests/cudapy/test_forall.py +++ b/numba/cuda/tests/cudapy/test_forall.py @@ -1,7 +1,7 @@ import numpy as np from numba import cuda -import numba.testing.unittest_support as unittest +import unittest from numba.cuda.testing import SerialMixin diff --git a/numba/cuda/tests/cudapy/test_gufunc.py b/numba/cuda/tests/cudapy/test_gufunc.py index 93028561394..12c628932f9 100644 --- a/numba/cuda/tests/cudapy/test_gufunc.py +++ b/numba/cuda/tests/cudapy/test_gufunc.py @@ -5,7 +5,7 @@ from numba import guvectorize from numba import cuda from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_gufunc_scalar.py b/numba/cuda/tests/cudapy/test_gufunc_scalar.py index 73e78173a0d..a77ffc79bb6 100644 --- a/numba/cuda/tests/cudapy/test_gufunc_scalar.py +++ b/numba/cuda/tests/cudapy/test_gufunc_scalar.py @@ -7,7 +7,7 @@ from numba import guvectorize, cuda from numba.tests.support import TestCase from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py index bcd7ebd0b62..2a240ef2939 100644 --- a/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +++ b/numba/cuda/tests/cudapy/test_gufunc_scheduling.py @@ -1,5 +1,5 @@ from numba.np.ufunc.deviceufunc import GUFuncEngine -from numba.testing import unittest_support as unittest +import unittest def template(signature, shapes, expects): diff --git a/numba/cuda/tests/cudapy/test_ipc.py b/numba/cuda/tests/cudapy/test_ipc.py index 7af11abd6bc..5763cb00b99 100644 --- a/numba/cuda/tests/cudapy/test_ipc.py +++ b/numba/cuda/tests/cudapy/test_ipc.py @@ -8,7 +8,7 @@ from numba import cuda from numba.cuda.cudadrv import drvapi, devicearray from numba.cuda.testing import skip_on_cudasim, CUDATestCase -from numba.testing import unittest_support as unittest +import unittest not_linux = not sys.platform.startswith('linux') diff --git a/numba/cuda/tests/cudapy/test_multigpu.py b/numba/cuda/tests/cudapy/test_multigpu.py index ce68450f87a..0eecde1a97e 100644 --- a/numba/cuda/tests/cudapy/test_multigpu.py +++ b/numba/cuda/tests/cudapy/test_multigpu.py @@ -2,7 +2,7 @@ import numpy as np from numba.cuda.testing import skip_on_cudasim, SerialMixin import threading -from numba.testing import unittest_support as unittest +import unittest class TestMultiGPUContext(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/cudapy/test_multiprocessing.py b/numba/cuda/tests/cudapy/test_multiprocessing.py index 78270168301..e3293ddf31e 100644 --- a/numba/cuda/tests/cudapy/test_multiprocessing.py +++ b/numba/cuda/tests/cudapy/test_multiprocessing.py @@ -5,7 +5,7 @@ from numba import cuda from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest has_mp_get_context = hasattr(mp, 'get_context') is_unix = os.name == 'posix' diff --git a/numba/cuda/tests/cudapy/test_multithreads.py b/numba/cuda/tests/cudapy/test_multithreads.py index 8b382d3ba15..5a2a3329abd 100644 --- a/numba/cuda/tests/cudapy/test_multithreads.py +++ b/numba/cuda/tests/cudapy/test_multithreads.py @@ -4,7 +4,7 @@ import numpy as np from numba import cuda from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest try: from concurrent.futures import ThreadPoolExecutor diff --git a/numba/cuda/tests/cudapy/test_print.py b/numba/cuda/tests/cudapy/test_print.py index 9c2f41e8a3f..2348f9c5619 100644 --- a/numba/cuda/tests/cudapy/test_print.py +++ b/numba/cuda/tests/cudapy/test_print.py @@ -2,7 +2,7 @@ from numba import cuda from numba.cuda.testing import captured_cuda_stdout, SerialMixin -from numba.testing import unittest_support as unittest +import unittest def cuhello(): diff --git a/numba/cuda/tests/cudapy/test_record_dtype.py b/numba/cuda/tests/cudapy/test_record_dtype.py index 10315e88c19..37ca8445f53 100644 --- a/numba/cuda/tests/cudapy/test_record_dtype.py +++ b/numba/cuda/tests/cudapy/test_record_dtype.py @@ -4,7 +4,7 @@ from numba import cuda from numba.core import types from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest from numba.np import numpy_support diff --git a/numba/cuda/tests/cudapy/test_reduction.py b/numba/cuda/tests/cudapy/test_reduction.py index 9a934010598..6457a8720e4 100644 --- a/numba/cuda/tests/cudapy/test_reduction.py +++ b/numba/cuda/tests/cudapy/test_reduction.py @@ -2,7 +2,7 @@ from numba import cuda from numba.core.config import ENABLE_CUDASIM from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest # Avoid recompilation of the sum_reduce function by keeping it at global scope sum_reduce = cuda.Reduce(lambda a, b: a + b) diff --git a/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py b/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py index f0a0a4ccb85..3e884adc823 100644 --- a/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +++ b/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py @@ -3,7 +3,7 @@ from numba import cuda from numba.cuda.args import wrap_arg from numba.cuda.testing import SerialMixin -from numba.testing import unittest_support as unittest +import unittest class DefaultIn(object): diff --git a/numba/cuda/tests/cudapy/test_serialize.py b/numba/cuda/tests/cudapy/test_serialize.py index 615f80cb446..9353e661725 100644 --- a/numba/cuda/tests/cudapy/test_serialize.py +++ b/numba/cuda/tests/cudapy/test_serialize.py @@ -3,7 +3,7 @@ from numba import cuda, vectorize from numba.core import types from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest from numba.np import numpy_support diff --git a/numba/cuda/tests/cudapy/test_vectorize.py b/numba/cuda/tests/cudapy/test_vectorize.py index c40f7dea247..78078216ba7 100644 --- a/numba/cuda/tests/cudapy/test_vectorize.py +++ b/numba/cuda/tests/cudapy/test_vectorize.py @@ -5,7 +5,7 @@ from numba.cuda.testing import skip_on_cudasim from numba.cuda.testing import CUDATestCase from numba.core import config -from numba.testing import unittest_support as unittest +import unittest sig = [int32(int32, int32), float32(float32, float32), diff --git a/numba/cuda/tests/cudapy/test_vectorize_complex.py b/numba/cuda/tests/cudapy/test_vectorize_complex.py index 5ec227110d3..fb3f1ea8b9d 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_complex.py +++ b/numba/cuda/tests/cudapy/test_vectorize_complex.py @@ -1,7 +1,7 @@ import numpy as np from numba import vectorize from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_vectorize_decor.py b/numba/cuda/tests/cudapy/test_vectorize_decor.py index d4c24096e79..b9d85a9454c 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_decor.py +++ b/numba/cuda/tests/cudapy/test_vectorize_decor.py @@ -4,7 +4,7 @@ from numba.tests.npyufunc.test_vectorize_decor import BaseVectorizeDecor, \ BaseVectorizeNopythonArg, BaseVectorizeUnrecognizedArg from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_vectorize_device.py b/numba/cuda/tests/cudapy/test_vectorize_device.py index 7948ffe7617..ee032fc96a6 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_device.py +++ b/numba/cuda/tests/cudapy/test_vectorize_device.py @@ -2,7 +2,7 @@ from numba import cuda, float32 import numpy as np from numba.cuda.testing import skip_on_cudasim, SerialMixin -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim('ufunc API unsupported in the simulator') diff --git a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py index 496ac22a88b..1baf1bdd3c8 100644 --- a/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +++ b/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py @@ -3,7 +3,7 @@ from numba import cuda, float64 from numba.cuda.testing import skip_on_cudasim, SerialMixin from numba.core import config -from numba.testing import unittest_support as unittest +import unittest sig = [float64(float64, float64)] diff --git a/numba/cuda/tests/cudasim/test_cudasim_issues.py b/numba/cuda/tests/cudasim/test_cudasim_issues.py index 796759e127d..9b685237ee0 100644 --- a/numba/cuda/tests/cudasim/test_cudasim_issues.py +++ b/numba/cuda/tests/cudasim/test_cudasim_issues.py @@ -5,7 +5,7 @@ from numba import cuda from numba.cuda.testing import SerialMixin, skip_unless_cudasim import numba.cuda.simulator as simulator -from numba.testing import unittest_support as unittest +import unittest class TestCudaSimIssues(SerialMixin, unittest.TestCase): diff --git a/numba/cuda/tests/nocuda/test_nvvm.py b/numba/cuda/tests/nocuda/test_nvvm.py index 7cc464c3260..6bcac98c6f6 100644 --- a/numba/cuda/tests/nocuda/test_nvvm.py +++ b/numba/cuda/tests/nocuda/test_nvvm.py @@ -2,7 +2,7 @@ from numba.cuda.cudadrv import nvvm from numba.cuda.testing import skip_on_cudasim, SerialMixin from numba.core import types, utils -from numba.testing import unittest_support as unittest +import unittest @skip_on_cudasim('libNVVM not supported in simulator') diff --git a/numba/roc/tests/hsadrv/test_async.py b/numba/roc/tests/hsadrv/test_async.py index 2221141ff24..0c390ea437e 100644 --- a/numba/roc/tests/hsadrv/test_async.py +++ b/numba/roc/tests/hsadrv/test_async.py @@ -1,7 +1,7 @@ import numpy as np from numba import roc -import numba.testing.unittest_support as unittest +import unittest from numba.roc.hsadrv.driver import dgpu_present diff --git a/numba/roc/tests/hsadrv/test_driver.py b/numba/roc/tests/hsadrv/test_driver.py index 10d504226eb..f833a857e3f 100644 --- a/numba/roc/tests/hsadrv/test_driver.py +++ b/numba/roc/tests/hsadrv/test_driver.py @@ -4,7 +4,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.roc.hsadrv.driver import hsa, Queue, Program, Executable,\ BrigModule, Context, dgpu_present diff --git a/numba/roc/tests/hsapy/test_async_kernel.py b/numba/roc/tests/hsapy/test_async_kernel.py index ee532ae0eff..8acb6295447 100644 --- a/numba/roc/tests/hsapy/test_async_kernel.py +++ b/numba/roc/tests/hsapy/test_async_kernel.py @@ -7,7 +7,7 @@ import numpy as np from numba import roc -import numba.testing.unittest_support as unittest +import unittest from numba.roc.hsadrv.driver import dgpu_present logger = logging.getLogger() diff --git a/numba/roc/tests/hsapy/test_atomics.py b/numba/roc/tests/hsapy/test_atomics.py index ee9d2eff282..74790f56494 100644 --- a/numba/roc/tests/hsapy/test_atomics.py +++ b/numba/roc/tests/hsapy/test_atomics.py @@ -2,7 +2,7 @@ import numba from numba import roc -import numba.testing.unittest_support as unittest +import unittest def atomic_add(ary): diff --git a/numba/roc/tests/hsapy/test_autojit.py b/numba/roc/tests/hsapy/test_autojit.py index 0279a218bba..8f4a690c823 100644 --- a/numba/roc/tests/hsapy/test_autojit.py +++ b/numba/roc/tests/hsapy/test_autojit.py @@ -1,6 +1,6 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import roc diff --git a/numba/roc/tests/hsapy/test_barrier.py b/numba/roc/tests/hsapy/test_barrier.py index 506845af8c6..8e6ac36339c 100644 --- a/numba/roc/tests/hsapy/test_barrier.py +++ b/numba/roc/tests/hsapy/test_barrier.py @@ -1,7 +1,7 @@ import numpy as np from numba import roc, float32 -from numba.testing import unittest_support as unittest +import unittest class TestBarrier(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_compiler.py b/numba/roc/tests/hsapy/test_compiler.py index 527c32f04d1..746bafbb329 100644 --- a/numba/roc/tests/hsapy/test_compiler.py +++ b/numba/roc/tests/hsapy/test_compiler.py @@ -2,7 +2,7 @@ import os import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import roc from numba.core import types from numba.roc import compiler diff --git a/numba/roc/tests/hsapy/test_decorator.py b/numba/roc/tests/hsapy/test_decorator.py index a062b8923db..c0d7882cd75 100644 --- a/numba/roc/tests/hsapy/test_decorator.py +++ b/numba/roc/tests/hsapy/test_decorator.py @@ -1,6 +1,6 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import roc diff --git a/numba/roc/tests/hsapy/test_gufuncbuilding.py b/numba/roc/tests/hsapy/test_gufuncbuilding.py index 94a4e905110..13e0ca25df4 100644 --- a/numba/roc/tests/hsapy/test_gufuncbuilding.py +++ b/numba/roc/tests/hsapy/test_gufuncbuilding.py @@ -3,7 +3,7 @@ from numba.roc.vectorizers import HsaGUFuncVectorize from numba.roc.dispatch import HSAGenerializedUFunc from numba import guvectorize -from numba.testing import unittest_support as unittest +import unittest def ufunc_add_core(a, b, c): diff --git a/numba/roc/tests/hsapy/test_intrinsics.py b/numba/roc/tests/hsapy/test_intrinsics.py index 385b00a8556..ff1d6fc41f3 100644 --- a/numba/roc/tests/hsapy/test_intrinsics.py +++ b/numba/roc/tests/hsapy/test_intrinsics.py @@ -3,7 +3,7 @@ from numba import roc from numba.core.errors import TypingError import operator as oper -from numba.testing import unittest_support as unittest +import unittest _WAVESIZE = roc.get_context().agent.wavefront_size diff --git a/numba/roc/tests/hsapy/test_large_code.py b/numba/roc/tests/hsapy/test_large_code.py index 77dc2e39af9..f9b2044c3c5 100644 --- a/numba/roc/tests/hsapy/test_large_code.py +++ b/numba/roc/tests/hsapy/test_large_code.py @@ -5,7 +5,7 @@ import math import numba -import numba.testing.unittest_support as unittest +import unittest class TestLargeCode(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_linkage.py b/numba/roc/tests/hsapy/test_linkage.py index a211a48038e..0167eafc6ec 100644 --- a/numba/roc/tests/hsapy/test_linkage.py +++ b/numba/roc/tests/hsapy/test_linkage.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba import roc diff --git a/numba/roc/tests/hsapy/test_math.py b/numba/roc/tests/hsapy/test_math.py index 3e7119dc7c2..db876442ef7 100644 --- a/numba/roc/tests/hsapy/test_math.py +++ b/numba/roc/tests/hsapy/test_math.py @@ -1,7 +1,7 @@ import numpy as np import math -import numba.testing.unittest_support as unittest +import unittest from numba import roc from numba.core import utils diff --git a/numba/roc/tests/hsapy/test_matmul.py b/numba/roc/tests/hsapy/test_matmul.py index 17c72a1e119..e8f766fb5a5 100644 --- a/numba/roc/tests/hsapy/test_matmul.py +++ b/numba/roc/tests/hsapy/test_matmul.py @@ -3,7 +3,7 @@ from numba import roc, float32 from numba.roc.hsadrv.error import HsaKernelLaunchError -from numba.testing import unittest_support as unittest +import unittest class TestMatMul(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_memory.py b/numba/roc/tests/hsapy/test_memory.py index f099bfdd099..57431821639 100644 --- a/numba/roc/tests/hsapy/test_memory.py +++ b/numba/roc/tests/hsapy/test_memory.py @@ -7,7 +7,7 @@ import numpy as np from numba import roc -import numba.testing.unittest_support as unittest +import unittest from numba.roc.hsadrv.driver import dgpu_present logger = logging.getLogger() diff --git a/numba/roc/tests/hsapy/test_occupancy.py b/numba/roc/tests/hsapy/test_occupancy.py index 8cf84f889cb..0a03ec5fc06 100644 --- a/numba/roc/tests/hsapy/test_occupancy.py +++ b/numba/roc/tests/hsapy/test_occupancy.py @@ -1,5 +1,5 @@ from numba.roc.gcn_occupancy import get_limiting_factors -from numba.testing import unittest_support as unittest +import unittest class TestOccupancy(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_positioning.py b/numba/roc/tests/hsapy/test_positioning.py index 46d134a2aac..63e5e6ae094 100644 --- a/numba/roc/tests/hsapy/test_positioning.py +++ b/numba/roc/tests/hsapy/test_positioning.py @@ -1,6 +1,6 @@ import numpy as np from numba import roc -import numba.testing.unittest_support as unittest +import unittest class TestPositioning(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_reduction.py b/numba/roc/tests/hsapy/test_reduction.py index e43c365fcb6..3199009ac97 100644 --- a/numba/roc/tests/hsapy/test_reduction.py +++ b/numba/roc/tests/hsapy/test_reduction.py @@ -1,7 +1,7 @@ import numpy as np from numba import roc, intp -from numba.testing import unittest_support as unittest +import unittest WAVESIZE = 64 diff --git a/numba/roc/tests/hsapy/test_scan.py b/numba/roc/tests/hsapy/test_scan.py index 59487fa3857..cd541985bde 100644 --- a/numba/roc/tests/hsapy/test_scan.py +++ b/numba/roc/tests/hsapy/test_scan.py @@ -1,7 +1,7 @@ import numpy as np from numba import roc, intp, int32 -from numba.testing import unittest_support as unittest +import unittest @roc.jit(device=True) diff --git a/numba/roc/tests/hsapy/test_simple.py b/numba/roc/tests/hsapy/test_simple.py index 1a5738937a0..8ee43e2d8e3 100644 --- a/numba/roc/tests/hsapy/test_simple.py +++ b/numba/roc/tests/hsapy/test_simple.py @@ -1,7 +1,7 @@ import numpy as np from numba import roc from numba.roc.hsadrv.error import HsaKernelLaunchError -import numba.testing.unittest_support as unittest +import unittest class TestSimple(unittest.TestCase): diff --git a/numba/roc/tests/hsapy/test_ufuncbuilding.py b/numba/roc/tests/hsapy/test_ufuncbuilding.py index c8288bddd53..29703f6b95c 100644 --- a/numba/roc/tests/hsapy/test_ufuncbuilding.py +++ b/numba/roc/tests/hsapy/test_ufuncbuilding.py @@ -3,7 +3,7 @@ from numba import vectorize from numba.roc.vectorizers import HsaVectorize from numba.roc.dispatch import HsaUFuncDispatcher -from numba.testing import unittest_support as unittest +import unittest def ufunc_add_core(a, b): diff --git a/numba/testing/__init__.py b/numba/testing/__init__.py index ec307f75c1b..57c4fc0e964 100644 --- a/numba/testing/__init__.py +++ b/numba/testing/__init__.py @@ -1,12 +1,12 @@ import os import sys import functools +import unittest import traceback from fnmatch import fnmatch from os.path import join, isfile, relpath, normpath, splitext from .main import NumbaTestProgram, SerialSuite, make_tag_decorator -import numba.testing.unittest_support as unittest from numba.core import config diff --git a/numba/testing/loader.py b/numba/testing/loader.py index 3c953f82777..66ba417d62b 100644 --- a/numba/testing/loader.py +++ b/numba/testing/loader.py @@ -1,4 +1,3 @@ -import numba.testing.unittest_support as unittest from unittest import loader, case from os.path import isdir, isfile, join, dirname, basename diff --git a/numba/testing/main.py b/numba/testing/main.py index 51ff424fa1f..e66ae58da90 100644 --- a/numba/testing/main.py +++ b/numba/testing/main.py @@ -1,5 +1,3 @@ -import numba.testing.unittest_support as unittest - import collections import contextlib import cProfile @@ -10,6 +8,7 @@ import random import sys import time +import unittest import warnings from io import StringIO diff --git a/numba/testing/notebook.py b/numba/testing/notebook.py index fb3b75c9482..646a92d739c 100644 --- a/numba/testing/notebook.py +++ b/numba/testing/notebook.py @@ -7,7 +7,7 @@ import re import json from copy import copy -from numba.testing import unittest_support as unittest +import unittest try: # py3 diff --git a/numba/testing/unittest_support.py b/numba/testing/unittest_support.py deleted file mode 100644 index 4a5e8f2febc..00000000000 --- a/numba/testing/unittest_support.py +++ /dev/null @@ -1,7 +0,0 @@ -""" -This file fixes portability issues for unittest -""" -import sys -import warnings -from unittest import * -from numba.core import config diff --git a/numba/tests/__init__.py b/numba/tests/__init__.py index 51dc0cfaf77..f04b1007dab 100644 --- a/numba/tests/__init__.py +++ b/numba/tests/__init__.py @@ -3,10 +3,11 @@ import multiprocessing import sys import time +import unittest import warnings from unittest.suite import TestSuite -from numba.testing import load_testsuite, unittest_support as unittest +from numba.testing import load_testsuite try: diff --git a/numba/tests/npyufunc/__init__.py b/numba/tests/npyufunc/__init__.py index 45a2bd85e0d..b2958441fe7 100644 --- a/numba/tests/npyufunc/__init__.py +++ b/numba/tests/npyufunc/__init__.py @@ -1,7 +1,8 @@ from os.path import dirname +import unittest from unittest.suite import TestSuite -from numba.testing import load_testsuite, unittest_support as unittest +from numba.testing import load_testsuite def load_tests(loader, tests, pattern): suite = TestSuite() diff --git a/numba/tests/npyufunc/test_caching.py b/numba/tests/npyufunc/test_caching.py index 865fcc5de92..9ee579905da 100644 --- a/numba/tests/npyufunc/test_caching.py +++ b/numba/tests/npyufunc/test_caching.py @@ -8,7 +8,7 @@ from ..support import capture_cache_log from ..test_dispatcher import BaseCacheTest from numba.core import config -from numba.testing import unittest_support as unittest +import unittest class UfuncCacheTest(BaseCacheTest): diff --git a/numba/tests/npyufunc/test_dufunc.py b/numba/tests/npyufunc/test_dufunc.py index 75ec91ec228..f648e65613d 100644 --- a/numba/tests/npyufunc/test_dufunc.py +++ b/numba/tests/npyufunc/test_dufunc.py @@ -4,7 +4,7 @@ from numba import njit, vectorize from ..support import MemoryLeakMixin -from numba.testing import unittest_support as unittest +import unittest from numba.np.ufunc import dufunc diff --git a/numba/tests/npyufunc/test_errors.py b/numba/tests/npyufunc/test_errors.py index 997e66b4f49..7024ad84cd7 100644 --- a/numba/tests/npyufunc/test_errors.py +++ b/numba/tests/npyufunc/test_errors.py @@ -6,7 +6,7 @@ from numba import vectorize, guvectorize from ..support import TestCase, CheckWarningsMixin -from numba.testing import unittest_support as unittest +import unittest def sqrt(val): diff --git a/numba/tests/npyufunc/test_gufunc.py b/numba/tests/npyufunc/test_gufunc.py index b4105c23ae3..66324fc599d 100644 --- a/numba/tests/npyufunc/test_gufunc.py +++ b/numba/tests/npyufunc/test_gufunc.py @@ -4,7 +4,7 @@ from numba import void, float32, jit, guvectorize from numba.np.ufunc import GUVectorize from ..support import tag, TestCase -from numba.testing import unittest_support as unittest +import unittest def matmulcore(A, B, C): diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index bd0a1697f64..8cf58eaae23 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -1,7 +1,7 @@ from numba.np.ufunc.parallel import get_thread_count from os import environ as env from numba.core import config -from numba.testing import unittest_support as unittest +import unittest class TestParallelEnvVariable(unittest.TestCase): diff --git a/numba/tests/npyufunc/test_parallel_low_work.py b/numba/tests/npyufunc/test_parallel_low_work.py index 0c744eb5ba2..cab4d42749f 100644 --- a/numba/tests/npyufunc/test_parallel_low_work.py +++ b/numba/tests/npyufunc/test_parallel_low_work.py @@ -6,7 +6,7 @@ from numba import float32, float64, int32, uint32 from numba.np.ufunc import Vectorize -from numba.testing import unittest_support as unittest +import unittest def vector_add(a, b): diff --git a/numba/tests/npyufunc/test_parallel_ufunc_issues.py b/numba/tests/npyufunc/test_parallel_ufunc_issues.py index c519a1348c6..22371222919 100644 --- a/numba/tests/npyufunc/test_parallel_ufunc_issues.py +++ b/numba/tests/npyufunc/test_parallel_ufunc_issues.py @@ -5,7 +5,7 @@ from numba.tests.support import captured_stdout from numba import vectorize, guvectorize -from numba.testing import unittest_support as unittest +import unittest class TestParUfuncIssues(unittest.TestCase): diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index 0382938da10..7c9ec44756e 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -4,7 +4,7 @@ from numba.np.ufunc import Vectorize from numba.core.errors import TypingError from ..support import TestCase -from numba.testing import unittest_support as unittest +import unittest dtype = np.float32 diff --git a/numba/tests/npyufunc/test_ufuncbuilding.py b/numba/tests/npyufunc/test_ufuncbuilding.py index 581e7d16afe..e1c48e1cabf 100644 --- a/numba/tests/npyufunc/test_ufuncbuilding.py +++ b/numba/tests/npyufunc/test_ufuncbuilding.py @@ -8,7 +8,7 @@ from numba.np.ufunc.dufunc import DUFunc as UFuncBuilder from ..support import tag, TestCase from numba.core import config -from numba.testing import unittest_support as unittest +import unittest def add(a, b): diff --git a/numba/tests/npyufunc/test_vectorize_decor.py b/numba/tests/npyufunc/test_vectorize_decor.py index ec5953adbb5..6a9562b9c86 100644 --- a/numba/tests/npyufunc/test_vectorize_decor.py +++ b/numba/tests/npyufunc/test_vectorize_decor.py @@ -4,7 +4,7 @@ from numba import int32, uint32, float32, float64, jit, vectorize from ..support import tag, CheckWarningsMixin -from numba.testing import unittest_support as unittest +import unittest pi = math.pi diff --git a/numba/tests/support.py b/numba/tests/support.py index 376226eae7e..3717993e184 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -26,7 +26,7 @@ from numba import testing from numba.core import errors, typing, utils, config, cpu from numba.core.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS -import numba.testing.unittest_support as unittest +import unittest from numba.runtime import rtsys from numba.np import numpy_support diff --git a/numba/tests/test_annotations.py b/numba/tests/test_annotations.py index 55b96a082be..739cdc5ed2f 100644 --- a/numba/tests/test_annotations.py +++ b/numba/tests/test_annotations.py @@ -4,7 +4,7 @@ import numba from numba.core.compiler import compile_isolated, Flags from numba.core import types -from numba.testing import unittest_support as unittest +import unittest try: import jinja2 diff --git a/numba/tests/test_api.py b/numba/tests/test_api.py index e38941214ef..4e3d67a7205 100644 --- a/numba/tests/test_api.py +++ b/numba/tests/test_api.py @@ -1,7 +1,7 @@ import numba from numba.tests.support import TestCase -from numba.testing import unittest_support as unittest +import unittest class TestNumbaModule(TestCase): diff --git a/numba/tests/test_array_analysis.py b/numba/tests/test_array_analysis.py index 7ab93186b5d..d706b272c03 100644 --- a/numba/tests/test_array_analysis.py +++ b/numba/tests/test_array_analysis.py @@ -21,7 +21,7 @@ from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass from numba.experimental import jitclass -from numba.testing import unittest_support as unittest +import unittest skip_unsupported = skip_parfors_unsupported diff --git a/numba/tests/test_array_attr.py b/numba/tests/test_array_attr.py index eddc3e39723..55176e132dd 100644 --- a/numba/tests/test_array_attr.py +++ b/numba/tests/test_array_attr.py @@ -1,6 +1,6 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated from numba.np.numpy_support import from_dtype from numba import njit, typeof diff --git a/numba/tests/test_array_constants.py b/numba/tests/test_array_constants.py index b374656b82d..ed1d13d30da 100644 --- a/numba/tests/test_array_constants.py +++ b/numba/tests/test_array_constants.py @@ -1,6 +1,6 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated from numba.core.errors import TypingError from numba import jit, typeof diff --git a/numba/tests/test_array_exprs.py b/numba/tests/test_array_exprs.py index ba79cb03999..7d971bdfc97 100644 --- a/numba/tests/test_array_exprs.py +++ b/numba/tests/test_array_exprs.py @@ -8,7 +8,7 @@ from numba.core import utils, types, typing, ir, compiler, cpu from numba.core.compiler import Compiler, Flags from numba.tests.support import MemoryLeakMixin, TestCase -from numba.testing import unittest_support as unittest +import unittest class Namespace(dict): diff --git a/numba/tests/test_array_iterators.py b/numba/tests/test_array_iterators.py index 47069b4adcc..2bce78ca84c 100644 --- a/numba/tests/test_array_iterators.py +++ b/numba/tests/test_array_iterators.py @@ -6,7 +6,7 @@ from numba.core import types from numba.core.compiler import compile_isolated from numba.tests.support import TestCase, CompilationCache, MemoryLeakMixin, tag -from numba.testing import unittest_support as unittest +import unittest def array_iter(arr): diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 70444286824..ab55604a4e6 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -3,7 +3,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit, njit, from_dtype, typeof from numba.core.errors import TypingError diff --git a/numba/tests/test_array_methods.py b/numba/tests/test_array_methods.py index 95dc22cecbd..685f02c7a92 100644 --- a/numba/tests/test_array_methods.py +++ b/numba/tests/test_array_methods.py @@ -11,7 +11,7 @@ from numba.np.numpy_support import as_dtype from numba.tests.support import (TestCase, CompilationCache, MemoryLeak, MemoryLeakMixin, tag, needs_blas) -from numba.testing import unittest_support as unittest +import unittest def np_around_array(arr, decimals, out): diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index 04f8c17c911..6e655abc26d 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -5,7 +5,7 @@ from numba import jit, typeof from numba.core.compiler import compile_isolated from numba.tests.support import TestCase, MemoryLeakMixin, tag -from numba.testing import unittest_support as unittest +import unittest def array_all(arr): diff --git a/numba/tests/test_array_return.py b/numba/tests/test_array_return.py index d87e4901d10..b5fd3cf32fa 100644 --- a/numba/tests/test_array_return.py +++ b/numba/tests/test_array_return.py @@ -3,7 +3,7 @@ from numba.core.compiler import compile_isolated from numba import typeof from numba.tests.support import MemoryLeakMixin -from numba.testing import unittest_support as unittest +import unittest def array_return(a, i): diff --git a/numba/tests/test_auto_constants.py b/numba/tests/test_auto_constants.py index 71b008e6541..04ee4a75ce0 100644 --- a/numba/tests/test_auto_constants.py +++ b/numba/tests/test_auto_constants.py @@ -4,7 +4,7 @@ import numpy as np from numba.core.compiler import compile_isolated -from numba.testing import unittest_support as unittest +import unittest class TestAutoConstants(unittest.TestCase): diff --git a/numba/tests/test_blackscholes.py b/numba/tests/test_blackscholes.py index 7e888ffc17c..0dde5803bbb 100644 --- a/numba/tests/test_blackscholes.py +++ b/numba/tests/test_blackscholes.py @@ -2,7 +2,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, compile_extra, Flags from numba.core import types, typing from numba.tests.support import TestCase diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index f5b846bdd28..6fa74dbbc2b 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -6,7 +6,7 @@ from numba.core.types import float64 from numba.tests.support import MemoryLeakMixin, override_env_config from numba.core import config -from numba.testing import unittest_support as unittest +import unittest BOUNDSCHECK_FLAGS = DEFAULT_FLAGS.copy() BOUNDSCHECK_FLAGS.set('boundscheck', True) diff --git a/numba/tests/test_buffer_protocol.py b/numba/tests/test_buffer_protocol.py index d9c6c05a7ed..c5ace3f1df7 100644 --- a/numba/tests/test_buffer_protocol.py +++ b/numba/tests/test_buffer_protocol.py @@ -4,7 +4,7 @@ from numba import jit from numba.tests.support import TestCase, compile_function, MemoryLeakMixin -from numba.testing import unittest_support as unittest +import unittest @jit(nopython=True) diff --git a/numba/tests/test_builtins.py b/numba/tests/test_builtins.py index 147e2249a81..82d0e0ffca8 100644 --- a/numba/tests/test_builtins.py +++ b/numba/tests/test_builtins.py @@ -5,7 +5,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit, typeof, njit from numba.core import errors, types, utils, config diff --git a/numba/tests/test_casting.py b/numba/tests/test_casting.py index c6f6f511f9b..901a8b91742 100644 --- a/numba/tests/test_casting.py +++ b/numba/tests/test_casting.py @@ -3,7 +3,7 @@ from numba import njit from numba.core import types import struct -from numba.testing import unittest_support as unittest +import unittest def float_to_int(x): diff --git a/numba/tests/test_cffi.py b/numba/tests/test_cffi.py index c9ae8a2eed1..7f0f0d89846 100644 --- a/numba/tests/test_cffi.py +++ b/numba/tests/test_cffi.py @@ -8,7 +8,7 @@ from numba.tests.support import TestCase, tag import numba.tests.cffi_usecases as mod -from numba.testing import unittest_support as unittest +import unittest enable_pyobj_flags = Flags() diff --git a/numba/tests/test_cfunc.py b/numba/tests/test_cfunc.py index 6795f3769e8..e6081287a19 100644 --- a/numba/tests/test_cfunc.py +++ b/numba/tests/test_cfunc.py @@ -16,7 +16,7 @@ import numba.core.typing.cffi_utils as cffi_support from numba.tests.support import TestCase, tag, captured_stderr from numba.tests.test_dispatcher import BaseCacheTest -from numba.testing import unittest_support as unittest +import unittest from numba.np import numpy_support skip_cffi_unsupported = unittest.skipUnless( diff --git a/numba/tests/test_cgutils.py b/numba/tests/test_cgutils.py index d333193589f..44485d9beb7 100644 --- a/numba/tests/test_cgutils.py +++ b/numba/tests/test_cgutils.py @@ -6,7 +6,7 @@ import llvmlite.llvmpy.core as lc import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core import types, typing, cgutils, cpu from numba.core.compiler_lock import global_compiler_lock from numba.tests.support import TestCase diff --git a/numba/tests/test_chained_assign.py b/numba/tests/test_chained_assign.py index 6d2e63373df..1e41c6c9701 100644 --- a/numba/tests/test_chained_assign.py +++ b/numba/tests/test_chained_assign.py @@ -1,5 +1,5 @@ from numba import jit -import numba.testing.unittest_support as unittest +import unittest import numpy as np import copy from numba.tests.support import MemoryLeakMixin diff --git a/numba/tests/test_cli.py b/numba/tests/test_cli.py index 000d852e53e..5fb7e7ac1a3 100644 --- a/numba/tests/test_cli.py +++ b/numba/tests/test_cli.py @@ -5,7 +5,7 @@ import sys import threading -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import TestCase diff --git a/numba/tests/test_closure.py b/numba/tests/test_closure.py index c681dd82f50..19a2892c7bc 100644 --- a/numba/tests/test_closure.py +++ b/numba/tests/test_closure.py @@ -2,7 +2,7 @@ import numpy as np import numpy -import numba.testing.unittest_support as unittest +import unittest from numba import njit, jit, testing from numba.core.errors import TypingError, UnsupportedError from numba.tests.support import TestCase diff --git a/numba/tests/test_codegen.py b/numba/tests/test_codegen.py index 734f863cf01..297bb19b788 100644 --- a/numba/tests/test_codegen.py +++ b/numba/tests/test_codegen.py @@ -13,7 +13,7 @@ import llvmlite.binding as ll -import numba.testing.unittest_support as unittest +import unittest from numba.core.codegen import JITCPUCodegen from numba.core.compiler_lock import global_compiler_lock from numba.tests.support import TestCase diff --git a/numba/tests/test_compile_cache.py b/numba/tests/test_compile_cache.py index 95e029f9ed8..372ef027060 100644 --- a/numba/tests/test_compile_cache.py +++ b/numba/tests/test_compile_cache.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from contextlib import contextmanager import llvmlite.llvmpy.core as lc diff --git a/numba/tests/test_complex.py b/numba/tests/test_complex.py index b1181f44a26..fc522536a43 100644 --- a/numba/tests/test_complex.py +++ b/numba/tests/test_complex.py @@ -7,7 +7,7 @@ from numba.core import types from numba.tests.support import TestCase, tag from .complex_usecases import * -from numba.testing import unittest_support as unittest +import unittest enable_pyobj_flags = Flags() enable_pyobj_flags.set("enable_pyobject") diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index 812b0a2d95f..b05badc4110 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import TestCase import sys diff --git a/numba/tests/test_conversion.py b/numba/tests/test_conversion.py index bb97673c9ba..0aee1a40e71 100644 --- a/numba/tests/test_conversion.py +++ b/numba/tests/test_conversion.py @@ -5,7 +5,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types diff --git a/numba/tests/test_copy_propagate.py b/numba/tests/test_copy_propagate.py index 90fdf838429..1b4c8dbe815 100644 --- a/numba/tests/test_copy_propagate.py +++ b/numba/tests/test_copy_propagate.py @@ -9,7 +9,7 @@ from numba.core.ir_utils import (copy_propagate, apply_copy_propagate, get_name_var_table) from numba.core.typed_passes import type_inference_stage -from numba.testing import unittest_support as unittest +import unittest def test_will_propagate(b, z, w): x = 3 diff --git a/numba/tests/test_ctypes.py b/numba/tests/test_ctypes.py index e4920dd3ea8..b0f37b1827b 100644 --- a/numba/tests/test_ctypes.py +++ b/numba/tests/test_ctypes.py @@ -11,7 +11,7 @@ from numba.core.typing import ctypes_utils from numba.tests.support import MemoryLeakMixin, tag, TestCase from numba.tests.ctypes_usecases import * -from numba.testing import unittest_support as unittest +import unittest class TestCTypesTypes(TestCase): diff --git a/numba/tests/test_dataflow.py b/numba/tests/test_dataflow.py index b908ab6952b..4cc47ee8198 100644 --- a/numba/tests/test_dataflow.py +++ b/numba/tests/test_dataflow.py @@ -1,6 +1,6 @@ import warnings -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, errors from numba.tests.support import (TestCase, CompilationCache, diff --git a/numba/tests/test_datamodel.py b/numba/tests/test_datamodel.py index acb7adee3ce..e04ff3f19f6 100644 --- a/numba/tests/test_datamodel.py +++ b/numba/tests/test_datamodel.py @@ -2,7 +2,7 @@ from numba.core import types, datamodel from numba.core.datamodel.testing import test_factory -from numba.testing import unittest_support as unittest +import unittest class TestBool(test_factory()): diff --git a/numba/tests/test_debug.py b/numba/tests/test_debug.py index 06d9ed3a03f..98fdc44ab29 100644 --- a/numba/tests/test_debug.py +++ b/numba/tests/test_debug.py @@ -16,7 +16,7 @@ from numba.core.errors import NumbaPerformanceWarning from numba import prange from numba.experimental import jitclass -from numba.testing import unittest_support as unittest +import unittest def simple_nopython(somearg): diff --git a/numba/tests/test_debuginfo.py b/numba/tests/test_debuginfo.py index 7882407d299..49eef2ea468 100644 --- a/numba/tests/test_debuginfo.py +++ b/numba/tests/test_debuginfo.py @@ -3,7 +3,7 @@ from numba.tests.support import TestCase, override_config from numba import jit from numba.core import types -from numba.testing import unittest_support as unittest +import unittest class TestDebugInfo(TestCase): diff --git a/numba/tests/test_del.py b/numba/tests/test_del.py index f0f47f10f16..53a6d773ce9 100644 --- a/numba/tests/test_del.py +++ b/numba/tests/test_del.py @@ -2,7 +2,7 @@ from numba.core.compiler import compile_isolated from numba.tests.support import TestCase -import numba.testing.unittest_support as unittest +import unittest from numba import testing diff --git a/numba/tests/test_deprecations.py b/numba/tests/test_deprecations.py index 1a4b49f9f01..3122b091db2 100644 --- a/numba/tests/test_deprecations.py +++ b/numba/tests/test_deprecations.py @@ -2,7 +2,7 @@ from numba import jit from numba.core.errors import (NumbaDeprecationWarning, NumbaPendingDeprecationWarning, NumbaWarning) -import numba.testing.unittest_support as unittest +import unittest class TestDeprecation(unittest.TestCase): diff --git a/numba/tests/test_dicts.py b/numba/tests/test_dicts.py index b05d612fda8..2474251ce16 100644 --- a/numba/tests/test_dicts.py +++ b/numba/tests/test_dicts.py @@ -1,6 +1,6 @@ from numba import njit from numba.core.errors import TypingError -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import TestCase, force_pyobj_flags diff --git a/numba/tests/test_dispatcher.py b/numba/tests/test_dispatcher.py index 5170f3104a5..42e9f0284fd 100644 --- a/numba/tests/test_dispatcher.py +++ b/numba/tests/test_dispatcher.py @@ -29,7 +29,7 @@ from numba.tests.support import skip_parfors_unsupported, needs_lapack import llvmlite.binding as ll -from numba.testing import unittest_support as unittest +import unittest from numba.parfors import parfor try: diff --git a/numba/tests/test_dummyarray.py b/numba/tests/test_dummyarray.py index 72dfa12673e..31b811e9c93 100644 --- a/numba/tests/test_dummyarray.py +++ b/numba/tests/test_dummyarray.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest import itertools import numpy as np from numba.misc.dummyarray import Array diff --git a/numba/tests/test_dyn_array.py b/numba/tests/test_dyn_array.py index 93fcd32b69f..f532b1584d1 100644 --- a/numba/tests/test_dyn_array.py +++ b/numba/tests/test_dyn_array.py @@ -9,7 +9,7 @@ from numba import njit from numba.core import types, utils, config from numba.tests.support import MemoryLeakMixin, TestCase, tag -from numba.testing import unittest_support as unittest +import unittest nrtjit = njit(_nrt=True, nogil=True) diff --git a/numba/tests/test_enums.py b/numba/tests/test_enums.py index 697f9f86b3b..28953cf80f5 100644 --- a/numba/tests/test_enums.py +++ b/numba/tests/test_enums.py @@ -4,7 +4,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import jit, vectorize from numba.tests.support import TestCase diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index c977a925ae5..c2dd267f877 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -17,7 +17,7 @@ from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass from numba.tests.support import skip_parfors_unsupported -from numba.testing import unittest_support as unittest +import unittest # used in TestMiscErrorHandling::test_handling_of_write_to_*_global _global_list = [1, 2, 3, 4] diff --git a/numba/tests/test_errormodels.py b/numba/tests/test_errormodels.py index 9c1b72c0df0..9635da294e0 100644 --- a/numba/tests/test_errormodels.py +++ b/numba/tests/test_errormodels.py @@ -3,7 +3,7 @@ """ from numba import jit -from numba.testing import unittest_support as unittest +import unittest class TestErrorModel(unittest.TestCase): diff --git a/numba/tests/test_exceptions.py b/numba/tests/test_exceptions.py index 7546db065f0..9e378404946 100644 --- a/numba/tests/test_exceptions.py +++ b/numba/tests/test_exceptions.py @@ -6,7 +6,7 @@ from numba import jit, njit from numba.core import types, errors from numba.tests.support import TestCase -from numba.testing import unittest_support as unittest +import unittest force_pyobj_flags = Flags() force_pyobj_flags.set("force_pyobject") diff --git a/numba/tests/test_extended_arg.py b/numba/tests/test_extended_arg.py index 52d5e0494e9..11f7a249974 100644 --- a/numba/tests/test_extended_arg.py +++ b/numba/tests/test_extended_arg.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest import dis import struct diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 98103d29c9d..d5ae7bda3ba 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -17,7 +17,7 @@ from numba.tests.support import (TestCase, captured_stdout, tag, temp_directory, override_config) from numba.core.errors import LoweringError -from numba.testing import unittest_support as unittest +import unittest from numba.extending import (typeof_impl, type_callable, lower_builtin, lower_cast, diff --git a/numba/tests/test_extending_types.py b/numba/tests/test_extending_types.py index 2fcedc6c62e..ed88e52473e 100644 --- a/numba/tests/test_extending_types.py +++ b/numba/tests/test_extending_types.py @@ -12,7 +12,7 @@ from numba.core.extending import overload from numba.core.extending import typeof_impl -from numba.testing import unittest_support as unittest +import unittest class TestExtTypDummy(unittest.TestCase): diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index ada77de6146..a3dd0206259 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -2,7 +2,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import jit, typeof from numba.core import types from numba.core.errors import TypingError diff --git a/numba/tests/test_fastmath.py b/numba/tests/test_fastmath.py index 777bbeeaed5..528adf494e9 100644 --- a/numba/tests/test_fastmath.py +++ b/numba/tests/test_fastmath.py @@ -3,7 +3,7 @@ from numba.tests.support import captured_stdout, override_config from numba import njit, vectorize, guvectorize -from numba.testing import unittest_support as unittest +import unittest class TestFastMath(unittest.TestCase): diff --git a/numba/tests/test_flow_control.py b/numba/tests/test_flow_control.py index 3178ddcc5ac..fc804778d1a 100644 --- a/numba/tests/test_flow_control.py +++ b/numba/tests/test_flow_control.py @@ -1,6 +1,6 @@ import itertools -import numba.testing.unittest_support as unittest +import unittest from numba.core.controlflow import CFGraph, ControlFlowAnalysis from numba.core.compiler import compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_func_interface.py b/numba/tests/test_func_interface.py index 51a26278155..546862858c4 100644 --- a/numba/tests/test_func_interface.py +++ b/numba/tests/test_func_interface.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba import jit diff --git a/numba/tests/test_func_lifetime.py b/numba/tests/test_func_lifetime.py index 04b5ab34df1..5624b57047b 100644 --- a/numba/tests/test_func_lifetime.py +++ b/numba/tests/test_func_lifetime.py @@ -4,7 +4,7 @@ from numba import jit from numba.core import types from numba.tests.support import TestCase -from numba.testing import unittest_support as unittest +import unittest class Dummy(object): diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index a33764b6694..066921095ef 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -14,7 +14,7 @@ from numba.misc.gdb_hook import _confirm_gdb from numba.tests.support import (TestCase, captured_stdout, tag, skip_parfors_unsupported) -from numba.testing import unittest_support as unittest +import unittest _platform = sys.platform diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py index 8b3e48c88b7..cd45a25d968 100644 --- a/numba/tests/test_generators.py +++ b/numba/tests/test_generators.py @@ -1,7 +1,7 @@ import sys import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types diff --git a/numba/tests/test_gil.py b/numba/tests/test_gil.py index 214b9d97957..7a60a756581 100644 --- a/numba/tests/test_gil.py +++ b/numba/tests/test_gil.py @@ -7,7 +7,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import errors diff --git a/numba/tests/test_globals.py b/numba/tests/test_globals.py index 9b42c896a66..38704fa6eb1 100644 --- a/numba/tests/test_globals.py +++ b/numba/tests/test_globals.py @@ -1,7 +1,7 @@ import numpy as np from numba import jit from numba.tests import usecases -from numba.testing import unittest_support as unittest +import unittest X = np.arange(10) diff --git a/numba/tests/test_hashing.py b/numba/tests/test_hashing.py index c7795fc52f9..b4760dc0d5b 100644 --- a/numba/tests/test_hashing.py +++ b/numba/tests/test_hashing.py @@ -3,7 +3,7 @@ Test hashing of various supported types. """ -import numba.testing.unittest_support as unittest +import unittest import sys from collections import defaultdict @@ -12,7 +12,7 @@ from numba import jit from numba.core import types, utils -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import TestCase, tag, CompilationCache from numba.cpython.unicode import compile_time_get_string_data diff --git a/numba/tests/test_import.py b/numba/tests/test_import.py index 6a0fe1286d3..19b477ddc22 100644 --- a/numba/tests/test_import.py +++ b/numba/tests/test_import.py @@ -2,7 +2,7 @@ import sys from numba.tests.support import TestCase -from numba.testing import unittest_support as unittest +import unittest class TestNumbaImport(TestCase): diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index a9dcd1feba8..1ced6c4dd1c 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -3,7 +3,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import njit, typeof from numba.core import utils, types, errors diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index 2333eb3d799..e5d65b910aa 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -20,7 +20,7 @@ IRLegalization, NoPythonBackend) from numba.core.compiler_machinery import FunctionPass, PassManager, register_pass -from numba.testing import unittest_support as unittest +import unittest @jit((types.int32,), nopython=True) def inner(a): diff --git a/numba/tests/test_interproc.py b/numba/tests/test_interproc.py index 714d6124c71..56265dfbe4c 100644 --- a/numba/tests/test_interproc.py +++ b/numba/tests/test_interproc.py @@ -1,7 +1,7 @@ import gc from numba import jit, int32 -from numba.testing import unittest_support as unittest +import unittest def foo(a, b): diff --git a/numba/tests/test_intwidth.py b/numba/tests/test_intwidth.py index 18481951091..76c0effebf1 100644 --- a/numba/tests/test_intwidth.py +++ b/numba/tests/test_intwidth.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest import math import sys diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index 0cb665e092d..087065746f8 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba import objmode import numpy as np from numba.core import ir, compiler diff --git a/numba/tests/test_itanium_mangler.py b/numba/tests/test_itanium_mangler.py index 8c0810ad3dd..10641f9d2ba 100644 --- a/numba/tests/test_itanium_mangler.py +++ b/numba/tests/test_itanium_mangler.py @@ -5,7 +5,7 @@ from numba import int32, int64, uint32, uint64, float32, float64 from numba.core.types import range_iter32_type from numba.core import itanium_mangler -from numba.testing import unittest_support as unittest +import unittest class TestItaniumManager(unittest.TestCase): diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index 8097ee40dc9..3e5ea35662e 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -1,7 +1,7 @@ import numpy as np from numba import njit -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, errors from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_jit_module.py b/numba/tests/test_jit_module.py index 3a73140c6f1..39574a409ce 100644 --- a/numba/tests/test_jit_module.py +++ b/numba/tests/test_jit_module.py @@ -9,7 +9,7 @@ import logging from io import StringIO -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import temp_directory, SerialMixin from numba.core import dispatcher diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index df5dd59dbd0..486b38183c9 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -14,7 +14,7 @@ from numba.runtime.nrt import MemInfo from numba.core.errors import LoweringError from numba.experimental import jitclass -from numba.testing import unittest_support as unittest +import unittest class TestClass1(object): diff --git a/numba/tests/test_jitmethod.py b/numba/tests/test_jitmethod.py index 5b334923005..192af60cb1d 100644 --- a/numba/tests/test_jitmethod.py +++ b/numba/tests/test_jitmethod.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest import numpy as np diff --git a/numba/tests/test_linalg.py b/numba/tests/test_linalg.py index fd522c088bf..e613706f3c7 100644 --- a/numba/tests/test_linalg.py +++ b/numba/tests/test_linalg.py @@ -12,7 +12,7 @@ from numba.core import errors from numba.tests.support import TestCase, tag, needs_lapack, needs_blas, _is_armv7l from .matmul_usecase import matmul_usecase -from numba.testing import unittest_support as unittest +import unittest def dot2(a, b): diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py index 43730c52c9d..b7c19b48d80 100644 --- a/numba/tests/test_lists.py +++ b/numba/tests/test_lists.py @@ -8,7 +8,7 @@ from numba.core.compiler import compile_isolated, Flags from numba import jit, typeof -import numba.testing.unittest_support as unittest +import unittest from numba import testing from numba.core import types, utils, errors from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_literal_dispatch.py b/numba/tests/test_literal_dispatch.py index 6374e19fc36..6bc32a22218 100644 --- a/numba/tests/test_literal_dispatch.py +++ b/numba/tests/test_literal_dispatch.py @@ -1,7 +1,7 @@ import numpy as np import numba -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import TestCase from numba import njit from numba.core import types, errors, cgutils diff --git a/numba/tests/test_llvm_version_check.py b/numba/tests/test_llvm_version_check.py index 917c0fef1d2..0be6fa23e08 100644 --- a/numba/tests/test_llvm_version_check.py +++ b/numba/tests/test_llvm_version_check.py @@ -1,7 +1,7 @@ import imp import sys -from numba.testing import unittest_support as unittest +import unittest class TestLlvmVersion(unittest.TestCase): diff --git a/numba/tests/test_locals.py b/numba/tests/test_locals.py index 8b59c678a4d..21f64a19bff 100644 --- a/numba/tests/test_locals.py +++ b/numba/tests/test_locals.py @@ -1,6 +1,6 @@ from numba import float32 from numba.core import compiler -from numba.testing import unittest_support as unittest +import unittest def foo(): x = 123 diff --git a/numba/tests/test_looplifting.py b/numba/tests/test_looplifting.py index 91662154eeb..df1fc8a1001 100644 --- a/numba/tests/test_looplifting.py +++ b/numba/tests/test_looplifting.py @@ -4,7 +4,7 @@ from numba.core import types from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, MemoryLeakMixin -from numba.testing import unittest_support as unittest +import unittest looplift_flags = Flags() diff --git a/numba/tests/test_make_function_to_jit_function.py b/numba/tests/test_make_function_to_jit_function.py index 0af505e2d8e..29161fff594 100644 --- a/numba/tests/test_make_function_to_jit_function.py +++ b/numba/tests/test_make_function_to_jit_function.py @@ -3,7 +3,7 @@ from numba.core.extending import overload import numpy as np -from numba.testing import unittest_support as unittest +import unittest @njit diff --git a/numba/tests/test_mandelbrot.py b/numba/tests/test_mandelbrot.py index 02c790b9097..43826b1ec53 100644 --- a/numba/tests/test_mandelbrot.py +++ b/numba/tests/test_mandelbrot.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, utils diff --git a/numba/tests/test_map_filter_reduce.py b/numba/tests/test_map_filter_reduce.py index 4e498e104c5..c6f46a156f0 100644 --- a/numba/tests/test_map_filter_reduce.py +++ b/numba/tests/test_map_filter_reduce.py @@ -1,7 +1,7 @@ from numba import njit from functools import reduce -from numba.testing import unittest_support as unittest +import unittest class TestMap(unittest.TestCase): diff --git a/numba/tests/test_mathlib.py b/numba/tests/test_mathlib.py index c3728bea36d..a640660f88a 100644 --- a/numba/tests/test_mathlib.py +++ b/numba/tests/test_mathlib.py @@ -9,7 +9,7 @@ from numba.core import utils, types from numba.core.config import IS_WIN32, IS_32BITS from numba.tests.support import TestCase, CompilationCache, tag -from numba.testing import unittest_support as unittest +import unittest from numba.np import numpy_support enable_pyobj_flags = Flags() diff --git a/numba/tests/test_maxmin.py b/numba/tests/test_maxmin.py index 48c3d63248b..84da5a33aab 100644 --- a/numba/tests/test_maxmin.py +++ b/numba/tests/test_maxmin.py @@ -1,6 +1,6 @@ from numba.core.compiler import compile_isolated from numba.core import types -from numba.testing import unittest_support as unittest +import unittest def domax3(a, b, c): diff --git a/numba/tests/test_multi3.py b/numba/tests/test_multi3.py index e235dc70c4c..018637922ac 100644 --- a/numba/tests/test_multi3.py +++ b/numba/tests/test_multi3.py @@ -4,7 +4,7 @@ from numba import njit from numba.core import types -from numba.testing import unittest_support as unittest +import unittest class TestMulti3(unittest.TestCase): """ diff --git a/numba/tests/test_nan.py b/numba/tests/test_nan.py index 6bcadad4451..9ef38775442 100644 --- a/numba/tests/test_nan.py +++ b/numba/tests/test_nan.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_nested_calls.py b/numba/tests/test_nested_calls.py index 84c5fc05992..6f18e639782 100644 --- a/numba/tests/test_nested_calls.py +++ b/numba/tests/test_nested_calls.py @@ -8,7 +8,7 @@ from numba import jit, generated_jit from numba.core import types from numba.tests.support import TestCase, tag -from numba.testing import unittest_support as unittest +import unittest @jit(nopython=True) diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 5ae51ebc1d7..64ffc1c9fc2 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -17,7 +17,7 @@ from numba.np.arraymath import cross2d from numba.tests.support import (TestCase, CompilationCache, MemoryLeakMixin, needs_blas) -from numba.testing import unittest_support as unittest +import unittest no_pyobj_flags = Flags() diff --git a/numba/tests/test_npdatetime.py b/numba/tests/test_npdatetime.py index 69a71536db9..35e6b5893c5 100644 --- a/numba/tests/test_npdatetime.py +++ b/numba/tests/test_npdatetime.py @@ -11,7 +11,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import jit, vectorize from numba.np.numpy_support import numpy_version from numba.core import types, config diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index c25001cb1ec..7c91a8ccc7d 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -25,7 +25,7 @@ from numba.tests.support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic from numba.core import cpu -from numba.testing import unittest_support as unittest +import unittest enable_nrt_flags = Flags() enable_nrt_flags.set("nrt") diff --git a/numba/tests/test_nrt_refct.py b/numba/tests/test_nrt_refct.py index 7bc404bc917..17f8712d73a 100644 --- a/numba/tests/test_nrt_refct.py +++ b/numba/tests/test_nrt_refct.py @@ -7,7 +7,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import njit from numba.runtime import rtsys from numba.tests.support import TestCase diff --git a/numba/tests/test_numberctor.py b/numba/tests/test_numberctor.py index f4dce69cb44..fdc83f21e41 100644 --- a/numba/tests/test_numberctor.py +++ b/numba/tests/test_numberctor.py @@ -5,7 +5,7 @@ from numba.core import types from numba.tests.support import TestCase, tag -from numba.testing import unittest_support as unittest +import unittest def dobool(a): diff --git a/numba/tests/test_numconv.py b/numba/tests/test_numconv.py index 8cdb5ee1a92..ac0217ed8f7 100644 --- a/numba/tests/test_numconv.py +++ b/numba/tests/test_numconv.py @@ -1,5 +1,5 @@ import itertools -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated from numba.core import types diff --git a/numba/tests/test_numpy_support.py b/numba/tests/test_numpy_support.py index 53f2d41d6a7..3a9a2ad0372 100644 --- a/numba/tests/test_numpy_support.py +++ b/numba/tests/test_numpy_support.py @@ -8,7 +8,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core import types from numba.tests.support import TestCase from numba.tests.enum_usecases import Shake, RequestError diff --git a/numba/tests/test_numpyadapt.py b/numba/tests/test_numpyadapt.py index 1ab20e155ab..b43b1a80a90 100644 --- a/numba/tests/test_numpyadapt.py +++ b/numba/tests/test_numpyadapt.py @@ -2,7 +2,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import _helperlib diff --git a/numba/tests/test_obj_lifetime.py b/numba/tests/test_obj_lifetime.py index dc2f9cb70f0..8279de13ba0 100644 --- a/numba/tests/test_obj_lifetime.py +++ b/numba/tests/test_obj_lifetime.py @@ -3,7 +3,7 @@ import weakref import gc -import numba.testing.unittest_support as unittest +import unittest from numba.core.controlflow import CFGraph, Loop from numba.core.compiler import compile_extra, compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_object_mode.py b/numba/tests/test_object_mode.py index 140192362e2..34b3e86bef3 100644 --- a/numba/tests/test_object_mode.py +++ b/numba/tests/test_object_mode.py @@ -5,7 +5,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import utils diff --git a/numba/tests/test_objects.py b/numba/tests/test_objects.py index 7372e4fa48c..b2a1a7e3a82 100644 --- a/numba/tests/test_objects.py +++ b/numba/tests/test_objects.py @@ -3,7 +3,7 @@ """ -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types from numba.tests.support import TestCase diff --git a/numba/tests/test_operators.py b/numba/tests/test_operators.py index 23e2f8a3f67..dd3ee666113 100644 --- a/numba/tests/test_operators.py +++ b/numba/tests/test_operators.py @@ -6,7 +6,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types, utils, errors, typeinfer diff --git a/numba/tests/test_optional.py b/numba/tests/test_optional.py index f92dd4b04eb..02be53fc5ad 100644 --- a/numba/tests/test_optional.py +++ b/numba/tests/test_optional.py @@ -2,7 +2,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import typeof, njit from numba.core import types, lowering diff --git a/numba/tests/test_overlap.py b/numba/tests/test_overlap.py index e1a13d0a862..eecf77c099c 100644 --- a/numba/tests/test_overlap.py +++ b/numba/tests/test_overlap.py @@ -3,7 +3,7 @@ from numba import jit from numba.core import types from numba.tests.support import TestCase, tag -from numba.testing import unittest_support as unittest +import unittest # Array overlaps involving a displacement diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 8c6c0a9bd6b..60750419938 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -21,7 +21,7 @@ import queue as t_queue from numba.testing.main import _TIMEOUT as _RUNNER_TIMEOUT from numba.core import config -from numba.testing import unittest_support as unittest +import unittest _TEST_TIMEOUT = _RUNNER_TIMEOUT - 60. diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index e3b644a484c..541dd07e994 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -34,7 +34,7 @@ skip_parfors_unsupported, _32bit, needs_blas, needs_lapack) import cmath -from numba.testing import unittest_support as unittest +import unittest test_disabled = unittest.skipIf(True, 'Test disabled') diff --git a/numba/tests/test_polynomial.py b/numba/tests/test_polynomial.py index 65f4bd24302..694492d0fd7 100644 --- a/numba/tests/test_polynomial.py +++ b/numba/tests/test_polynomial.py @@ -5,7 +5,7 @@ from numba import jit from numba.tests.support import TestCase, tag, needs_lapack -from numba.testing import unittest_support as unittest +import unittest def roots_fn(p): diff --git a/numba/tests/test_print.py b/numba/tests/test_print.py index 6d6aa897d84..419957bff66 100644 --- a/numba/tests/test_print.py +++ b/numba/tests/test_print.py @@ -2,7 +2,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types, errors, utils diff --git a/numba/tests/test_profiler.py b/numba/tests/test_profiler.py index 897a871fe15..8e9eae36ba1 100644 --- a/numba/tests/test_profiler.py +++ b/numba/tests/test_profiler.py @@ -8,7 +8,7 @@ from numba import jit from numba.tests.support import needs_blas -from numba.testing import unittest_support as unittest +import unittest def dot(a, b): diff --git a/numba/tests/test_pycc.py b/numba/tests/test_pycc.py index 44764089d83..11f3048cd47 100644 --- a/numba/tests/test_pycc.py +++ b/numba/tests/test_pycc.py @@ -19,7 +19,7 @@ from numba.pycc.platform import _external_compiler_ok from numba.tests.support import TestCase, tag, import_dynamic, temp_directory, has_blas -from numba.testing import unittest_support as unittest +import unittest try: diff --git a/numba/tests/test_python_int.py b/numba/tests/test_python_int.py index 2f85305e696..a5c52a24719 100644 --- a/numba/tests/test_python_int.py +++ b/numba/tests/test_python_int.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index b76d7cf3e39..758916d26db 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -10,7 +10,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import jit, _helperlib from numba.core import types from numba.core.compiler import compile_isolated diff --git a/numba/tests/test_range.py b/numba/tests/test_range.py index 6ea118013e5..c53f4035e6b 100644 --- a/numba/tests/test_range.py +++ b/numba/tests/test_range.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest import sys diff --git a/numba/tests/test_recarray_usecases.py b/numba/tests/test_recarray_usecases.py index 0e0c7c34d51..1dba7bb9ba2 100644 --- a/numba/tests/test_recarray_usecases.py +++ b/numba/tests/test_recarray_usecases.py @@ -5,7 +5,7 @@ from numba.core import types from numba.core.compiler import compile_isolated from numba.tests.support import captured_stdout, tag, TestCase -from numba.testing import unittest_support as unittest +import unittest from numba.np import numpy_support diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 27bdfb1b09f..3f4405dbc1c 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -8,7 +8,7 @@ from numba.core.itanium_mangler import mangle_type from numba.core.config import IS_WIN32 from numba.np.numpy_support import numpy_version -from numba.testing import unittest_support as unittest +import unittest from numba.np import numpy_support diff --git a/numba/tests/test_recursion.py b/numba/tests/test_recursion.py index 9655566d485..7a752c0ed38 100644 --- a/numba/tests/test_recursion.py +++ b/numba/tests/test_recursion.py @@ -4,7 +4,7 @@ from numba import jit from numba.core.errors import TypingError, NumbaWarning from numba.tests.support import TestCase -from numba.testing import unittest_support as unittest +import unittest class TestSelfRecursion(TestCase): diff --git a/numba/tests/test_remove_dead.py b/numba/tests/test_remove_dead.py index b1a8c9d309d..e39caccfc62 100644 --- a/numba/tests/test_remove_dead.py +++ b/numba/tests/test_remove_dead.py @@ -26,7 +26,7 @@ IRLegalization, NoPythonBackend) import numpy as np from numba.tests.support import skip_parfors_unsupported, needs_blas -from numba.testing import unittest_support as unittest +import unittest def test_will_propagate(b, z, w): diff --git a/numba/tests/test_return_values.py b/numba/tests/test_return_values.py index 322374c9776..d75ac612168 100644 --- a/numba/tests/test_return_values.py +++ b/numba/tests/test_return_values.py @@ -5,7 +5,7 @@ import math -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types from numba.core.errors import TypingError diff --git a/numba/tests/test_runtests.py b/numba/tests/test_runtests.py index db344b9f1c9..7aec441af1c 100755 --- a/numba/tests/test_runtests.py +++ b/numba/tests/test_runtests.py @@ -2,7 +2,7 @@ import subprocess from numba import cuda -from numba.testing import unittest_support as unittest +import unittest class TestCase(unittest.TestCase): diff --git a/numba/tests/test_serialize.py b/numba/tests/test_serialize.py index 4439852c4e5..f345eda65ca 100644 --- a/numba/tests/test_serialize.py +++ b/numba/tests/test_serialize.py @@ -7,7 +7,7 @@ from numba.core.errors import TypingError from numba.tests.support import TestCase, tag from .serialize_usecases import * -from numba.testing import unittest_support as unittest +import unittest from numba.core import registry diff --git a/numba/tests/test_sets.py b/numba/tests/test_sets.py index 53c4008db1d..8fac15abb3a 100644 --- a/numba/tests/test_sets.py +++ b/numba/tests/test_sets.py @@ -1,4 +1,4 @@ -import numba.testing.unittest_support as unittest +import unittest from collections import namedtuple import contextlib @@ -12,7 +12,7 @@ from numba.core.compiler import compile_isolated, Flags from numba import jit from numba.core import types -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import (TestCase, enable_pyobj_flags, MemoryLeakMixin, tag, compile_function) diff --git a/numba/tests/test_slices.py b/numba/tests/test_slices.py index e0346ebf202..cb40a3a8f3f 100644 --- a/numba/tests/test_slices.py +++ b/numba/tests/test_slices.py @@ -8,7 +8,7 @@ from numba import jit, typeof, TypingError from numba.core import utils from numba.tests.support import TestCase, MemoryLeakMixin -from numba.testing import unittest_support as unittest +import unittest def slice_passing(sl): diff --git a/numba/tests/test_sort.py b/numba/tests/test_sort.py index b9044251907..23bba1a2642 100644 --- a/numba/tests/test_sort.py +++ b/numba/tests/test_sort.py @@ -9,7 +9,7 @@ from numba.core.compiler import compile_isolated, Flags from numba import jit, njit from numba.core import types, utils, errors -import numba.testing.unittest_support as unittest +import unittest from numba import testing from numba.tests.support import TestCase, MemoryLeakMixin, tag diff --git a/numba/tests/test_stencils.py b/numba/tests/test_stencils.py index 3eccf5cb5de..261d6581e54 100644 --- a/numba/tests/test_stencils.py +++ b/numba/tests/test_stencils.py @@ -20,7 +20,7 @@ from numba.core.cpu import ParallelOptions from numba.tests.support import tag, skip_parfors_unsupported, _32bit from numba.core.errors import LoweringError, TypingError -from numba.testing import unittest_support as unittest +import unittest skip_unsupported = skip_parfors_unsupported diff --git a/numba/tests/test_storeslice.py b/numba/tests/test_storeslice.py index 47bcabb9c22..687a40723c3 100644 --- a/numba/tests/test_storeslice.py +++ b/numba/tests/test_storeslice.py @@ -1,6 +1,6 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, errors from numba.tests.support import TestCase diff --git a/numba/tests/test_support.py b/numba/tests/test_support.py index 850c5dc2daf..e35eda1ff27 100644 --- a/numba/tests/test_support.py +++ b/numba/tests/test_support.py @@ -6,7 +6,7 @@ from numba.core import utils from numba.tests.support import TestCase, forbid_codegen from .enum_usecases import * -from numba.testing import unittest_support as unittest +import unittest DBL_EPSILON = 2**-52 FLT_EPSILON = 2**-23 diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 2089b95ee88..459fdbbc653 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -12,7 +12,7 @@ from numba import prange, njit from numba.core.compiler import compile_isolated, Flags from numba.tests.support import TestCase, tag, override_env_config -from numba.testing import unittest_support as unittest +import unittest needs_svml = unittest.skipUnless(config.USING_SVML, "SVML tests need SVML to be present") diff --git a/numba/tests/test_target_overloadselector.py b/numba/tests/test_target_overloadselector.py index 13d89fb2c50..76acf30d79a 100644 --- a/numba/tests/test_target_overloadselector.py +++ b/numba/tests/test_target_overloadselector.py @@ -1,7 +1,7 @@ from itertools import product, permutations from collections import defaultdict -import numba.testing.unittest_support as unittest +import unittest from numba.core.base import OverloadSelector from numba.core.registry import cpu_target from numba.core.imputils import builtin_registry, RegistryLoader diff --git a/numba/tests/test_threadsafety.py b/numba/tests/test_threadsafety.py index 131f82719f9..19a974e244f 100644 --- a/numba/tests/test_threadsafety.py +++ b/numba/tests/test_threadsafety.py @@ -11,7 +11,7 @@ from numba.tests.support import temp_directory, override_config from numba.core import config -from numba.testing import unittest_support as unittest +import unittest def foo(n, v): diff --git a/numba/tests/test_tracing.py b/numba/tests/test_tracing.py index 7e134dc3082..0ab895efa2c 100644 --- a/numba/tests/test_tracing.py +++ b/numba/tests/test_tracing.py @@ -1,7 +1,7 @@ from io import StringIO import logging -import numba.testing.unittest_support as unittest +import unittest from numba.core import tracing logger = logging.getLogger('trace') diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index c29166097f3..4f4fadbaea7 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -7,7 +7,7 @@ from numba import njit, jit from numba.core import types, errors, utils from numba.tests.support import TestCase, MemoryLeakMixin, tag -from numba.testing import unittest_support as unittest +import unittest Rect = collections.namedtuple('Rect', ('width', 'height')) diff --git a/numba/tests/test_typeconv.py b/numba/tests/test_typeconv.py index 402c5856dc6..8e09ae76b67 100644 --- a/numba/tests/test_typeconv.py +++ b/numba/tests/test_typeconv.py @@ -4,7 +4,7 @@ from numba.core.typeconv.typeconv import TypeManager, TypeCastingRules from numba.core.typeconv import rules from numba.core.typeconv import castgraph, Conversion -from numba.testing import unittest_support as unittest +import unittest class CompatibilityTestMixin(unittest.TestCase): diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py index 597b1c73fd6..1ff196d0bef 100644 --- a/numba/tests/test_typeinfer.py +++ b/numba/tests/test_typeinfer.py @@ -10,7 +10,7 @@ from numba.tests.support import TestCase, tag from numba.tests.test_typeconv import CompatibilityTestMixin -from numba.testing import unittest_support as unittest +import unittest i8 = types.int8 diff --git a/numba/tests/test_typenames.py b/numba/tests/test_typenames.py index 1167ee2664f..531a8929747 100644 --- a/numba/tests/test_typenames.py +++ b/numba/tests/test_typenames.py @@ -1,7 +1,7 @@ import numpy as np from numba.core import types -from numba.testing import unittest_support as unittest +import unittest class TestTypeNames(unittest.TestCase): diff --git a/numba/tests/test_typeof.py b/numba/tests/test_typeof.py index 1761270c2b6..9ee172e6892 100644 --- a/numba/tests/test_typeof.py +++ b/numba/tests/test_typeof.py @@ -8,7 +8,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest import numba.core.typing.cffi_utils as cffi_support from numba.core import types from numba.misc.special import typeof diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 3e17b09ce83..826e69977bd 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -24,7 +24,7 @@ NativeValue, typeof_impl) from numba.tests.support import TestCase, temp_directory from numba.tests.enum_usecases import Color, Shake, Shape -from numba.testing import unittest_support as unittest +import unittest from numba.np import numpy_support diff --git a/numba/tests/test_typingerror.py b/numba/tests/test_typingerror.py index 66576bcc5fc..ee2b58b1118 100644 --- a/numba/tests/test_typingerror.py +++ b/numba/tests/test_typingerror.py @@ -5,7 +5,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated from numba import jit from numba.core import types diff --git a/numba/tests/test_ufuncs.py b/numba/tests/test_ufuncs.py index aed430f8302..dd6e384e96c 100644 --- a/numba/tests/test_ufuncs.py +++ b/numba/tests/test_ufuncs.py @@ -8,7 +8,7 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import typeof, njit from numba.core import types, typing, utils from numba.core.compiler import compile_isolated, Flags, DEFAULT_FLAGS diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index b582279a158..286e99693f9 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -4,7 +4,7 @@ from numba import njit from numba.core import types, utils -import numba.testing.unittest_support as unittest +import unittest from numba.tests.support import (TestCase, no_pyobj_flags, MemoryLeakMixin) from numba.core.errors import TypingError diff --git a/numba/tests/test_unicode_array.py b/numba/tests/test_unicode_array.py index 04603d285bc..e57a808c1a5 100644 --- a/numba/tests/test_unicode_array.py +++ b/numba/tests/test_unicode_array.py @@ -1,7 +1,7 @@ import platform import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import jit, from_dtype from numba.core import types, utils from numba.typed import Dict diff --git a/numba/tests/test_unpack_sequence.py b/numba/tests/test_unpack_sequence.py index 08c86268180..939dbe00554 100644 --- a/numba/tests/test_unpack_sequence.py +++ b/numba/tests/test_unpack_sequence.py @@ -1,6 +1,6 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import errors, types from numba import typeof diff --git a/numba/tests/test_usecases.py b/numba/tests/test_usecases.py index 4776117a7ea..6800105beb9 100644 --- a/numba/tests/test_usecases.py +++ b/numba/tests/test_usecases.py @@ -1,7 +1,7 @@ import itertools import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core.compiler import compile_isolated, Flags from numba.core import types, utils from numba.tests import usecases diff --git a/numba/tests/test_vectorization_type_inference.py b/numba/tests/test_vectorization_type_inference.py index c1ba840c4a0..0cb3adbeb43 100644 --- a/numba/tests/test_vectorization_type_inference.py +++ b/numba/tests/test_vectorization_type_inference.py @@ -1,5 +1,5 @@ from numba import vectorize, jit, bool_, double, int_, float_, typeof, int8 -import numba.testing.unittest_support as unittest +import unittest import numpy as np diff --git a/numba/tests/test_warnings.py b/numba/tests/test_warnings.py index e8809b9d08d..49cd5144dd9 100644 --- a/numba/tests/test_warnings.py +++ b/numba/tests/test_warnings.py @@ -4,7 +4,7 @@ import warnings import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba import jit from numba.core.errors import NumbaWarning, deprecated, NumbaDeprecationWarning from numba.core import errors diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index a2f8e70dd0f..6bc3c960d7c 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -14,7 +14,7 @@ from numba.core.extending import overload from numba.tests.support import (MemoryLeak, TestCase, captured_stdout, skip_unless_scipy) -from numba.testing import unittest_support as unittest +import unittest def get_func_ir(func): diff --git a/numba/tests/test_wrapper.py b/numba/tests/test_wrapper.py index 73aae932e53..b26a804ac7d 100644 --- a/numba/tests/test_wrapper.py +++ b/numba/tests/test_wrapper.py @@ -1,6 +1,6 @@ import numpy as np -import numba.testing.unittest_support as unittest +import unittest from numba.core import types, utils, compiler, registry From 9e9200f178c0b408a030ab732fc7bbf5e5fb7d85 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 15:45:08 +0000 Subject: [PATCH 457/595] Move numba.runtime to numba.core.runtime --- examples/binarytree.py | 2 +- examples/linkedlist.py | 2 +- examples/stack.py | 2 +- numba/_arraystruct.h | 2 +- numba/core/base.py | 2 +- numba/core/codegen.py | 4 ++-- numba/core/cpu.py | 2 +- numba/{ => core}/runtime/__init__.py | 0 numba/{ => core}/runtime/_nrt_python.c | 4 ++-- numba/{ => core}/runtime/_nrt_pythonmod.c | 0 numba/{ => core}/runtime/context.py | 4 ++-- numba/{ => core}/runtime/nrt.c | 2 +- numba/{ => core}/runtime/nrt.h | 2 +- numba/{ => core}/runtime/nrt.py | 4 ++-- numba/{ => core}/runtime/nrt_external.h | 0 numba/{ => core}/runtime/nrtdynmod.py | 0 numba/{ => core}/runtime/nrtopt.py | 0 numba/core/unsafe/refcount.py | 2 +- numba/experimental/jitclass/_box.c | 8 ++++---- numba/pycc/compiler.py | 2 +- numba/tests/support.py | 2 +- numba/tests/test_jitclasses.py | 2 +- numba/tests/test_nrt.py | 6 +++--- numba/tests/test_nrt_refct.py | 2 +- setup.py | 10 +++++----- 25 files changed, 33 insertions(+), 33 deletions(-) rename numba/{ => core}/runtime/__init__.py (100%) rename numba/{ => core}/runtime/_nrt_python.c (99%) rename numba/{ => core}/runtime/_nrt_pythonmod.c (100%) rename numba/{ => core}/runtime/context.py (98%) rename numba/{ => core}/runtime/nrt.c (99%) rename numba/{ => core}/runtime/nrt.h (99%) rename numba/{ => core}/runtime/nrt.py (97%) rename numba/{ => core}/runtime/nrt_external.h (100%) rename numba/{ => core}/runtime/nrtdynmod.py (100%) rename numba/{ => core}/runtime/nrtopt.py (100%) diff --git a/examples/binarytree.py b/examples/binarytree.py index 46d1ccd1605..f1b9f8afe35 100755 --- a/examples/binarytree.py +++ b/examples/binarytree.py @@ -11,7 +11,7 @@ from collections import OrderedDict from numba import njit from numba import int32, deferred_type, optional -from numba.runtime import rtsys +from numba.core.runtime import rtsys from numba.experimental import jitclass node_type = deferred_type() diff --git a/examples/linkedlist.py b/examples/linkedlist.py index 107bfb7cc90..0de103a71a1 100755 --- a/examples/linkedlist.py +++ b/examples/linkedlist.py @@ -10,7 +10,7 @@ import numpy as np from numba import njit from numba import int32, deferred_type, optional -from numba.runtime import rtsys +from numba.core.runtime import rtsys from numba.experimental import jitclass node_type = deferred_type() diff --git a/examples/stack.py b/examples/stack.py index 6fafcc618aa..a714906d88f 100755 --- a/examples/stack.py +++ b/examples/stack.py @@ -12,7 +12,7 @@ from collections import OrderedDict from numba import njit from numba import deferred_type, intp, optional -from numba.runtime import rtsys +from numba.core.runtime import rtsys from numba.experimental import jitclass diff --git a/numba/_arraystruct.h b/numba/_arraystruct.h index 0db07cbbffb..dcb866e2bac 100644 --- a/numba/_arraystruct.h +++ b/numba/_arraystruct.h @@ -7,7 +7,7 @@ */ typedef struct { - void *meminfo; /* see _nrt_python.c and nrt.h in numba/runtime */ + void *meminfo; /* see _nrt_python.c and nrt.h in numba/core/runtime */ PyObject *parent; npy_intp nitems; npy_intp itemsize; diff --git a/numba/core/base.py b/numba/core/base.py index cef3d781406..331c4e559ee 100644 --- a/numba/core/base.py +++ b/numba/core/base.py @@ -337,7 +337,7 @@ def target_data(self): @utils.cached_property def nrt(self): - from numba.runtime.context import NRTContext + from numba.core.runtime.context import NRTContext return NRTContext(self, self.enable_nrt) def subtarget(self, **kws): diff --git a/numba/core/codegen.py b/numba/core/codegen.py index e0752be9a4e..41721ea2114 100644 --- a/numba/core/codegen.py +++ b/numba/core/codegen.py @@ -10,8 +10,8 @@ import llvmlite.ir as llvmir from numba.core import utils, config, cgutils -from numba.runtime.nrtopt import remove_redundant_nrt_refct -from numba.runtime import rtsys +from numba.core.runtime.nrtopt import remove_redundant_nrt_refct +from numba.core.runtime import rtsys from numba.core.compiler_lock import require_global_compiler_lock _x86arch = frozenset(['x86', 'i386', 'i486', 'i586', 'i686', 'i786', diff --git a/numba/core/cpu.py b/numba/core/cpu.py index 9601f5d00a0..aceef0efac8 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -10,7 +10,7 @@ from numba.core import utils, types, config, cgutils, callconv, codegen, externals, fastmathpass, intrinsics from numba.core.utils import cached_property from numba.core.options import TargetOptions -from numba.runtime import rtsys +from numba.core.runtime import rtsys from numba.core.compiler_lock import global_compiler_lock import numba.core.entrypoints from numba.core.cpu_options import (ParallelOptions, FastMathOptions, diff --git a/numba/runtime/__init__.py b/numba/core/runtime/__init__.py similarity index 100% rename from numba/runtime/__init__.py rename to numba/core/runtime/__init__.py diff --git a/numba/runtime/_nrt_python.c b/numba/core/runtime/_nrt_python.c similarity index 99% rename from numba/runtime/_nrt_python.c rename to numba/core/runtime/_nrt_python.c index 0a270dfaba7..97f7f19efb3 100644 --- a/numba/runtime/_nrt_python.c +++ b/numba/core/runtime/_nrt_python.c @@ -3,13 +3,13 @@ * This module is included by _nrt_pythonmod.c and by pycc-compiled modules. */ -#include "../_pymodule.h" +#include "../../_pymodule.h" #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include #include -#include "../_arraystruct.h" +#include "../../_arraystruct.h" #include "nrt.h" diff --git a/numba/runtime/_nrt_pythonmod.c b/numba/core/runtime/_nrt_pythonmod.c similarity index 100% rename from numba/runtime/_nrt_pythonmod.c rename to numba/core/runtime/_nrt_pythonmod.c diff --git a/numba/runtime/context.py b/numba/core/runtime/context.py similarity index 98% rename from numba/runtime/context.py rename to numba/core/runtime/context.py index 02c0f3148db..2e887e41dec 100644 --- a/numba/runtime/context.py +++ b/numba/core/runtime/context.py @@ -170,7 +170,7 @@ def meminfo_data(self, builder, meminfo): """ self._require_nrt() - from numba.runtime.nrtdynmod import meminfo_data_ty + from numba.core.runtime.nrtdynmod import meminfo_data_ty mod = builder.module fn = mod.get_or_insert_function(meminfo_data_ty, @@ -199,7 +199,7 @@ def _call_incref_decref(self, builder, typ, value, funcname): """ self._require_nrt() - from numba.runtime.nrtdynmod import incref_decref_ty + from numba.core.runtime.nrtdynmod import incref_decref_ty meminfos = self.get_meminfos(builder, typ, value) for _, mi in meminfos: diff --git a/numba/runtime/nrt.c b/numba/core/runtime/nrt.c similarity index 99% rename from numba/runtime/nrt.c rename to numba/core/runtime/nrt.c index 2e541bd5adb..534681d5417 100644 --- a/numba/runtime/nrt.c +++ b/numba/core/runtime/nrt.c @@ -12,7 +12,7 @@ typedef int (*atomic_meminfo_cas_func)(void **ptr, void *cmp, void *repl, void **oldptr); -/* NOTE: if changing the layout, please update numba.runtime.atomicops */ +/* NOTE: if changing the layout, please update numba.core.runtime.atomicops */ struct MemInfo { size_t refct; NRT_dtor_function dtor; diff --git a/numba/runtime/nrt.h b/numba/core/runtime/nrt.h similarity index 99% rename from numba/runtime/nrt.h rename to numba/core/runtime/nrt.h index 6223fe9a924..3c74dc58f58 100644 --- a/numba/runtime/nrt.h +++ b/numba/core/runtime/nrt.h @@ -8,7 +8,7 @@ All functions described here are threadsafe. #include #include -#include "../_numba_common.h" +#include "../../_numba_common.h" #include "nrt_external.h" diff --git a/numba/runtime/nrt.py b/numba/core/runtime/nrt.py similarity index 97% rename from numba/runtime/nrt.py rename to numba/core/runtime/nrt.py index 53531789393..14f119ea983 100644 --- a/numba/runtime/nrt.py +++ b/numba/core/runtime/nrt.py @@ -1,13 +1,13 @@ from collections import namedtuple from weakref import finalize as _finalize -from numba.runtime import nrtdynmod +from numba.core.runtime import nrtdynmod from llvmlite import binding as ll from numba.core.compiler_lock import global_compiler_lock from numba.core.typing.typeof import typeof_impl from numba.core import types -from numba.runtime import _nrt_python as _nrt +from numba.core.runtime import _nrt_python as _nrt _nrt_mstats = namedtuple("nrt_mstats", ["alloc", "free", "mi_alloc", "mi_free"]) diff --git a/numba/runtime/nrt_external.h b/numba/core/runtime/nrt_external.h similarity index 100% rename from numba/runtime/nrt_external.h rename to numba/core/runtime/nrt_external.h diff --git a/numba/runtime/nrtdynmod.py b/numba/core/runtime/nrtdynmod.py similarity index 100% rename from numba/runtime/nrtdynmod.py rename to numba/core/runtime/nrtdynmod.py diff --git a/numba/runtime/nrtopt.py b/numba/core/runtime/nrtopt.py similarity index 100% rename from numba/runtime/nrtopt.py rename to numba/core/runtime/nrtopt.py diff --git a/numba/core/unsafe/refcount.py b/numba/core/unsafe/refcount.py index 4c6aaee853d..226d1776a6e 100644 --- a/numba/core/unsafe/refcount.py +++ b/numba/core/unsafe/refcount.py @@ -6,7 +6,7 @@ from numba.core import types, cgutils from numba.core.extending import intrinsic -from numba.runtime.nrtdynmod import _meminfo_struct_type +from numba.core.runtime.nrtdynmod import _meminfo_struct_type @intrinsic diff --git a/numba/experimental/jitclass/_box.c b/numba/experimental/jitclass/_box.c index 777a826ad4a..bf49de4fca8 100644 --- a/numba/experimental/jitclass/_box.c +++ b/numba/experimental/jitclass/_box.c @@ -9,7 +9,7 @@ typedef struct { } BoxObject; -/* Store function defined in numba.runtime._nrt_python for use in box_dealloc. +/* Store function defined in numba.core.runtime._nrt_python for use in box_dealloc. * It points to a function is code segment that does not need user deallocation * and does not disappear while the process is stil running. */ @@ -92,7 +92,7 @@ static PyTypeObject BoxType = { }; -/* Import MemInfo_Release from numba.runtime._nrt_python once for use in +/* Import MemInfo_Release from numba.core.runtime._nrt_python once for use in * Box_dealloc. */ static void * @@ -101,8 +101,8 @@ import_meminfo_release(void) { PyObject *helperdct = NULL; PyObject *mi_rel_fn = NULL; void *fnptr = NULL; - /* from numba.runtime import _nrt_python */ - nrtmod = PyImport_ImportModule("numba.runtime._nrt_python"); + /* from numba.core.runtime import _nrt_python */ + nrtmod = PyImport_ImportModule("numba.core.runtime._nrt_python"); if (!nrtmod) goto cleanup; /* helperdct = _nrt_python.c_helpers */ helperdct = PyObject_GetAttrString(nrtmod, "c_helpers"); diff --git a/numba/pycc/compiler.py b/numba/pycc/compiler.py index 4b2ec495625..7a99195178d 100644 --- a/numba/pycc/compiler.py +++ b/numba/pycc/compiler.py @@ -13,7 +13,7 @@ from numba.core.compiler_lock import global_compiler_lock from numba.core.registry import cpu_target -from numba.runtime import nrtdynmod +from numba.core.runtime import nrtdynmod from numba.core import cgutils diff --git a/numba/tests/support.py b/numba/tests/support.py index 3717993e184..d63d3b742cb 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -27,7 +27,7 @@ from numba.core import errors, typing, utils, config, cpu from numba.core.compiler import compile_extra, compile_isolated, Flags, DEFAULT_FLAGS import unittest -from numba.runtime import rtsys +from numba.core.runtime import rtsys from numba.np import numpy_support diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py index 486b38183c9..ab98ec6c2b0 100644 --- a/numba/tests/test_jitclasses.py +++ b/numba/tests/test_jitclasses.py @@ -11,7 +11,7 @@ from numba.core import types, errors from numba.tests.support import TestCase, MemoryLeakMixin from numba.experimental.jitclass import _box -from numba.runtime.nrt import MemInfo +from numba.core.runtime.nrt import MemInfo from numba.core.errors import LoweringError from numba.experimental import jitclass import unittest diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index 7c91a8ccc7d..ee753dc8b5b 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -9,7 +9,7 @@ from numba import njit from numba.core import typing, types from numba.core.compiler import compile_isolated, Flags -from numba.runtime import ( +from numba.core.runtime import ( rtsys, nrtopt, _nrt_python, @@ -581,7 +581,7 @@ def test_manage_memory(self): name = "{}_test_manage_memory".format(self.__class__.__name__) source = r""" #include -#include "numba/runtime/nrt_external.h" +#include "numba/core/runtime/nrt_external.h" int status = 0; @@ -622,7 +622,7 @@ def test_allocate(self): name = "{}_test_allocate".format(self.__class__.__name__) source = r""" #include -#include "numba/runtime/nrt_external.h" +#include "numba/core/runtime/nrt_external.h" NRT_MemInfo* test_nrt_api(NRT_api_functions *nrt, size_t n) { size_t *data = NULL; diff --git a/numba/tests/test_nrt_refct.py b/numba/tests/test_nrt_refct.py index 17f8712d73a..9b05f6ebed4 100644 --- a/numba/tests/test_nrt_refct.py +++ b/numba/tests/test_nrt_refct.py @@ -9,7 +9,7 @@ import unittest from numba import njit -from numba.runtime import rtsys +from numba.core.runtime import rtsys from numba.tests.support import TestCase diff --git a/setup.py b/setup.py index f08d7c95f7b..9ed18d1c9da 100644 --- a/setup.py +++ b/setup.py @@ -271,12 +271,12 @@ def check_file_at_path(path2file): extra_link_args=install_name_tool_fixer, sources=['numba/mviewbuf.c']) - ext_nrt_python = Extension(name='numba.runtime._nrt_python', - sources=['numba/runtime/_nrt_pythonmod.c', - 'numba/runtime/nrt.c'], - depends=['numba/runtime/nrt.h', + ext_nrt_python = Extension(name='numba.core.runtime._nrt_python', + sources=['numba/core/runtime/_nrt_pythonmod.c', + 'numba/core/runtime/nrt.c'], + depends=['numba/core/runtime/nrt.h', 'numba/_pymodule.h', - 'numba/runtime/_nrt_python.c'], + 'numba/core/runtime/_nrt_python.c'], **np_compile_args) ext_jitclass_box = Extension(name='numba.experimental.jitclass._box', From e50569bd67785e03b0a03a6faf15635910a0a042 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 18:06:24 +0000 Subject: [PATCH 458/595] Fix pycc --- numba/pycc/cc.py | 2 +- numba/pycc/modulemixin.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/numba/pycc/cc.py b/numba/pycc/cc.py index 25e4f64ff28..5a9fa817936 100644 --- a/numba/pycc/cc.py +++ b/numba/pycc/cc.py @@ -154,7 +154,7 @@ def _get_mixin_sources(self): here = os.path.dirname(__file__) mixin_sources = self._mixin_sources[:] if self._use_nrt: - mixin_sources.append('../runtime/nrt.c') + mixin_sources.append('../core/runtime/nrt.c') return [os.path.join(here, f) for f in mixin_sources] def _get_mixin_defines(self): diff --git a/numba/pycc/modulemixin.c b/numba/pycc/modulemixin.c index 6b45e85e92c..1aa3dbb6657 100644 --- a/numba/pycc/modulemixin.c +++ b/numba/pycc/modulemixin.c @@ -17,8 +17,8 @@ #include "../_dynfunc.c" #if PYCC_USE_NRT -#include "../runtime/_nrt_python.c" -#include "../runtime/nrt.h" +#include "../core/runtime/_nrt_python.c" +#include "../core/runtime/nrt.h" #endif From e171e8ca58002ab3109154b50e44c8c6b99bb5f8 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 18:08:53 +0000 Subject: [PATCH 459/595] Fix error handling --- numba/tests/test_errorhandling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_errorhandling.py b/numba/tests/test_errorhandling.py index c2dd267f877..1e54080f13f 100644 --- a/numba/tests/test_errorhandling.py +++ b/numba/tests/test_errorhandling.py @@ -110,7 +110,7 @@ def define_pipelines(self): pm.finalize() return [pm] - @numba.jit(pipeline_class=TestPipeline) + @njit(pipeline_class=TestPipeline) def f(a): return 0 From 2ed49ba62afcf11956c0facae252df0f340ba2a9 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 18:11:15 +0000 Subject: [PATCH 460/595] Fix help.inspector --- numba/tests/test_help.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_help.py b/numba/tests/test_help.py index 8db0695538e..a78f05f0a3c 100644 --- a/numba/tests/test_help.py +++ b/numba/tests/test_help.py @@ -57,7 +57,7 @@ def test_inspect_module(self): def test_inspect_cli(self): # Try CLI on math module - cmdbase = [sys.executable, '-m', 'numba.help.inspector'] + cmdbase = [sys.executable, '-m', 'numba.misc.help.inspector'] dirpath = temp_directory('{}.{}'.format(__name__, self.__class__.__name__)) From 919a1ed87eddc30e7a2645235c309a4ca171eccb Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 18:12:39 +0000 Subject: [PATCH 461/595] Fix up test_import --- numba/tests/test_import.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/numba/tests/test_import.py b/numba/tests/test_import.py index 19b477ddc22..2d8fff741e7 100644 --- a/numba/tests/test_import.py +++ b/numba/tests/test_import.py @@ -19,17 +19,16 @@ def test_laziness(self): 'cffi', 'distutils', 'numba.cuda', - 'numba.hsa', - 'numba.targets.mathimpl', - 'numba.targets.randomimpl', + 'numba.cpython.mathimpl', + 'numba.cpython.randomimpl', 'numba.tests', - 'numba.typing.collections', - 'numba.typing.listdecl', - 'numba.typing.npdatetime', + 'numba.core.typing.collections', + 'numba.core.typing.listdecl', + 'numba.core.typing.npdatetime', ] # Sanity check the modules still exist... for mod in blacklist: - if mod not in ('cffi', 'numba.hsa'): + if mod not in ('cffi',): __import__(mod) code = """if 1: From 246804bd48b1ac4ac6f83d2f356725bf87cdb797 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 18:14:34 +0000 Subject: [PATCH 462/595] Fix up test_jit_module --- numba/tests/test_jit_module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_jit_module.py b/numba/tests/test_jit_module.py index 39574a409ce..bab9b2efe96 100644 --- a/numba/tests/test_jit_module.py +++ b/numba/tests/test_jit_module.py @@ -159,7 +159,7 @@ def add(x, y): 'boundscheck': False}) def test_jit_module_logging_output(self): - logger = logging.getLogger('numba.decorators') + logger = logging.getLogger('numba.core.decorators') logger.setLevel(logging.DEBUG) jit_options = {"nopython": True, "error_model": "numpy", @@ -173,7 +173,7 @@ def test_jit_module_logging_output(self): self.assertTrue(all(i in logs for i in expected)) def test_jit_module_logging_level(self): - logger = logging.getLogger('numba.decorators') + logger = logging.getLogger('numba.core.decorators') # Test there's no logging for INFO level logger.setLevel(logging.INFO) with captured_logs(logger) as logs: From 75f89f21897c8f7eb57e2c8b8cb75497d4da4f73 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 18:20:16 +0000 Subject: [PATCH 463/595] Fix test_comprehension --- numba/tests/test_comprehension.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py index b05badc4110..615c77a5086 100644 --- a/numba/tests/test_comprehension.py +++ b/numba/tests/test_comprehension.py @@ -274,7 +274,7 @@ def comp_with_array_noinline(n): l = np.array([i + m for i in range(n)]) return l - import numba.inline_closurecall as ic + import numba.core.inline_closurecall as ic try: ic.enable_inline_arraycall = False self.check(comp_with_array_noinline, 5, assert_allocate_list=True) @@ -304,7 +304,7 @@ def comp_nest_with_array_noinline(n): l = np.array([[i * j for j in range(n)] for i in range(n)]) return l - import numba.inline_closurecall as ic + import numba.core.inline_closurecall as ic try: ic.enable_inline_arraycall = False self.check(comp_nest_with_array_noinline, 5, From d1c880cd297d2aa1940e86abed1f0d9952329e20 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 4 Feb 2020 18:22:05 +0000 Subject: [PATCH 464/595] Fix test_inlining --- numba/tests/test_inlining.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index e5d65b910aa..c0ba1ef2cf2 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -5,7 +5,8 @@ skip_parfors_unsupported) from numba import jit, njit from numba.core import types, ir, postproc, compiler -from numba.core.ir_utils import guard, find_callname, find_const, get_definition +from numba.core.ir_utils import (guard, find_callname, find_const, + get_definition, simplify_CFG) from numba.core.registry import CPUDispatcher from numba.core.inline_closurecall import inline_closure_call @@ -203,7 +204,7 @@ def test_impl(a): def test_inline_var_dict_ret(self): # make sure inline_closure_call returns the variable replacement dict # and it contains the original variable name used in locals - @numba.njit(locals={'b': numba.float64}) + @njit(locals={'b': types.float64}) def g(a): b = a + 1 return b @@ -278,7 +279,7 @@ def define_pipelines(self): # make sure IR doesn't have branches fir = j_func.overloads[(types.Omitted(None),)].metadata['preserved_ir'] - fir.blocks = numba.ir_utils.simplify_CFG(fir.blocks) + fir.blocks = simplify_CFG(fir.blocks) self.assertEqual(len(fir.blocks), 1) if __name__ == '__main__': From cb880491b7a2aa808b6735b939d5562463161a2f Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 4 Feb 2020 12:43:49 -0600 Subject: [PATCH 465/595] Fix dictimpl import --- numba/core/cpu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/core/cpu.py b/numba/core/cpu.py index aceef0efac8..6d2564a734d 100644 --- a/numba/core/cpu.py +++ b/numba/core/cpu.py @@ -57,6 +57,7 @@ def init(self): # Initialize additional implementations import numba.cpython.unicode + import numba.typed.dictimpl def load_additional_registries(self): # Add target specific implementations From 97a6d902b15a01809adb4e851a3f338d286c31bb Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 4 Feb 2020 18:30:28 -0600 Subject: [PATCH 466/595] Fix up array_analysis --- numba/parfors/array_analysis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index 5e41ffcdd31..85a87c5878e 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -778,7 +778,7 @@ def minus(x, y): if expr.op == 'call': fname, mod_name = find_callname( func_ir, expr, typemap=self.typemap) - if fname == 'wrap_index' and mod_name == 'numba.array_analysis': + if fname == 'wrap_index' and mod_name == 'numba.parfors.array_analysis': index = tuple(self.obj_to_ind.get(x.name, -1) for x in expr.args) if -1 in index: @@ -1779,12 +1779,12 @@ def _analyze_op_call_builtins_len(self, scope, equiv_set, args, kws): shape = equiv_set._get_shape(var) return shape[0], [], shape[0] - def _analyze_op_call_numba_array_analysis_assert_equiv(self, scope, + def _analyze_op_call_numba_parfors_array_analysis_assert_equiv(self, scope, equiv_set, args, kws): equiv_set.insert_equiv(*args[1:]) return None - def _analyze_op_call_numba_array_analysis_wrap_index(self, scope, + def _analyze_op_call_numba_parfors_array_analysis_wrap_index(self, scope, equiv_set, args, kws): """ Analyze wrap_index calls added by a previous run of Array Analysis From 40ceb84f7c117e82681aea393988c85cd7452fba Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 5 Feb 2020 12:20:05 +0000 Subject: [PATCH 467/595] Fix test_indexing --- numba/tests/test_indexing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/tests/test_indexing.py b/numba/tests/test_indexing.py index 1ced6c4dd1c..bedc1f05f6b 100644 --- a/numba/tests/test_indexing.py +++ b/numba/tests/test_indexing.py @@ -8,6 +8,8 @@ from numba import njit, typeof from numba.core import utils, types, errors from numba.tests.support import TestCase, tag +from numba.core.typing import arraydecl +from numba.core.types import intp, ellipsis, slice2_type, slice3_type enable_pyobj_flags = Flags() @@ -1065,8 +1067,6 @@ def test_layout(self): Check an appropriate layout is inferred for the result of array indexing. """ - from numba.typing import arraydecl - from numba.types import intp, ellipsis, slice2_type, slice3_type func = arraydecl.get_array_index_type From 4a1362b00e17daf43ad336f8cfe27fd32cec917a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 5 Feb 2020 15:34:32 +0000 Subject: [PATCH 468/595] Fix issue with nested stencil calls --- numba/core/inline_closurecall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 5faf7ca5ea4..8314ffd046d 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -168,7 +168,7 @@ def _inline_stencil(self, instr, call_name, func_def): expr.kws = func_def.value.kws return True # Otherwise we proceed to check if it is a call to numba.stencil - require(call_name == ('stencil', 'numba.stencil') or + require(call_name == ('stencil', 'numba.stencils.stencil') or call_name == ('stencil', 'numba')) require(expr not in self._processed_stencils) self._processed_stencils.append(expr) From 8f2bf280474b82356e7db6cf48c3c0975825e488 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 5 Feb 2020 16:05:13 +0000 Subject: [PATCH 469/595] Fix issue unsafe empty_inferred --- numba/parfors/array_analysis.py | 2 +- numba/tests/test_parfors.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/parfors/array_analysis.py b/numba/parfors/array_analysis.py index 85a87c5878e..0446fd92b75 100644 --- a/numba/parfors/array_analysis.py +++ b/numba/parfors/array_analysis.py @@ -1825,7 +1825,7 @@ def _analyze_numpy_create_array(self, scope, equiv_set, args, kws): def _analyze_op_call_numpy_empty(self, scope, equiv_set, args, kws): return self._analyze_numpy_create_array(scope, equiv_set, args, kws) - def _analyze_op_call_numba_unsafe_ndarray_empty_inferred(self, scope, + def _analyze_op_call_numba_np_unsafe_ndarray_empty_inferred(self, scope, equiv_set, args, kws): return self._analyze_numpy_create_array(scope, equiv_set, args, kws) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 541dd07e994..c07b6c50aae 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -412,7 +412,7 @@ def _count_array_allocs_inner(func_ir, block): and inst.value.op == 'call' and (guard(find_callname, func_ir, inst.value) == ('empty', 'numpy') or guard(find_callname, func_ir, inst.value) - == ('empty_inferred', 'numba.unsafe.ndarray'))): + == ('empty_inferred', 'numba.np.unsafe.ndarray'))): ret_count += 1 return ret_count From 1b27cd8bd8164563cd3c202b80116f6d5d24badb Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 5 Feb 2020 10:57:15 -0600 Subject: [PATCH 470/595] Fix import --- numba/cuda/tests/cudasim/test_cudasim_issues.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numba/cuda/tests/cudasim/test_cudasim_issues.py b/numba/cuda/tests/cudasim/test_cudasim_issues.py index 9b685237ee0..7aa0088ac75 100644 --- a/numba/cuda/tests/cudasim/test_cudasim_issues.py +++ b/numba/cuda/tests/cudasim/test_cudasim_issues.py @@ -16,7 +16,9 @@ def test_cuda_module_in_device_function(self): When the `cuda` module is referenced in a device function, it does not have the kernel API (e.g. cuda.threadIdx, cuda.shared) """ - from numba.tests.support import cuda_module_in_device_function as inner + from numba.cuda.tests.cudasim import support + + inner = support.cuda_module_in_device_function @cuda.jit def outer(out): From 0d5e30f385dbe2997ae799dd530cf0c44c66cf50 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 5 Feb 2020 16:43:37 +0000 Subject: [PATCH 471/595] Fix flake8 file --- .flake8 | 211 +++++++++++++++++++++++++++----------------------------- 1 file changed, 102 insertions(+), 109 deletions(-) diff --git a/.flake8 b/.flake8 index 003d5fc85e5..657acca04b5 100644 --- a/.flake8 +++ b/.flake8 @@ -21,90 +21,83 @@ exclude = *.h __init__.py # Grandfather in existing failing files. This list should shrink over time - numba/dispatcher.py - numba/serialize.py - numba/funcdesc.py - numba/postproc.py - numba/stencil.py - numba/smartarray.py - numba/transforms.py - numba/tracing.py - numba/ctypes_support.py - numba/withcontexts.py + numba/core/dispatcher.py + numba/core/serialize.py + numba/core/funcdesc.py + numba/core/postproc.py + numba/stencils/stencil.py + numba/core/transforms.py + numba/core/tracing.py + numba/core/withcontexts.py numba/_version.py - numba/inline_closurecall.py - numba/ir_utils.py - numba/pylowering.py + numba/core/inline_closurecall.py + numba/core/ir_utils.py + numba/core/pylowering.py numba/python_utils.py - numba/io_support.py - numba/parfor.py - numba/numba_entry.py - numba/stencilparfor.py - numba/ir.py - numba/itanium_mangler.py - numba/unittest_support.py - numba/array_analysis.py - numba/generators.py - numba/appdirs.py + numba/parfors/parfor.py + numba/misc/numba_entry.py + numba/stencils/stencilparfor.py + numba/core/ir.py + numba/core/itanium_mangler.py + numba/parfors/array_analysis.py + numba/core/generators.py + numba/misc/appdirs.py numba/cffi_support.py - numba/interpreter.py - numba/caching.py - numba/debuginfo.py - numba/pretty_annotate.py - numba/six.py - numba/dummyarray.py - numba/dataflow.py - numba/macro.py + numba/core/interpreter.py + numba/core/caching.py + numba/core/debuginfo.py + numba/core/annotations/pretty_annotate.py + numba/misc/dummyarray.py + numba/core/dataflow.py numba/runtests.py - numba/pythonapi.py + numba/core/pythonapi.py numba/extending.py - numba/decorators.py - numba/typeconv/typeconv.py - numba/typeconv/rules.py - numba/typeconv/castgraph.py - numba/rewrites/registry.py - numba/rewrites/macros.py - numba/rewrites/static_binop.py - numba/rewrites/ir_print.py - numba/types/abstract.py - numba/types/functions.py - numba/types/misc.py - numba/types/containers.py - numba/types/npytypes.py - numba/types/common.py - numba/types/iterators.py - numba/types/scalars.py - numba/targets/fastmathpass.py - numba/targets/setobj.py - numba/targets/options.py - numba/targets/printimpl.py - numba/targets/smartarray.py - numba/targets/cmathimpl.py - numba/targets/tupleobj.py - numba/targets/mathimpl.py - numba/targets/registry.py - numba/targets/imputils.py - numba/targets/builtins.py - numba/targets/cpu.py - numba/targets/quicksort.py - numba/targets/callconv.py - numba/targets/randomimpl.py - numba/targets/npyimpl.py - numba/targets/slicing.py - numba/targets/numbers.py - numba/targets/listobj.py - numba/targets/removerefctpass.py - numba/targets/boxing.py - numba/targets/cffiimpl.py - numba/targets/linalg.py - numba/targets/rangeobj.py - numba/targets/npyfuncs.py - numba/targets/iterators.py - numba/targets/codegen.py - numba/targets/polynomial.py - numba/targets/mergesort.py - numba/targets/base.py - numba/targets/npdatetime.py + numba/core/decorators.py + numba/core/typeconv/typeconv.py + numba/core/typeconv/rules.py + numba/core/typeconv/castgraph.py + numba/core/rewrites/registry.py + numba/core/rewrites/macros.py + numba/core/rewrites/static_binop.py + numba/core/rewrites/ir_print.py + numba/core/types/abstract.py + numba/core/types/functions.py + numba/core/types/misc.py + numba/core/types/containers.py + numba/core/types/npytypes.py + numba/core/types/common.py + numba/core/types/iterators.py + numba/core/types/scalars.py + numba/core/fastmathpass.py + numba/cpython/setobj.py + numba/core/options.py + numba/cpython/printimpl.py + numba/cpython/cmathimpl.py + numba/cpython/tupleobj.py + numba/cpython/mathimpl.py + numba/core/registry.py + numba/core/imputils.py + numba/cpython/builtins.py + numba/core/cpu.py + numba/misc/quicksort.py + numba/core/callconv.py + numba/cpython/randomimpl.py + numba/np/npyimpl.py + numba/cpython/slicing.py + numba/cpython/numbers.py + numba/cpython/listobj.py + numba/core/removerefctpass.py + numba/core/boxing.py + numba/misc/cffiimpl.py + numba/np/linalg.py + numba/cpython/rangeobj.py + numba/np/npyfuncs.py + numba/cpython/iterators.py + numba/core/codegen.py + numba/np/polynomial.py + numba/misc/mergesort.py + numba/core/base.py + numba/np/npdatetime.py numba/cuda/dispatcher.py numba/cuda/printimpl.py numba/cuda/libdevice.py @@ -198,8 +191,8 @@ exclude = numba/pycc/llvm_types.py numba/pycc/platform.py numba/pycc/decorators.py - numba/runtime/nrtdynmod.py - numba/runtime/context.py + numba/core/runtime/nrtdynmod.py + numba/core/runtime/context.py numba/tests/test_support.py numba/tests/test_llvm_version_check.py numba/tests/test_builtins.py @@ -313,7 +306,7 @@ exclude = numba/tests/pdlike_usecase.py numba/tests/test_range.py numba/tests/test_nrt_refct.py - numba/tests/timsort.py + numba/misc/timsort.py numba/tests/test_nested_calls.py numba/tests/test_chained_assign.py numba/tests/test_withlifting.py @@ -332,22 +325,22 @@ exclude = numba/tests/npyufunc/test_parallel_ufunc_issues.py numba/tests/npyufunc/test_parallel_env_variable.py numba/tests/npyufunc/test_gufunc.py - numba/typing/cmathdecl.py - numba/typing/bufproto.py - numba/typing/mathdecl.py - numba/typing/listdecl.py - numba/typing/builtins.py - numba/typing/randomdecl.py - numba/typing/setdecl.py - numba/typing/npydecl.py - numba/typing/arraydecl.py - numba/typing/collections.py - numba/typing/ctypes_utils.py - numba/typing/enumdecl.py - numba/typing/cffi_utils.py - numba/typing/typeof.py - numba/typing/npdatetime.py - numba/annotations/type_annotations.py + numba/core/typing/cmathdecl.py + numba/core/typing/bufproto.py + numba/core/typing/mathdecl.py + numba/core/typing/listdecl.py + numba/core/typing/builtins.py + numba/core/typing/randomdecl.py + numba/core/typing/setdecl.py + numba/core/typing/npydecl.py + numba/core/typing/arraydecl.py + numba/core/typing/collections.py + numba/core/typing/ctypes_utils.py + numba/core/typing/enumdecl.py + numba/core/typing/cffi_utils.py + numba/core/typing/typeof.py + numba/core/typing/npdatetime.py + numba/core/annotations/type_annotations.py numba/roc/mathdecl.py numba/roc/compiler.py numba/roc/hsadecl.py @@ -388,14 +381,14 @@ exclude = numba/testing/loader.py numba/testing/notebook.py numba/testing/main.py - numba/unsafe/ndarray.py - numba/npyufunc/deviceufunc.py - numba/npyufunc/sigparse.py - numba/npyufunc/parfor.py - numba/npyufunc/array_exprs.py - numba/npyufunc/decorators.py - numba/servicelib/service.py - numba/datamodel/models.py - numba/datamodel/packer.py - numba/datamodel/testing.py - numba/datamodel/manager.py + numba/np/unsafe/ndarray.py + numba/np/ufunc/deviceufunc.py + numba/np/ufunc/sigparse.py + numba/parfors/parfor_lowering.py + numba/np/ufunc/array_exprs.py + numba/np/ufunc/decorators.py + numba/roc/servicelib/service.py + numba/core/datamodel/models.py + numba/core/datamodel/packer.py + numba/core/datamodel/testing.py + numba/core/datamodel/manager.py From d47a413489cf78b3d8517292e1d0f916d932576e Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 5 Feb 2020 17:08:53 +0000 Subject: [PATCH 472/595] Fix flake8 violations --- numba/core/analysis.py | 3 +- numba/core/cgutils.py | 1 - numba/core/compiler.py | 6 +-- numba/core/errors.py | 1 - numba/core/extending.py | 22 ++++----- numba/core/lowering.py | 5 +- numba/core/object_mode_passes.py | 6 ++- numba/core/optional.py | 4 +- numba/core/typed_passes.py | 13 +++-- numba/core/typing/context.py | 4 +- numba/core/untyped_passes.py | 19 ++++++-- numba/core/utils.py | 3 +- numba/cpython/charseq.py | 4 +- numba/cpython/enumimpl.py | 4 +- numba/cpython/unicode.py | 62 ++++++++++++------------ numba/np/arraymath.py | 2 +- numba/np/arrayobj.py | 14 +++--- numba/tests/test_dictobject.py | 4 +- numba/tests/test_gdb.py | 3 +- numba/tests/test_ir_utils.py | 8 +-- numba/tests/test_mixed_tuple_unroller.py | 12 +++-- numba/tests/test_nrt.py | 3 +- numba/tests/test_parallel_backend.py | 2 +- numba/tests/test_typedlist.py | 2 +- numba/tests/test_types.py | 2 +- numba/typed/dictobject.py | 12 ++--- numba/typed/listobject.py | 11 ++--- 27 files changed, 122 insertions(+), 110 deletions(-) diff --git a/numba/core/analysis.py b/numba/core/analysis.py index 5a87caa413f..ad57b0f9b03 100644 --- a/numba/core/analysis.py +++ b/numba/core/analysis.py @@ -292,7 +292,8 @@ def dead_branch_prune(func_ir, called_args): func_ir is the IR called_args are the actual arguments with which the function is called """ - from numba.core.ir_utils import get_definition, guard, find_const, GuardException + from numba.core.ir_utils import (get_definition, guard, find_const, + GuardException) DEBUG = 0 diff --git a/numba/core/cgutils.py b/numba/core/cgutils.py index b43e40bbfd1..d2f3867e3ab 100644 --- a/numba/core/cgutils.py +++ b/numba/core/cgutils.py @@ -97,7 +97,6 @@ class _StructProxy(object): _fe_type = None def __init__(self, context, builder, value=None, ref=None): - from numba.core import datamodel # Avoid circular import self._context = context self._datamodel = self._context.data_model_manager[self._fe_type] if not isinstance(self._datamodel, numba.core.datamodel.StructModel): diff --git a/numba/core/compiler.py b/numba/core/compiler.py index 75ca744a9f6..f7f5d63b33b 100644 --- a/numba/core/compiler.py +++ b/numba/core/compiler.py @@ -3,7 +3,8 @@ import warnings from numba.core.tracing import event -from numba.core import utils, errors, typing, interpreter, bytecode, postproc, config, callconv, cpu +from numba.core import (utils, errors, typing, interpreter, bytecode, postproc, + config, callconv, cpu) from numba.parfors.parfor import ParforDiagnostics from numba.core.inline_closurecall import InlineClosureCallPass from numba.core.errors import CompilerError @@ -18,8 +19,7 @@ FindLiterallyCalls, MakeFunctionToJitFunction, CanonicalizeLoopExit, - CanonicalizeLoopEntry, LiteralUnroll, - ) + CanonicalizeLoopEntry, LiteralUnroll,) from numba.core.typed_passes import (NopythonTypeInference, AnnotateTypes, NopythonRewrites, PreParforPass, diff --git a/numba/core/errors.py b/numba/core/errors.py index 78b672df692..df5993f4d60 100644 --- a/numba/core/errors.py +++ b/numba/core/errors.py @@ -717,7 +717,6 @@ def new_error_context(fmt_, *args, **kwargs): raise except Exception as e: newerr = errcls(e).add_context(_format_msg(fmt_, args, kwargs)) - from numba import config tb = sys.exc_info()[2] if numba.core.config.FULL_TRACEBACKS else None reraise(type(newerr), newerr, tb) diff --git a/numba/core/extending.py b/numba/core/extending.py index a067c16ac92..61ca2de7924 100644 --- a/numba/core/extending.py +++ b/numba/core/extending.py @@ -1,5 +1,4 @@ import os -import inspect import uuid import weakref import collections @@ -8,16 +7,15 @@ from numba.core import types, errors, utils, config # Exported symbols -from numba.core.typing.typeof import typeof_impl -from numba.core.typing.templates import infer, infer_getattr -from numba.core.imputils import ( - lower_builtin, lower_getattr, lower_getattr_generic, - lower_setattr, lower_setattr_generic, lower_cast) -from numba.core.datamodel import models, register_default as register_model -from numba.core.pythonapi import box, unbox, reflect, NativeValue -from numba._helperlib import _import_cython_function - - +from numba.core.typing.typeof import typeof_impl # noqa: F401 +from numba.core.typing.templates import infer, infer_getattr # noqa: F401 +from numba.core.imputils import ( # noqa: F401 + lower_builtin, lower_getattr, lower_getattr_generic, # noqa: F401 + lower_setattr, lower_setattr_generic, lower_cast) # noqa: F401 +from numba.core.datamodel import models # noqa: F401 +from numba.core.datamodel import register_default as register_model # noqa: F401, E501 +from numba.core.pythonapi import box, unbox, reflect, NativeValue # noqa: F401 +from numba._helperlib import _import_cython_function # noqa: F401 def type_callable(func): @@ -109,7 +107,6 @@ def len_impl(seq): opts = _overload_default_jit_options.copy() opts.update(jit_options) # let user options override - def decorate(overload_func): template = make_overload_template(func, overload_func, opts, strict, inline) @@ -440,6 +437,7 @@ def sentry_literal_args(pysig, literal_args, args, kwargs): if missing: # Yes, there are missing required literal arguments e = errors.ForceLiteralArg(request_pos) + # A helper function to fold arguments def folded(args, kwargs): out = pysig.bind(*args, **kwargs).arguments.values() diff --git a/numba/core/lowering.py b/numba/core/lowering.py index b7b12bbb3bf..6b1350bdf3f 100644 --- a/numba/core/lowering.py +++ b/numba/core/lowering.py @@ -6,9 +6,10 @@ from llvmlite.llvmpy.core import Constant, Type, Builder from numba import _dynfunc -from numba.core import typing, utils, types, ir, debuginfo, funcdesc, generators, config, ir_utils, cgutils, removerefctpass +from numba.core import (typing, utils, types, ir, debuginfo, funcdesc, + generators, config, ir_utils, cgutils, removerefctpass) from numba.core.errors import (LoweringError, new_error_context, TypingError, - LiteralTypingError) + LiteralTypingError) from numba.core.funcdesc import default_mangler diff --git a/numba/core/object_mode_passes.py b/numba/core/object_mode_passes.py index b60d0c72228..88c4922aa64 100644 --- a/numba/core/object_mode_passes.py +++ b/numba/core/object_mode_passes.py @@ -1,7 +1,9 @@ from contextlib import contextmanager import warnings -from numba.core import errors, types, typing, funcdesc, config, pylowering, transforms -from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass +from numba.core import (errors, types, typing, funcdesc, config, pylowering, + transforms) +from numba.core.compiler_machinery import (FunctionPass, LoweringPass, + register_pass) from collections import defaultdict diff --git a/numba/core/optional.py b/numba/core/optional.py index dda2b017f57..16dcb52360a 100644 --- a/numba/core/optional.py +++ b/numba/core/optional.py @@ -3,8 +3,8 @@ from numba.core import types, typing, cgutils from numba.core.imputils import (lower_cast, lower_builtin, - lower_getattr_generic, impl_ret_untracked, - lower_setattr_generic) + lower_getattr_generic, impl_ret_untracked, + lower_setattr_generic) def always_return_true_impl(context, builder, sig, args): diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index b4a6d231522..e8ee787f082 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -1,17 +1,20 @@ from contextlib import contextmanager import warnings -from numba.core import errors, types, typing, ir, funcdesc, rewrites, typeinfer, config, lowering +from numba.core import (errors, types, typing, ir, funcdesc, rewrites, + typeinfer, config, lowering) from numba.parfors.parfor import PreParforPass as _parfor_PreParforPass from numba.parfors.parfor import ParforPass as _parfor_ParforPass from numba.parfors.parfor import Parfor -from numba.core.compiler_machinery import FunctionPass, LoweringPass, register_pass +from numba.core.compiler_machinery import (FunctionPass, LoweringPass, + register_pass) from numba.core.annotations import type_annotations from numba.core.ir_utils import (raise_on_unsupported_feature, warn_deprecated, - check_and_legalize_ir, guard, dead_code_elimination, - simplify_CFG, get_definition) + check_and_legalize_ir, guard, + dead_code_elimination, simplify_CFG, + get_definition) @contextmanager @@ -597,7 +600,7 @@ def _run_inliner( work_list, is_method, ): from numba.core.inline_closurecall import (inline_closure_call, - callee_ir_validator) + callee_ir_validator) do_inline = True if not inline_type.is_always_inline: diff --git a/numba/core/typing/context.py b/numba/core/typing/context.py index 29de9d4f04f..61f8452fcf8 100644 --- a/numba/core/typing/context.py +++ b/numba/core/typing/context.py @@ -394,8 +394,8 @@ def _get_global_type(self, gv): def _load_builtins(self): # Initialize declarations - from numba.core.typing import builtins, arraydecl, npdatetime # noqa: F401 - from numba.core.typing import ctypes_utils, bufproto # noqa: F401 + from numba.core.typing import builtins, arraydecl, npdatetime # noqa: F401, E501 + from numba.core.typing import ctypes_utils, bufproto # noqa: F401, E501 from numba.core.unsafe import eh # noqa: F401 self.install_registry(templates.builtin_registry) diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 87e4e9eda13..66c88c3f6b3 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -4,11 +4,20 @@ import warnings from numba.core.compiler_machinery import FunctionPass, register_pass -from numba.core import errors, types, ir, bytecode, postproc, rewrites, config, transforms +from numba.core import (errors, types, ir, bytecode, postproc, rewrites, config, + transforms) from numba.misc.special import literal_unroll -from .analysis import dead_branch_prune, rewrite_semantic_constants, find_literally_calls, compute_cfg_from_blocks, compute_use_defs -from numba.core.inline_closurecall import InlineClosureCallPass, inline_closure_call -from numba.core.ir_utils import guard, resolve_func_from_module, simplify_CFG, GuardException, convert_code_obj_to_function, mk_unique_var, build_definitions, replace_var_names, get_name_var_table, compile_to_numba_ir, get_definition, find_max_label, rename_labels +from numba.core.analysis import (dead_branch_prune, rewrite_semantic_constants, + find_literally_calls, compute_cfg_from_blocks, + compute_use_defs) +from numba.core.inline_closurecall import (InlineClosureCallPass, + inline_closure_call) +from numba.core.ir_utils import (guard, resolve_func_from_module, simplify_CFG, + GuardException, convert_code_obj_to_function, + mk_unique_var, build_definitions, + replace_var_names, get_name_var_table, + compile_to_numba_ir, get_definition, + find_max_label, rename_labels) from numba.core import interpreter @@ -305,7 +314,7 @@ def run_pass(self, state): def _do_work(self, state, work_list, block, i, expr): from numba.core.inline_closurecall import (inline_closure_call, - callee_ir_validator) + callee_ir_validator) from numba.core.compiler import run_frontend from numba.core.cpu import InlineOptions diff --git a/numba/core/utils.py b/numba/core/utils.py index ac5e26b5bfd..a89b3204768 100644 --- a/numba/core/utils.py +++ b/numba/core/utils.py @@ -17,7 +17,8 @@ from inspect import Signature as pySignature # noqa: F401 from inspect import Parameter as pyParameter # noqa: F401 -from numba.core.config import PYVERSION, MACHINE_BITS, DEVELOPER_MODE # noqa: F401 +from numba.core.config import (PYVERSION, MACHINE_BITS, # noqa: F401 + DEVELOPER_MODE) # noqa: F401 INT_TYPES = (int,) diff --git a/numba/cpython/charseq.py b/numba/cpython/charseq.py index a1f3df493a4..68a33bcc044 100644 --- a/numba/cpython/charseq.py +++ b/numba/cpython/charseq.py @@ -4,8 +4,8 @@ from llvmlite import ir from numba.core import types, cgutils -from numba.core.extending import (overload, intrinsic, overload_method, lower_cast, - register_jitable) +from numba.core.extending import (overload, intrinsic, overload_method, + lower_cast, register_jitable) from numba.core.cgutils import is_nonelike from numba.cpython import unicode diff --git a/numba/cpython/enumimpl.py b/numba/cpython/enumimpl.py index ffff4c752eb..e7fe77f92ff 100644 --- a/numba/cpython/enumimpl.py +++ b/numba/cpython/enumimpl.py @@ -3,7 +3,9 @@ """ import operator -from numba.core.imputils import lower_builtin, lower_getattr, lower_getattr_generic, lower_cast, lower_constant, impl_ret_untracked +from numba.core.imputils import (lower_builtin, lower_getattr, + lower_getattr_generic, lower_cast, + lower_constant, impl_ret_untracked) from numba.core import types diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index 3dc3bf2095c..5ef88103c1c 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -17,7 +17,7 @@ register_jitable, ) from numba.core.imputils import (lower_constant, lower_cast, lower_builtin, - iternext_impl, impl_ret_new_ref, RefType) + iternext_impl, impl_ret_new_ref, RefType) from numba.core.datamodel import register_default, StructModel from numba.core import utils, types, cgutils from numba.core.pythonapi import ( @@ -31,36 +31,36 @@ from numba.core.unsafe.bytes import memcpy_region from numba.core.errors import TypingError from numba.cpython.unicode_support import (_Py_TOUPPER, _Py_TOLOWER, _Py_UCS4, - _Py_ISALNUM, - _PyUnicode_ToUpperFull, - _PyUnicode_ToLowerFull, - _PyUnicode_ToFoldedFull, - _PyUnicode_ToTitleFull, - _PyUnicode_IsPrintable, - _PyUnicode_IsSpace, - _Py_ISSPACE, - _PyUnicode_IsXidStart, - _PyUnicode_IsXidContinue, - _PyUnicode_IsCased, - _PyUnicode_IsCaseIgnorable, - _PyUnicode_IsUppercase, - _PyUnicode_IsLowercase, - _PyUnicode_IsLineBreak, - _Py_ISLINEBREAK, - _Py_ISLINEFEED, - _Py_ISCARRIAGERETURN, - _PyUnicode_IsTitlecase, - _Py_ISLOWER, - _Py_ISUPPER, - _Py_TAB, - _Py_LINEFEED, - _Py_CARRIAGE_RETURN, - _Py_SPACE, - _PyUnicode_IsAlpha, - _PyUnicode_IsNumeric, - _Py_ISALPHA, - _PyUnicode_IsDigit, - _PyUnicode_IsDecimalDigit) + _Py_ISALNUM, + _PyUnicode_ToUpperFull, + _PyUnicode_ToLowerFull, + _PyUnicode_ToFoldedFull, + _PyUnicode_ToTitleFull, + _PyUnicode_IsPrintable, + _PyUnicode_IsSpace, + _Py_ISSPACE, + _PyUnicode_IsXidStart, + _PyUnicode_IsXidContinue, + _PyUnicode_IsCased, + _PyUnicode_IsCaseIgnorable, + _PyUnicode_IsUppercase, + _PyUnicode_IsLowercase, + _PyUnicode_IsLineBreak, + _Py_ISLINEBREAK, + _Py_ISLINEFEED, + _Py_ISCARRIAGERETURN, + _PyUnicode_IsTitlecase, + _Py_ISLOWER, + _Py_ISUPPER, + _Py_TAB, + _Py_LINEFEED, + _Py_CARRIAGE_RETURN, + _Py_SPACE, + _PyUnicode_IsAlpha, + _PyUnicode_IsNumeric, + _Py_ISALPHA, + _PyUnicode_IsDigit, + _PyUnicode_IsDecimalDigit) from numba.cpython import slicing diff --git a/numba/np/arraymath.py b/numba/np/arraymath.py index def65643c7e..be264303d2b 100644 --- a/numba/np/arraymath.py +++ b/numba/np/arraymath.py @@ -19,7 +19,7 @@ from numba.np.numpy_support import numpy_version from numba.np.numpy_support import is_nonelike from numba.core.imputils import (lower_builtin, impl_ret_borrowed, - impl_ret_new_ref, impl_ret_untracked) + impl_ret_new_ref, impl_ret_untracked) from numba.core.typing import signature from numba.np.arrayobj import make_array, load_item, store_item, _empty_nd_impl from numba.np.linalg import ensure_blas diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index f44ec3067fe..7b0e9b1b3a8 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -17,15 +17,15 @@ from numba import pndindex from numba.core import types, utils, typing, errors, cgutils, extending from numba.np.numpy_support import (as_dtype, carray, farray, is_contiguous, - is_fortran) + is_fortran) from numba.np.numpy_support import type_can_asarray, is_nonelike from numba.core.imputils import (lower_builtin, lower_getattr, - lower_getattr_generic, - lower_setattr_generic, - lower_cast, lower_constant, - iternext_impl, impl_ret_borrowed, - impl_ret_new_ref, impl_ret_untracked, - RefType) + lower_getattr_generic, + lower_setattr_generic, + lower_cast, lower_constant, + iternext_impl, impl_ret_borrowed, + impl_ret_new_ref, impl_ret_untracked, + RefType) from numba.core.typing import signature from numba.core.extending import register_jitable, overload, overload_method from numba.misc import quicksort, mergesort diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index b7610a26ee2..daaaf559ce6 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -18,8 +18,8 @@ from numba.typed.typedobjectutils import _sentry_safe_cast from numba.core.errors import TypingError from numba.core import types -from numba.tests.support import (TestCase, MemoryLeakMixin, unittest, override_config, - forbid_codegen) +from numba.tests.support import (TestCase, MemoryLeakMixin, unittest, + override_config, forbid_codegen) from numba.experimental import jitclass diff --git a/numba/tests/test_gdb.py b/numba/tests/test_gdb.py index 066921095ef..4003cb71a0c 100644 --- a/numba/tests/test_gdb.py +++ b/numba/tests/test_gdb.py @@ -13,7 +13,8 @@ from numba import jit from numba.misc.gdb_hook import _confirm_gdb -from numba.tests.support import (TestCase, captured_stdout, tag, skip_parfors_unsupported) +from numba.tests.support import (TestCase, captured_stdout, tag, + skip_parfors_unsupported) import unittest diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index 7f1ee34524f..83e0d778160 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -4,11 +4,11 @@ from numba.core.compiler import CompilerBase, Flags from numba.core.compiler_machinery import PassManager from numba.core import types, ir, bytecode, compiler, ir_utils, registry -from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, FixupArgs, - IRProcessing,) +from numba.core.untyped_passes import (ExtractByteCode, TranslateByteCode, + FixupArgs, IRProcessing,) -from numba.core.typed_passes import (NopythonTypeInference, type_inference_stage, - DeadCodeElimination) +from numba.core.typed_passes import (NopythonTypeInference, + type_inference_stage, DeadCodeElimination) from numba.experimental import jitclass # global constant for testing find_const diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 58c10c8b781..c10dfa10601 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -6,13 +6,15 @@ from numba.core import types, errors, ir from numba.testing import unittest from numba.core.extending import overload -from numba.core.compiler_machinery import PassManager, register_pass, FunctionPass +from numba.core.compiler_machinery import (PassManager, register_pass, + FunctionPass) from numba.core.compiler import CompilerBase -from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, - InlineClosureLikes, SimplifyCFG, - IterLoopCanonicalization, LiteralUnroll) +from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, + IRProcessing, InlineClosureLikes, + SimplifyCFG, IterLoopCanonicalization, + LiteralUnroll) from numba.core.typed_passes import (NopythonTypeInference, IRLegalization, - NoPythonBackend, PartialTypeInference) + NoPythonBackend, PartialTypeInference) from numba.core.ir_utils import (compute_cfg_from_blocks, flatten_labels) diff --git a/numba/tests/test_nrt.py b/numba/tests/test_nrt.py index ee753dc8b5b..69a195fd1db 100644 --- a/numba/tests/test_nrt.py +++ b/numba/tests/test_nrt.py @@ -23,7 +23,8 @@ import numba.core.typing.cffi_utils as cffi_support from numba.core.unsafe.nrt import NRT_get_api -from numba.tests.support import MemoryLeakMixin, TestCase, temp_directory, import_dynamic +from numba.tests.support import (MemoryLeakMixin, TestCase, temp_directory, + import_dynamic) from numba.core import cpu import unittest diff --git a/numba/tests/test_parallel_backend.py b/numba/tests/test_parallel_backend.py index 60750419938..96c233c1703 100644 --- a/numba/tests/test_parallel_backend.py +++ b/numba/tests/test_parallel_backend.py @@ -16,7 +16,7 @@ from numba import jit, vectorize, guvectorize from numba.tests.support import (temp_directory, override_config, TestCase, tag, - skip_parfors_unsupported, linux_only) + skip_parfors_unsupported, linux_only) import queue as t_queue from numba.testing.main import _TIMEOUT as _RUNNER_TIMEOUT diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index c2040c8ef24..6f0016507e2 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -10,7 +10,7 @@ from numba.typed import List, Dict from numba.core.errors import TypingError from numba.tests.support import (TestCase, MemoryLeakMixin, override_config, - forbid_codegen, skip_parfors_unsupported) + forbid_codegen, skip_parfors_unsupported) from numba.core.unsafe.refcount import get_refcount from numba.experimental import jitclass diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py index 826e69977bd..e9017862889 100644 --- a/numba/tests/test_types.py +++ b/numba/tests/test_types.py @@ -21,7 +21,7 @@ from numba.core.typing.templates import make_overload_template from numba import jit, njit, typeof from numba.core.extending import (overload, register_model, models, unbox, - NativeValue, typeof_impl) + NativeValue, typeof_impl) from numba.tests.support import TestCase, temp_directory from numba.tests.enum_usecases import Color, Shake, Shape import unittest diff --git a/numba/typed/dictobject.py b/numba/typed/dictobject.py index d55c535364f..553a04ee0a6 100644 --- a/numba/typed/dictobject.py +++ b/numba/typed/dictobject.py @@ -30,14 +30,10 @@ from numba.core.imputils import impl_ret_borrowed, RefType from numba.core.errors import TypingError from numba.core import typing -from numba.typed.typedobjectutils import (_as_bytes, - _cast, - _nonoptional, - _sentry_safe_cast_default, - _get_incref_decref, - _get_equal, - _container_get_data, - ) +from numba.typed.typedobjectutils import (_as_bytes, _cast, _nonoptional, + _sentry_safe_cast_default, + _get_incref_decref, + _get_equal, _container_get_data,) ll_dict_type = cgutils.voidptr_t diff --git a/numba/typed/listobject.py b/numba/typed/listobject.py index c45433c8776..836b5b5e672 100644 --- a/numba/typed/listobject.py +++ b/numba/typed/listobject.py @@ -30,13 +30,10 @@ from numba.core.imputils import impl_ret_borrowed, RefType from numba.core.errors import TypingError from numba.core import typing -from numba.typed.typedobjectutils import (_as_bytes, - _cast, - _nonoptional, - _get_incref_decref, - _container_get_data, - _container_get_meminfo, - ) +from numba.typed.typedobjectutils import (_as_bytes, _cast, _nonoptional, + _get_incref_decref, + _container_get_data, + _container_get_meminfo,) from numba.cpython import listobj ll_list_type = cgutils.voidptr_t From b9842e5e8317ba8927989d58acd92182310e8b6d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 5 Feb 2020 17:50:32 +0000 Subject: [PATCH 473/595] Fix up docs, re-export numba.types --- docs/source/developer/numba-runtime.rst | 12 +- docs/source/developer/repomap.rst | 369 ++++++++++++------------ docs/source/user/jitclass.rst | 2 +- numba/__init__.py | 3 + numba/core/types/__init__.py | 2 +- 5 files changed, 197 insertions(+), 191 deletions(-) diff --git a/docs/source/developer/numba-runtime.rst b/docs/source/developer/numba-runtime.rst index 8e7df11df60..f8f1cc4814f 100644 --- a/docs/source/developer/numba-runtime.rst +++ b/docs/source/developer/numba-runtime.rst @@ -123,23 +123,23 @@ Using the NRT from C code Externally compiled C code should use the ``NRT_api_functions`` struct as a function table to access the NRT API. The struct is defined in -:ghfile:`numba/runtime/nrt_external.h`. Users can use the utility function +:ghfile:`numba/core/runtime/nrt_external.h`. Users can use the utility function ``numba.extending.include_path()`` to determine the include directory for Numba provided C headers. -.. literalinclude:: ../../../numba/runtime/nrt_external.h +.. literalinclude:: ../../../numba/core/runtime/nrt_external.h :language: C - :caption: `numba/runtime/nrt_external.h` + :caption: `numba/core/runtime/nrt_external.h` -Inside Numba compiled code, the ``numba.unsafe.nrt.NRT_get_api()`` intrinsic -can be used to obtain a pointer to the ``NRT_api_functions``. +Inside Numba compiled code, the ``numba.core.unsafe.nrt.NRT_get_api()`` +intrinsic can be used to obtain a pointer to the ``NRT_api_functions``. Here is an example that uses the ``nrt_external.h``: .. code-block:: C #include - #include "numba/runtime/nrt_external.h" + #include "numba/core/runtime/nrt_external.h" void my_dtor(void *ptr) { free(ptr); diff --git a/docs/source/developer/repomap.rst b/docs/source/developer/repomap.rst index 126b25cb4e5..1ead15b4209 100644 --- a/docs/source/developer/repomap.rst +++ b/docs/source/developer/repomap.rst @@ -94,26 +94,26 @@ Public API These define aspects of the public Numba interface. -- :ghfile:`numba/decorators.py` - User-facing decorators for compiling +- :ghfile:`numba/core/decorators.py` - User-facing decorators for compiling regular functions on the CPU -- :ghfile:`numba/extending.py` - Public decorators for extending Numba +- :ghfile:`numba/core/extending.py` - Public decorators for extending Numba (``overload``, ``intrinsic``, etc) -- :ghfile:`numba/ccallback.py` - ``@cfunc`` decorator for compiling +- :ghfile:`numba/core/ccallback.py` - ``@cfunc`` decorator for compiling functions to a fixed C signature. Used to make callbacks. -- :ghfile:`numba/npyufunc/decorators.py` - ufunc/gufunc compilation +- :ghfile:`numba/np/ufunc/decorators.py` - ufunc/gufunc compilation decorators -- :ghfile:`numba/config.py` - Numba global config options and environment +- :ghfile:`numba/core/config.py` - Numba global config options and environment variable handling -- :ghfile:`numba/annotations` - Gathering and printing type annotations of +- :ghfile:`numba/core/annotations` - Gathering and printing type annotations of Numba IR -- :ghfile:`numba/pretty_annotate.py` - Code highlighting of Numba functions - and types (both ANSI terminal and HTML) +- :ghfile:`numba/core/annotations/pretty_annotate.py` - Code highlighting of + Numba functions and types (both ANSI terminal and HTML) Dispatching ''''''''''' -- :ghfile:`numba/dispatcher.py` - Dispatcher objects are compiled functions +- :ghfile:`numba/core/dispatcher.py` - Dispatcher objects are compiled functions produced by ``@jit``. A dispatcher has different implementations for different type signatures. - :ghfile:`numba/_dispatcher.{h,c}` - C interface to C++ dispatcher @@ -125,72 +125,71 @@ Dispatching Compiler Pipeline ''''''''''''''''' -- :ghfile:`numba/compiler.py` - Compiler pipelines and flags -- :ghfile:`numba/errors.py` - Numba exception and warning classes -- :ghfile:`numba/ir.py` - Numba IR data structure objects -- :ghfile:`numba/bytecode.py` - Bytecode parsing and function identity (??) -- :ghfile:`numba/interpreter.py` - Translate Python interpreter bytecode to +- :ghfile:`numba/core/compiler.py` - Compiler pipelines and flags +- :ghfile:`numba/core/errors.py` - Numba exception and warning classes +- :ghfile:`numba/core/ir.py` - Numba IR data structure objects +- :ghfile:`numba/core/bytecode.py` - Bytecode parsing and function identity (??) +- :ghfile:`numba/core/interpreter.py` - Translate Python interpreter bytecode to Numba IR -- :ghfile:`numba/analysis.py` - Utility functions to analyze Numba IR +- :ghfile:`numba/core/analysis.py` - Utility functions to analyze Numba IR (variable lifetime, prune branches, etc) -- :ghfile:`numba/dataflow.py` - Dataflow analysis for Python bytecode (used +- :ghfile:`numba/core/dataflow.py` - Dataflow analysis for Python bytecode (used in analysis.py) -- :ghfile:`numba/controlflow.py` - Control flow analysis of Numba IR and +- :ghfile:`numba/core/controlflow.py` - Control flow analysis of Numba IR and Python bytecode -- :ghfile:`numba/typeinfer.py` - Type inference algorithm -- :ghfile:`numba/transforms.py` - Numba IR transformations -- :ghfile:`numba/rewrites` - Rewrite passes used by compiler -- :ghfile:`numba/rewrites/__init__.py` - Loads all rewrite passes so they +- :ghfile:`numba/core/typeinfer.py` - Type inference algorithm +- :ghfile:`numba/core/transforms.py` - Numba IR transformations +- :ghfile:`numba/core/rewrites` - Rewrite passes used by compiler +- :ghfile:`numba/core/rewrites/__init__.py` - Loads all rewrite passes so they are put into the registry -- :ghfile:`numba/rewrites/registry.py` - Registry object for collecting +- :ghfile:`numba/core/rewrites/registry.py` - Registry object for collecting rewrite passes -- :ghfile:`numba/rewrites/ir_print.py` - Write print() calls into special +- :ghfile:`numba/core/rewrites/ir_print.py` - Write print() calls into special print nodes in the IR -- :ghfile:`numba/rewrites/static_raise.py` - Converts exceptions with static - arguments into a special form that can be lowered -- :ghfile:`numba/rewrites/macros.py` - Generic support for macro expansion +- :ghfile:`numba/core/rewrites/static_raise.py` - Converts exceptions with + static arguments into a special form that can be lowered +- :ghfile:`numba/core/rewrites/macros.py` - Generic support for macro expansion in the Numba IR -- :ghfile:`numba/rewrites/static_getitem.py` - Rewrites getitem and setitem +- :ghfile:`numba/core/rewrites/static_getitem.py` - Rewrites getitem and setitem with constant arguments to allow type inference -- :ghfile:`numba/rewrites/static_binop.py` - Rewrites binary operations +- :ghfile:`numba/core/rewrites/static_binop.py` - Rewrites binary operations (specifically ``**``) with constant arguments so faster code can be generated -- :ghfile:`numba/inline_closurecall.py` - Inlines body of closure functions +- :ghfile:`numba/core/inline_closurecall.py` - Inlines body of closure functions to call site. Support for array comprehensions, reduction inlining, and stencil inlining. -- :ghfile:`numba/macro.py` - Alias to ``numba.rewrites.macros`` -- :ghfile:`numba/postproc.py` - Postprocessor for Numba IR that computes +- :ghfile:`numba/core/postproc.py` - Postprocessor for Numba IR that computes variable lifetime, inserts del operations, and handles generators -- :ghfile:`numba/lowering.py` - General implementation of lowering Numba IR +- :ghfile:`numba/core/lowering.py` - General implementation of lowering Numba IR to LLVM -- :ghfile:`numba/withcontexts.py` - General scaffolding for implementing +- :ghfile:`numba/core/withcontexts.py` - General scaffolding for implementing context managers in nopython mode, and the objectmode context manager -- :ghfile:`numba/pylowering.py` - Lowering of Numba IR in object mode -- :ghfile:`numba/pythonapi.py` - LLVM IR code generation to interface with +- :ghfile:`numba/core/pylowering.py` - Lowering of Numba IR in object mode +- :ghfile:`numba/core/pythonapi.py` - LLVM IR code generation to interface with CPython API Type Management ''''''''''''''' -- :ghfile:`numba/typeconv/` - Implementation of type casting and type +- :ghfile:`numba/core/typeconv/` - Implementation of type casting and type signature matching in both C++ and Python - :ghfile:`numba/capsulethunk.h` - Used by typeconv -- :ghfile:`numba/types/` - definition of the Numba type hierarchy, used +- :ghfile:`numba/core/types/` - definition of the Numba type hierarchy, used everywhere in compiler to select implementations -- :ghfile:`numba/consts.py` - Constant inference (used to make constant +- :ghfile:`numba/core/consts.py` - Constant inference (used to make constant values available during codegen when possible) -- :ghfile:`numba/datamodel` - LLVM IR representations of data types in +- :ghfile:`numba/core/datamodel` - LLVM IR representations of data types in different contexts -- :ghfile:`numba/datamodel/models.py` - Models for most standard types -- :ghfile:`numba/datamodel/registry.py` - Decorator to register new data +- :ghfile:`numba/core/datamodel/models.py` - Models for most standard types +- :ghfile:`numba/core/datamodel/registry.py` - Decorator to register new data models -- :ghfile:`numba/datamodel/packer.py` - Pack typed values into a data +- :ghfile:`numba/core/datamodel/packer.py` - Pack typed values into a data structure -- :ghfile:`numba/datamodel/testing.py` - Data model tests (this should +- :ghfile:`numba/core/datamodel/testing.py` - Data model tests (this should move??) -- :ghfile:`numba/datamodel/manager.py` - Map types to data models +- :ghfile:`numba/core/datamodel/manager.py` - Map types to data models Compiled Extensions @@ -229,55 +228,50 @@ Misc Support '''''''''''' - :ghfile:`numba/_version.py` - Updated by versioneer -- :ghfile:`numba/runtime` - Language runtime. Currently manages +- :ghfile:`numba/core/runtime` - Language runtime. Currently manages reference-counted memory allocated on the heap by Numba-compiled functions -- :ghfile:`numba/ir_utils.py` - Utility functions for working with Numba IR +- :ghfile:`numba/core/ir_utils.py` - Utility functions for working with Numba IR data structures -- :ghfile:`numba/cgutils.py` - Utility functions for generating common code +- :ghfile:`numba/core/cgutils.py` - Utility functions for generating common code patterns in LLVM IR -- :ghfile:`numba/utils.py` - Python 2 backports of Python 3 functionality +- :ghfile:`numba/core/utils.py` - Python 2 backports of Python 3 functionality (also imports local copy of ``six``) -- :ghfile:`numba/appdirs.py` - Vendored package for determining application +- :ghfile:`numba/misc/appdirs.py` - Vendored package for determining application config directories on every platform -- :ghfile:`numba/compiler_lock.py` - Global compiler lock because Numba's usage - of LLVM is not thread-safe -- :ghfile:`numba/special.py` - Python stub implementations of special Numba +- :ghfile:`numba/core/compiler_lock.py` - Global compiler lock because Numba's + usage of LLVM is not thread-safe +- :ghfile:`numba/misc/special.py` - Python stub implementations of special Numba functions (prange, gdb*) -- :ghfile:`numba/servicelib/threadlocal.py` - Thread-local stack used by GPU - targets -- :ghfile:`numba/servicelib/service.py` - Should be removed? -- :ghfile:`numba/itanium_mangler.py` - Python implementation of Itanium C++ +- :ghfile:`numba/core/itanium_mangler.py` - Python implementation of Itanium C++ name mangling -- :ghfile:`numba/findlib.py` - Helper function for locating shared libraries - on all platforms -- :ghfile:`numba/debuginfo.py` - Helper functions to construct LLVM IR debug +- :ghfile:`numba/misc/findlib.py` - Helper function for locating shared + libraries on all platforms +- :ghfile:`numba/core/debuginfo.py` - Helper functions to construct LLVM IR + debug info -- :ghfile:`numba/unsafe` - ``@intrinsic`` helper functions that can be used - to implement direct memory/pointer manipulation from nopython mode - functions -- :ghfile:`numba/unsafe/refcount.py` - Read reference count of object -- :ghfile:`numba/unsafe/tuple.py` - Replace a value in a tuple slot -- :ghfile:`numba/unsafe/ndarray.py` - NumPy array helpers -- :ghfile:`numba/unsafe/bytes.py` - Copying and dereferencing data from void - pointers -- :ghfile:`numba/dummyarray.py` - Used by GPU backends to hold array information - on the host, but not the data. -- :ghfile:`numba/callwrapper.py` - Handles argument unboxing and releasing +- :ghfile:`numba/core/unsafe/refcount.py` - Read reference count of object +- :ghfile:`numba/core/unsafe/eh.py` - Exception handling helpers +- :ghfile:`numba/core/unsafe/nrt.py` - Numba runtime (NRT) helpers +- :ghfile:`numba/cpython/unsafe/tuple.py` - Replace a value in a tuple slot +- :ghfile:`numba/np/unsafe/ndarray.py` - NumPy array helpers +- :ghfile:`numba/core/unsafe/bytes.py` - Copying and dereferencing data from + void pointers +- :ghfile:`numba/misc/dummyarray.py` - Used by GPU backends to hold array + information on the host, but not the data. +- :ghfile:`numba/core/callwrapper.py` - Handles argument unboxing and releasing the GIL when moving from Python to nopython mode -- :ghfile:`numba/cffi_support.py` - Alias of numba.typing.cffi_utils for - backward compatibility (still needed?) -- :ghfile:`numba/numpy_support.py` - Helper functions for working with NumPy +- :ghfile:`numba/np/numpy_support.py` - Helper functions for working with NumPy and translating Numba types to and from NumPy dtypes. -- :ghfile:`numba/tracing.py` - Decorator for tracing Python calls and +- :ghfile:`numba/core/tracing.py` - Decorator for tracing Python calls and emitting log messages -- :ghfile:`numba/funcdesc.py` - Classes for describing function metadata +- :ghfile:`numba/core/funcdesc.py` - Classes for describing function metadata (used in the compiler) -- :ghfile:`numba/sigutils.py` - Helper functions for parsing and normalizing - Numba type signatures -- :ghfile:`numba/serialize.py` - Support for pickling compiled functions -- :ghfile:`numba/caching.py` - Disk cache for compiled functions -- :ghfile:`numba/npdatetime.py` - Helper functions for implementing NumPy +- :ghfile:`numba/core/sigutils.py` - Helper functions for parsing and + normalizing Numba type signatures +- :ghfile:`numba/core/serialize.py` - Support for pickling compiled functions +- :ghfile:`numba/core/caching.py` - Disk cache for compiled functions +- :ghfile:`numba/np/npdatetime.py` - Helper functions for implementing NumPy datetime64 support @@ -288,18 +282,19 @@ Core Python Data Types implementation - :ghfile:`numba/cext/dictobject.{h,c}` - C level implementation of typed dictionary -- :ghfile:`numba/dictobject.py` - Nopython mode wrapper for typed dictionary +- :ghfile:`numba/typed/dictobject.py` - Nopython mode wrapper for typed + dictionary - :ghfile:`numba/cext/listobject.{h,c}` - C level implementation of typed list -- :ghfile:`numba/listobject.py` - Nopython mode wrapper for typed list -- :ghfile:`numba/typedobjectutils.py` - Common utilities for typed dictionary - and list -- :ghfile:`numba/unicode.py` - Unicode strings (Python 3.5 and later) +- :ghfile:`numba/typed/listobject.py` - Nopython mode wrapper for typed list +- :ghfile:`numba/typed/typedobjectutils.py` - Common utilities for typed + dictionary and list +- :ghfile:`numba/cpython/unicode.py` - Unicode strings (Python 3.5 and later) - :ghfile:`numba/typed` - Python interfaces to statically typed containers - :ghfile:`numba/typed/typeddict.py` - Python interface to typed dictionary - :ghfile:`numba/typed/typedlist.py` - Python interface to typed list -- :ghfile:`numba/jitclass` - Implementation of JIT compilation of Python - classes -- :ghfile:`numba/generators.py` - Support for lowering Python generators +- :ghfile:`numba/experimental/jitclass` - Implementation of experimental JIT + compilation of Python classes +- :ghfile:`numba/core/generators.py` - Support for lowering Python generators Math @@ -317,21 +312,30 @@ ParallelAccelerator Code transformation passes that extract parallelizable code from a function and convert it into multithreaded gufunc calls. -- :ghfile:`numba/parfor.py` - General ParallelAccelerator -- :ghfile:`numba/stencil.py` - Stencil function decorator (implemented - without ParallelAccelerator) -- :ghfile:`numba/stencilparfor.py` - ParallelAccelerator implementation of - stencil -- :ghfile:`numba/array_analysis.py` - Array analysis passes used in +- :ghfile:`numba/parfors/parfor.py` - General ParallelAccelerator +- :ghfile:`numba/parfors/parfor_lowering.py` - gufunc lowering for + ParallelAccelerator +- :ghfile:`numba/parfors/array_analysis.py` - Array analysis passes used in ParallelAccelerator +Stencil +''''''' + +Implementation of ``@stencil``: + +- :ghfile:`numba/stencils/stencil.py` - Stencil function decorator (implemented + without ParallelAccelerator) +- :ghfile:`numba/stencils/stencilparfor.py` - ParallelAccelerator implementation + of stencil + + Debugging Support ''''''''''''''''' -- :ghfile:`numba/targets/gdb_hook.py` - Hooks to jump into GDB from nopython +- :ghfile:`numba/misc/gdb_hook.py` - Hooks to jump into GDB from nopython mode -- :ghfile:`numba/targets/cmdlang.gdb` - Commands to setup GDB for setting +- :ghfile:`numba/misc/cmdlang.gdb` - Commands to setup GDB for setting explicit breakpoints from Python @@ -343,33 +347,34 @@ declaration of allowed type signatures from the definition of implementations. This package contains registries of type signatures that must be matched during type inference. -- :ghfile:`numba/typing` - Type signature module -- :ghfile:`numba/typing/templates.py` - Base classes for type signature +- :ghfile:`numba/core/typing` - Type signature module +- :ghfile:`numba/core/typing/templates.py` - Base classes for type signature templates -- :ghfile:`numba/typing/cmathdecl.py` - Python complex math (``cmath``) +- :ghfile:`numba/core/typing/cmathdecl.py` - Python complex math (``cmath``) module -- :ghfile:`numba/typing/bufproto.py` - Interpreting objects supporting the +- :ghfile:`numba/core/typing/bufproto.py` - Interpreting objects supporting the buffer protocol -- :ghfile:`numba/typing/mathdecl.py` - Python ``math`` module -- :ghfile:`numba/typing/listdecl.py` - Python lists -- :ghfile:`numba/typing/builtins.py` - Python builtin global functions and +- :ghfile:`numba/core/typing/mathdecl.py` - Python ``math`` module +- :ghfile:`numba/core/typing/listdecl.py` - Python lists +- :ghfile:`numba/core/typing/builtins.py` - Python builtin global functions and operators -- :ghfile:`numba/typing/randomdecl.py` - Python and NumPy ``random`` modules -- :ghfile:`numba/typing/setdecl.py` - Python sets -- :ghfile:`numba/typing/npydecl.py` - NumPy ndarray (and operators), NumPy +- :ghfile:`numba/core/typing/randomdecl.py` - Python and NumPy ``random`` + modules +- :ghfile:`numba/core/typing/setdecl.py` - Python sets +- :ghfile:`numba/core/typing/npydecl.py` - NumPy ndarray (and operators), NumPy functions -- :ghfile:`numba/typing/arraydecl.py` - Python ``array`` module -- :ghfile:`numba/typing/context.py` - Implementation of typing context +- :ghfile:`numba/core/typing/arraydecl.py` - Python ``array`` module +- :ghfile:`numba/core/typing/context.py` - Implementation of typing context (class that collects methods used in type inference) -- :ghfile:`numba/typing/collections.py` - Generic container operations and +- :ghfile:`numba/core/typing/collections.py` - Generic container operations and namedtuples -- :ghfile:`numba/typing/ctypes_utils.py` - Typing ctypes-wrapped function +- :ghfile:`numba/core/typing/ctypes_utils.py` - Typing ctypes-wrapped function pointers -- :ghfile:`numba/typing/enumdecl.py` - Enum types -- :ghfile:`numba/typing/cffi_utils.py` - Typing of CFFI objects -- :ghfile:`numba/typing/typeof.py` - Implementation of typeof operations +- :ghfile:`numba/core/typing/enumdecl.py` - Enum types +- :ghfile:`numba/core/typing/cffi_utils.py` - Typing of CFFI objects +- :ghfile:`numba/core/typing/typeof.py` - Implementation of typeof operations (maps Python object to Numba type) -- :ghfile:`numba/typing/npdatetime.py` - Datetime dtype support for NumPy +- :ghfile:`numba/core/typing/npdatetime.py` - Datetime dtype support for NumPy arrays @@ -382,97 +387,94 @@ Note that some of these modules do not have counterparts in the typing package because newer Numba extension APIs (like overload) allow typing and implementation to be specified together. -- :ghfile:`numba/targets` - Implementations of compilable operations -- :ghfile:`numba/targets/cpu.py` - Context for code gen on CPU -- :ghfile:`numba/targets/base.py` - Base class for all target contexts -- :ghfile:`numba/targets/codegen.py` - Driver for code generation -- :ghfile:`numba/targets/boxing.py` - Boxing and unboxing for most data +- :ghfile:`numba/core/cpu.py` - Context for code gen on CPU +- :ghfile:`numba/core/base.py` - Base class for all target contexts +- :ghfile:`numba/core/codegen.py` - Driver for code generation +- :ghfile:`numba/core/boxing.py` - Boxing and unboxing for most data types -- :ghfile:`numba/targets/intrinsics.py` - Utilities for converting LLVM +- :ghfile:`numba/core/intrinsics.py` - Utilities for converting LLVM intrinsics to other math calls -- :ghfile:`numba/targets/callconv.py` - Implements different calling +- :ghfile:`numba/core/callconv.py` - Implements different calling conventions for Numba-compiled functions -- :ghfile:`numba/targets/iterators.py` - Iterable data types and iterators -- :ghfile:`numba/targets/hashing.py` - Hashing algorithms -- :ghfile:`numba/targets/ufunc_db.py` - Big table mapping types to ufunc - implementations -- :ghfile:`numba/targets/setobj.py` - Python set type -- :ghfile:`numba/targets/options.py` - Container for options that control +- :ghfile:`numba/core/options.py` - Container for options that control lowering -- :ghfile:`numba/targets/printimpl.py` - Print function -- :ghfile:`numba/targets/cmathimpl.py` - Python complex math module -- :ghfile:`numba/targets/optional.py` - Special type representing value or +- :ghfile:`numba/core/optional.py` - Special type representing value or ``None`` -- :ghfile:`numba/targets/tupleobj.py` - Tuples (statically typed as - immutable struct) -- :ghfile:`numba/targets/mathimpl.py` - Python ``math`` module -- :ghfile:`numba/targets/heapq.py` - Python ``heapq`` module -- :ghfile:`numba/targets/registry.py` - Registry object for collecting +- :ghfile:`numba/core/registry.py` - Registry object for collecting implementations for a specific target -- :ghfile:`numba/targets/imputils.py` - Helper functions for lowering -- :ghfile:`numba/targets/builtins.py` - Python builtin functions and - operators -- :ghfile:`numba/targets/externals.py` - Registers external C functions +- :ghfile:`numba/core/imputils.py` - Helper functions for lowering +- :ghfile:`numba/core/externals.py` - Registers external C functions needed to link generated code -- :ghfile:`numba/targets/quicksort.py` - Quicksort implementation used with - list and array objects -- :ghfile:`numba/targets/mergesort.py` - Mergesort implementation used with - array objects -- :ghfile:`numba/targets/randomimpl.py` - Python and NumPy ``random`` - modules -- :ghfile:`numba/targets/npyimpl.py` - Implementations of most NumPy ufuncs -- :ghfile:`numba/targets/slicing.py` - Slice objects, and index calculations - used in slicing -- :ghfile:`numba/targets/numbers.py` - Numeric values (int, float, etc) -- :ghfile:`numba/targets/listobj.py` - Python lists -- :ghfile:`numba/targets/fastmathpass.py` - Rewrite pass to add fastmath +- :ghfile:`numba/core/fastmathpass.py` - Rewrite pass to add fastmath attributes to function call sites and binary operations -- :ghfile:`numba/targets/removerefctpass.py` - Rewrite pass to remove +- :ghfile:`numba/core/removerefctpass.py` - Rewrite pass to remove unnecessary incref/decref pairs -- :ghfile:`numba/targets/cffiimpl.py` - CFFI functions -- :ghfile:`numba/targets/descriptors.py` - empty base class for all target +- :ghfile:`numba/core/descriptors.py` - empty base class for all target descriptors (is this needed?) -- :ghfile:`numba/targets/arraymath.py` - Math operations on arrays (both +- :ghfile:`numba/cpython/builtins.py` - Python builtin functions and + operators +- :ghfile:`numba/cpython/cmathimpl.py` - Python complex math module +- :ghfile:`numba/cpython/enumimpl.py` - Enum objects +- :ghfile:`numba/cpython/hashing.py` - Hashing algorithms +- :ghfile:`numba/cpython/heapq.py` - Python ``heapq`` module +- :ghfile:`numba/cpython/iterators.py` - Iterable data types and iterators +- :ghfile:`numba/cpython/listobj.py` - Python lists +- :ghfile:`numba/cpython/mathimpl.py` - Python ``math`` module +- :ghfile:`numba/cpython/numbers.py` - Numeric values (int, float, etc) +- :ghfile:`numba/cpython/printimpl.py` - Print function +- :ghfile:`numba/cpython/randomimpl.py` - Python and NumPy ``random`` + modules +- :ghfile:`numba/cpython/rangeobj.py` - Python `range` objects +- :ghfile:`numba/cpython/slicing.py` - Slice objects, and index calculations + used in slicing +- :ghfile:`numba/cpython/setobj.py` - Python set type +- :ghfile:`numba/cpython/tupleobj.py` - Tuples (statically typed as + immutable struct) +- :ghfile:`numba/misc/cffiimpl.py` - CFFI functions +- :ghfile:`numba/misc/quicksort.py` - Quicksort implementation used with + list and array objects +- :ghfile:`numba/misc/mergesort.py` - Mergesort implementation used with + array objects +- :ghfile:`numba/np/arraymath.py` - Math operations on arrays (both Python and NumPy) -- :ghfile:`numba/targets/linalg.py` - NumPy linear algebra operations -- :ghfile:`numba/targets/rangeobj.py` - Python `range` objects -- :ghfile:`numba/targets/npyfuncs.py` - Kernels used in generating some - NumPy ufuncs -- :ghfile:`numba/targets/arrayobj.py` - Array operations (both NumPy and +- :ghfile:`numba/np/arrayobj.py` - Array operations (both NumPy and buffer protocol) -- :ghfile:`numba/targets/enumimpl.py` - Enum objects -- :ghfile:`numba/targets/polynomial.py` - ``numpy.roots`` function -- :ghfile:`numba/targets/npdatetime.py` - NumPy datetime operations +- :ghfile:`numba/np/linalg.py` - NumPy linear algebra operations +- :ghfile:`numba/np/npdatetime.py` - NumPy datetime operations +- :ghfile:`numba/np/npyfuncs.py` - Kernels used in generating some + NumPy ufuncs +- :ghfile:`numba/np/npyimpl.py` - Implementations of most NumPy ufuncs +- :ghfile:`numba/np/polynomial.py` - ``numpy.roots`` function +- :ghfile:`numba/np/ufunc_db.py` - Big table mapping types to ufunc + implementations Ufunc Compiler and Runtime '''''''''''''''''''''''''' -- :ghfile:`numba/npyufunc` - ufunc compiler implementation -- :ghfile:`numba/npyufunc/_internal.{h,c}` - Python extension module with +- :ghfile:`numba/np/ufunc` - ufunc compiler implementation +- :ghfile:`numba/np/ufunc/_internal.{h,c}` - Python extension module with helper functions that use CPython & NumPy C API -- :ghfile:`numba/npyufunc/_ufunc.c` - Used by `_internal.c` -- :ghfile:`numba/npyufunc/deviceufunc.py` - Custom ufunc dispatch for +- :ghfile:`numba/np/ufunc/_ufunc.c` - Used by `_internal.c` +- :ghfile:`numba/np/ufunc/deviceufunc.py` - Custom ufunc dispatch for non-CPU targets -- :ghfile:`numba/npyufunc/gufunc_scheduler.{h,cpp}` - Schedule work chunks +- :ghfile:`numba/np/ufunc/gufunc_scheduler.{h,cpp}` - Schedule work chunks to threads -- :ghfile:`numba/npyufunc/dufunc.py` - Special ufunc that can compile new +- :ghfile:`numba/np/ufunc/dufunc.py` - Special ufunc that can compile new implementations at call time -- :ghfile:`numba/npyufunc/ufuncbuilder.py` - Top-level orchestration of +- :ghfile:`numba/np/ufunc/ufuncbuilder.py` - Top-level orchestration of ufunc/gufunc compiler pipeline -- :ghfile:`numba/npyufunc/sigparse.py` - Parser for generalized ufunc +- :ghfile:`numba/np/ufunc/sigparse.py` - Parser for generalized ufunc indexing signatures -- :ghfile:`numba/npyufunc/parfor.py` - gufunc lowering for - ParallelAccelerator -- :ghfile:`numba/npyufunc/parallel.py` - Codegen for ``parallel`` target -- :ghfile:`numba/npyufunc/array_exprs.py` - Rewrite pass for turning array +- :ghfile:`numba/np/ufunc/parallel.py` - Codegen for ``parallel`` target +- :ghfile:`numba/np/ufunc/array_exprs.py` - Rewrite pass for turning array expressions in regular functions into ufuncs -- :ghfile:`numba/npyufunc/wrappers.py` - Wrap scalar function kernel with +- :ghfile:`numba/np/ufunc/wrappers.py` - Wrap scalar function kernel with loops -- :ghfile:`numba/npyufunc/workqueue.{h,c}` - Threading backend based on +- :ghfile:`numba/np/ufunc/workqueue.{h,c}` - Threading backend based on pthreads/Windows threads and queues -- :ghfile:`numba/npyufunc/omppool.cpp` - Threading backend based on OpenMP -- :ghfile:`numba/npyufunc/tbbpool.cpp` - Threading backend based on TBB +- :ghfile:`numba/np/ufunc/omppool.cpp` - Threading backend based on OpenMP +- :ghfile:`numba/np/ufunc/tbbpool.cpp` - Threading backend based on TBB @@ -486,7 +488,7 @@ CPU unit tests (GPU target unit tests listed in later sections - :ghfile:`run_coverage.py` - Runs test suite with coverage tracking enabled - :ghfile:`.coveragerc` - Coverage.py configuration - :ghfile:`numba/runtests.py` - Entry point to unittest runner -- :ghfile:`numba/_runtests.py` - Implementation of custom test runner +- :ghfile:`numba/testing/_runtests.py` - Implementation of custom test runner command line interface - :ghfile:`numba/tests/test_*` - Test cases - :ghfile:`numba/tests/*_usecases.py` - Python functions compiled by some @@ -496,8 +498,6 @@ CPU unit tests (GPU target unit tests listed in later sections - :ghfile:`numba/tests/dummy_module.py` - Module used in ``test_dispatcher.py`` - :ghfile:`numba/tests/npyufunc` - ufunc / gufunc compiler tests -- :ghfile:`numba/unittest_support.py` - Import instead of unittest to handle - portability issues - :ghfile:`numba/testing` - Support code for testing - :ghfile:`numba/testing/loader.py` - Find tests on disk - :ghfile:`numba/testing/notebook.py` - Support for testing notebooks @@ -508,7 +508,7 @@ Command Line Utilities '''''''''''''''''''''' - :ghfile:`bin/numba` - Command line stub, delegates to main in ``numba_entry.py`` -- :ghfile:`numba/numba_entry.py` - Main function for ``numba`` command line +- :ghfile:`numba/misc/numba_entry.py` - Main function for ``numba`` command line tool - :ghfile:`numba/pycc` - Ahead of time compilation of functions to shared library extension @@ -625,6 +625,9 @@ target was based on the HSA API, so "hsa" appears in many places. - :ghfile:`numba/roc/codegen.py` - Codegen subclass for ROCm target - :ghfile:`numba/roc/decorators.py` - ``@jit`` decorator for kernels and device functions +- :ghfile:`numba/roc/servicelib/threadlocal.py` - Thread-local stack used by ROC + targets +- :ghfile:`numba/roc/servicelib/service.py` - Should be removed? - :ghfile:`numba/roc/tests` - Unit tests for ROCm target - :ghfile:`numba/roc/tests/hsapy` - Tests of compiling ROCm kernels written in Python syntax diff --git a/docs/source/user/jitclass.rst b/docs/source/user/jitclass.rst index 9864febbbc6..f98f6e819c0 100644 --- a/docs/source/user/jitclass.rst +++ b/docs/source/user/jitclass.rst @@ -178,4 +178,4 @@ Limitations The decorator: ``@jitclass`` ============================ -.. autofunction:: numba.jitclass +.. autofunction:: numba.experimental.jitclass diff --git a/numba/__init__.py b/numba/__init__.py index 0add9918895..698867fc0b4 100644 --- a/numba/__init__.py +++ b/numba/__init__.py @@ -24,6 +24,9 @@ # Re-export error classes from numba.core.errors import * +# Re-export types itself +import numba.core.types as types + # Re-export all type names from numba.core.types import * diff --git a/numba/core/types/__init__.py b/numba/core/types/__init__.py index 98915c8435a..4b37577c098 100644 --- a/numba/core/types/__init__.py +++ b/numba/core/types/__init__.py @@ -72,7 +72,7 @@ complex_domain = frozenset([complex64, complex128]) number_domain = real_domain | integer_domain | complex_domain -# Aliases to Numpy type names +# Aliases to NumPy type names b1 = bool_ i1 = int8 From 4657d360948651d58d590a6c9f774acd4bc3543c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 6 Feb 2020 14:09:46 +0000 Subject: [PATCH 474/595] Remove AUTHORS list As title. AUTHORS is dated and git records this information. --- AUTHORS | 60 --------------------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index 49ea12e229a..00000000000 --- a/AUTHORS +++ /dev/null @@ -1,60 +0,0 @@ -Numba proof of concept was originally written by -Travis Oliphant - -If you have contributed to Numba add your name to this file: - -ahmadia -Alberto Valverde -Antoine Pitrou -Bengt Lüers -Björn Linse -Christoph Gohlke -Dag Sverre Seljebotn -Dan Christensen -Dan Yamins -David Warde-Farley -Falcon Dai -Francesc Alted -Frederic -Gaëtan de Menten -GFKjunior -Graham Markall -Hernan Grecco -Ilan Schnell -James Bergstra -Jay Bourque -Jens Timmerman -Jim Garrison -Jon Riehl (Resilient Science) -Juan Luis Cano Rodríguez -kichik -Lars Buitinck -Laurent Fasnacht -liuzhenhai <1989lzhh@gmail.com> -Maggie Mari -majidaldo -Mark Florisson -Mark Wiebe -Martin Fiers -Martin Spacek -Meador Inge -Michael Joyce -Matthew Goodman -Ondřej Čertík -Óscar Villellas Guillén -Pablo Jiménez Mateo -Phillip Cloud -Scott Chadde -Shiquan Wang -Siu Kwan Lam -Stan Seibert -Stefan Seefeld -Thomas Kluyver -timo -Travis E. Oliphant -Uri Laserson -Valentin Haenel -Yaroslav Halchenko -Yauhen Yakimovich -Yuval Langer - From 190de9353905feb0219ee189312865e766655c43 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 6 Feb 2020 14:21:14 +0000 Subject: [PATCH 475/595] Remove reference to file in docs --- docs/source/developer/repomap.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/developer/repomap.rst b/docs/source/developer/repomap.rst index 126b25cb4e5..d1b0d359175 100644 --- a/docs/source/developer/repomap.rst +++ b/docs/source/developer/repomap.rst @@ -53,8 +53,6 @@ Documentation / Examples - :ghfile:`README.rst` - README for repo, also uploaded to PyPI - :ghfile:`CONTRIBUTING.md` - Documentation on how to contribute to project (out of date, should be updated to point to Sphinx docs) -- :ghfile:`AUTHORS` - List of Github users who have contributed PRs (out of - date) - :ghfile:`CHANGE_LOG` - History of Numba releases, also directly embedded into Sphinx documentation - :ghfile:`docs/` - Documentation source From 2b4c126294d1738f202e2aff6a08ab84a225853d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 6 Feb 2020 15:29:09 +0000 Subject: [PATCH 476/595] Add missing stencils/__init__.py --- numba/stencils/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 numba/stencils/__init__.py diff --git a/numba/stencils/__init__.py b/numba/stencils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 27e47ab44ab8278aa8e626a7b7e40fa951fc77f0 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 6 Feb 2020 10:07:50 -0600 Subject: [PATCH 477/595] Fix build script entry point --- buildscripts/condarecipe.local/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildscripts/condarecipe.local/meta.yaml b/buildscripts/condarecipe.local/meta.yaml index 90dcffdb898..cfa1d5e6a79 100644 --- a/buildscripts/condarecipe.local/meta.yaml +++ b/buildscripts/condarecipe.local/meta.yaml @@ -10,7 +10,7 @@ build: string: np{{ NPY_VER }}py{{ PY_VER }}h{{ PKG_HASH }}_{{GIT_DESCRIBE_HASH}}_{{ GIT_DESCRIBE_NUMBER }} entry_points: - pycc = numba.pycc:main - - numba = numba.numba_entry:main + - numba = numba.misc.numba_entry:main script_env: - PY_VCRUNTIME_REDIST missing_dso_whitelist: # [osx] From 526c6096aed247b526fb7f8a9e4133f57ddb2d27 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 6 Feb 2020 11:25:31 -0600 Subject: [PATCH 478/595] Fix package data --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 9ed18d1c9da..b9a847fea94 100644 --- a/setup.py +++ b/setup.py @@ -325,17 +325,17 @@ def check_file_at_path(path2file): ], package_data={ # HTML templates for type annotations - "numba.annotations": ["*.html"], + "numba.core.annotations": ["*.html"], # Various test data "numba.cuda.tests.cudadrv.data": ["*.ptx"], "numba.tests": ["pycc_distutils_usecase/*.py"], # Some C files are needed by pycc "numba": ["*.c", "*.h"], "numba.pycc": ["*.c", "*.h"], - "numba.runtime": ["*.c", "*.h"], + "numba.core.runtime": ["*.c", "*.h"], "numba.cext": ["*.c", "*.h"], # numba gdb hook init command language file - "numba.targets": ["cmdlang.gdb"], + "numba.misc": ["cmdlang.gdb"], }, scripts=["numba/pycc/pycc", "bin/numba"], author="Anaconda, Inc.", From 4913e5c4a53378040ecf44d19b5c4540cc4130dd Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Thu, 6 Feb 2020 23:47:03 +0100 Subject: [PATCH 479/595] added support for global tuples --- numba/tests/test_record_dtype.py | 36 ++++++++++++++++++++++++++++++++ numba/typeinfer.py | 3 +++ numba/untyped_passes.py | 4 ++++ 3 files changed, 43 insertions(+) diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 50181ee56e1..1b1cbb77d32 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -263,6 +263,19 @@ def get_field2(rec): return out +fs = ('e', 'f') +def get_field3(rec): + f = fs[1] + return rec[f] + + +def get_field4(rec): + out = 0 + for f in literal_unroll(fs): + out += rec[f] + return out + + recordtype = np.dtype([('a', np.float64), ('b', np.int16), ('c', np.complex64), @@ -1008,6 +1021,29 @@ def test_literal_unroll(self): jitfunc = njit(pyfunc) self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) + def test_literal_variable_global_tuple(self): + """ + this tests the getitem of record array when the indexes come from a + global tuple. It tests getitem behaviour but also tests that a global + tuple is being typed as a tuple of constants. + """ + arr = np.array([1, 2], dtype=recordtype2) + pyfunc = get_field3 + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) + + def test_literal_unroll_global_tuple(self): + """ + this tests the getitem of record array when the indexes come from a + global tuple and are being unrolled. + It tests getitem behaviour but also tests that literal_unroll accepts + a global tuple as argument + """ + arr = np.array([1, 2], dtype=recordtype2) + pyfunc = get_field4 + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) + if __name__ == '__main__': unittest.main() diff --git a/numba/typeinfer.py b/numba/typeinfer.py index 789c8ae6f9a..72b493bbd8e 100644 --- a/numba/typeinfer.py +++ b/numba/typeinfer.py @@ -1478,6 +1478,9 @@ def typeof_global(self, inst, target, gvar): # Global array in nopython mode is constant typ = typ.copy(readonly=True) + if isinstance(typ, (types.Tuple, types.UniTuple)): + typ = types.Tuple([types.literal(val) for val in gvar.value]) + self.sentry_modified_builtin(inst, gvar) # Setting literal_value for globals because they are handled # like const value in numba diff --git a/numba/untyped_passes.py b/numba/untyped_passes.py index d5735e6f8b5..4075ea6fc8c 100644 --- a/numba/untyped_passes.py +++ b/numba/untyped_passes.py @@ -676,6 +676,10 @@ def run_pass(self, state): to_unroll.op == "build_tuple"): # this is fine, do nothing pass + elif (isinstance(to_unroll, ir.Global) and + isinstance(to_unroll.value, tuple)): + # this is fine, do nothing + pass elif isinstance(to_unroll, ir.Arg): # this is only fine if the arg is a tuple ty = state.typemap[to_unroll.name] From 314c56565e20befa630b3626513690f1b0221195 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 09:27:33 +0100 Subject: [PATCH 480/595] extended docs for struct scalars --- docs/source/reference/numpysupported.rst | 38 +++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index 4e90f58fd14..237d37aa035 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -96,7 +96,43 @@ Whereas the following will not work: print(i.view(np.uint64)) Structured scalars support attribute getting and setting, as well as -member lookup using constant strings. +member lookup using constant strings. These constant strings are allowed to be stored +in a local or global tuple. + +.. code:: pycon + + + + >>> import numpy as np + >>> from numba import njit + >>> arr = np.array([1, 2], dtype=[('a1', 'f8'), ('a2', 'f8')]) + >>> @njit + >>> fields_gl = ('a1', 'a2') + >>> def get_field_sum(rec): + >>> fields_lc = ('a1', 'a2') + >>> field_name1 = fields_lc[0] + >>> field_name2 = fields_gl[1] + >>> return rec[field_name1] + rec[field_name2] + >>> + >>> get_field_sum(arr[0]) + 3 + +It is also possible to use local or global tuples together with ``literal_unroll``: + + + >>> import numpy as np + >>> from numba import njit + >>> arr = np.array([1, 2], dtype=[('a1', 'f8'), ('a2', 'f8')]) + >>> @njit + >>> fields_gl = ('a1', 'a2') + >>> def get_field_sum(rec): + >>> out = 0 + >>> for f in literal_unroll(fields_gl): + >>> out += arr[f] + >>> return out + >>> + >>> get_field_sum(arr[0]) + 3 .. seealso:: `Numpy scalars `_ From 83f29651e0592e31af25fd0cdccdaef5550a709a Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 09:48:45 +0100 Subject: [PATCH 481/595] flake8 fixes --- numba/core/untyped_passes.py | 2 +- numba/tests/test_record_dtype.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 719faabdeed..b3787773197 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -674,7 +674,7 @@ def run_pass(self, state): # this is fine, do nothing pass elif (isinstance(to_unroll, ir.Global) and - isinstance(to_unroll.value, tuple)): + isinstance(to_unroll.value, tuple)): # this is fine, do nothing pass elif isinstance(to_unroll, ir.Arg): diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 5d305863cf1..488585222a0 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -266,6 +266,8 @@ def get_field2(rec): fs = ('e', 'f') + + def get_field3(rec): f = fs[1] return rec[f] From 1188310b99be1dc48e0994e7e2f76ecf80b1214d Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 10:13:43 +0100 Subject: [PATCH 482/595] doc improvement --- docs/source/reference/numpysupported.rst | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index 776a89834df..509bcf6727a 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -96,8 +96,8 @@ Whereas the following will not work: print(i.view(np.uint64)) Structured scalars support attribute getting and setting, as well as -member lookup using constant strings. These constant strings are allowed to be stored -in a local or global tuple. +member lookup using constant strings. Strings stored in a local or global tuple +are considered constant strings and can be used for member lookup. .. code:: pycon @@ -106,14 +106,14 @@ in a local or global tuple. >>> import numpy as np >>> from numba import njit >>> arr = np.array([1, 2], dtype=[('a1', 'f8'), ('a2', 'f8')]) - >>> @njit >>> fields_gl = ('a1', 'a2') - >>> def get_field_sum(rec): - >>> fields_lc = ('a1', 'a2') - >>> field_name1 = fields_lc[0] - >>> field_name2 = fields_gl[1] - >>> return rec[field_name1] + rec[field_name2] - >>> + >>> @njit + ... def get_field_sum(rec): + ... fields_lc = ('a1', 'a2') + ... field_name1 = fields_lc[0] + ... field_name2 = fields_gl[1] + ... return rec[field_name1] + rec[field_name2] + ... >>> get_field_sum(arr[0]) 3 @@ -123,14 +123,14 @@ It is also possible to use local or global tuples together with ``literal_unroll >>> import numpy as np >>> from numba import njit >>> arr = np.array([1, 2], dtype=[('a1', 'f8'), ('a2', 'f8')]) - >>> @njit >>> fields_gl = ('a1', 'a2') - >>> def get_field_sum(rec): - >>> out = 0 - >>> for f in literal_unroll(fields_gl): - >>> out += arr[f] - >>> return out - >>> + >>> @njit + ... def get_field_sum(rec): + ... out = 0 + ... for f in literal_unroll(fields_gl): + ... out += arr[f] + ... return out + ... >>> get_field_sum(arr[0]) 3 From f4bf50e34af3734e79dfb85c336273345a1bbebe Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 11:14:46 +0100 Subject: [PATCH 483/595] added tests for global and freevar typing and literal unrolling --- numba/tests/test_globals.py | 37 +++++++++++++++++++++++- numba/tests/test_mixed_tuple_unroller.py | 23 +++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_globals.py b/numba/tests/test_globals.py index 38704fa6eb1..9faaaa5675b 100644 --- a/numba/tests/test_globals.py +++ b/numba/tests/test_globals.py @@ -1,5 +1,5 @@ import numpy as np -from numba import jit +from numba import jit, njit from numba.tests import usecases import unittest @@ -71,6 +71,25 @@ def global_record_func(x): def global_module_func(x, y): return usecases.andornopython(x, y) +# Test a global tuple +tup_int = (1, 2) +tup_str = ('a', 'b') +tup_mixed = (1, 'a') + + +def global_int_tuple(): + return tup_int[0] + tup_int[1] + + +def global_str_tuple(): + return tup_str[0] + tup_str[1] + + +def global_mixed_tuple(): + idx = tup_mixed[0] + field = tup_mixed[1] + return rec_X[idx][field] + class TestGlobals(unittest.TestCase): @@ -166,5 +185,21 @@ def test_global_record(self): res = global_record_func(x) self.assertEqual(False, res) + def test_global_int_tuple(self): + pyfunc = global_int_tuple + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(), jitfunc()) + + def test_global_str_tuple(self): + pyfunc = global_str_tuple + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(), jitfunc()) + + def test_global_mixed_tuple(self): + pyfunc = global_mixed_tuple + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(), jitfunc()) + + if __name__ == '__main__': unittest.main() diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index c10dfa10601..2ed131fbdcb 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -17,6 +17,7 @@ NoPythonBackend, PartialTypeInference) from numba.core.ir_utils import (compute_cfg_from_blocks, flatten_labels) +x_global = (10, 11) class TestLiteralTupleInterpretation(MemoryLeakMixin, TestCase): @@ -1660,6 +1661,28 @@ def foo(): ['a 1', 'b 2', '3 c', '4 d'], ) + def test_unroll_global_tuple(self): + + @njit + def foo(): + out = 0 + for i in literal_unroll(x_global): + out += i + return out + + self.assertEqual(foo(), foo.py_func()) + + def test_unroll_freevar_tuple(self): + x = (10, 11) + + @njit + def foo(): + out = 0 + for i in literal_unroll(x): + out += i + return out + + self.assertEqual(foo(), foo.py_func()) def capture(real_pass): """ Returns a compiler pass that captures the mutation state reported From 71166d858001ab647bff36773e62fec23d59849f Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 11:15:27 +0100 Subject: [PATCH 484/595] restricted literal typing of global tuples to Unicode and Integer cases --- numba/core/typeinfer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/numba/core/typeinfer.py b/numba/core/typeinfer.py index 083092faa36..f8e4dfb6648 100644 --- a/numba/core/typeinfer.py +++ b/numba/core/typeinfer.py @@ -1479,8 +1479,16 @@ def typeof_global(self, inst, target, gvar): # Global array in nopython mode is constant typ = typ.copy(readonly=True) - if isinstance(typ, (types.Tuple, types.UniTuple)): - typ = types.Tuple([types.literal(val) for val in gvar.value]) + if isinstance(typ, types.Tuple): + if all(isinstance(ty, (types.Integer, types.UnicodeType)) for ty in typ): + typ = types.Tuple([types.literal(val) for val in gvar.value]) + + if isinstance(typ, types.UniTuple): + # since this test makes typ into a Tuple, it must be placed after + # the test for types.Tuple to prevent double-triggering + if isinstance(typ.dtype, (types.Integer, types.UnicodeType)): + typ = types.Tuple([types.literal(val) for val in gvar.value]) + self.sentry_modified_builtin(inst, gvar) # Setting literal_value for globals because they are handled From a262116692839186ef5602735974ccd02267deb1 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 11:16:32 +0100 Subject: [PATCH 485/595] added FreeVar as acceptable input to literal_unroll --- numba/core/untyped_passes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index b3787773197..7c9a7aedc95 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -673,7 +673,7 @@ def run_pass(self, state): to_unroll.op == "build_tuple"): # this is fine, do nothing pass - elif (isinstance(to_unroll, ir.Global) and + elif (isinstance(to_unroll, (ir.Global, ir.FreeVar)) and isinstance(to_unroll.value, tuple)): # this is fine, do nothing pass From 0931220b40228a5a5da3f4699de15a3e919fbb4d Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 11:20:55 +0100 Subject: [PATCH 486/595] one test on float tuple global --- numba/tests/test_globals.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_globals.py b/numba/tests/test_globals.py index 9faaaa5675b..10d0c33cd20 100644 --- a/numba/tests/test_globals.py +++ b/numba/tests/test_globals.py @@ -75,7 +75,7 @@ def global_module_func(x, y): tup_int = (1, 2) tup_str = ('a', 'b') tup_mixed = (1, 'a') - +tup_float = (1.2, 3.5) def global_int_tuple(): return tup_int[0] + tup_int[1] @@ -91,6 +91,10 @@ def global_mixed_tuple(): return rec_X[idx][field] +def global_float_tuple(): + return tup_float[0] + tup_float[1] + + class TestGlobals(unittest.TestCase): def check_global_ndarray(self, **jitargs): @@ -200,6 +204,11 @@ def test_global_mixed_tuple(self): jitfunc = njit(pyfunc) self.assertEqual(pyfunc(), jitfunc()) + def test_global_float_tuple(self): + pyfunc = global_float_tuple + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(), jitfunc()) + if __name__ == '__main__': unittest.main() From 5936a42925096ebc02f712bae163f6e90202e3da Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 13:06:33 +0100 Subject: [PATCH 487/595] flake8 fix --- numba/core/typeinfer.py | 4 ++-- numba/tests/test_mixed_tuple_unroller.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/numba/core/typeinfer.py b/numba/core/typeinfer.py index f8e4dfb6648..b4488554ee2 100644 --- a/numba/core/typeinfer.py +++ b/numba/core/typeinfer.py @@ -1480,7 +1480,8 @@ def typeof_global(self, inst, target, gvar): typ = typ.copy(readonly=True) if isinstance(typ, types.Tuple): - if all(isinstance(ty, (types.Integer, types.UnicodeType)) for ty in typ): + if all(isinstance(ty, (types.Integer, types.UnicodeType)) + for ty in typ): typ = types.Tuple([types.literal(val) for val in gvar.value]) if isinstance(typ, types.UniTuple): @@ -1489,7 +1490,6 @@ def typeof_global(self, inst, target, gvar): if isinstance(typ.dtype, (types.Integer, types.UnicodeType)): typ = types.Tuple([types.literal(val) for val in gvar.value]) - self.sentry_modified_builtin(inst, gvar) # Setting literal_value for globals because they are handled # like const value in numba diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 2ed131fbdcb..f3e4b0d64c4 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -19,6 +19,7 @@ x_global = (10, 11) + class TestLiteralTupleInterpretation(MemoryLeakMixin, TestCase): def check(self, func, var): @@ -1684,6 +1685,7 @@ def foo(): self.assertEqual(foo(), foo.py_func()) + def capture(real_pass): """ Returns a compiler pass that captures the mutation state reported by the pass used in the argument""" From 2c9097423df08fc4b37fd31f4422eff93e510259 Mon Sep 17 00:00:00 2001 From: Rohit Sanjay Date: Fri, 7 Feb 2020 19:40:04 +0530 Subject: [PATCH 488/595] fix `.strip()` by including all whitespace types --- numba/cpython/unicode.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index 5ef88103c1c..7b186dd3414 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -1388,7 +1388,7 @@ def zfill_impl(string, width): # ------------------------------------------------------------------------------ @register_jitable def unicode_strip_left_bound(string, chars): - chars = ' ' if chars is None else chars + chars = ' \t\n\r\x0b\x0c' if chars is None else chars str_len = len(string) for i in range(str_len): @@ -1399,7 +1399,7 @@ def unicode_strip_left_bound(string, chars): @register_jitable def unicode_strip_right_bound(string, chars): - chars = ' ' if chars is None else chars + chars = ' \t\n\r\x0b\x0c' if chars is None else chars str_len = len(string) for i in range(str_len - 1, -1, -1): From 94c05ec78f645740b3ec8b0407c6306304486f64 Mon Sep 17 00:00:00 2001 From: Rohit Sanjay Date: Fri, 7 Feb 2020 19:56:02 +0530 Subject: [PATCH 489/595] added tests for whitespace strip --- numba/tests/test_unicode.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 286e99693f9..3054fe5bdeb 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -1701,7 +1701,12 @@ def test_strip(self): (' tú quién te crees? ', None), ('大处 着眼,小处着手。大大大处', '大处'), (' 大处大处 ', ''), - (' 大处大处 ', None) + (' 大处大处 ', None), + ('\t abcd \t', None), + ('\n abcd \n', None), + ('\r abcd \r', None), + ('\x0b abcd \x0b', None), + ('\x0c abcd \x0c', None) ] # form with no parameter From d99ae8e3a6f87ee60ede8908e5c5d2dfa048320b Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 7 Feb 2020 11:27:11 -0600 Subject: [PATCH 490/595] Add test for #5215 --- numba/tests/test_tuples.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index 4f4fadbaea7..0d3cedc38f1 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -520,6 +520,22 @@ def foo(): r = foo() self.assertEqual(r, Rect(width=10, height='somestring')) + def test_dispatcher_mistreat(self): + # Test for issue #5215 that mistreat namedtuple as tuples + @jit(nopython=True) + def foo(x): + return x + + in1 = (1, 2, 3) + out1 = foo(in1) + self.assertEqual(in1, out1) + + in2 = Point(1, 2, 3) + out2 = foo(in2) + self.assertEqual(in2, out2) + + self.assertEqual(len(foo.nopython_signatures), 2) + class TestTupleNRT(TestCase, MemoryLeakMixin): def test_tuple_add(self): From f1c53ea292d2468a3359bc7f4eba39e538a1333d Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 7 Feb 2020 11:27:23 -0600 Subject: [PATCH 491/595] Fix #5215 --- numba/_typeof.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/_typeof.c b/numba/_typeof.c index a4a97657717..242150cccd0 100644 --- a/numba/_typeof.c +++ b/numba/_typeof.c @@ -256,7 +256,7 @@ compute_fingerprint(string_writer_t *w, PyObject *val) return string_writer_put_char(w, OP_FLOAT); if (PyComplex_CheckExact(val)) return string_writer_put_char(w, OP_COMPLEX); - if (PyTuple_Check(val)) { + if (PyTuple_CheckExact(val)) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(val); TRY(string_writer_put_char, w, OP_START_TUPLE); From a04adcc7e4b04f43b333487a435d0a41f64cd1ce Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Fri, 7 Feb 2020 11:31:06 -0600 Subject: [PATCH 492/595] Make sure the signatures matches the expectation --- numba/tests/test_tuples.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index 0d3cedc38f1..a23ea35585f 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -4,7 +4,7 @@ import numpy as np from numba.core.compiler import compile_isolated -from numba import njit, jit +from numba import njit, jit, typeof from numba.core import types, errors, utils from numba.tests.support import TestCase, MemoryLeakMixin, tag import unittest @@ -534,7 +534,10 @@ def foo(x): out2 = foo(in2) self.assertEqual(in2, out2) + # Check the signatures self.assertEqual(len(foo.nopython_signatures), 2) + self.assertEqual(foo.nopython_signatures[0].args[0], typeof(in1)) + self.assertEqual(foo.nopython_signatures[1].args[0], typeof(in2)) class TestTupleNRT(TestCase, MemoryLeakMixin): From 234f256b920c007524a5f42cb0f9a31bd1e3bd88 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Fri, 7 Feb 2020 19:50:09 +0100 Subject: [PATCH 493/595] clean up --- numba/np/arrayobj.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 11e7eadf9f3..7b0e9b1b3a8 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -2411,15 +2411,6 @@ def record_getitem(context, builder, sig, args): return impl(context, builder, sig.args[0], args[0], args[1]) -# @lower_builtin(operator.getitem, types.Record, types.StringLiteral) -# def record_getitem(context, builder, sig, args): -# """ -# Record.__getitem__ redirects to getattr() -# """ -# impl = context.get_getattr(sig.args[0], args[1]) -# return impl(context, builder, sig.args[0], args[0], args[1]) - - @lower_builtin('static_setitem', types.Record, types.StringLiteral, types.Any) def record_setitem(context, builder, sig, args): """ From 4291c199103777f44bb01de35d285da6325f9581 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sun, 9 Feb 2020 14:28:46 +0000 Subject: [PATCH 494/595] Fix compiler warnings due to missing (void) In C, `ret_type func()` is a function with unspecified arguments, not a function with no arguments. `ret_type func(void)` is the correct spelling. --- numba/tests/cffi_usecases.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numba/tests/cffi_usecases.py b/numba/tests/cffi_usecases.py index 59b7c91e05b..a101b977d88 100644 --- a/numba/tests/cffi_usecases.py +++ b/numba/tests/cffi_usecases.py @@ -20,7 +20,7 @@ def load_inline_module(): double _numba_test_sin(double x); double _numba_test_cos(double x); double _numba_test_funcptr(double (*func)(double)); - bool _numba_test_boolean(); + bool _numba_test_boolean(void); """ ffi = FFI() @@ -55,7 +55,7 @@ def load_ool_module(): """ defs = numba_complex + """ - bool boolean(); + bool boolean(void); double sin(double x); double cos(double x); int foo(int a, int b, int c); @@ -66,7 +66,7 @@ def load_ool_module(): """ source = numba_complex + bool_define + """ - static bool boolean() + static bool boolean(void) { return true; } From 9f9da8e7fff70bd419c5493cc6e604b87f404d86 Mon Sep 17 00:00:00 2001 From: Rohit Sanjay Date: Mon, 10 Feb 2020 16:36:36 +0530 Subject: [PATCH 495/595] use `_PyUnicode_IsSpace` to account for all whitespace characters --- numba/cpython/unicode.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index 7b186dd3414..1978e603a76 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -1388,24 +1388,35 @@ def zfill_impl(string, width): # ------------------------------------------------------------------------------ @register_jitable def unicode_strip_left_bound(string, chars): - chars = ' \t\n\r\x0b\x0c' if chars is None else chars str_len = len(string) - for i in range(str_len): - if string[i] not in chars: - return i + if chars is not None: + for i in range(str_len): + if string[i] not in chars: + return i + else: + for i in range(str_len): + if not _PyUnicode_IsSpace(string[i]): + return i + return str_len @register_jitable def unicode_strip_right_bound(string, chars): - chars = ' \t\n\r\x0b\x0c' if chars is None else chars str_len = len(string) - for i in range(str_len - 1, -1, -1): - if string[i] not in chars: - i += 1 - break + if chars is not None: + for i in range(str_len - 1, -1, -1): + if string[i] not in chars: + i += 1 + break + else: + for i in range(str_len - 1, -1, -1): + if not _PyUnicode_IsSpace(string[i]): + i += 1 + break + return i From 44f23f7a9b527355c08f821f45de87d0fefde266 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 10 Feb 2020 11:08:39 +0000 Subject: [PATCH 496/595] Add test for upper/lower bounds in chr() As title --- numba/tests/test_unicode.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 16250fa1e78..16c6c9f3a17 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -2433,6 +2433,9 @@ def test_chr(self): for x in ex: a = ord(x) self.assertPreciseEqual(pyfunc(a), cfunc(a)) + # test upper/lower bounds + for a in (0x0, _MAX_UNICODE): + self.assertPreciseEqual(pyfunc(a), cfunc(a)) def test_chr_invalid(self): pyfunc = chr_usecase From 9b5c92bd78e11c23bd39cc94577a37c6d25b2331 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 10 Feb 2020 11:18:31 +0000 Subject: [PATCH 497/595] Add comment about code appearing a bit different to CPython. As title. --- numba/cpython/unicode.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py index eff9351c1cf..692df1567c0 100644 --- a/numba/cpython/unicode.py +++ b/numba/cpython/unicode.py @@ -2295,6 +2295,11 @@ def impl(c): # https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/unicodeobject.c#L2005-L2028 # noqa: E501 +# This looks a bit different to the cpython implementation but, with the +# exception of a latin1 fast path is logically the same. It finds the "kind" of +# the codepoint `ch`, creates a length 1 string of that kind and then injects +# the code point into the zero position of that string. Cpython does similar but +# branches for each kind (this is encapsulated in Numba's _set_code_point). @register_jitable def _unicode_char(ch): assert ch <= _MAX_UNICODE From e11a66b20c620c763d061b9ef11c5755c721465f Mon Sep 17 00:00:00 2001 From: Rohit Sanjay Date: Mon, 10 Feb 2020 18:13:57 +0530 Subject: [PATCH 498/595] added test cases added test case where `chars` is not `None` fixed error --- numba/tests/test_unicode.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py index 3054fe5bdeb..c62cc79b85d 100644 --- a/numba/tests/test_unicode.py +++ b/numba/tests/test_unicode.py @@ -1701,12 +1701,15 @@ def test_strip(self): (' tú quién te crees? ', None), ('大处 着眼,小处着手。大大大处', '大处'), (' 大处大处 ', ''), + ('\t\nabcd\t', '\ta'), (' 大处大处 ', None), ('\t abcd \t', None), ('\n abcd \n', None), ('\r abcd \r', None), ('\x0b abcd \x0b', None), - ('\x0c abcd \x0c', None) + ('\x0c abcd \x0c', None), + ('\u2029abcd\u205F', None), + ('\u0085abcd\u2009', None) ] # form with no parameter From 53f9190227ad6d608f650302052725c903686ca3 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 10 Feb 2020 11:54:36 -0600 Subject: [PATCH 499/595] Revert "Fix README formatting" This reverts commit baee51e73bd243803e91bf79dbc5eb828c9429a3. --- README.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/README.rst b/README.rst index ee3d5e140e5..6d5da15ea4f 100644 --- a/README.rst +++ b/README.rst @@ -32,7 +32,6 @@ Supported Platforms - macOS: x86_64 * (Optional) Accelerators and GPUs: - * NVIDIA GPUs (Kepler architecture or later) via CUDA driver on Linux, Windows, macOS (< 10.14) * AMD GPUs via ROCm driver on Linux From a733ecf1ace2876e2861b9efc3af4164061e59f3 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 10 Feb 2020 12:09:34 -0600 Subject: [PATCH 500/595] Revert "Revert "Fix README formatting"" This reverts commit 53f9190227ad6d608f650302052725c903686ca3. --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 6d5da15ea4f..ee3d5e140e5 100644 --- a/README.rst +++ b/README.rst @@ -32,6 +32,7 @@ Supported Platforms - macOS: x86_64 * (Optional) Accelerators and GPUs: + * NVIDIA GPUs (Kepler architecture or later) via CUDA driver on Linux, Windows, macOS (< 10.14) * AMD GPUs via ROCm driver on Linux From 52b5a44918c6db1013dbfa16556cf3bb43844409 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 10 Feb 2020 13:41:17 -0600 Subject: [PATCH 501/595] Add test that matches the #5215 problem --- numba/tests/test_tuples.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/numba/tests/test_tuples.py b/numba/tests/test_tuples.py index a23ea35585f..f7959f481aa 100644 --- a/numba/tests/test_tuples.py +++ b/numba/tests/test_tuples.py @@ -14,6 +14,8 @@ Point = collections.namedtuple('Point', ('x', 'y', 'z')) +Point2 = collections.namedtuple('Point2', ('x', 'y', 'z')) + Empty = collections.namedtuple('Empty', ()) def tuple_return_usecase(a, b): @@ -539,6 +541,13 @@ def foo(x): self.assertEqual(foo.nopython_signatures[0].args[0], typeof(in1)) self.assertEqual(foo.nopython_signatures[1].args[0], typeof(in2)) + # Differently named + in3 = Point2(1, 2, 3) + out3 = foo(in3) + self.assertEqual(in3, out3) + self.assertEqual(len(foo.nopython_signatures), 3) + self.assertEqual(foo.nopython_signatures[2].args[0], typeof(in3)) + class TestTupleNRT(TestCase, MemoryLeakMixin): def test_tuple_add(self): From 09a0fa5d925316509c80346d2d7cf495f3a4e524 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 11 Feb 2020 08:20:15 -0600 Subject: [PATCH 502/595] Fix import --- numba/tests/test_extending.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/numba/tests/test_extending.py b/numba/tests/test_extending.py index 2fdbe81248b..2e43f376861 100644 --- a/numba/tests/test_extending.py +++ b/numba/tests/test_extending.py @@ -10,7 +10,7 @@ import numpy as np from numba import njit, jit -from numba.core import types, errors, typing, compiler +from numba.core import types, errors, typing, compiler, cgutils from numba.core.typed_passes import type_inference_stage from numba.core.registry import cpu_target from numba.core.compiler import compile_isolated @@ -32,7 +32,6 @@ ) from numba.core.typing.templates import ( ConcreteTemplate, signature, infer, infer_global, AbstractTemplate) -from numba import cgutils # Pandas-like API implementation From e7949b8ae1ea94107d32a8b9373bf6bee2d51315 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Mon, 20 Jan 2020 18:07:53 +0000 Subject: [PATCH 503/595] Add support for iterating over 2D arrays We could also have just used `basic_indexing` here, but I assume that was ignored for performance. --- numba/core/typing/builtins.py | 11 +----- numba/np/arrayobj.py | 56 +++++++++++++++++------------ numba/tests/test_array_iterators.py | 24 ++++++++++--- numba/tests/test_iteration.py | 18 ---------- 4 files changed, 55 insertions(+), 54 deletions(-) diff --git a/numba/core/typing/builtins.py b/numba/core/typing/builtins.py index fd44ae46154..660e6b5f58f 100644 --- a/numba/core/typing/builtins.py +++ b/numba/core/typing/builtins.py @@ -99,16 +99,7 @@ def generic(self, args, kws): assert not kws [obj] = args if isinstance(obj, types.IterableType): - # Raise this here to provide a very specific message about this - # common issue, delaying the error until later leads to something - # less specific being noted as the problem (e.g. no support for - # getiter on array(<>, 2, 'C')). - if isinstance(obj, types.Array) and obj.ndim > 1: - msg = ("Direct iteration is not supported for arrays with " - "dimension > 1. Try using indexing instead.") - raise errors.TypingError(msg) - else: - return signature(obj.iterator_type, obj) + return signature(obj.iterator_type, obj) @infer diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 7b0e9b1b3a8..c599b3acc81 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -274,13 +274,25 @@ def getiter_array(context, builder, sig, args): return out -def _getitem_array1d(context, builder, arrayty, array, idx, wraparound): - """ - Look up and return an element from a 1D array. - """ - ptr = cgutils.get_item_pointer(context, builder, arrayty, array, [idx], - wraparound=wraparound) - return load_item(context, builder, arrayty, ptr) +def _getitem_array_single_int(context, builder, return_type, aryty, ary, idx): + """ Evaluate `ary[idx]`, where idx is a single int. """ + # optimized form of _getitem_array_generic + shapes = cgutils.unpack_tuple(builder, ary.shape, count=aryty.ndim) + strides = cgutils.unpack_tuple(builder, ary.strides, count=aryty.ndim) + offset = builder.mul(strides[0], idx) + dataptr = cgutils.pointer_add(builder, ary.data, offset) + view_shapes = shapes[1:] + view_strides = strides[1:] + + if isinstance(return_type, types.Buffer): + # Build array view + retary = make_view(context, builder, aryty, ary, return_type, + dataptr, view_shapes, view_strides) + return retary._getvalue() + else: + # Load scalar from 0-d result + assert not view_shapes + return load_item(context, builder, aryty, dataptr) @lower_builtin('iternext', types.ArrayIterator) @@ -290,10 +302,6 @@ def iternext_array(context, builder, sig, args, result): [iter] = args arrayty = iterty.array_type - if arrayty.ndim != 1: - # TODO - raise NotImplementedError("iterating over %dD array" % arrayty.ndim) - iterobj = context.make_helper(builder, iterty, value=iter) ary = make_array(arrayty)(context, builder, value=iterobj.array) @@ -304,8 +312,9 @@ def iternext_array(context, builder, sig, args, result): result.set_valid(is_valid) with builder.if_then(is_valid): - value = _getitem_array1d(context, builder, arrayty, ary, index, - wraparound=False) + value = _getitem_array_single_int( + context, builder, iterty.yield_type, arrayty, ary, index + ) result.yield_(value) nindex = cgutils.increment_index(builder, index) builder.store(nindex, iterobj.index) @@ -718,9 +727,10 @@ def loop_head(self): ): builder.branch(self.bb_end) # Load the actual index from the array of indices - index = _getitem_array1d(self.context, builder, - self.idxty, self.idxary, - cur_index, wraparound=False) + index = _getitem_array_single_int( + self.context, builder, self.idxty.dtype, self.idxty, self.idxary, + cur_index + ) index = fix_integer_index(self.context, builder, self.idxty.dtype, index, self.size) return index, cur_index @@ -763,9 +773,10 @@ def get_size(self): # Sum all true values with cgutils.for_range(builder, self.size) as loop: c = builder.load(count) - pred = _getitem_array1d(self.context, builder, - self.idxty, self.idxary, - loop.index, wraparound=False) + pred = _getitem_array_single_int( + self.context, builder, self.idxty.dtype, + self.idxty, self.idxary, loop.index + ) c = builder.add(c, builder.zext(pred, c.type)) builder.store(c, count) @@ -792,9 +803,10 @@ def loop_head(self): likely=False): builder.branch(self.bb_end) # Load the predicate and branch if false - pred = _getitem_array1d(self.context, builder, - self.idxty, self.idxary, - cur_index, wraparound=False) + pred = _getitem_array_single_int( + self.context, builder, self.idxty.dtype, self.idxty, self.idxary, + cur_index + ) with builder.if_then(builder.not_(pred)): builder.branch(self.bb_tail) # Increment the count for next iteration diff --git a/numba/tests/test_array_iterators.py b/numba/tests/test_array_iterators.py index 2bce78ca84c..59303775b86 100644 --- a/numba/tests/test_array_iterators.py +++ b/numba/tests/test_array_iterators.py @@ -15,6 +15,9 @@ def array_iter(arr): total += i * v return total +def array_iter_items(arr): + return list(iter(arr)) + def array_view_iter(arr, idx): total = 0 for i, v in enumerate(arr[idx]): @@ -124,13 +127,20 @@ def setUp(self): super(TestArrayIterators, self).setUp() self.ccache = CompilationCache() - def check_array_iter(self, arr): + def check_array_iter_1d(self, arr): pyfunc = array_iter cres = compile_isolated(pyfunc, [typeof(arr)]) cfunc = cres.entry_point expected = pyfunc(arr) self.assertPreciseEqual(cfunc(arr), expected) + def check_array_iter_items(self, arr): + pyfunc = array_iter_items + cres = compile_isolated(pyfunc, [typeof(arr)]) + cfunc = cres.entry_point + expected = pyfunc(arr) + self.assertPreciseEqual(cfunc(arr), expected) + def check_array_view_iter(self, arr, index): pyfunc = array_view_iter cres = compile_isolated(pyfunc, [typeof(arr), typeof(index)]) @@ -166,13 +176,19 @@ def check_array_ndenumerate_sum(self, arr, arrty): def test_array_iter(self): # Test iterating over a 1d array arr = np.arange(6) - self.check_array_iter(arr) + self.check_array_iter_1d(arr) + self.check_array_iter_items(arr) arr = arr[::2] self.assertFalse(arr.flags.c_contiguous) self.assertFalse(arr.flags.f_contiguous) - self.check_array_iter(arr) + self.check_array_iter_1d(arr) + self.check_array_iter_items(arr) arr = np.bool_([1, 0, 0, 1]) - self.check_array_iter(arr) + self.check_array_iter_1d(arr) + self.check_array_iter_items(arr) + arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) + self.check_array_iter_items(arr) + self.check_array_iter_items(arr.T) def test_array_view_iter(self): # Test iterating over a 1d view over a 2d array diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index 3e5ea35662e..5d7a48cd207 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -188,24 +188,6 @@ def test_array_1d_record_mutate_npm(self, flags=no_pyobj_flags): def test_array_1d_record_mutate(self): self.test_array_1d_record_mutate_npm(flags=force_pyobj_flags) - def test_array_2d_raises(self): - - def foo(x): - for i in x: - pass - - # 1D is fine - aryty = types.Array(types.int32, 1, 'C') - compile_isolated(foo, (aryty,)) - - # 2d is typing error - with self.assertRaises(errors.TypingError) as raises: - aryty = types.Array(types.int32, 2, 'C') - compile_isolated(foo, (aryty,)) - - self.assertIn("Direct iteration is not supported", - str(raises.exception)) - def test_tuple_iter_issue1504(self): # The issue is due to `row` being typed as heterogeneous tuple. def bar(x, y): From 419c1fa26df62fee9dfe612109c3fb0fbb2923c6 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 4 Feb 2020 15:21:11 +0000 Subject: [PATCH 504/595] Improve the error message for iterating over 0d arrays --- numba/core/types/iterators.py | 5 ++++- numba/tests/test_iteration.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/numba/core/types/iterators.py b/numba/core/types/iterators.py index 4279ce7c6ab..20f427c1ac8 100644 --- a/numba/core/types/iterators.py +++ b/numba/core/types/iterators.py @@ -1,4 +1,5 @@ from .common import SimpleIterableType, SimpleIteratorType +from ..errors import TypingError class RangeType(SimpleIterableType): @@ -96,7 +97,9 @@ def __init__(self, array_type): self.array_type = array_type name = "iter(%s)" % (self.array_type,) nd = array_type.ndim - if nd == 0 or nd == 1: + if nd == 0: + raise TypingError("iteration over a 0-d array") + elif nd == 1: yield_type = array_type.dtype else: yield_type = array_type.copy(ndim=array_type.ndim - 1) diff --git a/numba/tests/test_iteration.py b/numba/tests/test_iteration.py index 5d7a48cd207..b7304d5cf96 100644 --- a/numba/tests/test_iteration.py +++ b/numba/tests/test_iteration.py @@ -188,6 +188,19 @@ def test_array_1d_record_mutate_npm(self, flags=no_pyobj_flags): def test_array_1d_record_mutate(self): self.test_array_1d_record_mutate_npm(flags=force_pyobj_flags) + def test_array_0d_raises(self): + + def foo(x): + for i in x: + pass + + # 0d is typing error + with self.assertRaises(errors.TypingError) as raises: + aryty = types.Array(types.int32, 0, 'C') + compile_isolated(foo, (aryty,)) + + self.assertIn("0-d array", str(raises.exception)) + def test_tuple_iter_issue1504(self): # The issue is due to `row` being typed as heterogeneous tuple. def bar(x, y): From 4c24949321376e374a77fe186f48b44a61391460 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 11 Feb 2020 09:44:51 -0700 Subject: [PATCH 505/595] Update docs/source/user/threading-layer.rst Co-Authored-By: Graham Markall <535640+gmarkall@users.noreply.github.com> --- docs/source/user/threading-layer.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/user/threading-layer.rst b/docs/source/user/threading-layer.rst index f6f26c2f523..0f69b1f5a03 100644 --- a/docs/source/user/threading-layer.rst +++ b/docs/source/user/threading-layer.rst @@ -256,7 +256,7 @@ API Reference The total (maximum) number of threads launched by numba. - Defaults :obj:`numba.config.NUMBA_DEFAULT_NUM_THREADS`, but can be + Defaults to :obj:`numba.config.NUMBA_DEFAULT_NUM_THREADS`, but can be overridden with the :envvar:`NUMBA_NUM_THREADS` environment variable. .. py:data:: numba.config.NUMBA_DEFAULT_NUM_THREADS From a82bc3189df9c50629ae25e71efa037ed886d142 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 11 Feb 2020 18:10:36 +0000 Subject: [PATCH 506/595] Prvent use of TBB if the interface is of too low version --- numba/np/ufunc/parallel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/np/ufunc/parallel.py b/numba/np/ufunc/parallel.py index 0240df359e4..b5387c03722 100644 --- a/numba/np/ufunc/parallel.py +++ b/numba/np/ufunc/parallel.py @@ -353,6 +353,7 @@ def _check_tbb_version_compatible(): "threading layer is disabled.") problem = errors.NumbaWarning(msg % tbb_iface_ver) warnings.warn(problem) + raise ImportError("Problem with TBB. Reason: %s" % msg) except (ValueError, OSError) as e: # Translate as an ImportError for consistent error class use, this error # will never materialise From baaa14bb0423bc492c04eecf80b80cd793d6e093 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 11 Feb 2020 18:15:30 +0000 Subject: [PATCH 507/595] Add in TBB from defaults --- buildscripts/azure/azure-windows.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index dc053a8ddbc..d9b82d8c0ab 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -37,18 +37,11 @@ jobs: buildscripts\\incremental\\setup_conda_environment.cmd displayName: 'Before Install' - # VC 9.0 cannot build tbbpool.cpp in Numba, so we need to remove - # tbb from the environment before the build stage. - script: | + # use TBB call activate %CONDA_ENV% - conda remove -y tbb tbb-devel - displayName: 'Remove TBB' - - - script: | - # temporarily patch this in to get a recent TBB - call activate %CONDA_ENV% - conda install -c conda-forge -y tbb tbb-devel - displayName: 'Add in conda-forge TBB' + conda install -y tbb tbb-devel + displayName: 'Add in TBB' - script: | buildscripts\\incremental\\build.cmd From 3e95d8e91a7b86cf47b5218def6bcc0d34e19c0a Mon Sep 17 00:00:00 2001 From: ARF1 <5834577+ARF1@users.noreply.github.com> Date: Wed, 12 Feb 2020 12:18:07 +0100 Subject: [PATCH 508/595] fix test discovery for unittest --- numba/tests/npyufunc/test_caching.py | 4 ++-- numba/tests/npyufunc/test_dufunc.py | 2 +- numba/tests/npyufunc/test_errors.py | 2 +- numba/tests/npyufunc/test_gufunc.py | 2 +- numba/tests/npyufunc/test_ufunc.py | 2 +- numba/tests/npyufunc/test_ufuncbuilding.py | 2 +- numba/tests/npyufunc/test_vectorize_decor.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/numba/tests/npyufunc/test_caching.py b/numba/tests/npyufunc/test_caching.py index 9ee579905da..758a3040d1a 100644 --- a/numba/tests/npyufunc/test_caching.py +++ b/numba/tests/npyufunc/test_caching.py @@ -5,8 +5,8 @@ import numpy as np -from ..support import capture_cache_log -from ..test_dispatcher import BaseCacheTest +from numba.tests.support import capture_cache_log +from numba.tests.test_dispatcher import BaseCacheTest from numba.core import config import unittest diff --git a/numba/tests/npyufunc/test_dufunc.py b/numba/tests/npyufunc/test_dufunc.py index f648e65613d..19bed27b661 100644 --- a/numba/tests/npyufunc/test_dufunc.py +++ b/numba/tests/npyufunc/test_dufunc.py @@ -3,7 +3,7 @@ import numpy as np from numba import njit, vectorize -from ..support import MemoryLeakMixin +from numba.tests.support import MemoryLeakMixin import unittest from numba.np.ufunc import dufunc diff --git a/numba/tests/npyufunc/test_errors.py b/numba/tests/npyufunc/test_errors.py index 7024ad84cd7..a373885b5a9 100644 --- a/numba/tests/npyufunc/test_errors.py +++ b/numba/tests/npyufunc/test_errors.py @@ -5,7 +5,7 @@ from numba import vectorize, guvectorize -from ..support import TestCase, CheckWarningsMixin +from numba.tests.support import TestCase, CheckWarningsMixin import unittest diff --git a/numba/tests/npyufunc/test_gufunc.py b/numba/tests/npyufunc/test_gufunc.py index 66324fc599d..219825f56f0 100644 --- a/numba/tests/npyufunc/test_gufunc.py +++ b/numba/tests/npyufunc/test_gufunc.py @@ -3,7 +3,7 @@ from numba import void, float32, jit, guvectorize from numba.np.ufunc import GUVectorize -from ..support import tag, TestCase +from numba.tests.support import tag, TestCase import unittest diff --git a/numba/tests/npyufunc/test_ufunc.py b/numba/tests/npyufunc/test_ufunc.py index 7c9ec44756e..7257678a027 100644 --- a/numba/tests/npyufunc/test_ufunc.py +++ b/numba/tests/npyufunc/test_ufunc.py @@ -3,7 +3,7 @@ from numba import float32, jit from numba.np.ufunc import Vectorize from numba.core.errors import TypingError -from ..support import TestCase +from numba.tests.support import TestCase import unittest diff --git a/numba/tests/npyufunc/test_ufuncbuilding.py b/numba/tests/npyufunc/test_ufuncbuilding.py index e1c48e1cabf..1d4e83e7fe5 100644 --- a/numba/tests/npyufunc/test_ufuncbuilding.py +++ b/numba/tests/npyufunc/test_ufuncbuilding.py @@ -6,7 +6,7 @@ from numba import vectorize, guvectorize from numba.np.ufunc import PyUFunc_One from numba.np.ufunc.dufunc import DUFunc as UFuncBuilder -from ..support import tag, TestCase +from numba.tests.support import tag, TestCase from numba.core import config import unittest diff --git a/numba/tests/npyufunc/test_vectorize_decor.py b/numba/tests/npyufunc/test_vectorize_decor.py index 6a9562b9c86..e1fdf1d77a6 100644 --- a/numba/tests/npyufunc/test_vectorize_decor.py +++ b/numba/tests/npyufunc/test_vectorize_decor.py @@ -3,7 +3,7 @@ import numpy as np from numba import int32, uint32, float32, float64, jit, vectorize -from ..support import tag, CheckWarningsMixin +from numba.tests.support import tag, CheckWarningsMixin import unittest From 38bd9926af71d80ab9940b7e4cf2e1d37659e487 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 12 Feb 2020 14:27:04 +0000 Subject: [PATCH 509/595] tmp patch for debug --- numba/np/ufunc/parallel.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/numba/np/ufunc/parallel.py b/numba/np/ufunc/parallel.py index b5387c03722..a77bc200c25 100644 --- a/numba/np/ufunc/parallel.py +++ b/numba/np/ufunc/parallel.py @@ -23,10 +23,10 @@ import llvmlite.binding as ll from numba.np.numpy_support import as_dtype -from numba.core import types, config, errors +from numba.core import types, config, errors, cgutils from numba.np.ufunc.wrappers import _wrapper_info from numba.np.ufunc import ufuncbuilder -from numba.extending import overload +from numba.extending import overload, intrinsic _IS_OSX = sys.platform.startswith('darwin') @@ -518,6 +518,17 @@ def _load_num_threads_funcs(lib): # Some helpers to make set_num_threads jittable +@intrinsic +def debug(tyctx, max_t, ill_t): + max_t_ty = getattr(max_t, 'literal_type', max_t) + ill_t_ty = getattr(ill_t, 'literal_type', ill_t) + sig = types.void(max_t_ty, ill_t_ty) + def codegen(cgctx, builder, sig, args): + a, b = args + cgutils.printf(builder, "Max threads %d. Illegal thread count %d\n", a, + b) + return sig, codegen + def gen_snt_check(): from numba.core.config import NUMBA_NUM_THREADS @@ -525,6 +536,7 @@ def gen_snt_check(): def snt_check(n): if n > NUMBA_NUM_THREADS or n < 1: + debug(NUMBA_NUM_THREADS, n) raise ValueError(msg) return snt_check From a8c43c4246228a15ec1cfb176be6693926c03147 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 10 Feb 2020 12:40:04 +0100 Subject: [PATCH 510/595] implement is_mutable member Implement an additional struct member for the list called `is_mutable` and provide functions to query and set it. c-level test included. --- numba/_helpermod.c | 2 ++ numba/cext/listobject.c | 36 ++++++++++++++++++++++++++++++++++++ numba/cext/listobject.h | 14 ++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/numba/_helpermod.c b/numba/_helpermod.c index a8240db71d5..d8ee632e2ac 100644 --- a/numba/_helpermod.c +++ b/numba/_helpermod.c @@ -151,6 +151,8 @@ build_c_helpers_dict(void) declmethod(list_free); declmethod(list_length); declmethod(list_allocated); + declmethod(list_is_mutable); + declmethod(list_set_is_mutable); declmethod(list_setitem); declmethod(list_getitem); declmethod(list_append); diff --git a/numba/cext/listobject.c b/numba/cext/listobject.c index 72abc2683c0..0d2789e0d88 100644 --- a/numba/cext/listobject.c +++ b/numba/cext/listobject.c @@ -57,6 +57,11 @@ * - Initialization of iter numba_list_iter * - Get next item from iter numba_list_iter_next * + * Two methods are provided to query and set the 'is_mutable': + * + * - Query numba_list_is_mutable + * - Set numba_list_set_is_mutable + * * Lastly a set of pure C level tests are provided which come in handy when * needing to use valgrind and friends. * @@ -71,6 +76,7 @@ typedef enum { LIST_ERR_NO_MEMORY = -2, LIST_ERR_MUTATED = -3, LIST_ERR_ITER_EXHAUSTED = -4, + LIST_ERR_IMMUTABLE = -4, } ListStatus; /* Copy an item from a list. @@ -166,6 +172,7 @@ numba_list_new(NB_List **out, Py_ssize_t item_size, Py_ssize_t allocated){ lp->size = 0; lp->item_size = item_size; lp->allocated = allocated; + lp->is_mutable = 1; // set method table to zero */ memset(&lp->methods, 0x00, sizeof(list_type_based_methods_table)); // allocate memory to hold items, if requested @@ -227,6 +234,27 @@ numba_list_allocated(NB_List *lp) { return lp->allocated; } +/* Return the mutability status of the list + * + * lp: a list + * + */ +int +numba_list_is_mutable(NB_List *lp){ + return lp->is_mutable; +} + +/* Set the is_mutable attribute + * + * lp: a list + * is_mutable: an int, 0(False) or 1(True) + * + */ +void +numba_list_set_is_mutable(NB_List *lp, int is_mutable){ + lp->is_mutable = is_mutable; +} + /* Set an item in a list. * * lp: a list @@ -568,6 +596,14 @@ numba_test_list(void) { CHECK(lp->item_size == 4); CHECK(lp->size == 0); CHECK(lp->allocated == 0); + CHECK(lp->is_mutable == 1); + + // flip and check the is_mutable bit + CHECK(numba_list_is_mutable(lp) == 1); + numba_list_set_is_mutable(lp, 0); + CHECK(numba_list_is_mutable(lp) == 0); + numba_list_set_is_mutable(lp, 1); + CHECK(numba_list_is_mutable(lp) == 1); // append 1st item, this will cause a realloc status = numba_list_append(lp, "abc"); diff --git a/numba/cext/listobject.h b/numba/cext/listobject.h index 5f0f42d97d7..363edf94123 100644 --- a/numba/cext/listobject.h +++ b/numba/cext/listobject.h @@ -41,6 +41,12 @@ typedef struct { * * Items must normally not be NULL, except during construction when * the list is not yet visible outside the function that builds it. + * + * Additionally, this list has boolean member 'is_mutable' that can be used to + * set a list as immutable. Two functions to query and set this member are + * provided. Any attempt to mutate an immutable list will result in a status + * of LIST_ERR_IMMUTABLE. + * */ typedef struct { /* size of the list in items */ @@ -49,6 +55,8 @@ typedef struct { Py_ssize_t item_size; /* total allocated slots in items */ Py_ssize_t allocated; + /* is the list mutable */ + int is_mutable; /* method table for type-dependent operations */ list_type_based_methods_table methods; /* array/pointer for items. Interpretation is governed by item_size */ @@ -80,6 +88,12 @@ numba_list_length(NB_List *lp); NUMBA_EXPORT_FUNC(Py_ssize_t) numba_list_allocated(NB_List *lp); +NUMBA_EXPORT_FUNC(int) +numba_list_is_mutable(NB_List *lp); + +NUMBA_EXPORT_FUNC(void) +numba_list_set_is_mutable(NB_List *lp, int is_mutable); + NUMBA_EXPORT_FUNC(int) numba_list_setitem(NB_List *lp, Py_ssize_t index, const char *item); From a98de4f7f4c986a1ae3dc932adb1319128237a3c Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 10 Feb 2020 13:02:36 +0100 Subject: [PATCH 511/595] guard all mutation functions Now we guard all functions that could mutate the list with a check for mutability and fail in case the list is immutable. Tests included. --- numba/cext/listobject.c | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/numba/cext/listobject.c b/numba/cext/listobject.c index 0d2789e0d88..6cbfcf62c86 100644 --- a/numba/cext/listobject.c +++ b/numba/cext/listobject.c @@ -76,7 +76,7 @@ typedef enum { LIST_ERR_NO_MEMORY = -2, LIST_ERR_MUTATED = -3, LIST_ERR_ITER_EXHAUSTED = -4, - LIST_ERR_IMMUTABLE = -4, + LIST_ERR_IMMUTABLE = -5, } ListStatus; /* Copy an item from a list. @@ -268,6 +268,10 @@ numba_list_set_is_mutable(NB_List *lp, int is_mutable){ int numba_list_setitem(NB_List *lp, Py_ssize_t index, const char *item) { char *loc; + // check for mutability + if (!lp->is_mutable) { + return LIST_ERR_IMMUTABLE; + } // check index is valid // FIXME: this can be (and probably is) checked at the compiler level if (!valid_index(index, lp->size)) { @@ -309,6 +313,10 @@ numba_list_getitem(NB_List *lp, Py_ssize_t index, char *out) { int numba_list_append(NB_List *lp, const char *item) { char *loc; + // check for mutability + if (!lp->is_mutable) { + return LIST_ERR_IMMUTABLE; + } // resize by one, will change list size int result = numba_list_resize(lp, lp->size + 1); if(result < LIST_OK) { @@ -331,6 +339,10 @@ int numba_list_pop(NB_List *lp, Py_ssize_t index, char *out) { char *loc, *new_loc; int result; + // check for mutability + if (!lp->is_mutable) { + return LIST_ERR_IMMUTABLE; + } Py_ssize_t leftover_bytes; // check index is valid // FIXME: this can be (and probably is) checked at the compiler level @@ -387,6 +399,10 @@ numba_list_pop(NB_List *lp, Py_ssize_t index, char *out) { int numba_list_resize(NB_List *lp, Py_ssize_t newsize) { char * items; + // check for mutability + if (!lp->is_mutable) { + return LIST_ERR_IMMUTABLE; + } size_t new_allocated, num_allocated_bytes; /* Bypass realloc() when a previous overallocation is large enough to accommodate the newsize. If the newsize falls lower than half @@ -446,6 +462,10 @@ numba_list_delete_slice(NB_List *lp, int result, i, slicelength, new_length; char *loc, *new_loc; Py_ssize_t leftover_bytes, cur, lim; + // check for mutability + if (!lp->is_mutable) { + return LIST_ERR_IMMUTABLE; + } // calculate the slicelength, taken from PySlice_AdjustIndices, see the top // of this file for the exact source if (step > 0) { @@ -675,6 +695,27 @@ numba_test_list(void) { CHECK(memcmp(got_item, "mno", 4) == 0); CHECK(memcmp(lp->items, "def\x00ghi\x00jkl\x00", 12) == 0); + // flip and check the is_mutable member + CHECK(numba_list_is_mutable(lp) == 1); + numba_list_set_is_mutable(lp, 0); + CHECK(numba_list_is_mutable(lp) == 0); + + // ensure that any attempts to mutate an immutable list fail + CHECK(numba_list_setitem(lp, 0, "zzz") == LIST_ERR_IMMUTABLE); + CHECK(numba_list_append(lp, "zzz") == LIST_ERR_IMMUTABLE); + CHECK(numba_list_pop(lp, 0, got_item) == LIST_ERR_IMMUTABLE); + CHECK(numba_list_resize(lp, 23) == LIST_ERR_IMMUTABLE); + CHECK(numba_list_delete_slice(lp, 0, 3, 1) == LIST_ERR_IMMUTABLE); + + // ensure that all attempts to query/read from and immutable list succeed + CHECK(numba_list_length(lp) == 3); + status = numba_list_getitem(lp, 0, got_item); + CHECK(status == LIST_OK); + CHECK(memcmp(got_item, "def", 4) == 0); + + // flip the is_mutable member back and check + numba_list_set_is_mutable(lp, 1); + CHECK(numba_list_is_mutable(lp) == 1); // test iterator CHECK(lp->size > 0); From 83ac0747732d5cb4b8ba5683e33d0f85b386a7ff Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Wed, 12 Feb 2020 16:45:31 +0100 Subject: [PATCH 512/595] implement Python test for C These are the Python level test for the changes to the C level implementation of the typed list. --- numba/tests/test_listimpl.py | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/numba/tests/test_listimpl.py b/numba/tests/test_listimpl.py index 0cd38e9b2a3..e35fb95d811 100644 --- a/numba/tests/test_listimpl.py +++ b/numba/tests/test_listimpl.py @@ -14,6 +14,7 @@ LIST_ERR_NO_MEMORY = -2 LIST_ERR_MUTATED = -3 LIST_ERR_ITER_EXHAUSTED = -4 +LIST_ERR_IMMUTABLE = -5 class List(object): @@ -58,6 +59,16 @@ def __delitem__(self, i): def allocated(self): return self.list_allocated() + @property + def is_mutable(self): + return self.list_is_mutable() + + def set_mutable(self): + return self.list_set_is_mutable(1) + + def set_immutable(self): + return self.list_set_is_mutable(0) + def append(self, item): self.list_append(item) @@ -80,10 +91,18 @@ def list_length(self): def list_allocated(self): return self.tc.numba_list_allocated(self.lp) + def list_is_mutable(self): + return self.tc.numba_list_is_mutable(self.lp) + + def list_set_is_mutable(self, is_mutable): + return self.tc.numba_list_set_is_mutable(self.lp, is_mutable) + def list_setitem(self, i, item): status = self.tc.numba_list_setitem(self.lp, i, item) if status == LIST_ERR_INDEX: raise IndexError("list index out of range") + elif status == LIST_ERR_IMMUTABLE: + raise ValueError("list is immutable") else: self.tc.assertEqual(status, LIST_OK) @@ -98,6 +117,8 @@ def list_getitem(self, i): def list_append(self, item): status = self.tc.numba_list_append(self.lp, item) + if status == LIST_ERR_IMMUTABLE: + raise ValueError("list is immutable") self.tc.assertEqual(status, LIST_OK) def list_pop(self, i): @@ -111,6 +132,8 @@ def list_pop(self, i): status = self.tc.numba_list_pop(self.lp, i, item_out_buffer) if status == LIST_ERR_INDEX: raise IndexError("list index out of range") + elif status == LIST_ERR_IMMUTABLE: + raise ValueError("list is immutable") else: self.tc.assertEqual(status, LIST_OK) return item_out_buffer.raw @@ -122,6 +145,8 @@ def list_delitem(self, i): i.start, i.stop, i.step) + if status == LIST_ERR_IMMUTABLE: + raise ValueError("list is immutable") self.tc.assertEqual(status, LIST_OK) # must be an integer, defer to pop else: @@ -205,6 +230,18 @@ def wrap(name, restype, argtypes=()): ctypes.c_int, [list_t], ) + # numba_list_is_mutable(NB_List *lp) + self.numba_list_is_mutable = wrap( + 'list_is_mutable', + ctypes.c_int, + [list_t], + ) + # numba_list_set_is_mutable(NB_List *lp, int is_mutable) + self.numba_list_set_is_mutable = wrap( + 'list_set_is_mutable', + None, + [list_t, ctypes.c_int], + ) # numba_list_setitem(NB_List *l, Py_ssize_t i, const char *item) self.numba_list_setitem = wrap( 'list_setitem', @@ -421,3 +458,39 @@ def test_sizing(self): # Check different sizes of the key & value. for i in range(1, 16): self.check_sizing(item_size=i, nmax=2**i) + + def test_mutability(self): + # setup and populate a singleton + l = List(self, 8, 1) + one = struct.pack("q", 1) + l.append(one) + self.assertTrue(l.is_mutable) + self.assertEqual(len(l), 1) + r = struct.unpack("q", l[0])[0] + self.assertEqual(r, 1) + + # set to immutable and test guards + l.set_immutable() + self.assertFalse(l.is_mutable) + # append + with self.assertRaises(ValueError): + l.append(one) + # setitem + with self.assertRaises(ValueError): + l[0] = one + # pop + with self.assertRaises(ValueError): + l.pop() + # delitem with index + with self.assertRaises(ValueError): + del l[0] + # delitem with slice + with self.assertRaises(ValueError): + del l[0:1:1] + l.set_mutable() + + # check that nothing has changed + self.assertTrue(l.is_mutable) + self.assertEqual(len(l), 1) + r = struct.unpack("q", l[0])[0] + self.assertEqual(r, 1) From 7b4512c8df269e9f1c356f70ce5151cc29908b0f Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 10 Feb 2020 17:49:27 +0100 Subject: [PATCH 513/595] implement the compiler part for immutable typed-lists This is the compiler part of the immutable typed list. It allows the typed-list to be queried for mutability and set to im/mutable in `@njit` compiled functions. --- numba/tests/test_listobject.py | 97 ++++++++++++++++++++++++++++++ numba/typed/listobject.py | 107 +++++++++++++++++++++++++++++++-- 2 files changed, 199 insertions(+), 5 deletions(-) diff --git a/numba/tests/test_listobject.py b/numba/tests/test_listobject.py index cad8bf392a6..76e7e08b2e6 100644 --- a/numba/tests/test_listobject.py +++ b/numba/tests/test_listobject.py @@ -11,8 +11,11 @@ """ +from textwrap import dedent + from numba import njit from numba import int32 +from numba.extending import register_jitable from numba.core import types from numba.core.errors import TypingError from numba.tests.support import (TestCase, MemoryLeakMixin, override_config, @@ -1502,3 +1505,97 @@ def foo(): 'Cannot cast int32 to unicode_type', str(raises.exception), ) + + +@register_jitable +def make_test_list(): + l = listobject.new_list(int32) + l.append(int32(1)) + return l + + +class TestImmutable(MemoryLeakMixin, TestCase): + + def test_is_immutable(self): + @njit + def foo(): + l = make_test_list() + return l._is_mutable() + self.assertTrue(foo()) + + def test_make_immutable_is_immutable(self): + @njit + def foo(): + l = make_test_list() + l._make_immutable() + return l._is_mutable() + self.assertFalse(foo()) + + def test_length_still_works_when_immutable(self): + @njit + def foo(): + l = make_test_list() + l._make_immutable() + return len(l),l._is_mutable() + length, mutable = foo() + self.assertEqual(length, 1) + self.assertFalse(mutable) + + def test_getitem_still_works_when_immutable(self): + @njit + def foo(): + l = make_test_list() + l._make_immutable() + return l[0], l._is_mutable() + test_item, mutable = foo() + self.assertEqual(test_item, 1) + self.assertFalse(mutable) + + def test_append_fails(self): + self.disable_leak_check() + @njit + def foo(): + l = make_test_list() + l._make_immutable() + l.append(int32(1)) + with self.assertRaises(ValueError) as raises: + foo() + self.assertIn( + 'list is immutable', + str(raises.exception), + ) + + def test_mutation_fails(self): + """ Test that any attempt to mutate an immutable typed list fails. """ + self.disable_leak_check() + + def generate_function(line): + context = {} + exec(dedent(""" + from numba.typed import listobject + from numba import int32 + def bar(): + lst = listobject.new_list(int32) + lst.append(int32(1)) + lst._make_immutable() + zero = int32(0) + {} + """.format(line)), context) + return njit(context["bar"]) + for line in ("lst.append(zero)", + "lst[0] = zero", + "lst.pop()", + "del lst[0]", + "lst.extend((zero,))", + "lst.insert(0, zero)", + "lst.clear()", + "lst.reverse()", + "lst.sort()", + ): + foo = generate_function(line) + with self.assertRaises(ValueError) as raises: + foo() + self.assertIn( + "list is immutable", + str(raises.exception), + ) diff --git a/numba/typed/listobject.py b/numba/typed/listobject.py index 836b5b5e672..4f4071e5107 100644 --- a/numba/typed/listobject.py +++ b/numba/typed/listobject.py @@ -80,6 +80,7 @@ class ListStatus(IntEnum): LIST_ERR_NO_MEMORY = -2 LIST_ERR_MUTATED = -3 LIST_ERR_ITER_EXHAUSTED = -4 + LIST_ERR_IMMUTABLE = -5 class ErrorHandler(object): @@ -467,6 +468,85 @@ def codegen(context, builder, sig, args): return sig, codegen +@overload_method(types.ListType, "_is_mutable") +def impl_is_mutable(l): + """list._is_mutable()""" + if isinstance(l, types.ListType): + def impl(l): + return bool(_list_is_mutable(l)) + + return impl + + +@intrinsic +def _list_is_mutable(typingctx, l): + """Wrap numba_list_is_mutable + + Returns the state of the is_mutable member + """ + resty = types.int32 + sig = resty(l) + + def codegen(context, builder, sig, args): + fnty = ir.FunctionType( + ll_status, + [ll_list_type], + ) + fn = builder.module.get_or_insert_function( + fnty, name='numba_list_is_mutable') + [l] = args + [tl] = sig.args + lp = _container_get_data(context, builder, tl, l) + n = builder.call(fn, [lp]) + return n + + return sig, codegen + + +@overload_method(types.ListType, "_make_mutable") +def impl_make_mutable(l): + """list._make_mutable()""" + if isinstance(l, types.ListType): + def impl(l): + _list_set_is_mutable(l, 1) + + return impl + + +@overload_method(types.ListType, "_make_immutable") +def impl_make_immutable(l): + """list._make_immutable()""" + if isinstance(l, types.ListType): + def impl(l): + _list_set_is_mutable(l, 0) + + return impl + + +@intrinsic +def _list_set_is_mutable(typingctx, l, is_mutable): + """Wrap numba_list_set_mutable + + Sets the state of the is_mutable member. + """ + resty = types.void + sig = resty(l, is_mutable) + + def codegen(context, builder, sig, args): + fnty = ir.FunctionType( + ir.VoidType(), + [ll_list_type, cgutils.intp_t], + ) + fn = builder.module.get_or_insert_function( + fnty, name='numba_list_set_is_mutable') + [l, i] = args + [tl, ti] = sig.args + lp = _container_get_data(context, builder, tl, l) + builder.call(fn, [lp, i]) + + return sig, codegen + + @intrinsic def _list_append(typingctx, l, item): """Wrap numba_list_append @@ -515,6 +595,8 @@ def impl(l, item): status = _list_append(l, casteditem) if status == ListStatus.LIST_OK: return + elif status == ListStatus.LIST_ERR_IMMUTABLE: + raise ValueError('list is immutable') elif status == ListStatus.LIST_ERR_NO_MEMORY: raise MemoryError('Unable to allocate memory to append item') else: @@ -737,6 +819,8 @@ def impl_integer(l, index, item): status = _list_setitem(l, castedindex, casteditem) if status == ListStatus.LIST_OK: return + elif status == ListStatus.LIST_ERR_IMMUTABLE: + raise ValueError("list is immutable") else: raise AssertionError("internal list error during settitem") @@ -748,6 +832,8 @@ def impl_integer(l, index, item): "with assignment/setitem") def impl_slice(l, index, item): + if not l._is_mutable(): + raise ValueError("list is immutable") # special case "a[i:j] = a", need to copy first if l is item: item = item.copy() @@ -816,6 +902,8 @@ def impl(l, index=-1): status, item = _list_pop(l, castedindex) if status == ListStatus.LIST_OK: return _nonoptional(item) + elif status == ListStatus.LIST_ERR_IMMUTABLE: + raise ValueError("list is immutable") else: raise AssertionError("internal list error during pop") return impl @@ -870,10 +958,13 @@ def integer_impl(l, index): elif isinstance(index, types.SliceType): def slice_impl(l, index): slice_range = handle_slice(l, index) - _list_delete_slice(l, - slice_range.start, - slice_range.stop, - slice_range.step) + status = _list_delete_slice( + l, + slice_range.start, + slice_range.stop, + slice_range.step) + if status == ListStatus.LIST_ERR_MUTATED: + raise ValueError("list is immutable") return slice_impl else: @@ -925,11 +1016,13 @@ def impl_extend(l, iterable): if not isinstance(iterable, types.IterableType): raise TypingError("extend argument must be iterable") - _check_for_none_typed(l, 'insert') + _check_for_none_typed(l, 'extend') def select_impl(): if isinstance(iterable, types.ListType): def impl(l, iterable): + if not l._is_mutable(): + raise ValueError("list is immutable") # guard against l.extend(l) if l is iterable: iterable = iterable.copy() @@ -1053,6 +1146,8 @@ def impl_reverse(l): _check_for_none_typed(l, 'reverse') def impl(l): + if not l._is_mutable(): + raise ValueError("list is immutable") front = 0 back = len(l) - 1 while front < back: @@ -1127,6 +1222,8 @@ def ol_list_sort(lst, key=None, reverse=False): sort_b = listobj.arg_sort_backwards def impl(lst, key=None, reverse=False): + if not lst._is_mutable(): + raise ValueError("list is immutable") if KEY is True: # There's an unknown refct problem in reflected list. # Using an explicit loop with typedlist somehow "fixed" it. From f6669014278350e2abf08cc84a8ab8a2c7655533 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Wed, 12 Feb 2020 16:06:24 +0100 Subject: [PATCH 514/595] interpreter-level immutable typed-lists This exposes querying of and access to the `is_mutable` member of the underlying c-level struct from Python. This means that `_is_mutable`, `_make_mutable` and `_make_immutable` are accessible outside of `@njit` compiled functions. Tests are included. --- numba/tests/test_typedlist.py | 95 +++++++++++++++++++++++++++++++++++ numba/typed/typedlist.py | 24 +++++++++ 2 files changed, 119 insertions(+) diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py index 6f0016507e2..9f26b13271d 100644 --- a/numba/tests/test_typedlist.py +++ b/numba/tests/test_typedlist.py @@ -1141,3 +1141,98 @@ def foo(lst): list(foo(my_lists['nb'])), foo.py_func(my_lists['py']), ) + + +class TestImmutable(MemoryLeakMixin, TestCase): + + def test_is_immutable(self): + @njit + def foo(): + l = List() + l.append(1) + return l._is_mutable() + self.assertTrue(foo()) + self.assertTrue(foo.py_func()) + + def test_make_immutable_is_immutable(self): + @njit + def foo(): + l = List() + l.append(1) + l._make_immutable() + return l._is_mutable() + self.assertFalse(foo()) + self.assertFalse(foo.py_func()) + + def test_length_still_works_when_immutable(self): + @njit + def foo(): + l = List() + l.append(1) + l._make_immutable() + return len(l),l._is_mutable() + length, mutable = foo() + self.assertEqual(length, 1) + self.assertFalse(mutable) + + def test_getitem_still_works_when_immutable(self): + @njit + def foo(): + l = List() + l.append(1) + l._make_immutable() + return l[0], l._is_mutable() + test_item, mutable = foo() + self.assertEqual(test_item, 1) + self.assertFalse(mutable) + + def test_append_fails(self): + self.disable_leak_check() + @njit + def foo(): + l = List() + l.append(1) + l._make_immutable() + l.append(1) + + for func in (foo, foo.py_func): + with self.assertRaises(ValueError) as raises: + func() + self.assertIn( + 'list is immutable', + str(raises.exception), + ) + + def test_mutation_fails(self): + """ Test that any attempt to mutate an immutable typed list fails. """ + self.disable_leak_check() + + def generate_function(line): + context = {} + exec(dedent(""" + from numba.typed import List + def bar(): + lst = List() + lst.append(1) + lst._make_immutable() + {} + """.format(line)), context) + return njit(context["bar"]) + for line in ("lst.append(0)", + "lst[0] = 0", + "lst.pop()", + "del lst[0]", + "lst.extend((0,))", + "lst.insert(0, 0)", + "lst.clear()", + "lst.reverse()", + "lst.sort()", + ): + foo = generate_function(line) + for func in (foo, foo.py_func): + with self.assertRaises(ValueError) as raises: + func() + self.assertIn( + "list is immutable", + str(raises.exception), + ) diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index 747311055aa..993489b2484 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -42,6 +42,21 @@ def _allocated(l): return l._allocated() +@njit +def _is_mutable(l): + return l._is_mutable() + + +@njit +def _make_mutable(l): + return l._make_mutable() + + +@njit +def _make_immutable(l): + return l._make_immutable() + + @njit def _append(l, item): l.append(item) @@ -236,6 +251,15 @@ def _allocated(self): else: return _allocated(self) + def _is_mutable(self): + return _is_mutable(self) + + def _make_mutable(self): + return _make_mutable(self) + + def _make_immutable(self): + return _make_immutable(self) + def __eq__(self, other): return _eq(self, other) From a11048dcbfaeb04d40fbc2e2f333a090218b2480 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 12 Feb 2020 16:59:29 +0000 Subject: [PATCH 515/595] Make debug work in python code --- numba/np/ufunc/parallel.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/numba/np/ufunc/parallel.py b/numba/np/ufunc/parallel.py index a77bc200c25..c8d176589d1 100644 --- a/numba/np/ufunc/parallel.py +++ b/numba/np/ufunc/parallel.py @@ -27,6 +27,7 @@ from numba.np.ufunc.wrappers import _wrapper_info from numba.np.ufunc import ufuncbuilder from numba.extending import overload, intrinsic +from numba import njit _IS_OSX = sys.platform.startswith('darwin') @@ -518,8 +519,9 @@ def _load_num_threads_funcs(lib): # Some helpers to make set_num_threads jittable + @intrinsic -def debug(tyctx, max_t, ill_t): +def _debug(tyctx, max_t, ill_t): max_t_ty = getattr(max_t, 'literal_type', max_t) ill_t_ty = getattr(ill_t, 'literal_type', ill_t) sig = types.void(max_t_ty, ill_t_ty) @@ -529,6 +531,9 @@ def codegen(cgctx, builder, sig, args): b) return sig, codegen +@njit +def debug(max_t, ill_t): + _debug(max_t, ill_t) def gen_snt_check(): from numba.core.config import NUMBA_NUM_THREADS From 6f72a7ff26b2fd92678eb08ff0e70cb2c053ffcf Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 11:18:17 -0700 Subject: [PATCH 516/595] Don't allow reloading NUMBA_NUM_THREADS if threads have already been launched --- numba/core/config.py | 13 ++++++++++++- .../npyufunc/test_parallel_env_variable.py | 17 +++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/numba/core/config.py b/numba/core/config.py index aaeaafcba7f..b53b3f95a2e 100644 --- a/numba/core/config.py +++ b/numba/core/config.py @@ -322,8 +322,19 @@ def avx_default(): NUMBA_DEFAULT_NUM_THREADS = max(1, multiprocessing.cpu_count()) # Numba thread pool size (defaults to number of CPUs on the system). - NUMBA_NUM_THREADS = _readenv("NUMBA_NUM_THREADS", int, + _NUMBA_NUM_THREADS = _readenv("NUMBA_NUM_THREADS", int, NUMBA_DEFAULT_NUM_THREADS) + if ('NUMBA_NUM_THREADS' in globals() + and globals()['NUMBA_NUM_THREADS'] != _NUMBA_NUM_THREADS): + from numba.np.ufunc import parallel + if parallel._is_initialized: + raise RuntimeError("Cannot set NUMBA_NUM_THREADS to a " + "different value once the threads have been launched " + "(%s != %s)" % (_NUMBA_NUM_THREADS, + globals()['NUMBA_NUM_THREADS'])) + + NUMBA_NUM_THREADS = _NUMBA_NUM_THREADS + del _NUMBA_NUM_THREADS # Profiling support diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index 8cf58eaae23..3044ee383c8 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -20,14 +20,19 @@ def test_num_threads_variable(self): current = str(getattr(env, key, config.NUMBA_DEFAULT_NUM_THREADS)) threads = "3154" env[key] = threads - config.reload_config() try: - self.assertEqual(threads, str(get_thread_count())) - self.assertEqual(threads, str(config.NUMBA_NUM_THREADS)) - finally: - # reset the env variable/set to default - env[key] = current config.reload_config() + except RuntimeError as e: + # This test should fail if threads have already been launched + self.assertIn("Cannot set NUMBA_NUM_THREADS", e.args[0]) + else: + try: + self.assertEqual(threads, str(get_thread_count())) + self.assertEqual(threads, str(config.NUMBA_NUM_THREADS)) + finally: + # reset the env variable/set to default + env[key] = current + config.reload_config() if __name__ == '__main__': unittest.main() From 24333a8a5968c33cc7e0be62e09c1b1429b06e4c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 11:24:51 -0700 Subject: [PATCH 517/595] Fix flake8 --- numba/core/config.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/numba/core/config.py b/numba/core/config.py index b53b3f95a2e..3456b33ff32 100644 --- a/numba/core/config.py +++ b/numba/core/config.py @@ -323,14 +323,16 @@ def avx_default(): # Numba thread pool size (defaults to number of CPUs on the system). _NUMBA_NUM_THREADS = _readenv("NUMBA_NUM_THREADS", int, - NUMBA_DEFAULT_NUM_THREADS) + NUMBA_DEFAULT_NUM_THREADS) if ('NUMBA_NUM_THREADS' in globals() - and globals()['NUMBA_NUM_THREADS'] != _NUMBA_NUM_THREADS): + and globals()['NUMBA_NUM_THREADS'] != _NUMBA_NUM_THREADS): + from numba.np.ufunc import parallel if parallel._is_initialized: raise RuntimeError("Cannot set NUMBA_NUM_THREADS to a " - "different value once the threads have been launched " - "(%s != %s)" % (_NUMBA_NUM_THREADS, + "different value once the threads have been " + "launched (%s != %s)" % + (_NUMBA_NUM_THREADS, globals()['NUMBA_NUM_THREADS'])) NUMBA_NUM_THREADS = _NUMBA_NUM_THREADS From 6167215e4ed49e8a4300f327d5b4ed4540d1a420 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 12:03:56 -0700 Subject: [PATCH 518/595] Fix the parallel env variable test to reset the env correctly --- numba/tests/npyufunc/test_parallel_env_variable.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index 3044ee383c8..b391d2c1014 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -26,13 +26,13 @@ def test_num_threads_variable(self): # This test should fail if threads have already been launched self.assertIn("Cannot set NUMBA_NUM_THREADS", e.args[0]) else: - try: - self.assertEqual(threads, str(get_thread_count())) - self.assertEqual(threads, str(config.NUMBA_NUM_THREADS)) - finally: - # reset the env variable/set to default - env[key] = current - config.reload_config() + self.assertEqual(threads, str(get_thread_count())) + self.assertEqual(threads, str(config.NUMBA_NUM_THREADS)) + finally: + # reset the env variable/set to default. Should not fail even if + # threads are launched because the value is the same. + env[key] = current + config.reload_config() if __name__ == '__main__': unittest.main() From 554572f327e4b9c920f65b416bfc6a3a5b549846 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 12:29:41 -0700 Subject: [PATCH 519/595] Reset the num threads to the env variable, not the default --- numba/tests/npyufunc/test_parallel_env_variable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index b391d2c1014..7d11692ad34 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -17,7 +17,7 @@ def test_num_threads_variable(self): Tests the NUMBA_NUM_THREADS env variable behaves as expected. """ key = 'NUMBA_NUM_THREADS' - current = str(getattr(env, key, config.NUMBA_DEFAULT_NUM_THREADS)) + current = str(getattr(env, key, config.NUMBA_NUM_THREADS)) threads = "3154" env[key] = threads try: From 185950bfada928476f3a1ec4ec8479b9583e13ef Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 12:29:41 -0700 Subject: [PATCH 520/595] Reset the num threads to the env variable, not the default --- numba/tests/npyufunc/test_parallel_env_variable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/npyufunc/test_parallel_env_variable.py b/numba/tests/npyufunc/test_parallel_env_variable.py index 8cf58eaae23..dd3f36bc890 100644 --- a/numba/tests/npyufunc/test_parallel_env_variable.py +++ b/numba/tests/npyufunc/test_parallel_env_variable.py @@ -17,7 +17,7 @@ def test_num_threads_variable(self): Tests the NUMBA_NUM_THREADS env variable behaves as expected. """ key = 'NUMBA_NUM_THREADS' - current = str(getattr(env, key, config.NUMBA_DEFAULT_NUM_THREADS)) + current = str(getattr(env, key, config.NUMBA_NUM_THREADS)) threads = "3154" env[key] = threads config.reload_config() From ffff5044b462dd7d3d841692a744dc595aba973b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 13:51:35 -0700 Subject: [PATCH 521/595] Update numba/core/config.py Co-Authored-By: stuartarchibald --- numba/core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/core/config.py b/numba/core/config.py index 3456b33ff32..1303ec79f81 100644 --- a/numba/core/config.py +++ b/numba/core/config.py @@ -331,7 +331,7 @@ def avx_default(): if parallel._is_initialized: raise RuntimeError("Cannot set NUMBA_NUM_THREADS to a " "different value once the threads have been " - "launched (%s != %s)" % + "launched (currently have %s, trying to set %s)" % (_NUMBA_NUM_THREADS, globals()['NUMBA_NUM_THREADS'])) From 6d0a050898deff8612ce2b28ab812c1292daaef7 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 13:58:32 -0700 Subject: [PATCH 522/595] Fix flake8 --- numba/core/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numba/core/config.py b/numba/core/config.py index 1303ec79f81..8dada97f6ae 100644 --- a/numba/core/config.py +++ b/numba/core/config.py @@ -331,7 +331,8 @@ def avx_default(): if parallel._is_initialized: raise RuntimeError("Cannot set NUMBA_NUM_THREADS to a " "different value once the threads have been " - "launched (currently have %s, trying to set %s)" % + "launched (currently have %s, " + "trying to set %s)" % (_NUMBA_NUM_THREADS, globals()['NUMBA_NUM_THREADS'])) From fb10f425263541149de73de8d049f6c3d0dacbc5 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 12 Feb 2020 15:42:46 -0700 Subject: [PATCH 523/595] Use set_num_threads instead of NUMBA_NUM_THREADS in TestParforsVectorizer --- numba/tests/test_parfors.py | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index c07b6c50aae..79a8d74088e 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -19,7 +19,7 @@ from collections import defaultdict import numba.parfors.parfor -from numba import njit, prange +from numba import njit, prange, set_num_threads, get_num_threads from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler, cpu from numba.core.registry import cpu_target from numba.core.annotations import type_annotations @@ -2417,35 +2417,40 @@ def get_gufunc_asm(self, func, schedule_type, *args, **kwargs): fastmath = kwargs.pop('fastmath', False) nthreads = kwargs.pop('nthreads', 2) + old_nthreads = get_num_threads() cpu_name = kwargs.pop('cpu_name', 'skylake-avx512') assertions = kwargs.pop('assertions', True) env_opts = {'NUMBA_CPU_NAME': cpu_name, 'NUMBA_CPU_FEATURES': '', - 'NUMBA_NUM_THREADS': str(nthreads) } overrides = [] for k, v in env_opts.items(): overrides.append(override_env_config(k, v)) - with overrides[0], overrides[1], overrides[2]: - sig = tuple([numba.typeof(x) for x in args]) - pfunc_vectorizable = self.generate_prange_func(func, None) - if fastmath == True: - cres = self.compile_parallel_fastmath(pfunc_vectorizable, sig) - else: - cres = self.compile_parallel(pfunc_vectorizable, sig) - - # get the gufunc asm - asm = self._get_gufunc_asm(cres) - - if assertions: - schedty = re.compile('call\s+\w+\*\s+@do_scheduling_(\w+)\(') - matches = schedty.findall(cres.library.get_llvm_str()) - self.assertGreaterEqual(len(matches), 1) # at least 1 parfor call - self.assertEqual(matches[0], schedule_type) - self.assertTrue(asm != {}) + with overrides[0], overrides[1]: + # Replace this with set_num_threads as a context manager when that exists + try: + set_num_threads(nthreads) + sig = tuple([numba.typeof(x) for x in args]) + pfunc_vectorizable = self.generate_prange_func(func, None) + if fastmath == True: + cres = self.compile_parallel_fastmath(pfunc_vectorizable, sig) + else: + cres = self.compile_parallel(pfunc_vectorizable, sig) + + # get the gufunc asm + asm = self._get_gufunc_asm(cres) + + if assertions: + schedty = re.compile('call\s+\w+\*\s+@do_scheduling_(\w+)\(') + matches = schedty.findall(cres.library.get_llvm_str()) + self.assertGreaterEqual(len(matches), 1) # at least 1 parfor call + self.assertEqual(matches[0], schedule_type) + self.assertTrue(asm != {}) + finally: + set_num_threads(old_nthreads) return asm From 371af96af9a47d816cff8fcc604760ebf5e0b12d Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 22 Jan 2020 11:30:00 -0800 Subject: [PATCH 524/595] Better debugging messages. --- numba/parfors/parfor_lowering.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/numba/parfors/parfor_lowering.py b/numba/parfors/parfor_lowering.py index 38aea5cf9ab..081b5bfeef1 100644 --- a/numba/parfors/parfor_lowering.py +++ b/numba/parfors/parfor_lowering.py @@ -414,6 +414,9 @@ def _lower_parfor_parallel(lowerer, parfor): # Beginning of this function. lowerer.fndesc.typemap = orig_typemap + if config.DEBUG_ARRAY_OPT: + print("_lower_parfor_parallel done") + # A work-around to prevent circular imports lowering.lower_extensions[parfor.Parfor] = _lower_parfor_parallel @@ -785,6 +788,9 @@ def _create_gufunc_for_parfor_body( for the parfor body inserted. ''' + if config.DEBUG_ARRAY_OPT >= 1: + print("starting _create_gufunc_for_parfor_body") + loc = parfor.init_block.loc # The parfor body and the main function body share ir.Var nodes. @@ -812,6 +818,12 @@ def _create_gufunc_for_parfor_body( set(parfor_outputs) - set(parfor_redvars))) + if config.DEBUG_ARRAY_OPT >= 1: + print("parfor_params = ", parfor_params, " ", type(parfor_params)) + print("parfor_outputs = ", parfor_outputs, " ", type(parfor_outputs)) + print("parfor_inputs = ", parfor_inputs, " ", type(parfor_inputs)) + print("parfor_redvars = ", parfor_redvars, " ", type(parfor_redvars)) + races = races.difference(set(parfor_redvars)) for race in races: msg = ("Variable %s used in parallel loop may be written " @@ -820,12 +832,6 @@ def _create_gufunc_for_parfor_body( warnings.warn(NumbaParallelSafetyWarning(msg, loc)) replace_var_with_array(races, loop_body, typemap, lowerer.fndesc.calltypes) - if config.DEBUG_ARRAY_OPT >= 1: - print("parfor_params = ", parfor_params, " ", type(parfor_params)) - print("parfor_outputs = ", parfor_outputs, " ", type(parfor_outputs)) - print("parfor_inputs = ", parfor_inputs, " ", type(parfor_inputs)) - print("parfor_redvars = ", parfor_redvars, " ", type(parfor_redvars)) - # Reduction variables are represented as arrays, so they go under # different names. parfor_redarrs = [] @@ -1159,7 +1165,7 @@ def _create_gufunc_for_parfor_body( kernel_sig = signature(types.none, *gufunc_param_types) if config.DEBUG_ARRAY_OPT: - print("kernel_sig = ", kernel_sig) + print("finished create_gufunc_for_parfor_body. kernel_sig = ", kernel_sig) return kernel_func, parfor_args, kernel_sig, redargstartdim, func_arg_types From 0f8179cba63c1da3dfc530fede9e60f6f26b1985 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 22 Jan 2020 11:32:26 -0800 Subject: [PATCH 525/595] Don't consider variables of type Module to be parfor races since push_call_vars() in the parfor pass copies such variables to later parfors if they are used there. --- numba/parfors/parfor.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 28951a7f280..2fc77f92e2b 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -604,6 +604,8 @@ def dump(self, file=None): file = file or sys.stdout print(("begin parfor {}".format(self.id)).center(20, '-'), file=file) print("index_var = ", self.index_var, file=file) + print("params = ", self.params, file=file) + print("races = ", self.races, file=file) for loopnest in self.loop_nests: print(loopnest, file=file) print("init block:", file=file) @@ -1550,6 +1552,7 @@ def run(self): # push function call variables inside parfors so gufunc function # wouldn't need function variables as argument push_call_vars(self.func_ir.blocks, {}, {}, self.typemap) + dprint_func_ir(self.func_ir, "after push call vars") # simplify again simplify(self.func_ir, self.typemap, self.calltypes) dprint_func_ir(self.func_ir, "after optimization") @@ -1788,6 +1791,13 @@ def _convert_loop(self, blocks): for bl in loop.exits: exit_lives = exit_lives.union(live_map[bl]) races = bodydefs.intersection(exit_lives) + # It is possible for the result of an ir.Global to be flagged + # as a race if it is defined in this Parfor and then used in + # a subsequent Parfor. push_call_vars() in the Parfor pass + # copies such ir.Global nodes into the Parfors in which they + # are used so no need to treat things of type Module as a race. + races = races.intersection({x for x in races + if not isinstance(self.typemap[x], types.misc.Module)}) # replace jumps to header block with the end block for l in body_labels: @@ -1961,6 +1971,9 @@ def find_mask_from_size(size_var): blocks.pop(loop.header) for l in body_labels: blocks.pop(l) + if config.DEBUG_ARRAY_OPT >= 1: + print("parfor from loop") + parfor.dump() def _replace_loop_access_indices(self, loop_body, index_set, new_index): """ @@ -2236,6 +2249,7 @@ def _arrayexpr_to_parfor(self, equiv_set, lhs, arrayexpr, avail_vars): body_block.body.append(setitem_node) parfor.loop_body = {body_label: body_block} if config.DEBUG_ARRAY_OPT >= 1: + print("parfor from arrayexpr") parfor.dump() return parfor @@ -2329,6 +2343,7 @@ def _setitem_to_parfor(self, equiv_set, loc, target, index, value, shape=None): true_block.body.append(ir.Jump(end_label, loc)) if config.DEBUG_ARRAY_OPT >= 1: + print("parfor from setitem") parfor.dump() return parfor @@ -2515,6 +2530,9 @@ def _reduce_to_parfor(self, equiv_set, lhs, args, loc): parfor = Parfor(loopnests, init_block, loop_body, loc, index_var, equiv_set, ('{} function'.format(call_name), 'reduction'), self.flags) + if config.DEBUG_ARRAY_OPT >= 1: + print("parfor from reduction") + parfor.dump() return parfor @@ -2965,7 +2983,6 @@ def get_parfor_params(blocks, options_fusion, fusion_info): def get_parfor_params_inner(parfor, pre_defs, options_fusion, fusion_info): - blocks = wrap_parfor_blocks(parfor) cfg = compute_cfg_from_blocks(blocks) usedefs = compute_use_defs(blocks) From 86ae90c29d4b2f504aad9a1afd36bb9a76e369b7 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 13 Feb 2020 10:39:19 +0000 Subject: [PATCH 526/595] Add test case for #5098 --- numba/tests/test_parfors.py | 61 ++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index c07b6c50aae..58efa955dc9 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -20,7 +20,10 @@ import numba.parfors.parfor from numba import njit, prange -from numba.core import types, utils, typing, errors, ir, rewrites, typed_passes, inline_closurecall, config, compiler, cpu +from numba.core import (types, utils, typing, errors, ir, rewrites, + typed_passes, inline_closurecall, config, compiler, cpu) +from numba.extending import (overload_method, register_model, + typeof_impl, unbox, NativeValue, models) from numba.core.registry import cpu_target from numba.core.annotations import type_annotations from numba.core.ir_utils import (find_callname, guard, build_definitions, @@ -3097,6 +3100,62 @@ def test_impl(): self.check(test_impl) + @skip_parfors_unsupported + def test_issue_5098(self): + class DummyType(types.Opaque): + pass + + dummy_type = DummyType("my_dummy") + register_model(DummyType)(models.OpaqueModel) + + class Dummy(object): + pass + + @typeof_impl.register(Dummy) + def typeof_Dummy(val, c): + return dummy_type + + @unbox(DummyType) + def unbox_index(typ, obj, c): + return NativeValue(c.context.get_dummy_value()) + + @overload_method(DummyType, "method1", jit_options={"parallel":True}) + def _get_method1(obj, arr, func): + def _foo(obj, arr, func): + def baz(a, f): + c = a.copy() + c[np.isinf(a)] = np.nan + return f(c) + + length = len(arr) + output_arr = np.empty(length, dtype=np.float64) + for i in prange(length): + output_arr[i] = baz(arr[i], func) + for i in prange(length - 1): + output_arr[i] += baz(arr[i], func) + return output_arr + return _foo + + @njit + def bar(v): + return v.mean() + + @njit + def test1(d): + return d.method1(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]), bar) + + save_state = numba.parfors.parfor.sequential_parfor_lowering + self.assertFalse(save_state) + try: + test1(Dummy()) + self.assertFalse(numba.parfors.parfor.sequential_parfor_lowering) + finally: + # always set the sequential_parfor_lowering state back to the + # original state + numba.parfors.parfor.sequential_parfor_lowering = save_state + + + @skip_parfors_unsupported class TestParforsDiagnostics(TestParforsBase): From 282333a1901b08d142565c28641131c3e9b8328d Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 13 Feb 2020 12:54:04 +0000 Subject: [PATCH 527/595] Undo debug code --- numba/np/ufunc/parallel.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/numba/np/ufunc/parallel.py b/numba/np/ufunc/parallel.py index c8d176589d1..b5387c03722 100644 --- a/numba/np/ufunc/parallel.py +++ b/numba/np/ufunc/parallel.py @@ -23,11 +23,10 @@ import llvmlite.binding as ll from numba.np.numpy_support import as_dtype -from numba.core import types, config, errors, cgutils +from numba.core import types, config, errors from numba.np.ufunc.wrappers import _wrapper_info from numba.np.ufunc import ufuncbuilder -from numba.extending import overload, intrinsic -from numba import njit +from numba.extending import overload _IS_OSX = sys.platform.startswith('darwin') @@ -520,28 +519,12 @@ def _load_num_threads_funcs(lib): # Some helpers to make set_num_threads jittable -@intrinsic -def _debug(tyctx, max_t, ill_t): - max_t_ty = getattr(max_t, 'literal_type', max_t) - ill_t_ty = getattr(ill_t, 'literal_type', ill_t) - sig = types.void(max_t_ty, ill_t_ty) - def codegen(cgctx, builder, sig, args): - a, b = args - cgutils.printf(builder, "Max threads %d. Illegal thread count %d\n", a, - b) - return sig, codegen - -@njit -def debug(max_t, ill_t): - _debug(max_t, ill_t) - def gen_snt_check(): from numba.core.config import NUMBA_NUM_THREADS msg = "The number of threads must be between 1 and %s" % NUMBA_NUM_THREADS def snt_check(n): if n > NUMBA_NUM_THREADS or n < 1: - debug(NUMBA_NUM_THREADS, n) raise ValueError(msg) return snt_check From e520c809aa666dc45f997465de17f0b49337716a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 13 Feb 2020 12:48:46 +0000 Subject: [PATCH 528/595] Disable TBB on linux x86 --- buildscripts/condarecipe.local/meta.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildscripts/condarecipe.local/meta.yaml b/buildscripts/condarecipe.local/meta.yaml index 6b6e52bd8c5..53a51f5961d 100644 --- a/buildscripts/condarecipe.local/meta.yaml +++ b/buildscripts/condarecipe.local/meta.yaml @@ -36,7 +36,7 @@ requirements: - funcsigs # [py27] - singledispatch # [py27] # TBB devel version is to match TBB libs - - tbb-devel >=2019.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] + - tbb-devel >=2019.5 # [not (armv6l or armv7l or aarch64 or linux32)] run: - python >=3.6 - numpy >=1.15 @@ -48,7 +48,7 @@ requirements: run_constrained: # If TBB is present it must be at least this version from Anaconda due to # build flag issues triggering UB - - tbb >=2019.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] + - tbb >=2019.5 # [not (armv6l or armv7l or aarch64 or linux32)] # avoid confusion from openblas bugs - libopenblas !=0.3.6 # [x86_64] # CUDA 8.0 or later is required for CUDA support @@ -65,7 +65,7 @@ test: - ipython # [not (armv6l or armv7l or aarch64)] - setuptools - faulthandler # [py27 and (not (armv6l or armv7l or aarch64))] - - tbb >=2019.5 # [not ((armv6l or armv7l or aarch64) or (win and py27))] + - tbb >=2019.5 # [not (armv6l or armv7l or aarch64 or linux32)] - intel-openmp # [osx] # Need these for AOT. Do not init msvc as it may not be present - {{ compiler('c') }} # [not (win or armv6l or armv7l or aarch64)] From 7fe82e9ff53f4c0dfe11e69d9536ccc25785176a Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 13 Feb 2020 13:17:15 +0000 Subject: [PATCH 529/595] Remove dead code in gufunc asm test --- numba/tests/test_parfors.py | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 79a8d74088e..890dfd857d7 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -2416,8 +2416,6 @@ class TestParforsVectorizer(TestPrangeBase): def get_gufunc_asm(self, func, schedule_type, *args, **kwargs): fastmath = kwargs.pop('fastmath', False) - nthreads = kwargs.pop('nthreads', 2) - old_nthreads = get_num_threads() cpu_name = kwargs.pop('cpu_name', 'skylake-avx512') assertions = kwargs.pop('assertions', True) @@ -2430,29 +2428,24 @@ def get_gufunc_asm(self, func, schedule_type, *args, **kwargs): overrides.append(override_env_config(k, v)) with overrides[0], overrides[1]: - # Replace this with set_num_threads as a context manager when that exists - try: - set_num_threads(nthreads) - sig = tuple([numba.typeof(x) for x in args]) - pfunc_vectorizable = self.generate_prange_func(func, None) - if fastmath == True: - cres = self.compile_parallel_fastmath(pfunc_vectorizable, sig) - else: - cres = self.compile_parallel(pfunc_vectorizable, sig) + sig = tuple([numba.typeof(x) for x in args]) + pfunc_vectorizable = self.generate_prange_func(func, None) + if fastmath == True: + cres = self.compile_parallel_fastmath(pfunc_vectorizable, sig) + else: + cres = self.compile_parallel(pfunc_vectorizable, sig) - # get the gufunc asm - asm = self._get_gufunc_asm(cres) + # get the gufunc asm + asm = self._get_gufunc_asm(cres) - if assertions: - schedty = re.compile('call\s+\w+\*\s+@do_scheduling_(\w+)\(') - matches = schedty.findall(cres.library.get_llvm_str()) - self.assertGreaterEqual(len(matches), 1) # at least 1 parfor call - self.assertEqual(matches[0], schedule_type) - self.assertTrue(asm != {}) - finally: - set_num_threads(old_nthreads) + if assertions: + schedty = re.compile('call\s+\w+\*\s+@do_scheduling_(\w+)\(') + matches = schedty.findall(cres.library.get_llvm_str()) + self.assertGreaterEqual(len(matches), 1) # at least 1 parfor call + self.assertEqual(matches[0], schedule_type) + self.assertTrue(asm != {}) - return asm + return asm # this is a common match pattern for something like: # \n\tvsqrtpd\t-192(%rbx,%rsi,8), %zmm0\n From 5fe9aaa10e65b4324ea093fd920535ed677f687f Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Thu, 13 Feb 2020 18:01:58 +0100 Subject: [PATCH 530/595] fix target path for See also As title --- numba/typed/typedlist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py index 747311055aa..d59f1e9a75a 100644 --- a/numba/typed/typedlist.py +++ b/numba/typed/typedlist.py @@ -433,7 +433,7 @@ def impl_numba_typeref_ctor(cls): cls : TypeRef Expecting a TypeRef of a precise ListType. - See also: `redirect_type_ctor` in numba/target/bulitins.py + See also: `redirect_type_ctor` in numba/cpython/bulitins.py """ list_ty = cls.instance_type if not isinstance(list_ty, types.ListType): From c995a15890ed05e4e262df607fdc75732ed87ce1 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 13 Feb 2020 20:50:30 +0000 Subject: [PATCH 531/595] Add in changes from #5114 As title --- numba/parfors/parfor_lowering.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/numba/parfors/parfor_lowering.py b/numba/parfors/parfor_lowering.py index 38aea5cf9ab..3cbb93a1865 100644 --- a/numba/parfors/parfor_lowering.py +++ b/numba/parfors/parfor_lowering.py @@ -224,10 +224,12 @@ def _lower_parfor_parallel(lowerer, parfor): for l in parfor.loop_nests[1:]: assert typemap[l.index_variable.name] == index_var_typ numba.parfors.parfor.sequential_parfor_lowering = True - func, func_args, func_sig, redargstartdim, func_arg_types = _create_gufunc_for_parfor_body( - lowerer, parfor, typemap, typingctx, targetctx, flags, {}, - bool(alias_map), index_var_typ, parfor.races) - numba.parfors.parfor.sequential_parfor_lowering = False + try: + func, func_args, func_sig, redargstartdim, func_arg_types = _create_gufunc_for_parfor_body( + lowerer, parfor, typemap, typingctx, targetctx, flags, {}, + bool(alias_map), index_var_typ, parfor.races) + finally: + numba.parfors.parfor.sequential_parfor_lowering = False # get the shape signature func_args = ['sched'] + func_args From d86a4f9ad06eaaec7e633cd1a2f68c8b0db36dd4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 13 Feb 2020 20:59:20 +0000 Subject: [PATCH 532/595] Add in test for changes proposed in #5114 As title --- numba/tests/test_parfors.py | 61 ++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index c07b6c50aae..9f3ae3535f3 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -27,8 +27,11 @@ get_definition, is_getitem, is_setitem, index_var_of_get_setitem) from numba.np.unsafe.ndarray import empty_inferred as unsafe_empty -from numba.core.compiler import compile_isolated, Flags from numba.core.bytecode import ByteCodeIter +from numba.core.compiler import (compile_isolated, Flags, CompilerBase, + DefaultPassBuilder) +from numba.core.compiler_machinery import register_pass, FunctionPass +from numba.core.typed_passes import IRLegalization from numba.tests.support import (TestCase, captured_stdout, MemoryLeakMixin, override_env_config, linux_only, tag, skip_parfors_unsupported, _32bit, needs_blas, @@ -3097,6 +3100,62 @@ def test_impl(): self.check(test_impl) + @skip_parfors_unsupported + def test_no_state_change_in_gufunc_lowering_on_error(self): + # tests #5098, if there's an exception arising in gufunc lowering the + # sequential_parfor_lowering global variable should remain as False on + # stack unwind. + + @register_pass(mutates_CFG=True, analysis_only=False) + class BreakParfors(FunctionPass): + _name = "break_parfors" + + def __init__(self): + FunctionPass.__init__(self) + + def run_pass(self, state): + for blk in state.func_ir.blocks.values(): + for stmt in blk.body: + if isinstance(stmt, numba.parfors.parfor.Parfor): + # races should be a set(), that list is iterable + # permits it to get through to the + # _create_gufunc_for_parfor_body routine at which + # point it needs to be a set so e.g. set.difference + # can be computed, this therefore creates an error + # in the right location. + stmt.races = [] + return True + + + class BreakParforsCompiler(CompilerBase): + + def define_pipelines(self): + pm = DefaultPassBuilder.define_nopython_pipeline(self.state) + pm.add_pass_after(BreakParfors, IRLegalization) + pm.finalize() + return [pm] + + + @njit(parallel=True, pipeline_class=BreakParforsCompiler) + def foo(): + x = 1 + for _ in prange(1): + x += 1 + return x + + # assert default state for global + self.assertFalse(numba.parfors.parfor.sequential_parfor_lowering) + + with self.assertRaises(errors.LoweringError) as raises: + foo() + + self.assertIn("'list' object has no attribute 'difference'", + str(raises.exception)) + + # assert state has not changed + self.assertFalse(numba.parfors.parfor.sequential_parfor_lowering) + + @skip_parfors_unsupported class TestParforsDiagnostics(TestParforsBase): From 29860d04a5c3579966a7ddca15439a53b7805e0f Mon Sep 17 00:00:00 2001 From: Antonio Russo Date: Thu, 13 Feb 2020 18:16:27 -0700 Subject: [PATCH 533/595] Trivially fix SyntaxWarning The is keyword should not be used with a literal, instead equality, ==, should be tested for. Signed-off-by: Antonio Russo --- numba/tests/test_listimpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_listimpl.py b/numba/tests/test_listimpl.py index 0cd38e9b2a3..6dd2b4a5972 100644 --- a/numba/tests/test_listimpl.py +++ b/numba/tests/test_listimpl.py @@ -105,7 +105,7 @@ def list_pop(self, i): # support -1 to be last element of the list here if i < -1 or len(self) == 0: IndexError("list index out of range") - elif i is -1: + elif i == -1: i = len(self) - 1 item_out_buffer = ctypes.create_string_buffer(self.item_size) status = self.tc.numba_list_pop(self.lp, i, item_out_buffer) From cc90701facec7e184d200e81e714424d9d35f9aa Mon Sep 17 00:00:00 2001 From: hdf Date: Fri, 14 Feb 2020 20:43:08 +0100 Subject: [PATCH 534/595] boundscheck fix Without this, even if it is set to False, the error will be raised. --- numba/cuda/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/decorators.py b/numba/cuda/decorators.py index 3877db0339c..a5ecbb183e7 100644 --- a/numba/cuda/decorators.py +++ b/numba/cuda/decorators.py @@ -51,7 +51,7 @@ def jit(func_or_sig=None, argtypes=None, device=False, inline=False, bind=True, if link and config.ENABLE_CUDASIM: raise NotImplementedError('Cannot link PTX in the simulator') - if 'boundscheck' in kws: + if kws.get('boundscheck') == True: raise NotImplementedError("bounds checking is not supported for CUDA") fastmath = kws.get('fastmath', False) From 37e308d427fcbfed030b06a94ceec306bdcd03f9 Mon Sep 17 00:00:00 2001 From: hdf Date: Sun, 16 Feb 2020 14:58:58 +0100 Subject: [PATCH 535/595] added test for #5257 --- numba/tests/test_boundscheck.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index 6fa74dbbc2b..3bbdeef2874 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -120,6 +120,10 @@ def test_no_cuda_boundscheck(self): def func(): pass + @cuda.jit(boundscheck=False) + def func(): + pass + with override_env_config('NUMBA_BOUNDSCHECK', '1'): @cuda.jit def func2(x, a): From 4a1e6d8de70126e77565feee94471feb88355437 Mon Sep 17 00:00:00 2001 From: hdf Date: Sun, 16 Feb 2020 17:27:24 +0100 Subject: [PATCH 536/595] fix extension for #5257 If this is disagreeable, than just close this Pull request. --- numba/cuda/simulator/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/simulator/api.py b/numba/cuda/simulator/api.py index 118f6f8e464..abdc11269d5 100644 --- a/numba/cuda/simulator/api.py +++ b/numba/cuda/simulator/api.py @@ -76,7 +76,7 @@ def jit(func_or_sig=None, device=False, debug=False, argtypes=None, boundscheck=None, ): # Here for API compatibility - if boundscheck is not None: + if boundscheck == True: raise NotImplementedError("bounds checking is not supported for CUDA") if link is not None: From cc6692d0dda96c4fda0b0f28a7a534ea5672da3e Mon Sep 17 00:00:00 2001 From: hdf Date: Sun, 16 Feb 2020 17:35:58 +0100 Subject: [PATCH 537/595] fix lack of attention --- numba/tests/test_boundscheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index 3bbdeef2874..b058a8f0846 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -121,7 +121,7 @@ def func(): pass @cuda.jit(boundscheck=False) - def func(): + def func3(): pass with override_env_config('NUMBA_BOUNDSCHECK', '1'): From 1d26fce142879026a79cc2d8230e51672b3ccb23 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 17 Feb 2020 11:08:03 +0100 Subject: [PATCH 538/595] fix typo in inlining docs As title --- docs/source/developer/inlining.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/developer/inlining.rst b/docs/source/developer/inlining.rst index 6739471021d..da2b200e878 100644 --- a/docs/source/developer/inlining.rst +++ b/docs/source/developer/inlining.rst @@ -37,7 +37,7 @@ As an example, consider the following snippet: This will fail to compile and run, because the type of ``z`` can not be inferred as it will only be refined within ``bar``. If we now add ``inline=True`` to the -decorator for ``bar`` the snippet will compile and run. This i because inlining +decorator for ``bar`` the snippet will compile and run. This is because inlining the call to ``a.append(10)`` will mean that ``z`` will be refined to hold integers and so type inference will succeed. From 70e705e3c49fac865a137570f00f8da454432d71 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Mon, 17 Feb 2020 15:56:34 +0100 Subject: [PATCH 539/595] check the exception content The `ValueError` is so common, better to check the string in the exception also. --- numba/tests/test_listimpl.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/numba/tests/test_listimpl.py b/numba/tests/test_listimpl.py index e35fb95d811..34515e6ae1a 100644 --- a/numba/tests/test_listimpl.py +++ b/numba/tests/test_listimpl.py @@ -473,20 +473,25 @@ def test_mutability(self): l.set_immutable() self.assertFalse(l.is_mutable) # append - with self.assertRaises(ValueError): + with self.assertRaises(ValueError) as raises: l.append(one) + self.assertIn("list is immutable", str(raises.exception)) # setitem - with self.assertRaises(ValueError): + with self.assertRaises(ValueError) as raises: l[0] = one + self.assertIn("list is immutable", str(raises.exception)) # pop - with self.assertRaises(ValueError): + with self.assertRaises(ValueError) as raises: l.pop() + self.assertIn("list is immutable", str(raises.exception)) # delitem with index - with self.assertRaises(ValueError): + with self.assertRaises(ValueError) as raises: del l[0] + self.assertIn("list is immutable", str(raises.exception)) # delitem with slice - with self.assertRaises(ValueError): + with self.assertRaises(ValueError) as raises: del l[0:1:1] + self.assertIn("list is immutable", str(raises.exception)) l.set_mutable() # check that nothing has changed From ed5dae9b960d8dc781c6fe3b4a279b7f29f71491 Mon Sep 17 00:00:00 2001 From: hdf Date: Mon, 17 Feb 2020 18:06:47 +0100 Subject: [PATCH 540/595] adding requested comment --- numba/tests/test_boundscheck.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/tests/test_boundscheck.py b/numba/tests/test_boundscheck.py index b058a8f0846..08cb88e9b83 100644 --- a/numba/tests/test_boundscheck.py +++ b/numba/tests/test_boundscheck.py @@ -120,6 +120,8 @@ def test_no_cuda_boundscheck(self): def func(): pass + # Make sure we aren't raising "not supported" error if we aren't + # requesting bounds checking anyway. Related pull request: #5257 @cuda.jit(boundscheck=False) def func3(): pass From 648fa8178347275e54412fdec3250e212b742c11 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 17 Feb 2020 18:07:16 -0600 Subject: [PATCH 541/595] Fix missing skip because of mistake in previous merge --- numba/tests/test_parfors.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index dd369ea95a6..256cb901eaf 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -3156,6 +3156,7 @@ def foo(): # assert state has not changed self.assertFalse(numba.parfors.parfor.sequential_parfor_lowering) + @skip_parfors_unsupported def test_issue_5098(self): class DummyType(types.Opaque): pass From 28de558baad81488f971ce1539bacc1506a5932b Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Tue, 18 Feb 2020 11:01:15 +0100 Subject: [PATCH 542/595] fix 'see also' in typeddict docs As title --- numba/typed/typeddict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/typed/typeddict.py b/numba/typed/typeddict.py index fd3752d2f8d..d6c288f75e7 100644 --- a/numba/typed/typeddict.py +++ b/numba/typed/typeddict.py @@ -303,7 +303,7 @@ def impl_numba_typeref_ctor(cls): cls : TypeRef Expecting a TypeRef of a precise DictType. - See also: `redirect_type_ctor` in numba/target/bulitins.py + See also: `redirect_type_ctor` in numba/cpython/bulitins.py """ dict_ty = cls.instance_type if not isinstance(dict_ty, types.DictType): From 661cc2ad114401513e7f9fd72c88f3c6e68973f9 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 17 Feb 2020 14:44:43 -0600 Subject: [PATCH 543/595] Make pytest happy --- numba/tests/test_parfors.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 256cb901eaf..50561bf8f34 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -43,7 +43,7 @@ import unittest -test_disabled = unittest.skipIf(True, 'Test disabled') +disabled_test = unittest.skipIf(True, 'Test disabled') x86_only = unittest.skipIf(platform.machine() not in ('i386', 'x86_64'), 'x86 only test') _GLOBAL_INT_FOR_TESTING1 = 17 @@ -280,7 +280,7 @@ def lr_impl(Y, X, w, iterations): w -= np.dot(((1.0 / (1.0 + np.exp(-Y * np.dot(X, w))) - 1.0) * Y), X) return w -def test_kmeans_example(A, numCenter, numIter, init_centroids): +def example_kmeans_test(A, numCenter, numIter, init_centroids): centroids = init_centroids N, D = A.shape @@ -577,14 +577,14 @@ def test_kmeans(self): centers = 3 A = np.random.ranf((N, D)) init_centroids = np.random.ranf((centers, D)) - self.check(test_kmeans_example, A, centers, 3, init_centroids, + self.check(example_kmeans_test, A, centers, 3, init_centroids, decimal=1) # TODO: count parfors after k-means fusion is working # requires recursive parfor counting arg_typs = (types.Array(types.float64, 2, 'C'), types.intp, types.intp, types.Array(types.float64, 2, 'C')) self.assertTrue( - countNonParforArrayAccesses(test_kmeans_example, arg_typs) == 0) + countNonParforArrayAccesses(example_kmeans_test, arg_typs) == 0) @unittest.skipIf(not _32bit, "Only impacts 32 bit hardware") @needs_blas @@ -754,7 +754,7 @@ def test_impl(): return np.sum(A[:, b]) self.check(test_impl) - @test_disabled + @disabled_test def test_simple_operator_15(self): """same as corresponding test_simple_ case but using operator.add""" def test_impl(v1, v2, m1, m2): @@ -762,14 +762,14 @@ def test_impl(v1, v2, m1, m2): self.check(test_impl, *self.simple_args) - @test_disabled + @disabled_test def test_simple_operator_16(self): def test_impl(v1, v2, m1, m2): return operator.add(m1, m1) self.check(test_impl, *self.simple_args) - @test_disabled + @disabled_test def test_simple_operator_17(self): def test_impl(v1, v2, m1, m2): return operator.add(m2, v1) @@ -1237,7 +1237,7 @@ def test_impl(n): self.assertEqual(countNonParforArrayAccesses(test_impl, (types.intp,)), 0) @skip_parfors_unsupported - @test_disabled # Test itself is problematic, see #3155 + @disabled_test # Test itself is problematic, see #3155 def test_parfor_hoist_setitem(self): # Make sure that read of out is not hoisted. def test_impl(out): @@ -2133,7 +2133,7 @@ def test_impl(n): self.assertIn(msg, str(raises.exception)) # @skip_parfors_unsupported - @test_disabled + @disabled_test def test_check_error_model(self): def test_impl(): n = 32 @@ -2695,7 +2695,7 @@ def test_impl(a): self.assertIn("do not match", str(raises.exception)) # @skip_parfors_unsupported - @test_disabled + @disabled_test def test_parfor_slice8(self): def test_impl(a): (m,n) = a.shape @@ -2706,7 +2706,7 @@ def test_impl(a): self.check(test_impl, np.arange(9).reshape((3,3))) # @skip_parfors_unsupported - @test_disabled + @disabled_test def test_parfor_slice9(self): def test_impl(a): (m,n) = a.shape @@ -2717,7 +2717,7 @@ def test_impl(a): self.check(test_impl, np.arange(12).reshape((3,4))) # @skip_parfors_unsupported - @test_disabled + @disabled_test def test_parfor_slice10(self): def test_impl(a): (m,n) = a.shape @@ -2779,7 +2779,7 @@ def test_impl(a): self.check(test_impl, np.arange(12).reshape((3,4))) - @test_disabled + @disabled_test def test_parfor_slice16(self): """ This test is disabled because if n is larger than the array size then n and n-1 will both be the end of the array and thus the From 150cab6b4105a4596421bc19d0c11a30dc78b288 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 17 Feb 2020 18:11:14 -0600 Subject: [PATCH 544/595] Split into ConvertSetItemPass --- numba/parfors/parfor.py | 397 ++++++++++++++----------- numba/tests/test_parfors_components.py | 164 ++++++++++ 2 files changed, 381 insertions(+), 180 deletions(-) create mode 100644 numba/tests/test_parfors_components.py diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 2fc77f92e2b..2a88bad12c9 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -1470,13 +1470,8 @@ def find_template(op): if ft.key == op: return ft -class ParforPass(object): - """ParforPass class is responsible for converting Numpy - calls in Numba intermediate representation to Parfors, which - will lower into either sequential or parallel loops during lowering - stage. - """ +class ParforPassStates: def __init__(self, func_ir, typemap, calltypes, return_type, typingctx, options, flags, diagnostics=ParforDiagnostics()): @@ -1491,24 +1486,224 @@ def __init__(self, func_ir, typemap, calltypes, return_type, typingctx, self.fusion_info = diagnostics.fusion_info self.nested_fusion_info = diagnostics.nested_fusion_info - self.array_analysis = array_analysis.ArrayAnalysis(typingctx, func_ir, typemap, - calltypes) + self.array_analysis = array_analysis.ArrayAnalysis( + typingctx, func_ir, typemap, calltypes, + ) + ir_utils._max_label = max(func_ir.blocks.keys()) self.flags = flags - def run(self): - """run parfor conversion pass: replace Numpy calls - with Parfors when possible and optimize the IR.""" + +class ConvertSetItemPass: + def __init__(self, pass_states): + self.pass_states = pass_states + self.rewritten = [] + + def run(self, blocks): + pass_states = self.pass_states + # convert setitem expressions like A[C] = c or A[C] = B[C] to parfor, + # where C is a boolean array. + topo_order = find_topo_order(blocks) + # variables available in the program so far (used for finding map + # functions in array_expr lowering) + avail_vars = [] + for label in topo_order: + block = blocks[label] + new_body = [] + equiv_set = pass_states.array_analysis.get_equiv_set(label) + for instr in block.body: + if isinstance(instr, ir.StaticSetItem) or isinstance(instr, ir.SetItem): + loc = instr.loc + target = instr.target + index = (instr.index if isinstance(instr, ir.SetItem) + else instr.index_var) + value = instr.value + target_typ = pass_states.typemap[target.name] + index_typ = pass_states.typemap[index.name] + value_typ = pass_states.typemap[value.name] + # Handle A[boolean_array] = + if isinstance(target_typ, types.npytypes.Array): + if (isinstance(index_typ, types.npytypes.Array) and + isinstance(index_typ.dtype, types.Boolean) and + target_typ.ndim == index_typ.ndim): + # RHS is a scalar number + if isinstance(value_typ, types.Number): + new_instr = self._setitem_to_parfor(equiv_set, + loc, target, index, value) + self.rewritten.append( + dict(old=instr, new=new_instr, + reason='masked_assign_boardcast_scalar'), + ) + instr = new_instr + # RHS is an + elif isinstance(value_typ, types.npytypes.Array): + val_def = guard(get_definition, pass_states.func_ir, + value.name) + if (isinstance(val_def, ir.Expr) and + val_def.op == 'getitem' and + val_def.index.name == index.name): + new_instr = self._setitem_to_parfor(equiv_set, + loc, target, index, val_def.value) + self.rewritten.append( + dict(old=instr, new=new_instr, + reason='masked_assign_array'), + ) + instr = new_instr + else: + # Handle A[:] = x + shape = equiv_set.get_shape(instr) + if shape is not None: + new_instr = self._setitem_to_parfor(equiv_set, + loc, target, index, value, shape=shape) + self.rewritten.append( + dict(old=instr, new=new_instr, + reason='slice'), + ) + instr = new_instr + new_body.append(instr) + block.body = new_body + + def _setitem_to_parfor(self, equiv_set, loc, target, index, value, shape=None): + """generate parfor from setitem node with a boolean or slice array indices. + The value can be either a scalar or an array variable, and if a boolean index + is used for the latter case, the same index must be used for the value too. + """ + pass_states = self.pass_states + scope = target.scope + arr_typ = pass_states.typemap[target.name] + el_typ = arr_typ.dtype + index_typ = pass_states.typemap[index.name] + init_block = ir.Block(scope, loc) + + if shape: + # Slice index is being used on the target array, we'll have to create + # a sub-array so that the target dimension matches the given shape. + assert(isinstance(index_typ, types.BaseTuple) or + isinstance(index_typ, types.SliceType)) + # setitem has a custom target shape + size_vars = shape + # create a new target array via getitem + subarr_var = ir.Var(scope, mk_unique_var("$subarr"), loc) + getitem_call = ir.Expr.getitem(target, index, loc) + subarr_typ = typing.arraydecl.get_array_index_type( arr_typ, index_typ).result + pass_states.typemap[subarr_var.name] = subarr_typ + pass_states.calltypes[getitem_call] = self._type_getitem((arr_typ, index_typ)) + init_block.append(ir.Assign(getitem_call, subarr_var, loc)) + target = subarr_var + else: + # Otherwise it is a boolean array that is used as index. + assert(isinstance(index_typ, types.ArrayCompatible)) + size_vars = equiv_set.get_shape(target) + bool_typ = index_typ.dtype + + # generate loopnests and size variables from lhs correlations + loopnests = [] + index_vars = [] + for size_var in size_vars: + index_var = ir.Var(scope, mk_unique_var("parfor_index"), loc) + index_vars.append(index_var) + pass_states.typemap[index_var.name] = types.uintp + loopnests.append(LoopNest(index_var, 0, size_var, 1)) + + # generate body + body_label = next_label() + body_block = ir.Block(scope, loc) + index_var, index_var_typ = _make_index_var( + pass_states.typemap, scope, index_vars, body_block) + parfor = Parfor(loopnests, init_block, {}, loc, index_var, equiv_set, + ('setitem', ''), pass_states.flags) + if shape: + # slice subarray + parfor.loop_body = {body_label: body_block} + true_block = body_block + end_label = None + else: + # boolean mask + true_label = next_label() + true_block = ir.Block(scope, loc) + end_label = next_label() + end_block = ir.Block(scope, loc) + parfor.loop_body = {body_label: body_block, + true_label: true_block, + end_label: end_block, + } + mask_var = ir.Var(scope, mk_unique_var("$mask_var"), loc) + pass_states.typemap[mask_var.name] = bool_typ + mask_val = ir.Expr.getitem(index, index_var, loc) + body_block.body.extend([ + ir.Assign(mask_val, mask_var, loc), + ir.Branch(mask_var, true_label, end_label, loc) + ]) + + value_typ = pass_states.typemap[value.name] + if isinstance(value_typ, types.npytypes.Array): + value_var = ir.Var(scope, mk_unique_var("$value_var"), loc) + pass_states.typemap[value_var.name] = value_typ.dtype + getitem_call = ir.Expr.getitem(value, index_var, loc) + pass_states.calltypes[getitem_call] = signature( + value_typ.dtype, value_typ, index_var_typ) + true_block.body.append(ir.Assign(getitem_call, value_var, loc)) + else: + value_var = value + setitem_node = ir.SetItem(target, index_var, value_var, loc) + pass_states.calltypes[setitem_node] = signature( + types.none, pass_states.typemap[target.name], index_var_typ, el_typ) + true_block.body.append(setitem_node) + if end_label: + true_block.body.append(ir.Jump(end_label, loc)) + + if config.DEBUG_ARRAY_OPT >= 1: + print("parfor from setitem") + parfor.dump() + return parfor + + def _type_getitem(self, args): + fnty = operator.getitem + return self.pass_states.typingctx.resolve_function_type(fnty, tuple(args), {}) + + +def _make_index_var(typemap, scope, index_vars, body_block): + ndims = len(index_vars) + loc = body_block.loc + if ndims > 1: + tuple_var = ir.Var(scope, mk_unique_var( + "$parfor_index_tuple_var"), loc) + typemap[tuple_var.name] = types.containers.UniTuple( + types.uintp, ndims) + tuple_call = ir.Expr.build_tuple(list(index_vars), loc) + tuple_assign = ir.Assign(tuple_call, tuple_var, loc) + body_block.body.append(tuple_assign) + return tuple_var, types.containers.UniTuple(types.uintp, ndims) + elif ndims == 1: + return index_vars[0], types.uintp + else: + raise NotImplementedError( + "Parfor does not handle arrays of dimension 0") + +class ParforPass(ParforPassStates): + + """ParforPass class is responsible for converting Numpy + calls in Numba intermediate representation to Parfors, which + will lower into either sequential or parallel loops during lowering + stage. + """ + + def _pre_run(self): # run array analysis, a pre-requisite for parfor translation remove_dels(self.func_ir.blocks) self.array_analysis.run(self.func_ir.blocks) + + def run(self): + """run parfor conversion pass: replace Numpy calls + with Parfors when possible and optimize the IR.""" + self._pre_run() # run stencil translation to parfor if self.options.stencil: stencil_pass = StencilPass(self.func_ir, self.typemap, self.calltypes, self.array_analysis, self.typingctx, self.flags) stencil_pass.run() if self.options.setitem: - self._convert_setitem(self.func_ir.blocks) + ConvertSetItemPass(self).run(self.func_ir.blocks) if self.options.numpy: self._convert_numpy(self.func_ir.blocks) if self.options.reduction: @@ -1676,49 +1871,6 @@ def _convert_reduce(self, blocks): block.body = new_body return - def _convert_setitem(self, blocks): - # convert setitem expressions like A[C] = c or A[C] = B[C] to parfor, - # where C is a boolean array. - topo_order = find_topo_order(blocks) - # variables available in the program so far (used for finding map - # functions in array_expr lowering) - avail_vars = [] - for label in topo_order: - block = blocks[label] - new_body = [] - equiv_set = self.array_analysis.get_equiv_set(label) - for instr in block.body: - if isinstance(instr, ir.StaticSetItem) or isinstance(instr, ir.SetItem): - loc = instr.loc - target = instr.target - index = instr.index if isinstance(instr, ir.SetItem) else instr.index_var - value = instr.value - target_typ = self.typemap[target.name] - index_typ = self.typemap[index.name] - value_typ = self.typemap[value.name] - if isinstance(target_typ, types.npytypes.Array): - if (isinstance(index_typ, types.npytypes.Array) and - isinstance(index_typ.dtype, types.Boolean) and - target_typ.ndim == index_typ.ndim): - if isinstance(value_typ, types.Number): - instr = self._setitem_to_parfor(equiv_set, - loc, target, index, value) - elif isinstance(value_typ, types.npytypes.Array): - val_def = guard(get_definition, self.func_ir, - value.name) - if (isinstance(val_def, ir.Expr) and - val_def.op == 'getitem' and - val_def.index.name == index.name): - instr = self._setitem_to_parfor(equiv_set, - loc, target, index, val_def.value) - else: - shape = equiv_set.get_shape(instr) - if shape != None: - instr = self._setitem_to_parfor(equiv_set, - loc, target, index, value, shape=shape) - new_body.append(instr) - block.body = new_body - def _convert_loop(self, blocks): call_table, _ = get_call_table(blocks) cfg = compute_cfg_from_blocks(blocks) @@ -1883,8 +2035,9 @@ def find_mask_from_size(size_var): for x in mask_indices) first_body_block = loop_body[min(loop_body.keys())] body_block = ir.Block(scope, loc) - index_var, index_var_typ = self._make_index_var( - scope, index_vars, body_block) + index_var, index_var_typ = _make_index_var( + self.typemap, scope, index_vars, body_block, + ) body = body_block.body + first_body_block.body first_body_block.body = body if mask_indices: @@ -2168,24 +2321,6 @@ def _is_C_order(self, arr_name): typ = self.typemap[arr_name] return isinstance(typ, types.npytypes.Array) and typ.layout == 'C' and typ.ndim > 0 - def _make_index_var(self, scope, index_vars, body_block): - ndims = len(index_vars) - loc = body_block.loc - if ndims > 1: - tuple_var = ir.Var(scope, mk_unique_var( - "$parfor_index_tuple_var"), loc) - self.typemap[tuple_var.name] = types.containers.UniTuple( - types.uintp, ndims) - tuple_call = ir.Expr.build_tuple(list(index_vars), loc) - tuple_assign = ir.Assign(tuple_call, tuple_var, loc) - body_block.body.append(tuple_assign) - return tuple_var, types.containers.UniTuple(types.uintp, ndims) - elif ndims == 1: - return index_vars[0], types.uintp - else: - raise NotImplementedError( - "Parfor does not handle arrays of dimension 0") - def _mk_parfor_loops(self, size_vars, scope, loc): """ Create loop index variables and build LoopNest objects for a parfor. @@ -2222,8 +2357,8 @@ def _arrayexpr_to_parfor(self, equiv_set, lhs, arrayexpr, avail_vars): expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc) self.typemap[expr_out_var.name] = el_typ - index_var, index_var_typ = self._make_index_var( - scope, index_vars, body_block) + index_var, index_var_typ = _make_index_var( + self.typemap, scope, index_vars, body_block) body_block.body.extend( _arrayexpr_tree_to_ir( @@ -2253,104 +2388,6 @@ def _arrayexpr_to_parfor(self, equiv_set, lhs, arrayexpr, avail_vars): parfor.dump() return parfor - def _setitem_to_parfor(self, equiv_set, loc, target, index, value, shape=None): - """generate parfor from setitem node with a boolean or slice array indices. - The value can be either a scalar or an array variable, and if a boolean index - is used for the latter case, the same index must be used for the value too. - """ - scope = target.scope - arr_typ = self.typemap[target.name] - el_typ = arr_typ.dtype - index_typ = self.typemap[index.name] - init_block = ir.Block(scope, loc) - - if shape: - # Slice index is being used on the target array, we'll have to create - # a sub-array so that the target dimension matches the given shape. - assert(isinstance(index_typ, types.BaseTuple) or - isinstance(index_typ, types.SliceType)) - # setitem has a custom target shape - size_vars = shape - # create a new target array via getitem - subarr_var = ir.Var(scope, mk_unique_var("$subarr"), loc) - getitem_call = ir.Expr.getitem(target, index, loc) - subarr_typ = typing.arraydecl.get_array_index_type( arr_typ, index_typ).result - self.typemap[subarr_var.name] = subarr_typ - self.calltypes[getitem_call] = self._type_getitem((arr_typ, index_typ)) - init_block.append(ir.Assign(getitem_call, subarr_var, loc)) - target = subarr_var - else: - # Otherwise it is a boolean array that is used as index. - assert(isinstance(index_typ, types.ArrayCompatible)) - size_vars = equiv_set.get_shape(target) - bool_typ = index_typ.dtype - - - # generate loopnests and size variables from lhs correlations - loopnests = [] - index_vars = [] - for size_var in size_vars: - index_var = ir.Var(scope, mk_unique_var("parfor_index"), loc) - index_vars.append(index_var) - self.typemap[index_var.name] = types.uintp - loopnests.append(LoopNest(index_var, 0, size_var, 1)) - - # generate body - body_label = next_label() - body_block = ir.Block(scope, loc) - index_var, index_var_typ = self._make_index_var( - scope, index_vars, body_block) - parfor = Parfor(loopnests, init_block, {}, loc, index_var, equiv_set, - ('setitem', ''), self.flags) - if shape: - # slice subarray - parfor.loop_body = {body_label: body_block} - true_block = body_block - end_label = None - else: - # boolean mask - true_label = next_label() - true_block = ir.Block(scope, loc) - end_label = next_label() - end_block = ir.Block(scope, loc) - parfor.loop_body = {body_label: body_block, - true_label: true_block, - end_label: end_block, - } - mask_var = ir.Var(scope, mk_unique_var("$mask_var"), loc) - self.typemap[mask_var.name] = bool_typ - mask_val = ir.Expr.getitem(index, index_var, loc) - body_block.body.extend([ - ir.Assign(mask_val, mask_var, loc), - ir.Branch(mask_var, true_label, end_label, loc) - ]) - - value_typ = self.typemap[value.name] - if isinstance(value_typ, types.npytypes.Array): - value_var = ir.Var(scope, mk_unique_var("$value_var"), loc) - self.typemap[value_var.name] = value_typ.dtype - getitem_call = ir.Expr.getitem(value, index_var, loc) - self.calltypes[getitem_call] = signature( - value_typ.dtype, value_typ, index_var_typ) - true_block.body.append(ir.Assign(getitem_call, value_var, loc)) - else: - value_var = value - setitem_node = ir.SetItem(target, index_var, value_var, loc) - self.calltypes[setitem_node] = signature( - types.none, self.typemap[target.name], index_var_typ, el_typ) - true_block.body.append(setitem_node) - if end_label: - true_block.body.append(ir.Jump(end_label, loc)) - - if config.DEBUG_ARRAY_OPT >= 1: - print("parfor from setitem") - parfor.dump() - return parfor - - def _type_getitem(self, args): - fnty = operator.getitem - return self.typingctx.resolve_function_type(fnty, tuple(args), {}) - def _is_supported_npycall(self, expr): """check if we support parfor translation for this Numpy call. @@ -2401,8 +2438,8 @@ def _numpy_map_to_parfor(self, equiv_set, call_name, lhs, args, kws, expr): expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc) self.typemap[expr_out_var.name] = el_typ - index_var, index_var_typ = self._make_index_var( - scope, index_vars, body_block) + index_var, index_var_typ = _make_index_var( + self.typemap, scope, index_vars, body_block) if call_name == 'zeros': value = ir.Const(el_typ(0), loc) @@ -2451,8 +2488,8 @@ def _mk_reduction_body(self, call_name, scope, loc, arr_typ = self.typemap[in_arr.name] in_typ = arr_typ.dtype body_block = ir.Block(scope, loc) - index_var, index_var_type = self._make_index_var( - scope, index_vars, body_block) + index_var, index_var_type = _make_index_var( + self.typemap, scope, index_vars, body_block) tmp_var = ir.Var(scope, mk_unique_var("$val"), loc) self.typemap[tmp_var.name] = in_typ @@ -3696,7 +3733,7 @@ def remove_dead_parfor(parfor, lives, lives_n_aliases, arg_aliases, alias_map, f argument lives instead of lives_n_aliases. The former does not include the aliases of live variables but only the live variable names themselves. See a comment in this function for how that - is used. + is used. """ remove_dead_parfor_recursive( parfor, lives, arg_aliases, alias_map, func_ir, typemap) diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py new file mode 100644 index 00000000000..0b427623fdb --- /dev/null +++ b/numba/tests/test_parfors_components.py @@ -0,0 +1,164 @@ +""" +Tests for sub-components of parfors. +""" +import unittest + +import numpy as np + +import numba.parfors.parfor +from numba.core import ( + typing, + rewrites, + typed_passes, + inline_closurecall, + compiler, + cpu, +) +from numba.core.registry import cpu_target +from numba.tests.support import TestCase + + +class TestPipeline(object): + def __init__(self, typingctx, targetctx, args, test_ir): + self.state = compiler.StateDict() + self.state.typingctx = typingctx + self.state.targetctx = targetctx + self.state.args = args + self.state.func_ir = test_ir + self.state.typemap = None + self.state.return_type = None + self.state.calltypes = None + + +def run_parfor_sub_pass(test_func, args, **kws): + # TODO: refactor this with get_optimized_numba_ir() where this is + # copied from + typingctx = typing.Context() + targetctx = cpu.CPUContext(typingctx) + test_ir = compiler.run_frontend(test_func) + if kws: + options = cpu.ParallelOptions(kws) + else: + options = cpu.ParallelOptions(True) + + tp = TestPipeline(typingctx, targetctx, args, test_ir) + + with cpu_target.nested_context(typingctx, targetctx): + typingctx.refresh() + targetctx.refresh() + + inline_pass = inline_closurecall.InlineClosureCallPass( + tp.state.func_ir, options, typed=True + ) + inline_pass.run() + + rewrites.rewrite_registry.apply("before-inference", tp.state) + + ( + tp.state.typemap, + tp.state.return_type, + tp.state.calltypes, + ) = typed_passes.type_inference_stage( + tp.state.typingctx, tp.state.func_ir, tp.state.args, None + ) + + diagnostics = numba.parfors.parfor.ParforDiagnostics() + + preparfor_pass = numba.parfors.parfor.PreParforPass( + tp.state.func_ir, + tp.state.typemap, + tp.state.calltypes, + tp.state.typingctx, + options, + swapped=diagnostics.replaced_fns, + ) + preparfor_pass.run() + + rewrites.rewrite_registry.apply("after-inference", tp.state) + + flags = compiler.Flags() + parfor_pass = numba.parfors.parfor.ParforPass( + tp.state.func_ir, + tp.state.typemap, + tp.state.calltypes, + tp.state.return_type, + tp.state.typingctx, + options, + flags, + diagnostics=diagnostics, + ) + parfor_pass._pre_run() + # Run subpass + sub_pass = numba.parfors.parfor.ConvertSetItemPass(parfor_pass) + sub_pass.run(parfor_pass.func_ir.blocks) + + return sub_pass + + +class TestConvertSetItemPass(TestCase): + def test_setitem_full_slice(self): + def test_impl(): + n = 10 + a = np.ones(n) + a[:] = 7 + return a + + sub_pass = run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "slice") + + def test_setitem_slice_stop_bound(self): + def test_impl(): + n = 10 + a = np.ones(n) + a[:5] = 7 + return a + + sub_pass = run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "slice") + + def test_setitem_slice_start_bound(self): + def test_impl(): + n = 10 + a = np.ones(n) + a[4:] = 7 + return a + + sub_pass = run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "slice") + + def test_setitem_gather_if_scalar(self): + def test_impl(): + n = 10 + a = np.ones(n) + b = np.ones_like(a, dtype=np.bool_) + a[b] = 7 + return a + + sub_pass = run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "masked_assign_boardcast_scalar") + + def test_setitem_gather_if_array(self): + def test_impl(): + n = 10 + a = np.ones(n) + b = np.ones_like(a, dtype=np.bool_) + c = np.ones_like(a) + a[b] = c[b] + return a + + sub_pass = run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "masked_assign_array") + + +if __name__ == "__main__": + unittest.main() From eab6d47d001ef93dded674e224e647497e3faa01 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Tue, 18 Feb 2020 11:21:48 -0800 Subject: [PATCH 545/595] Add prange variant to has_no_side_effect. --- numba/core/ir_utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index 31b3de51d9b..1687b744bc4 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -593,6 +593,8 @@ def remove_dead_block(block, lives, call_table, arg_aliases, alias_map, stmt = f(stmt, lives, lives_n_aliases, arg_aliases, alias_map, func_ir, typemap) if stmt is None: + if config.DEBUG_ARRAY_OPT >= 2: + print("Statement was removed.") removed = True continue @@ -602,21 +604,29 @@ def remove_dead_block(block, lives, call_table, arg_aliases, alias_map, rhs = stmt.value if lhs.name not in lives and has_no_side_effect( rhs, lives_n_aliases, call_table): + if config.DEBUG_ARRAY_OPT >= 2: + print("Statement was removed.") removed = True continue if isinstance(rhs, ir.Var) and lhs.name == rhs.name: + if config.DEBUG_ARRAY_OPT >= 2: + print("Statement was removed.") removed = True continue # TODO: remove other nodes like SetItem etc. if isinstance(stmt, ir.Del): if stmt.value not in lives: + if config.DEBUG_ARRAY_OPT >= 2: + print("Statement was removed.") removed = True continue if isinstance(stmt, ir.SetItem): name = stmt.target.name if name not in lives_n_aliases: + if config.DEBUG_ARRAY_OPT >= 2: + print("Statement was removed.") continue if type(stmt) in analysis.ir_extension_usedefs: @@ -662,6 +672,7 @@ def has_no_side_effect(rhs, lives, call_table): call_list == ['dtype', numpy] or call_list == [array_analysis.wrap_index] or call_list == [prange] or + call_list == ['prange', numba] or call_list == [parfor.internal_prange]): return True elif (isinstance(call_list[0], _Intrinsic) and From d3289951ab7d9f6fe42979a4bb46aafd4594a2fc Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 18 Feb 2020 13:35:36 -0600 Subject: [PATCH 546/595] Split out ConvertNumpyPass --- numba/parfors/parfor.py | 390 +++++++++++++------------ numba/tests/test_parfors_components.py | 249 +++++++++++----- 2 files changed, 381 insertions(+), 258 deletions(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 2a88bad12c9..0ece0293ba7 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -1680,6 +1680,208 @@ def _make_index_var(typemap, scope, index_vars, body_block): raise NotImplementedError( "Parfor does not handle arrays of dimension 0") + +def _mk_parfor_loops(typemap, size_vars, scope, loc): + """ + Create loop index variables and build LoopNest objects for a parfor. + """ + loopnests = [] + index_vars = [] + for size_var in size_vars: + index_var = ir.Var(scope, mk_unique_var("parfor_index"), loc) + index_vars.append(index_var) + typemap[index_var.name] = types.uintp + loopnests.append(LoopNest(index_var, 0, size_var, 1)) + return index_vars, loopnests + +class ConvertNumpyPass: + """ + Convert supported Numpy functions, as well as arrayexpr nodes, to + parfor nodes. + """ + def __init__(self, pass_states): + self.pass_states = pass_states + self.rewritten = [] + + def run(self, blocks): + pass_states = self.pass_states + topo_order = find_topo_order(blocks) + # variables available in the program so far (used for finding map + # functions in array_expr lowering) + avail_vars = [] + for label in topo_order: + block = blocks[label] + new_body = [] + equiv_set = pass_states.array_analysis.get_equiv_set(label) + for instr in block.body: + if isinstance(instr, ir.Assign): + expr = instr.value + lhs = instr.target + if self._is_C_order(lhs.name): + # only translate C order since we can't allocate F + if guard(self._is_supported_npycall, expr): + new_instr = self._numpy_to_parfor(equiv_set, lhs, expr) + self.rewritten.append(dict( + old=instr, + new=new_instr, + reason='numpy_allocator', + )) + instr = new_instr + elif isinstance(expr, ir.Expr) and expr.op == 'arrayexpr': + new_instr = self._arrayexpr_to_parfor( + equiv_set, lhs, expr, avail_vars) + self.rewritten.append(dict( + old=instr, + new=new_instr, + reason='arrayexpr', + )) + instr = new_instr + avail_vars.append(lhs.name) + new_body.append(instr) + block.body = new_body + + def _is_C_order(self, arr_name): + typ = self.pass_states.typemap[arr_name] + return isinstance(typ, types.npytypes.Array) and typ.layout == 'C' and typ.ndim > 0 + + def _arrayexpr_to_parfor(self, equiv_set, lhs, arrayexpr, avail_vars): + """generate parfor from arrayexpr node, which is essentially a + map with recursive tree. + """ + pass_states = self.pass_states + scope = lhs.scope + loc = lhs.loc + expr = arrayexpr.expr + arr_typ = pass_states.typemap[lhs.name] + el_typ = arr_typ.dtype + + # generate loopnests and size variables from lhs correlations + size_vars = equiv_set.get_shape(lhs) + index_vars, loopnests = _mk_parfor_loops(pass_states.typemap, size_vars, scope, loc) + + # generate init block and body + init_block = ir.Block(scope, loc) + init_block.body = mk_alloc(pass_states.typemap, pass_states.calltypes, lhs, + tuple(size_vars), el_typ, scope, loc) + body_label = next_label() + body_block = ir.Block(scope, loc) + expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc) + pass_states.typemap[expr_out_var.name] = el_typ + + index_var, index_var_typ = _make_index_var( + pass_states.typemap, scope, index_vars, body_block) + + body_block.body.extend( + _arrayexpr_tree_to_ir( + pass_states.func_ir, + pass_states.typingctx, + pass_states.typemap, + pass_states.calltypes, + equiv_set, + init_block, + expr_out_var, + expr, + index_var, + index_vars, + avail_vars)) + + pat = ('array expression {}'.format(repr_arrayexpr(arrayexpr.expr)),) + + parfor = Parfor(loopnests, init_block, {}, loc, index_var, equiv_set, pat[0], pass_states.flags) + + setitem_node = ir.SetItem(lhs, index_var, expr_out_var, loc) + pass_states.calltypes[setitem_node] = signature( + types.none, pass_states.typemap[lhs.name], index_var_typ, el_typ) + body_block.body.append(setitem_node) + parfor.loop_body = {body_label: body_block} + if config.DEBUG_ARRAY_OPT >= 1: + print("parfor from arrayexpr") + parfor.dump() + return parfor + + def _is_supported_npycall(self, expr): + """check if we support parfor translation for + this Numpy call. + """ + call_name, mod_name = find_callname(self.pass_states.func_ir, expr) + if not (isinstance(mod_name, str) and mod_name.startswith('numpy')): + return False + if call_name in ['zeros', 'ones']: + return True + if mod_name == 'numpy.random' and call_name in random_calls: + return True + # TODO: add more calls + return False + + def _numpy_to_parfor(self, equiv_set, lhs, expr): + call_name, mod_name = find_callname(self.pass_states.func_ir, expr) + args = expr.args + kws = dict(expr.kws) + if call_name in ['zeros', 'ones'] or mod_name == 'numpy.random': + return self._numpy_map_to_parfor(equiv_set, call_name, lhs, args, kws, expr) + # return error if we couldn't handle it (avoid rewrite infinite loop) + raise NotImplementedError("parfor translation failed for ", expr) + + def _numpy_map_to_parfor(self, equiv_set, call_name, lhs, args, kws, expr): + """generate parfor from Numpy calls that are maps. + """ + pass_states = self.pass_states + scope = lhs.scope + loc = lhs.loc + arr_typ = pass_states.typemap[lhs.name] + el_typ = arr_typ.dtype + + # generate loopnests and size variables from lhs correlations + size_vars = equiv_set.get_shape(lhs) + index_vars, loopnests = _mk_parfor_loops(pass_states.typemap, size_vars, scope, loc) + + # generate init block and body + init_block = ir.Block(scope, loc) + init_block.body = mk_alloc(pass_states.typemap, pass_states.calltypes, lhs, + tuple(size_vars), el_typ, scope, loc) + body_label = next_label() + body_block = ir.Block(scope, loc) + expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc) + pass_states.typemap[expr_out_var.name] = el_typ + + index_var, index_var_typ = _make_index_var( + pass_states.typemap, scope, index_vars, body_block) + + if call_name == 'zeros': + value = ir.Const(el_typ(0), loc) + elif call_name == 'ones': + value = ir.Const(el_typ(1), loc) + elif call_name in random_calls: + # remove size arg to reuse the call expr for single value + _remove_size_arg(call_name, expr) + # update expr type + new_arg_typs, new_kw_types = _get_call_arg_types( + expr, pass_states.typemap) + pass_states.calltypes.pop(expr) + pass_states.calltypes[expr] = pass_states.typemap[expr.func.name].get_call_type( + typing.Context(), new_arg_typs, new_kw_types) + value = expr + else: + NotImplementedError( + "Map of numpy.{} to parfor is not implemented".format(call_name)) + + value_assign = ir.Assign(value, expr_out_var, loc) + body_block.body.append(value_assign) + + parfor = Parfor(loopnests, init_block, {}, loc, index_var, equiv_set, + ('{} function'.format(call_name,), 'NumPy mapping'), + pass_states.flags) + + setitem_node = ir.SetItem(lhs, index_var, expr_out_var, loc) + pass_states.calltypes[setitem_node] = signature( + types.none, pass_states.typemap[lhs.name], index_var_typ, el_typ) + body_block.body.append(setitem_node) + parfor.loop_body = {body_label: body_block} + if config.DEBUG_ARRAY_OPT >= 1: + print("generated parfor for numpy map:") + parfor.dump() + return parfor + class ParforPass(ParforPassStates): """ParforPass class is responsible for converting Numpy @@ -1705,7 +1907,7 @@ def run(self): if self.options.setitem: ConvertSetItemPass(self).run(self.func_ir.blocks) if self.options.numpy: - self._convert_numpy(self.func_ir.blocks) + ConvertNumpyPass(self).run(self.func_ir.blocks) if self.options.reduction: self._convert_reduce(self.func_ir.blocks) if self.options.prange: @@ -1813,37 +2015,6 @@ def run(self): return - def _convert_numpy(self, blocks): - """ - Convert supported Numpy functions, as well as arrayexpr nodes, to - parfor nodes. - """ - topo_order = find_topo_order(blocks) - # variables available in the program so far (used for finding map - # functions in array_expr lowering) - avail_vars = [] - for label in topo_order: - block = blocks[label] - new_body = [] - equiv_set = self.array_analysis.get_equiv_set(label) - for instr in block.body: - if isinstance(instr, ir.Assign): - expr = instr.value - lhs = instr.target - if self._is_C_order(lhs.name): - # only translate C order since we can't allocate F - if guard(self._is_supported_npycall, expr): - instr = self._numpy_to_parfor(equiv_set, lhs, expr) - if isinstance(instr, tuple): - pre_stmts, instr = instr - new_body.extend(pre_stmts) - elif isinstance(expr, ir.Expr) and expr.op == 'arrayexpr': - instr = self._arrayexpr_to_parfor( - equiv_set, lhs, expr, avail_vars) - avail_vars.append(lhs.name) - new_body.append(instr) - block.body = new_body - def _convert_reduce(self, blocks): """ Find reduce() calls and convert them to parfors. @@ -2317,164 +2488,11 @@ def _get_loop_kind(self, func_var, call_table): kind = 'pndindex', '' return kind - def _is_C_order(self, arr_name): - typ = self.typemap[arr_name] - return isinstance(typ, types.npytypes.Array) and typ.layout == 'C' and typ.ndim > 0 - def _mk_parfor_loops(self, size_vars, scope, loc): """ Create loop index variables and build LoopNest objects for a parfor. """ - loopnests = [] - index_vars = [] - for size_var in size_vars: - index_var = ir.Var(scope, mk_unique_var("parfor_index"), loc) - index_vars.append(index_var) - self.typemap[index_var.name] = types.uintp - loopnests.append(LoopNest(index_var, 0, size_var, 1)) - return index_vars, loopnests - - def _arrayexpr_to_parfor(self, equiv_set, lhs, arrayexpr, avail_vars): - """generate parfor from arrayexpr node, which is essentially a - map with recursive tree. - """ - scope = lhs.scope - loc = lhs.loc - expr = arrayexpr.expr - arr_typ = self.typemap[lhs.name] - el_typ = arr_typ.dtype - - # generate loopnests and size variables from lhs correlations - size_vars = equiv_set.get_shape(lhs) - index_vars, loopnests = self._mk_parfor_loops(size_vars, scope, loc) - - # generate init block and body - init_block = ir.Block(scope, loc) - init_block.body = mk_alloc(self.typemap, self.calltypes, lhs, - tuple(size_vars), el_typ, scope, loc) - body_label = next_label() - body_block = ir.Block(scope, loc) - expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc) - self.typemap[expr_out_var.name] = el_typ - - index_var, index_var_typ = _make_index_var( - self.typemap, scope, index_vars, body_block) - - body_block.body.extend( - _arrayexpr_tree_to_ir( - self.func_ir, - self.typingctx, - self.typemap, - self.calltypes, - equiv_set, - init_block, - expr_out_var, - expr, - index_var, - index_vars, - avail_vars)) - - pat = ('array expression {}'.format(repr_arrayexpr(arrayexpr.expr)),) - - parfor = Parfor(loopnests, init_block, {}, loc, index_var, equiv_set, pat[0], self.flags) - - setitem_node = ir.SetItem(lhs, index_var, expr_out_var, loc) - self.calltypes[setitem_node] = signature( - types.none, self.typemap[lhs.name], index_var_typ, el_typ) - body_block.body.append(setitem_node) - parfor.loop_body = {body_label: body_block} - if config.DEBUG_ARRAY_OPT >= 1: - print("parfor from arrayexpr") - parfor.dump() - return parfor - - def _is_supported_npycall(self, expr): - """check if we support parfor translation for - this Numpy call. - """ - call_name, mod_name = find_callname(self.func_ir, expr) - if not (isinstance(mod_name, str) and mod_name.startswith('numpy')): - return False - if call_name in ['zeros', 'ones']: - return True - if call_name in ['arange', 'linspace']: - return True - if mod_name == 'numpy.random' and call_name in random_calls: - return True - # TODO: add more calls - return False - - def _get_ndims(self, arr): - # return len(self.array_analysis.array_shape_classes[arr]) - return self.typemap[arr].ndim - - def _numpy_to_parfor(self, equiv_set, lhs, expr): - call_name, mod_name = find_callname(self.func_ir, expr) - args = expr.args - kws = dict(expr.kws) - if call_name in ['zeros', 'ones'] or mod_name == 'numpy.random': - return self._numpy_map_to_parfor(equiv_set, call_name, lhs, args, kws, expr) - # return error if we couldn't handle it (avoid rewrite infinite loop) - raise NotImplementedError("parfor translation failed for ", expr) - - def _numpy_map_to_parfor(self, equiv_set, call_name, lhs, args, kws, expr): - """generate parfor from Numpy calls that are maps. - """ - scope = lhs.scope - loc = lhs.loc - arr_typ = self.typemap[lhs.name] - el_typ = arr_typ.dtype - - # generate loopnests and size variables from lhs correlations - size_vars = equiv_set.get_shape(lhs) - index_vars, loopnests = self._mk_parfor_loops(size_vars, scope, loc) - - # generate init block and body - init_block = ir.Block(scope, loc) - init_block.body = mk_alloc(self.typemap, self.calltypes, lhs, - tuple(size_vars), el_typ, scope, loc) - body_label = next_label() - body_block = ir.Block(scope, loc) - expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc) - self.typemap[expr_out_var.name] = el_typ - - index_var, index_var_typ = _make_index_var( - self.typemap, scope, index_vars, body_block) - - if call_name == 'zeros': - value = ir.Const(el_typ(0), loc) - elif call_name == 'ones': - value = ir.Const(el_typ(1), loc) - elif call_name in random_calls: - # remove size arg to reuse the call expr for single value - _remove_size_arg(call_name, expr) - # update expr type - new_arg_typs, new_kw_types = _get_call_arg_types( - expr, self.typemap) - self.calltypes.pop(expr) - self.calltypes[expr] = self.typemap[expr.func.name].get_call_type( - typing.Context(), new_arg_typs, new_kw_types) - value = expr - else: - NotImplementedError( - "Map of numpy.{} to parfor is not implemented".format(call_name)) - - value_assign = ir.Assign(value, expr_out_var, loc) - body_block.body.append(value_assign) - - parfor = Parfor(loopnests, init_block, {}, loc, index_var, equiv_set, - ('{} function'.format(call_name,), 'NumPy mapping'), - self.flags) - - setitem_node = ir.SetItem(lhs, index_var, expr_out_var, loc) - self.calltypes[setitem_node] = signature( - types.none, self.typemap[lhs.name], index_var_typ, el_typ) - body_block.body.append(setitem_node) - parfor.loop_body = {body_label: body_block} - if config.DEBUG_ARRAY_OPT >= 1: - print("generated parfor for numpy map:") - parfor.dump() - return parfor + return _mk_parfor_loops(self.typemap, size_vars, scope, loc) def _mk_reduction_body(self, call_name, scope, loc, index_vars, in_arr, acc_var): diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py index 0b427623fdb..a04050543cd 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_components.py @@ -5,6 +5,7 @@ import numpy as np +from numba import njit, typeof import numba.parfors.parfor from numba.core import ( typing, @@ -18,7 +19,7 @@ from numba.tests.support import TestCase -class TestPipeline(object): +class MyPipeline(object): def __init__(self, typingctx, targetctx, args, test_ir): self.state = compiler.StateDict() self.state.typingctx = typingctx @@ -30,72 +31,95 @@ def __init__(self, typingctx, targetctx, args, test_ir): self.state.calltypes = None -def run_parfor_sub_pass(test_func, args, **kws): - # TODO: refactor this with get_optimized_numba_ir() where this is - # copied from - typingctx = typing.Context() - targetctx = cpu.CPUContext(typingctx) - test_ir = compiler.run_frontend(test_func) - if kws: - options = cpu.ParallelOptions(kws) - else: - options = cpu.ParallelOptions(True) - - tp = TestPipeline(typingctx, targetctx, args, test_ir) - - with cpu_target.nested_context(typingctx, targetctx): - typingctx.refresh() - targetctx.refresh() - - inline_pass = inline_closurecall.InlineClosureCallPass( - tp.state.func_ir, options, typed=True - ) - inline_pass.run() - - rewrites.rewrite_registry.apply("before-inference", tp.state) - - ( - tp.state.typemap, - tp.state.return_type, - tp.state.calltypes, - ) = typed_passes.type_inference_stage( - tp.state.typingctx, tp.state.func_ir, tp.state.args, None - ) - - diagnostics = numba.parfors.parfor.ParforDiagnostics() - - preparfor_pass = numba.parfors.parfor.PreParforPass( - tp.state.func_ir, - tp.state.typemap, - tp.state.calltypes, - tp.state.typingctx, - options, - swapped=diagnostics.replaced_fns, - ) - preparfor_pass.run() - - rewrites.rewrite_registry.apply("after-inference", tp.state) - - flags = compiler.Flags() - parfor_pass = numba.parfors.parfor.ParforPass( - tp.state.func_ir, - tp.state.typemap, - tp.state.calltypes, - tp.state.return_type, - tp.state.typingctx, - options, - flags, - diagnostics=diagnostics, - ) - parfor_pass._pre_run() - # Run subpass - sub_pass = numba.parfors.parfor.ConvertSetItemPass(parfor_pass) - sub_pass.run(parfor_pass.func_ir.blocks) - - return sub_pass - - -class TestConvertSetItemPass(TestCase): +class BaseTest(TestCase): + @classmethod + def run_parfor_sub_pass(cls, test_func, args, **kws): + # TODO: refactor this with get_optimized_numba_ir() where this is + # copied from + typingctx = typing.Context() + targetctx = cpu.CPUContext(typingctx) + test_ir = compiler.run_frontend(test_func) + if kws: + options = cpu.ParallelOptions(kws) + else: + options = cpu.ParallelOptions(True) + + tp = MyPipeline(typingctx, targetctx, args, test_ir) + + with cpu_target.nested_context(typingctx, targetctx): + typingctx.refresh() + targetctx.refresh() + + inline_pass = inline_closurecall.InlineClosureCallPass( + tp.state.func_ir, options, typed=True + ) + inline_pass.run() + + rewrites.rewrite_registry.apply("before-inference", tp.state) + + ( + tp.state.typemap, + tp.state.return_type, + tp.state.calltypes, + ) = typed_passes.type_inference_stage( + tp.state.typingctx, tp.state.func_ir, tp.state.args, None + ) + + diagnostics = numba.parfors.parfor.ParforDiagnostics() + + preparfor_pass = numba.parfors.parfor.PreParforPass( + tp.state.func_ir, + tp.state.typemap, + tp.state.calltypes, + tp.state.typingctx, + options, + swapped=diagnostics.replaced_fns, + ) + preparfor_pass.run() + + rewrites.rewrite_registry.apply("after-inference", tp.state) + + flags = compiler.Flags() + parfor_pass = numba.parfors.parfor.ParforPass( + tp.state.func_ir, + tp.state.typemap, + tp.state.calltypes, + tp.state.return_type, + tp.state.typingctx, + options, + flags, + diagnostics=diagnostics, + ) + parfor_pass._pre_run() + # Run subpass + sub_pass = cls.sub_pass_class(parfor_pass) + sub_pass.run(parfor_pass.func_ir.blocks) + + return sub_pass + + def run_parallel(self, func, *args, **kwargs): + cfunc = njit(parallel=True)(func) + expect = func(*args, **kwargs) + got = cfunc(*args, **kwargs) + self.assertPreciseEqual(expect, got) + + def run_parallel_check_output_array(self, func, *args, **kwargs): + # Don't match the value, just the return type. must return array + cfunc = njit(parallel=True)(func) + expect = func(*args, **kwargs) + got = cfunc(*args, **kwargs) + self.assertIsInstance(expect, np.ndarray) + self.assertIsInstance(got, np.ndarray) + self.assertEqual(expect.shape, got.shape) + + def check_records(self, records): + for rec in records: + self.assertIsInstance(rec['new'], numba.parfors.parfor.Parfor) + + +class TestConvertSetItemPass(BaseTest): + sub_pass_class = numba.parfors.parfor.ConvertSetItemPass + def test_setitem_full_slice(self): def test_impl(): n = 10 @@ -103,10 +127,13 @@ def test_impl(): a[:] = 7 return a - sub_pass = run_parfor_sub_pass(test_impl, ()) + sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten self.assertEqual(record["reason"], "slice") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) def test_setitem_slice_stop_bound(self): def test_impl(): @@ -115,10 +142,13 @@ def test_impl(): a[:5] = 7 return a - sub_pass = run_parfor_sub_pass(test_impl, ()) + sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten self.assertEqual(record["reason"], "slice") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) def test_setitem_slice_start_bound(self): def test_impl(): @@ -127,10 +157,13 @@ def test_impl(): a[4:] = 7 return a - sub_pass = run_parfor_sub_pass(test_impl, ()) + sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten self.assertEqual(record["reason"], "slice") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) def test_setitem_gather_if_scalar(self): def test_impl(): @@ -140,10 +173,13 @@ def test_impl(): a[b] = 7 return a - sub_pass = run_parfor_sub_pass(test_impl, ()) + sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten self.assertEqual(record["reason"], "masked_assign_boardcast_scalar") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) def test_setitem_gather_if_array(self): def test_impl(): @@ -154,10 +190,79 @@ def test_impl(): a[b] = c[b] return a - sub_pass = run_parfor_sub_pass(test_impl, ()) + sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten self.assertEqual(record["reason"], "masked_assign_array") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) + + +class TestConvertNumpyPass(BaseTest): + sub_pass_class = numba.parfors.parfor.ConvertNumpyPass + + def check_numpy_allocators(self, fn): + def test_impl(): + n = 10 + a = fn(n) + return a + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "numpy_allocator") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) + + def check_numpy_random(self, fn): + def test_impl(): + n = 10 + a = fn(n) + return a + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "numpy_allocator") + self.check_records(sub_pass.rewritten) + + self.run_parallel_check_output_array(test_impl) + + def test_numpy_allocators(self): + fns = [ + np.ones, + np.zeros, + ] + for fn in fns: + with self.subTest(fn.__name__): + self.check_numpy_allocators(fn) + + def test_numpy_random(self): + fns = [ + np.random.random, + ] + for fn in fns: + with self.subTest(fn.__name__): + self.check_numpy_random(fn) + + def test_numpy_arrayexpr(self): + def test_impl(a, b): + return a + b + + a = b = np.ones(10) + + args = (a, b) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "arrayexpr") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl, *args) if __name__ == "__main__": From 7ea3fa708ef58f3c3cffa0522e34665af0a266c4 Mon Sep 17 00:00:00 2001 From: ARF1 <5834577+ARF1@users.noreply.github.com> Date: Wed, 19 Feb 2020 10:23:07 +0100 Subject: [PATCH 547/595] fix error messages in test_array_reductions --- numba/tests/test_array_reductions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_array_reductions.py b/numba/tests/test_array_reductions.py index 6e655abc26d..4c648a6d9e4 100644 --- a/numba/tests/test_array_reductions.py +++ b/numba/tests/test_array_reductions.py @@ -962,7 +962,7 @@ def new_test_function(self, redFunc=red_func, # some architectures (power, 32bit) for complex input ulps = 3 npr, nbr = run_comparative(redFunc, testArray) - self.assertPreciseEqual(npr, nbr, msg=test_name, + self.assertPreciseEqual(npr, nbr, msg=testName, prec="single", ulps=ulps) # Install it into the class From ed1b0ca16cbdd16d1aa81b4d04a4eaa276ac921a Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Wed, 19 Feb 2020 08:13:56 -0600 Subject: [PATCH 548/595] Added some hints for debugging entry points. This is a follow-up of a conversation on the [numba/numba Gitter](https://gitter.im/numba/numba) on Feb 19, 2020. --- docs/source/extending/entrypoints.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/source/extending/entrypoints.rst b/docs/source/extending/entrypoints.rst index 0c2e72e80d7..200a8e6db44 100644 --- a/docs/source/extending/entrypoints.rst +++ b/docs/source/extending/entrypoints.rst @@ -44,3 +44,16 @@ as long as it matches what is listed in ``setup.py``) that takes no arguments, and the return value is ignored. This function should register types, overloads, or call other Numba extension APIs. The order of initialization of extensions is undefined. + +Testing your Entry Point +------------------------ + +Numba loads all entry points when the first function is compiled. To test your entry point, it is not sufficient to just ``import numba``; you have to define and run a small function, like this: + +.. code-block:: python + + import numba; numba.njit(lambda x: x + 1)(123) + +It is not necessary to import your module: entry points are identified by the ``entry_points.txt`` file in your library's ``*.egg-info`` directory. + +The ``setup.py build`` command does not create eggs, but ``setup.py sdist`` (for testing in a local directory) and ``setup.py install`` do. All entry points registered in eggs that are on the Python path are loaded. Be sure to check for stale ``entry_points.txt`` when debugging. From 277ab72b059d31d69e4217a78980eefed3d80b05 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 17 Feb 2020 17:51:17 +0000 Subject: [PATCH 549/595] Make IR ir.Del free until legalized. As title. --- numba/core/compiler.py | 5 ++-- numba/core/compiler_machinery.py | 6 ++++ numba/core/inline_closurecall.py | 10 +++++-- numba/core/ir_utils.py | 37 +++++++++++++++--------- numba/core/postproc.py | 27 +++++++++++++---- numba/core/typed_passes.py | 28 +++++++++++++----- numba/core/untyped_passes.py | 7 +++-- numba/parfors/parfor.py | 6 ++-- numba/tests/test_inlining.py | 8 ++--- numba/tests/test_ir.py | 18 ++++++++---- numba/tests/test_mixed_tuple_unroller.py | 28 +++++------------- numba/tests/test_parfors.py | 6 ++-- 12 files changed, 115 insertions(+), 71 deletions(-) diff --git a/numba/core/compiler.py b/numba/core/compiler.py index f7f5d63b33b..217df10fab5 100644 --- a/numba/core/compiler.py +++ b/numba/core/compiler.py @@ -180,12 +180,13 @@ def compile_isolated(func, args, return_type=None, flags=DEFAULT_FLAGS, flags, locals) -def run_frontend(func, inline_closures=False): +def run_frontend(func, inline_closures=False, emit_dels=False): """ Run the compiler frontend over the given Python function, and return the function's canonical Numba IR. If inline_closures is Truthy then closure inlining will be run + If emit_dels is Truthy the ir.Del nodes will be emitted appropriately """ # XXX make this a dedicated Pipeline? func_id = bytecode.FunctionIdentity.from_function(func) @@ -197,7 +198,7 @@ def run_frontend(func, inline_closures=False): {}, False) inline_pass.run() post_proc = postproc.PostProcessor(func_ir) - post_proc.run() + post_proc.run(emit_dels) return func_ir diff --git a/numba/core/compiler_machinery.py b/numba/core/compiler_machinery.py index 83956cc2b9b..069f0ed919b 100644 --- a/numba/core/compiler_machinery.py +++ b/numba/core/compiler_machinery.py @@ -7,6 +7,7 @@ from numba.core.utils import add_metaclass from numba.core.tracing import event from numba.core.postproc import PostProcessor +from numba.core.ir_utils import enforce_no_dels # terminal color markup _termcolor = errors.termcolor() @@ -291,6 +292,11 @@ def debug_print(pass_name, print_condition, printable_condition): with SimpleTimer() as finalize_time: mutated |= check(pss.run_finalizer, internal_state) + # Check that if the pass is an instance of a FunctionPass that it hasn't + # emitted ir.Dels. + if isinstance(pss, FunctionPass): + enforce_no_dels(internal_state.func_ir) + if self._ENFORCING: # TODO: Add in self consistency enforcement for # `func_ir._definitions` etc diff --git a/numba/core/inline_closurecall.py b/numba/core/inline_closurecall.py index 8314ffd046d..374883db07a 100644 --- a/numba/core/inline_closurecall.py +++ b/numba/core/inline_closurecall.py @@ -30,7 +30,7 @@ compute_cfg_from_blocks, compute_use_defs, compute_live_variables) - +from numba.core import postproc from numba.cpython.rangeobj import range_iter_len from numba.np.unsafe.ndarray import empty_inferred as unsafe_empty_inferred import numpy as np @@ -68,6 +68,10 @@ def __init__(self, func_ir, parallel_options, swapped={}, typed=False): def run(self): """Run inline closure call pass. """ + # Analysis relies on ir.Del presence, strip out later + pp = postproc.PostProcessor(self.func_ir) + pp.run(True) + modified = False work_list = list(self.func_ir.blocks.items()) debug_print = _make_debug_print("InlineClosureCallPass") @@ -118,12 +122,14 @@ def run(self): _fix_nested_array(self.func_ir) if modified: - remove_dels(self.func_ir.blocks) # run dead code elimination dead_code_elimination(self.func_ir) # do label renaming self.func_ir.blocks = rename_labels(self.func_ir.blocks) + # inlining done, strip dels + remove_dels(self.func_ir.blocks) + debug_print("END") def _inline_reduction(self, work_list, block, i, expr, call_name): diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index 31b3de51d9b..a09dac8c61d 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -22,7 +22,7 @@ compute_cfg_from_blocks) from numba.core.errors import (TypingError, UnsupportedError, NumbaPendingDeprecationWarning, NumbaWarning, - feedback_details) + feedback_details, CompilerError) import copy @@ -511,7 +511,7 @@ def remove_args(blocks): def dead_code_elimination(func_ir, typemap=None, alias_map=None, arg_aliases=None): """ Performs dead code elimination and leaves the IR in a valid state on - exit (ir.Dels are present in correct locations). + exit """ do_post_proc = False while (remove_dead(func_ir.blocks, func_ir.arg_names, func_ir, typemap, @@ -1633,7 +1633,7 @@ def _create_function_from_code_obj(fcode, func_env, func_arg, func_clo, glbls): def get_ir_of_code(glbls, fcode): """ - Compile a code object to get its IR. + Compile a code object to get its IR, ir.Del nodes are emitted """ nfree = len(fcode.co_freevars) func_env = "\n".join([" c_%d = None" % i for i in range(nfree)]) @@ -1665,7 +1665,7 @@ def __init__(self, f_ir): ir, numba.core.cpu.ParallelOptions(False), swapped) inline_pass.run() post_proc = postproc.PostProcessor(ir) - post_proc.run() + post_proc.run(True) return ir def replace_arg_nodes(block, args): @@ -2056,20 +2056,29 @@ def resolve_mod(mod): return None +def enforce_no_dels(func_ir): + """ + Enforce there being no ir.Del nodes in the IR. + """ + strict = True + for blk in func_ir.blocks.values(): + dels = [x for x in blk.find_insts(ir.Del)] + if dels: + msg = "Illegal IR, del found at: %s" % dels[0] + if strict: + raise CompilerError(msg, loc=dels[0].loc) + else: + warnings.warn(NumbaWarning(msg)) + + def check_and_legalize_ir(func_ir): """ - This checks that the IR presented is legal, warns and legalizes if not + This checks that the IR presented is legal """ - orig_ir = func_ir.copy() + enforce_no_dels(func_ir) + # postprocess and emit ir.Dels post_proc = postproc.PostProcessor(func_ir) - post_proc.run() - msg = ("\nNumba has detected inconsistencies in its internal " - "representation of the code at %s. Numba can probably recover from " - "this problem and is attempting to do, however something inside " - "Numba needs fixing...\n%s\n") % (func_ir.loc, feedback_details) - if not func_ir.equal_ir(orig_ir): - msg += func_ir.diff_str(orig_ir) - warnings.warn(NumbaWarning(msg, loc=func_ir.loc)) + post_proc.run(True) def convert_code_obj_to_function(code_obj, caller_ir): diff --git a/numba/core/postproc.py b/numba/core/postproc.py index c019493afb1..4ffd522ab6f 100644 --- a/numba/core/postproc.py +++ b/numba/core/postproc.py @@ -65,7 +65,7 @@ class PostProcessor(object): def __init__(self, func_ir): self.func_ir = func_ir - def run(self): + def run(self, emit_dels=False): """ Run the following passes over Numba IR: - canonicalize the CFG @@ -77,9 +77,6 @@ def run(self): vlt = VariableLifetime(self.func_ir.blocks) self.func_ir.variable_lifetime = vlt - # Emit del nodes - self._insert_var_dels() - bev = analysis.compute_live_variables(vlt.cfg, self.func_ir.blocks, vlt.usedefs.defmap, vlt.deadmaps.combined) @@ -92,6 +89,11 @@ def run(self): else: self.func_ir.generator_info = None + # Emit del nodes, do this last as the generator info parsing generates + # and then strips dels as part of its analysis. + if emit_dels: + self._insert_var_dels() + def _populate_generator_info(self): """ Fill `index` for the Yield instruction and create YieldPoints. @@ -113,8 +115,9 @@ def _compute_generator_info(self): Compute the generator's state variables as the union of live variables at all yield points. """ + # generate del info, it's used in analysis here, strip it out at the end + self._insert_var_dels() self._populate_generator_info() - gi = self.func_ir.generator_info for yp in gi.get_yield_points(): live_vars = set(self.func_ir.get_block_entry_vars(yp.block)) @@ -147,6 +150,7 @@ def _compute_generator_info(self): st |= yp.live_vars st |= yp.weak_live_vars gi.state_vars = sorted(st) + self.remove_dels() def _insert_var_dels(self): """ @@ -209,3 +213,16 @@ def _patch_var_dels(self, internal_dead_map, escaping_dead_map): escape_dead_set = escaping_dead_map[offset] for var_name in sorted(escape_dead_set): ir_block.prepend(ir.Del(var_name, loc=ir_block.body[0].loc)) + + + def remove_dels(self): + """ + Strips the IR of Del nodes + """ + for block in self.func_ir.blocks.values(): + new_body = [] + for stmt in block.body: + if not isinstance(stmt, ir.Del): + new_body.append(stmt) + block.body = new_body + return diff --git a/numba/core/typed_passes.py b/numba/core/typed_passes.py index e8ee787f082..9a7ef4f8611 100644 --- a/numba/core/typed_passes.py +++ b/numba/core/typed_passes.py @@ -9,12 +9,13 @@ from numba.parfors.parfor import Parfor from numba.core.compiler_machinery import (FunctionPass, LoweringPass, - register_pass) + AnalysisPass, register_pass) from numba.core.annotations import type_annotations from numba.core.ir_utils import (raise_on_unsupported_feature, warn_deprecated, check_and_legalize_ir, guard, dead_code_elimination, simplify_CFG, - get_definition) + get_definition, remove_dels) +from numba.core import postproc @contextmanager @@ -197,6 +198,11 @@ def run_pass(self, state): Perform any intermediate representation rewrites after type inference. """ + # a bunch of these passes are either making assumptions or rely on some + # very picky and slightly bizarre state particularly in relation to + # ir.Del presence. To accommodate, ir.Dels are added ahead of running + # this pass and stripped at the end. + # Ensure we have an IR and type information. assert state.func_ir assert isinstance(getattr(state, 'typemap', None), dict) @@ -204,8 +210,12 @@ def run_pass(self, state): msg = ('Internal error in post-inference rewriting ' 'pass encountered during compilation of ' 'function "%s"' % (state.func_id.func_name,)) + + pp = postproc.PostProcessor(state.func_ir) + pp.run(True) with fallback_context(state, msg): rewrites.rewrite_registry.apply('after-inference', state) + pp.remove_dels() return True @@ -268,6 +278,8 @@ def run_pass(self, state): state.parfor_diagnostics) parfor_pass.run() + remove_dels(state.func_ir.blocks) + # check the parfor pass worked and warn if it didn't has_parfor = False for blk in state.func_ir.blocks.values(): @@ -298,12 +310,12 @@ def run_pass(self, state): @register_pass(mutates_CFG=False, analysis_only=True) -class DumpParforDiagnostics(FunctionPass): +class DumpParforDiagnostics(AnalysisPass): _name = "dump_parfor_diagnostics" def __init__(self): - FunctionPass.__init__(self) + AnalysisPass.__init__(self) def run_pass(self, state): if state.flags.auto_parallel.enabled: @@ -369,12 +381,12 @@ def run_pass(self, state): @register_pass(mutates_CFG=False, analysis_only=True) -class IRLegalization(FunctionPass): +class IRLegalization(AnalysisPass): _name = "ir_legalization" def __init__(self): - FunctionPass.__init__(self) + AnalysisPass.__init__(self) def run_pass(self, state): raise_on_unsupported_feature(state.func_ir, state.typemap) @@ -385,12 +397,12 @@ def run_pass(self, state): @register_pass(mutates_CFG=True, analysis_only=False) -class NoPythonBackend(FunctionPass): +class NoPythonBackend(LoweringPass): _name = "nopython_backend" def __init__(self): - FunctionPass.__init__(self) + LoweringPass.__init__(self) def run_pass(self, state): """ diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py index 66c88c3f6b3..e342ad80f9c 100644 --- a/numba/core/untyped_passes.py +++ b/numba/core/untyped_passes.py @@ -3,7 +3,8 @@ from copy import deepcopy, copy import warnings -from numba.core.compiler_machinery import FunctionPass, register_pass +from numba.core.compiler_machinery import (FunctionPass, AnalysisPass, + register_pass) from numba.core import (errors, types, ir, bytecode, postproc, rewrites, config, transforms) from numba.misc.special import literal_unroll @@ -382,7 +383,7 @@ def _do_work(self, state, work_list, block, i, expr): @register_pass(mutates_CFG=False, analysis_only=False) -class PreserveIR(FunctionPass): +class PreserveIR(AnalysisPass): """ Preserves the IR in the metadata """ @@ -390,7 +391,7 @@ class PreserveIR(FunctionPass): _name = "preserve_ir" def __init__(self): - FunctionPass.__init__(self) + AnalysisPass.__init__(self) def run_pass(self, state): state.metadata['preserved_ir'] = state.func_ir.copy() diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 2fc77f92e2b..949f0e3e7c9 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -45,7 +45,6 @@ replace_vars_inner, visit_vars, visit_vars_inner, - remove_dels, remove_dead, copy_propagate, get_block_copies, @@ -1500,7 +1499,6 @@ def run(self): """run parfor conversion pass: replace Numpy calls with Parfors when possible and optimize the IR.""" # run array analysis, a pre-requisite for parfor translation - remove_dels(self.func_ir.blocks) self.array_analysis.run(self.func_ir.blocks) # run stencil translation to parfor if self.options.stencil: @@ -1588,7 +1586,7 @@ def run(self): # run post processor again to generate Del nodes post_proc = postproc.PostProcessor(self.func_ir) - post_proc.run() + post_proc.run(True) if self.func_ir.is_generator: fix_generator_types(self.func_ir.generator_info, self.return_type, self.typemap) @@ -2871,7 +2869,7 @@ def lower_parfor_sequential(typingctx, func_ir, typemap, calltypes): dprint_func_ir(func_ir, "after parfor sequential simplify") # add dels since simplify removes dels post_proc = postproc.PostProcessor(func_ir) - post_proc.run() + post_proc.run(True) return diff --git a/numba/tests/test_inlining.py b/numba/tests/test_inlining.py index c0ba1ef2cf2..76a7565fa4e 100644 --- a/numba/tests/test_inlining.py +++ b/numba/tests/test_inlining.py @@ -57,11 +57,11 @@ def run_pass(self, state): inline_closure_call(state.func_ir, {}, block, i, lambda: None, state.typingctx, (), state.type_annotation.typemap, state.type_annotation.calltypes) - # also fix up the IR so that ir.Dels appear correctly/in correct - # locations - post_proc = postproc.PostProcessor(state.func_ir) - post_proc.run() break + # also fix up the IR + post_proc = postproc.PostProcessor(state.func_ir) + post_proc.run() + post_proc.remove_dels() return True diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index 087065746f8..a07acef9422 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -337,6 +337,10 @@ def gen_block(): self.check(a, same=[b], different=[c]) def test_functionir(self): + + def run_frontend(x): + return compiler.run_frontend(x, emit_dels=True) + # this creates a function full of all sorts of things to ensure the IR # is pretty involved, it then compares two instances of the compiled # function IR to check the IR is the same invariant of objects, and then @@ -382,8 +386,9 @@ def foo(a, b, c=12, d=1j, e=None): x = gen() y = gen() - x_ir = compiler.run_frontend(x) - y_ir = compiler.run_frontend(y) + x_ir = run_frontend(x) + y_ir = run_frontend(y) + self.assertTrue(x_ir.equal_ir(y_ir)) def check_diffstr(string, pointing_at=[]): @@ -411,7 +416,7 @@ def check_diffstr(string, pointing_at=[]): z = gen() self.assertFalse(x_ir.equal_ir(y_ir)) - z_ir = compiler.run_frontend(z) + z_ir = run_frontend(z) change_set = set() for label in reversed(list(z_ir.blocks.keys())): @@ -431,6 +436,7 @@ def check_diffstr(string, pointing_at=[]): b[idx], b[idx + 1] = b[idx + 1], b[idx] break + assert change_set self.assertFalse(x_ir.equal_ir(z_ir)) self.assertEqual(len(change_set), 2) for item in change_set: @@ -455,12 +461,12 @@ def baz(a, b): e = np.sqrt(d + 1) return e - foo_ir = compiler.run_frontend(foo) - bar_ir = compiler.run_frontend(bar) + foo_ir = run_frontend(foo) + bar_ir = run_frontend(bar) self.assertTrue(foo_ir.equal_ir(bar_ir)) self.assertIn("IR is considered equivalent", foo_ir.diff_str(bar_ir)) - baz_ir = compiler.run_frontend(baz) + baz_ir = run_frontend(baz) self.assertFalse(foo_ir.equal_ir(baz_ir)) tmp = foo_ir.diff_str(baz_ir) self.assertIn("Other block contains more statements", tmp) diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index c10dfa10601..416b57c7acf 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -7,12 +7,12 @@ from numba.testing import unittest from numba.core.extending import overload from numba.core.compiler_machinery import (PassManager, register_pass, - FunctionPass) + FunctionPass, AnalysisPass) from numba.core.compiler import CompilerBase from numba.core.untyped_passes import (FixupArgs, TranslateByteCode, IRProcessing, InlineClosureLikes, SimplifyCFG, IterLoopCanonicalization, - LiteralUnroll) + LiteralUnroll, PreserveIR) from numba.core.typed_passes import (NopythonTypeInference, IRLegalization, NoPythonBackend, PartialTypeInference) from numba.core.ir_utils import (compute_cfg_from_blocks, flatten_labels) @@ -58,18 +58,6 @@ def foo(): self.assertIn("non literal", str(e.exception)) -@register_pass(mutates_CFG=False, analysis_only=True) -class PreserveIR(FunctionPass): - _name = "preserve_ir" - - def __init__(self): - FunctionPass.__init__(self) - - def run_pass(self, state): - state.metadata['func_ir'] = state.func_ir - return False - - @register_pass(mutates_CFG=False, analysis_only=False) class ResetTypeInfo(FunctionPass): _name = "reset_the_type_information" @@ -143,7 +131,7 @@ def foo(tup): x = (1, 2, 3) self.assertEqual(foo(x), foo.py_func(x)) cres = foo.overloads[foo.signatures[0]] - func_ir = cres.metadata['func_ir'] + func_ir = cres.metadata['preserved_ir'] return func_ir, cres.fndesc ignore_loops_ir, ignore_loops_fndesc = \ @@ -201,7 +189,7 @@ def foo(): self.assertEqual(foo(), foo.py_func()) cres = foo.overloads[foo.signatures[0]] - func_ir = cres.metadata['func_ir'] + func_ir = cres.metadata['preserved_ir'] return func_ir, cres.fndesc ignore_loops_ir, ignore_loops_fndesc = \ @@ -325,7 +313,7 @@ def foo(tup): x = (1, 2, 3) self.assertEqual(foo(x), foo.py_func(x)) cres = foo.overloads[foo.signatures[0]] - func_ir = cres.metadata['func_ir'] + func_ir = cres.metadata['preserved_ir'] return func_ir, cres.fndesc ignore_loops_ir, ignore_loops_fndesc = \ @@ -394,7 +382,7 @@ def foo(tup): x = (1, 2, 3) self.assertEqual(foo(x), foo.py_func(x)) cres = foo.overloads[foo.signatures[0]] - func_ir = cres.metadata['func_ir'] + func_ir = cres.metadata['preserved_ir'] return func_ir, cres.fndesc ignore_loops_ir, ignore_loops_fndesc = \ @@ -439,7 +427,7 @@ def bar(n): x = (1, 2, 3) self.assertEqual(foo(x), foo.py_func(x)) cres = foo.overloads[foo.signatures[0]] - func_ir = cres.metadata['func_ir'] + func_ir = cres.metadata['preserved_ir'] return func_ir, cres.fndesc ignore_loops_ir, ignore_loops_fndesc = \ @@ -1665,7 +1653,7 @@ def capture(real_pass): """ Returns a compiler pass that captures the mutation state reported by the pass used in the argument""" @register_pass(mutates_CFG=False, analysis_only=True) - class ResultCapturer(FunctionPass): + class ResultCapturer(AnalysisPass): _name = "capture_%s" % real_pass._name _real_pass = real_pass diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 256cb901eaf..def2b2141c9 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -33,7 +33,7 @@ from numba.core.bytecode import ByteCodeIter from numba.core.compiler import (compile_isolated, Flags, CompilerBase, DefaultPassBuilder) -from numba.core.compiler_machinery import register_pass, FunctionPass +from numba.core.compiler_machinery import register_pass, AnalysisPass from numba.core.typed_passes import IRLegalization from numba.tests.support import (TestCase, captured_stdout, MemoryLeakMixin, override_env_config, linux_only, tag, @@ -3108,11 +3108,11 @@ def test_no_state_change_in_gufunc_lowering_on_error(self): # stack unwind. @register_pass(mutates_CFG=True, analysis_only=False) - class BreakParfors(FunctionPass): + class BreakParfors(AnalysisPass): _name = "break_parfors" def __init__(self): - FunctionPass.__init__(self) + AnalysisPass.__init__(self) def run_pass(self, state): for blk in state.func_ir.blocks.values(): From d819e3fbdf3c59ec79f75019bfff3e2f9f167e08 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Tue, 18 Feb 2020 16:22:59 -0600 Subject: [PATCH 550/595] Split up ConvertReducePass --- numba/parfors/parfor.py | 314 +++++++++++++++---------- numba/tests/test_parfors_components.py | 37 +++ 2 files changed, 230 insertions(+), 121 deletions(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 0ece0293ba7..4f4a2d3d941 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -1882,6 +1882,196 @@ def _numpy_map_to_parfor(self, equiv_set, call_name, lhs, args, kws, expr): parfor.dump() return parfor + +class ConvertReducePass: + """ + Find reduce() calls and convert them to parfors. + """ + def __init__(self, pass_states): + self.pass_states = pass_states + self.rewritten = [] + + def run(self, blocks): + pass_states = self.pass_states + + topo_order = find_topo_order(blocks) + for label in topo_order: + block = blocks[label] + new_body = [] + equiv_set = pass_states.array_analysis.get_equiv_set(label) + for instr in block.body: + parfor = None + if isinstance(instr, ir.Assign): + loc = instr.loc + lhs = instr.target + expr = instr.value + callname = guard(find_callname, pass_states.func_ir, expr) + if (callname == ('reduce', 'builtins') + or callname == ('reduce', '_functools')): + # reduce function with generic function + parfor = guard(self._reduce_to_parfor, equiv_set, lhs, + expr.args, loc) + if parfor: + self.rewritten.append(dict( + new=parfor, + old=instr, + reason='reduce', + )) + instr = parfor + new_body.append(instr) + block.body = new_body + return + + def _reduce_to_parfor(self, equiv_set, lhs, args, loc): + """ + Convert a reduce call to a parfor. + The call arguments should be (call_name, array, init_value). + """ + pass_states = self.pass_states + + scope = lhs.scope + call_name = args[0] + in_arr = args[1] + arr_def = get_definition(pass_states.func_ir, in_arr.name) + + mask_var = None + mask_indices = None + + # Search for array[boolean_mask] + mask_query_result = guard(_find_mask, pass_states.typemap, pass_states.func_ir, arr_def) + if mask_query_result: + in_arr, mask_var, mask_typ, mask_indices = mask_query_result + + init_val = args[2] + size_vars = equiv_set.get_shape(in_arr if mask_indices == None else mask_var) + index_vars, loopnests = _mk_parfor_loops(pass_states.typemap, size_vars, scope, loc) + mask_index = index_vars + if mask_indices: + assert False, "DEAD" + index_vars = tuple(x if x else index_vars[0] for x in mask_indices) + acc_var = lhs + + # init block has to init the reduction variable + init_block = ir.Block(scope, loc) + init_block.body.append(ir.Assign(init_val, acc_var, loc)) + + # produce loop body + body_label = next_label() + index_var, loop_body = self._mk_reduction_body(call_name, + scope, loc, index_vars, in_arr, acc_var) + if mask_indices: + assert False, "DEAD" + index_var = mask_index[0] + + if mask_var != None: + true_label = min(loop_body.keys()) + false_label = max(loop_body.keys()) + body_block = ir.Block(scope, loc) + loop_body[body_label] = body_block + mask = ir.Var(scope, mk_unique_var("$mask_val"), loc) + pass_states.typemap[mask.name] = mask_typ + mask_val = ir.Expr.getitem(mask_var, index_var, loc) + body_block.body.extend([ + ir.Assign(mask_val, mask, loc), + ir.Branch(mask, true_label, false_label, loc) + ]) + + parfor = Parfor(loopnests, init_block, loop_body, loc, index_var, + equiv_set, ('{} function'.format(call_name), + 'reduction'), pass_states.flags) + if config.DEBUG_ARRAY_OPT >= 1: + print("parfor from reduction") + parfor.dump() + return parfor + + def _mk_reduction_body(self, call_name, scope, loc, + index_vars, in_arr, acc_var): + """ + Produce the body blocks for a reduction function indicated by call_name. + """ + from numba.core.inline_closurecall import check_reduce_func + + pass_states = self.pass_states + reduce_func = get_definition(pass_states.func_ir, call_name) + fcode = check_reduce_func(pass_states.func_ir, reduce_func) + + arr_typ = pass_states.typemap[in_arr.name] + in_typ = arr_typ.dtype + body_block = ir.Block(scope, loc) + index_var, index_var_type = _make_index_var( + pass_states.typemap, scope, index_vars, body_block) + + tmp_var = ir.Var(scope, mk_unique_var("$val"), loc) + pass_states.typemap[tmp_var.name] = in_typ + getitem_call = ir.Expr.getitem(in_arr, index_var, loc) + pass_states.calltypes[getitem_call] = signature( + in_typ, arr_typ, index_var_type) + body_block.append(ir.Assign(getitem_call, tmp_var, loc)) + + reduce_f_ir = compile_to_numba_ir(fcode, + pass_states.func_ir.func_id.func.__globals__, + pass_states.typingctx, + (in_typ, in_typ), + pass_states.typemap, + pass_states.calltypes) + loop_body = reduce_f_ir.blocks + end_label = next_label() + end_block = ir.Block(scope, loc) + loop_body[end_label] = end_block + first_reduce_label = min(reduce_f_ir.blocks.keys()) + first_reduce_block = reduce_f_ir.blocks[first_reduce_label] + body_block.body.extend(first_reduce_block.body) + first_reduce_block.body = body_block.body + replace_arg_nodes(first_reduce_block, [acc_var, tmp_var]) + replace_returns(loop_body, acc_var, end_label) + return index_var, loop_body + + +def _find_mask(typemap, func_ir, arr_def): + """check if an array is of B[...M...], where M is a + boolean array, and other indices (if available) are ints. + If found, return B, M, M's type, and a tuple representing mask indices. + Otherwise, raise GuardException. + """ + require(isinstance(arr_def, ir.Expr) and arr_def.op == 'getitem') + value = arr_def.value + index = arr_def.index + value_typ = typemap[value.name] + index_typ = typemap[index.name] + ndim = value_typ.ndim + require(isinstance(value_typ, types.npytypes.Array)) + if (isinstance(index_typ, types.npytypes.Array) and + isinstance(index_typ.dtype, types.Boolean) and + ndim == index_typ.ndim): + return value, index, index_typ.dtype, None + elif isinstance(index_typ, types.BaseTuple): + # Handle multi-dimension differently by requiring + # all indices to be constant except the one for mask. + seq, op = find_build_sequence(func_ir, index) + require(op == 'build_tuple' and len(seq) == ndim) + count_consts = 0 + mask_indices = [] + mask_var = None + for ind in seq: + index_typ = typemap[ind.name] + if (isinstance(index_typ, types.npytypes.Array) and + isinstance(index_typ.dtype, types.Boolean)): + mask_var = ind + mask_typ = index_typ.dtype + mask_indices.append(None) + elif (isinstance(index_typ, types.npytypes.Array) and + isinstance(index_typ.dtype, types.Integer)): + mask_var = ind + mask_typ = index_typ.dtype + mask_indices.append(None) + elif isinstance(index_typ, types.Integer): + count_consts += 1 + mask_indices.append(ind) + require(mask_var and count_consts == ndim - 1) + return value, mask_var, mask_typ, mask_indices + raise GuardException + + class ParforPass(ParforPassStates): """ParforPass class is responsible for converting Numpy @@ -1909,7 +2099,7 @@ def run(self): if self.options.numpy: ConvertNumpyPass(self).run(self.func_ir.blocks) if self.options.reduction: - self._convert_reduce(self.func_ir.blocks) + ConvertReducePass(self).run(self.func_ir.blocks) if self.options.prange: self._convert_loop(self.func_ir.blocks) @@ -2015,33 +2205,6 @@ def run(self): return - def _convert_reduce(self, blocks): - """ - Find reduce() calls and convert them to parfors. - """ - topo_order = find_topo_order(blocks) - for label in topo_order: - block = blocks[label] - new_body = [] - equiv_set = self.array_analysis.get_equiv_set(label) - for instr in block.body: - parfor = None - if isinstance(instr, ir.Assign): - loc = instr.loc - lhs = instr.target - expr = instr.value - callname = guard(find_callname, self.func_ir, expr) - if (callname == ('reduce', 'builtins') - or callname == ('reduce', '_functools')): - # reduce function with generic function - parfor = guard(self._reduce_to_parfor, equiv_set, lhs, - expr.args, loc) - if parfor: - instr = parfor - new_body.append(instr) - block.body = new_body - return - def _convert_loop(self, blocks): call_table, _ = get_call_table(blocks) cfg = compute_cfg_from_blocks(blocks) @@ -2377,43 +2540,8 @@ def _find_mask(self, arr_def): If found, return B, M, M's type, and a tuple representing mask indices. Otherwise, raise GuardException. """ - require(isinstance(arr_def, ir.Expr) and arr_def.op == 'getitem') - value = arr_def.value - index = arr_def.index - value_typ = self.typemap[value.name] - index_typ = self.typemap[index.name] - ndim = value_typ.ndim - require(isinstance(value_typ, types.npytypes.Array)) - if (isinstance(index_typ, types.npytypes.Array) and - isinstance(index_typ.dtype, types.Boolean) and - ndim == index_typ.ndim): - return value, index, index_typ.dtype, None - elif isinstance(index_typ, types.BaseTuple): - # Handle multi-dimension differently by requiring - # all indices to be constant except the one for mask. - seq, op = find_build_sequence(self.func_ir, index) - require(op == 'build_tuple' and len(seq) == ndim) - count_consts = 0 - mask_indices = [] - mask_var = None - for ind in seq: - index_typ = self.typemap[ind.name] - if (isinstance(index_typ, types.npytypes.Array) and - isinstance(index_typ.dtype, types.Boolean)): - mask_var = ind - mask_typ = index_typ.dtype - mask_indices.append(None) - elif (isinstance(index_typ, types.npytypes.Array) and - isinstance(index_typ.dtype, types.Integer)): - mask_var = ind - mask_typ = index_typ.dtype - mask_indices.append(None) - elif isinstance(index_typ, types.Integer): - count_consts += 1 - mask_indices.append(ind) - require(mask_var and count_consts == ndim - 1) - return value, mask_var, mask_typ, mask_indices - raise GuardException + return _find_mask(self.typemap, self.func_ir, arr_def) + def _get_prange_init_block(self, entry_block, call_table, prange_args): """ @@ -2534,62 +2662,6 @@ def _mk_reduction_body(self, call_name, scope, loc, replace_returns(loop_body, acc_var, end_label) return index_var, loop_body - def _reduce_to_parfor(self, equiv_set, lhs, args, loc): - """ - Convert a reduce call to a parfor. - The call arguments should be (call_name, array, init_value). - """ - scope = lhs.scope - call_name = args[0] - in_arr = args[1] - arr_def = get_definition(self.func_ir, in_arr.name) - - mask_var = None - mask_indices = None - result = guard(self._find_mask, arr_def) - if result: - in_arr, mask_var, mask_typ, mask_indices = result - - init_val = args[2] - size_vars = equiv_set.get_shape(in_arr if mask_indices == None else mask_var) - index_vars, loopnests = self._mk_parfor_loops(size_vars, scope, loc) - mask_index = index_vars - if mask_indices: - index_vars = tuple(x if x else index_vars[0] for x in mask_indices) - acc_var = lhs - - # init block has to init the reduction variable - init_block = ir.Block(scope, loc) - init_block.body.append(ir.Assign(init_val, acc_var, loc)) - - # produce loop body - body_label = next_label() - index_var, loop_body = self._mk_reduction_body(call_name, - scope, loc, index_vars, in_arr, acc_var) - if mask_indices: - index_var = mask_index[0] - - if mask_var != None: - true_label = min(loop_body.keys()) - false_label = max(loop_body.keys()) - body_block = ir.Block(scope, loc) - loop_body[body_label] = body_block - mask = ir.Var(scope, mk_unique_var("$mask_val"), loc) - self.typemap[mask.name] = mask_typ - mask_val = ir.Expr.getitem(mask_var, index_var, loc) - body_block.body.extend([ - ir.Assign(mask_val, mask, loc), - ir.Branch(mask, true_label, false_label, loc) - ]) - - parfor = Parfor(loopnests, init_block, loop_body, loc, index_var, - equiv_set, ('{} function'.format(call_name), - 'reduction'), self.flags) - if config.DEBUG_ARRAY_OPT >= 1: - print("parfor from reduction") - parfor.dump() - return parfor - def fuse_parfors(self, array_analysis, blocks): for label, block in blocks.items(): diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py index a04050543cd..9488e53b184 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_components.py @@ -2,6 +2,7 @@ Tests for sub-components of parfors. """ import unittest +from functools import reduce import numpy as np @@ -265,5 +266,41 @@ def test_impl(a, b): self.run_parallel(test_impl, *args) +class TestConvertReducePass(BaseTest): + sub_pass_class = numba.parfors.parfor.ConvertReducePass + + def test_reduce_max_basic(self): + def test_impl(arr): + return reduce(lambda x, y: max(x, y), arr, 0.0) + + x = np.ones(10) + args = (x,) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "reduce") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl, *args) + + def test_reduce_max_masked(self): + def test_impl(arr): + return reduce(lambda x, y: max(x, y), arr[arr > 5], 0.0) + + x = np.ones(10) + args = (x,) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "reduce") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl, *args) + + if __name__ == "__main__": unittest.main() From 83b82a05bbcbe80124953a0d494b13a8422dd25d Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 19 Feb 2020 08:53:04 -0800 Subject: [PATCH 551/595] Add test for prange side effect. --- numba/tests/test_parfors.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 256cb901eaf..0e5b309f2f8 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -1539,6 +1539,23 @@ def test_impl(x, half): x = np.ones(20) self.check(test_impl, x, True, check_scheduling=False) + @skip_parfors_unsupported + def test_prange_side_effects(self): + def test_impl(a, b): + data = np.empty(len(a), dtype=np.float64) + size = len(data) + for i in numba.prange(size): + data[i] = a[i] + for i in numba.prange(size): + data[i] = data[i] + b[i] + return data + + x = np.arange(10 ** 2, dtype=float) + y = np.arange(10 ** 2, dtype=float) + + self.check(test_impl, x, y) + self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 1, 'C'), types.Array(types.float64, 1, 'C'))) == 1) + class TestParforsLeaks(MemoryLeakMixin, TestParforsBase): def check(self, pyfunc, *args, **kwargs): From 43a48a2ddffec4e8d218b94e05e7a659f8051db8 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 19 Feb 2020 09:00:02 -0800 Subject: [PATCH 552/595] Line length. --- numba/tests/test_parfors.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 0e5b309f2f8..837098186c3 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -1554,7 +1554,9 @@ def test_impl(a, b): y = np.arange(10 ** 2, dtype=float) self.check(test_impl, x, y) - self.assertTrue(countParfors(test_impl, (types.Array(types.float64, 1, 'C'), types.Array(types.float64, 1, 'C'))) == 1) + self.assertTrue(countParfors(test_impl, + (types.Array(types.float64, 1, 'C'), + types.Array(types.float64, 1, 'C'))) == 1) class TestParforsLeaks(MemoryLeakMixin, TestParforsBase): From b899b524b9e0718932d7c94d55ade0f0e7b5fded Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 19 Feb 2020 11:10:58 -0600 Subject: [PATCH 553/595] Fix up test on 32bit --- numba/tests/support.py | 6 +++++- numba/tests/test_parfors_components.py | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/numba/tests/support.py b/numba/tests/support.py index d63d3b742cb..14af940700f 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -52,7 +52,11 @@ tag = testing.make_tag_decorator(['important', 'long_running']) _32bit = sys.maxsize <= 2 ** 32 -skip_parfors_unsupported = unittest.skipIf(_32bit, 'parfors not supported') +is_parfors_unsupported = _32bit +skip_parfors_unsupported = unittest.skipIf( + is_parfors_unsupported, + 'parfors not supported', +) skip_py38_or_later = unittest.skipIf( utils.PYVERSION >= (3, 8), "unsupported on py3.8 or later" diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py index 9488e53b184..81aebbbe21e 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_components.py @@ -17,7 +17,7 @@ cpu, ) from numba.core.registry import cpu_target -from numba.tests.support import TestCase +from numba.tests.support import TestCase, is_parfors_unsupported class MyPipeline(object): @@ -98,17 +98,25 @@ def run_parfor_sub_pass(cls, test_func, args, **kws): return sub_pass - def run_parallel(self, func, *args, **kwargs): + def _run_parallel(self, func, *args, **kwargs): cfunc = njit(parallel=True)(func) expect = func(*args, **kwargs) got = cfunc(*args, **kwargs) + return expect, got + + def run_parallel(self, func, *args, **kwargs): + if is_parfors_unsupported: + # Skip + return + expect, got = self._run_parallel(func, *args, **kwargs) self.assertPreciseEqual(expect, got) def run_parallel_check_output_array(self, func, *args, **kwargs): + if is_parfors_unsupported: + # Skip + return + expect, got = self._run_parallel(func, *args, **kwargs) # Don't match the value, just the return type. must return array - cfunc = njit(parallel=True)(func) - expect = func(*args, **kwargs) - got = cfunc(*args, **kwargs) self.assertIsInstance(expect, np.ndarray) self.assertIsInstance(got, np.ndarray) self.assertEqual(expect.shape, got.shape) From 7a60252cfc0f3710fc2584811b0c7bd32ae209cf Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 19 Feb 2020 15:52:01 -0600 Subject: [PATCH 554/595] Split up ConvertLoopPass --- numba/parfors/parfor.py | 552 +++++++++++++------------ numba/tests/test_parfors_components.py | 180 +++++++- 2 files changed, 459 insertions(+), 273 deletions(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 4f4a2d3d941..a8ee55791b1 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -2027,185 +2027,16 @@ def _mk_reduction_body(self, call_name, scope, loc, return index_var, loop_body -def _find_mask(typemap, func_ir, arr_def): - """check if an array is of B[...M...], where M is a - boolean array, and other indices (if available) are ints. - If found, return B, M, M's type, and a tuple representing mask indices. - Otherwise, raise GuardException. +class ConvertLoopPass: + """Build Parfor nodes from prange loops. """ - require(isinstance(arr_def, ir.Expr) and arr_def.op == 'getitem') - value = arr_def.value - index = arr_def.index - value_typ = typemap[value.name] - index_typ = typemap[index.name] - ndim = value_typ.ndim - require(isinstance(value_typ, types.npytypes.Array)) - if (isinstance(index_typ, types.npytypes.Array) and - isinstance(index_typ.dtype, types.Boolean) and - ndim == index_typ.ndim): - return value, index, index_typ.dtype, None - elif isinstance(index_typ, types.BaseTuple): - # Handle multi-dimension differently by requiring - # all indices to be constant except the one for mask. - seq, op = find_build_sequence(func_ir, index) - require(op == 'build_tuple' and len(seq) == ndim) - count_consts = 0 - mask_indices = [] - mask_var = None - for ind in seq: - index_typ = typemap[ind.name] - if (isinstance(index_typ, types.npytypes.Array) and - isinstance(index_typ.dtype, types.Boolean)): - mask_var = ind - mask_typ = index_typ.dtype - mask_indices.append(None) - elif (isinstance(index_typ, types.npytypes.Array) and - isinstance(index_typ.dtype, types.Integer)): - mask_var = ind - mask_typ = index_typ.dtype - mask_indices.append(None) - elif isinstance(index_typ, types.Integer): - count_consts += 1 - mask_indices.append(ind) - require(mask_var and count_consts == ndim - 1) - return value, mask_var, mask_typ, mask_indices - raise GuardException - - -class ParforPass(ParforPassStates): - - """ParforPass class is responsible for converting Numpy - calls in Numba intermediate representation to Parfors, which - will lower into either sequential or parallel loops during lowering - stage. - """ - - def _pre_run(self): - # run array analysis, a pre-requisite for parfor translation - remove_dels(self.func_ir.blocks) - self.array_analysis.run(self.func_ir.blocks) - - def run(self): - """run parfor conversion pass: replace Numpy calls - with Parfors when possible and optimize the IR.""" - self._pre_run() - # run stencil translation to parfor - if self.options.stencil: - stencil_pass = StencilPass(self.func_ir, self.typemap, self.calltypes, - self.array_analysis, self.typingctx, self.flags) - stencil_pass.run() - if self.options.setitem: - ConvertSetItemPass(self).run(self.func_ir.blocks) - if self.options.numpy: - ConvertNumpyPass(self).run(self.func_ir.blocks) - if self.options.reduction: - ConvertReducePass(self).run(self.func_ir.blocks) - if self.options.prange: - self._convert_loop(self.func_ir.blocks) - - # setup diagnostics now parfors are found - self.diagnostics.setup(self.func_ir, self.options.fusion) - - dprint_func_ir(self.func_ir, "after parfor pass") - - # simplify CFG of parfor body loops since nested parfors with extra - # jumps can be created with prange conversion - simplify_parfor_body_CFG(self.func_ir.blocks) - # simplify before fusion - simplify(self.func_ir, self.typemap, self.calltypes) - # need two rounds of copy propagation to enable fusion of long sequences - # of parfors like test_fuse_argmin (some PYTHONHASHSEED values since - # apply_copies_parfor depends on set order for creating dummy assigns) - simplify(self.func_ir, self.typemap, self.calltypes) - - if self.options.fusion: - self.func_ir._definitions = build_definitions(self.func_ir.blocks) - self.array_analysis.equiv_sets = dict() - self.array_analysis.run(self.func_ir.blocks) - # reorder statements to maximize fusion - # push non-parfors down - maximize_fusion(self.func_ir, self.func_ir.blocks, self.typemap, - up_direction=False) - dprint_func_ir(self.func_ir, "after maximize fusion down") - self.fuse_parfors(self.array_analysis, self.func_ir.blocks) - # push non-parfors up - maximize_fusion(self.func_ir, self.func_ir.blocks, self.typemap) - dprint_func_ir(self.func_ir, "after maximize fusion up") - # try fuse again after maximize - self.fuse_parfors(self.array_analysis, self.func_ir.blocks) - dprint_func_ir(self.func_ir, "after fusion") - # simplify again - simplify(self.func_ir, self.typemap, self.calltypes) - # push function call variables inside parfors so gufunc function - # wouldn't need function variables as argument - push_call_vars(self.func_ir.blocks, {}, {}, self.typemap) - dprint_func_ir(self.func_ir, "after push call vars") - # simplify again - simplify(self.func_ir, self.typemap, self.calltypes) - dprint_func_ir(self.func_ir, "after optimization") - if config.DEBUG_ARRAY_OPT >= 1: - print("variable types: ", sorted(self.typemap.items())) - print("call types: ", self.calltypes) - - if config.DEBUG_ARRAY_OPT >= 3: - for(block_label, block) in self.func_ir.blocks.items(): - new_block = [] - scope = block.scope - for stmt in block.body: - new_block.append(stmt) - if isinstance(stmt, ir.Assign): - loc = stmt.loc - lhs = stmt.target - rhs = stmt.value - lhs_typ = self.typemap[lhs.name] - print("Adding print for assignment to ", lhs.name, lhs_typ, type(lhs_typ)) - if lhs_typ in types.number_domain or isinstance(lhs_typ, types.Literal): - str_var = ir.Var(scope, mk_unique_var("str_var"), loc) - self.typemap[str_var.name] = types.StringLiteral(lhs.name) - lhs_const = ir.Const(lhs.name, loc) - str_assign = ir.Assign(lhs_const, str_var, loc) - new_block.append(str_assign) - str_print = ir.Print([str_var], None, loc) - self.calltypes[str_print] = signature(types.none, self.typemap[str_var.name]) - new_block.append(str_print) - ir_print = ir.Print([lhs], None, loc) - self.calltypes[ir_print] = signature(types.none, lhs_typ) - new_block.append(ir_print) - block.body = new_block - - # run post processor again to generate Del nodes - post_proc = postproc.PostProcessor(self.func_ir) - post_proc.run() - if self.func_ir.is_generator: - fix_generator_types(self.func_ir.generator_info, self.return_type, - self.typemap) - if sequential_parfor_lowering: - lower_parfor_sequential( - self.typingctx, self.func_ir, self.typemap, self.calltypes) - else: - # prepare for parallel lowering - # add parfor params to parfors here since lowering is destructive - # changing the IR after this is not allowed - parfor_ids, parfors = get_parfor_params(self.func_ir.blocks, - self.options.fusion, - self.nested_fusion_info) - for p in parfors: - get_parfor_reductions(self.func_ir, p, p.params, self.calltypes) - if config.DEBUG_ARRAY_OPT_STATS: - name = self.func_ir.func_id.func_qualname - n_parfors = len(parfor_ids) - if n_parfors > 0: - after_fusion = ("After fusion" if self.options.fusion - else "With fusion disabled") - print(('{}, function {} has ' - '{} parallel for-loop(s) #{}.').format( - after_fusion, name, n_parfors, parfor_ids)) - else: - print('Function {} has no Parfor.'.format(name)) + def __init__(self, pass_states): + self.pass_states = pass_states + self.rewritten = [] - return + def run(self, blocks): + pass_states = self.pass_states - def _convert_loop(self, blocks): call_table, _ = get_call_table(blocks) cfg = compute_cfg_from_blocks(blocks) usedefs = compute_use_defs(blocks) @@ -2252,14 +2083,14 @@ def _convert_loop(self, blocks): # loop_index may be assigned to other vars # get header copies to find all of them cps, _ = get_block_copies({0: blocks[loop.header]}, - self.typemap) + pass_states.typemap) cps = cps[0] loop_index_vars = set(t for t, v in cps if v == loop_index) loop_index_vars.add(loop_index) scope = blocks[entry].scope loc = inst.loc - equiv_set = self.array_analysis.get_equiv_set(loop.header) + equiv_set = pass_states.array_analysis.get_equiv_set(loop.header) init_block = ir.Block(scope, loc) init_block.body = self._get_prange_init_block(blocks[entry], call_table, args) @@ -2283,7 +2114,7 @@ def _convert_loop(self, blocks): # copies such ir.Global nodes into the Parfors in which they # are used so no need to treat things of type Module as a race. races = races.intersection({x for x in races - if not isinstance(self.typemap[x], types.misc.Module)}) + if not isinstance(pass_states.typemap[x], types.misc.Module)}) # replace jumps to header block with the end block for l in body_labels: @@ -2324,7 +2155,7 @@ def find_mask_from_size(size_var): """Find the case where size_var is defined by A[M].shape, where M is a boolean array. """ - size_def = get_definition(self.func_ir, size_var) + size_def = get_definition(pass_states.func_ir, size_var) require(size_def and isinstance(size_def, ir.Expr) and size_def.op == 'getattr' and size_def.attr == 'shape') arr_var = size_def.value @@ -2334,8 +2165,11 @@ def find_mask_from_size(size_var): # input array has to be dead after loop require(arr_var.name not in live_vars) # loop for arr's definition, where size = arr.shape - arr_def = get_definition(self.func_ir, size_def.value) - result = self._find_mask(arr_def) + arr_def = get_definition(pass_states.func_ir, size_def.value) + result = _find_mask(pass_states.typemap, pass_states.func_ir, arr_def) + + # The following is never tested. + raise AssertionError("unreachable") # Found the mask. # Replace B[i] with A[i], where B = A[M] for expr in index_exprs: @@ -2358,8 +2192,9 @@ def find_mask_from_size(size_var): in_arr = args[0] size_vars = equiv_set.get_shape(in_arr if mask_indices == None else mask_var) - index_vars, loops = self._mk_parfor_loops( - size_vars, scope, loc) + index_vars, loops = _mk_parfor_loops( + pass_states.typemap, size_vars, scope, loc, + ) orig_index = index_vars if mask_indices: # replace mask indices if required; @@ -2370,7 +2205,7 @@ def find_mask_from_size(size_var): first_body_block = loop_body[min(loop_body.keys())] body_block = ir.Block(scope, loc) index_var, index_var_typ = _make_index_var( - self.typemap, scope, index_vars, body_block, + pass_states.typemap, scope, index_vars, body_block, ) body = body_block.body + first_body_block.body first_body_block.body = body @@ -2382,6 +2217,8 @@ def find_mask_from_size(size_var): # if masked array optimization is being applied, create # the branch for array selection if mask_var != None: + # The following code are not tested + raise AssertionError("unreachable") body_label = next_label() # loop_body needs new labels greater than body_label loop_body = add_offset_to_labels(loop_body, @@ -2392,7 +2229,7 @@ def find_mask_from_size(size_var): body_block = ir.Block(scope, loc) loop_body[body_label] = body_block mask = ir.Var(scope, mk_unique_var("$mask_val"), loc) - self.typemap[mask.name] = mask_typ + pass_states.typemap[mask.name] = mask_typ mask_val = ir.Expr.getitem(mask_var, orig_index_var, loc) body_block.body.extend([ ir.Assign(mask_val, mask, loc), @@ -2409,7 +2246,7 @@ def find_mask_from_size(size_var): start = args[0] size_var = args[1] try: - step = self.func_ir.get_definition(args[2]) + step = pass_states.func_ir.get_definition(args[2]) except KeyError: raise NotImplementedError( "Only known step size is supported for prange") @@ -2429,7 +2266,7 @@ def find_mask_from_size(size_var): index_var_typ = types.intp unsigned_index = False loops = [LoopNest(index_var, start, size_var, step)] - self.typemap[index_var.name] = index_var_typ + pass_states.typemap[index_var.name] = index_var_typ # We can't just drop the header block since there can be things # in there other than the prange looping infrastructure. @@ -2449,11 +2286,16 @@ def find_mask_from_size(size_var): orig_index_var if mask_indices else index_var, equiv_set, ("prange", loop_kind, loop_replacing), - self.flags, races=races) + pass_states.flags, races=races) # add parfor to entry block's jump target jump = blocks[entry].body[-1] jump.target = list(loop.exits)[0] blocks[jump.target].body.insert(0, parfor) + self.rewritten.append(dict( + old_loop=loop, + new=parfor, + reason='prange', + )) # remove loop blocks from top level dict blocks.pop(loop.header) for l in body_labels: @@ -2462,6 +2304,80 @@ def find_mask_from_size(size_var): print("parfor from loop") parfor.dump() + def _is_parallel_loop(self, func_var, call_table): + # prange can be either getattr (numba.prange) or global (prange) + if func_var not in call_table: + return False + call = call_table[func_var] + return len(call) > 0 and (call[0] == 'prange' or call[0] == prange + or call[0] == 'internal_prange' or call[0] == internal_prange + or call[0] == 'pndindex' or call[0] == pndindex) + + def _get_loop_kind(self, func_var, call_table): + """see if prange is user prange or internal""" + pass_states = self.pass_states + # prange can be either getattr (numba.prange) or global (prange) + assert func_var in call_table + call = call_table[func_var] + assert len(call) > 0 + kind = 'user', '' + if call[0] == 'internal_prange' or call[0] == internal_prange: + try: + kind = 'internal', (pass_states.swapped_fns[func_var][0], pass_states.swapped_fns[func_var][-1]) + except KeyError: + # FIXME: Fix this issue... the code didn't manage to trace the + # swapout for func_var so set the kind as internal so that the + # transform can occur, it's just not tracked + kind = 'internal', ('', '') + elif call[0] == 'pndindex' or call[0] == pndindex: + kind = 'pndindex', '' + return kind + + def _get_prange_init_block(self, entry_block, call_table, prange_args): + """ + If there is init_prange, find the code between init_prange and prange + calls. Remove the code from entry_block and return it. + """ + init_call_ind = -1 + prange_call_ind = -1 + init_body = [] + for i, inst in enumerate(entry_block.body): + # if init_prange call + if (isinstance(inst, ir.Assign) and isinstance(inst.value, ir.Expr) + and inst.value.op == 'call' + and self._is_prange_init(inst.value.func.name, call_table)): + init_call_ind = i + if (isinstance(inst, ir.Assign) and isinstance(inst.value, ir.Expr) + and inst.value.op == 'call' + and self._is_parallel_loop(inst.value.func.name, call_table)): + prange_call_ind = i + if init_call_ind != -1 and prange_call_ind != -1: + # we save instructions that are used to calculate prange call args + # in the entry block. The rest go to parfor init_block + arg_related_vars = {v.name for v in prange_args} + saved_nodes = [] + for i in reversed(range(init_call_ind+1, prange_call_ind)): + inst = entry_block.body[i] + inst_vars = {v.name for v in inst.list_vars()} + if arg_related_vars & inst_vars: + arg_related_vars |= inst_vars + saved_nodes.append(inst) + else: + init_body.append(inst) + + init_body.reverse() + saved_nodes.reverse() + entry_block.body = (entry_block.body[:init_call_ind] + + saved_nodes + entry_block.body[prange_call_ind+1:]) + + return init_body + + def _is_prange_init(self, func_var, call_table): + if func_var not in call_table: + return False + call = call_table[func_var] + return len(call) > 0 and (call[0] == 'init_prange' or call[0] == init_prange) + def _replace_loop_access_indices(self, loop_body, index_set, new_index): """ Replace array access indices in a loop body with a new index. @@ -2501,7 +2417,7 @@ def _replace_loop_access_indices(self, loop_body, index_set, new_index): # statics can have none indices if index is None: continue - ind_def = guard(get_definition, self.func_ir, + ind_def = guard(get_definition, self.pass_states.func_ir, index, lhs_only=True) if (index.name in index_set or (ind_def is not None @@ -2524,16 +2440,196 @@ def _replace_multi_dim_ind(self, ind_var, index_set, new_index): replace individual indices in multi-dimensional access variable, which is a build_tuple """ + pass_states = self.pass_states require(ind_var is not None) # check for Tuple instead of UniTuple since some dims could be slices - require(isinstance(self.typemap[ind_var.name], + require(isinstance(pass_states.typemap[ind_var.name], (types.Tuple, types.UniTuple))) - ind_def_node = get_definition(self.func_ir, ind_var) + ind_def_node = get_definition(pass_states.func_ir, ind_var) require(isinstance(ind_def_node, ir.Expr) and ind_def_node.op == 'build_tuple') ind_def_node.items = [new_index if v.name in index_set else v for v in ind_def_node.items] + +def _find_mask(typemap, func_ir, arr_def): + """check if an array is of B[...M...], where M is a + boolean array, and other indices (if available) are ints. + If found, return B, M, M's type, and a tuple representing mask indices. + Otherwise, raise GuardException. + """ + require(isinstance(arr_def, ir.Expr) and arr_def.op == 'getitem') + value = arr_def.value + index = arr_def.index + value_typ = typemap[value.name] + index_typ = typemap[index.name] + ndim = value_typ.ndim + require(isinstance(value_typ, types.npytypes.Array)) + if (isinstance(index_typ, types.npytypes.Array) and + isinstance(index_typ.dtype, types.Boolean) and + ndim == index_typ.ndim): + return value, index, index_typ.dtype, None + elif isinstance(index_typ, types.BaseTuple): + # Handle multi-dimension differently by requiring + # all indices to be constant except the one for mask. + seq, op = find_build_sequence(func_ir, index) + require(op == 'build_tuple' and len(seq) == ndim) + count_consts = 0 + mask_indices = [] + mask_var = None + for ind in seq: + index_typ = typemap[ind.name] + if (isinstance(index_typ, types.npytypes.Array) and + isinstance(index_typ.dtype, types.Boolean)): + mask_var = ind + mask_typ = index_typ.dtype + mask_indices.append(None) + elif (isinstance(index_typ, types.npytypes.Array) and + isinstance(index_typ.dtype, types.Integer)): + mask_var = ind + mask_typ = index_typ.dtype + mask_indices.append(None) + elif isinstance(index_typ, types.Integer): + count_consts += 1 + mask_indices.append(ind) + require(mask_var and count_consts == ndim - 1) + return value, mask_var, mask_typ, mask_indices + raise GuardException + + +class ParforPass(ParforPassStates): + + """ParforPass class is responsible for converting Numpy + calls in Numba intermediate representation to Parfors, which + will lower into either sequential or parallel loops during lowering + stage. + """ + + def _pre_run(self): + # run array analysis, a pre-requisite for parfor translation + remove_dels(self.func_ir.blocks) + self.array_analysis.run(self.func_ir.blocks) + + def run(self): + """run parfor conversion pass: replace Numpy calls + with Parfors when possible and optimize the IR.""" + self._pre_run() + # run stencil translation to parfor + if self.options.stencil: + stencil_pass = StencilPass(self.func_ir, self.typemap, self.calltypes, + self.array_analysis, self.typingctx, self.flags) + stencil_pass.run() + if self.options.setitem: + ConvertSetItemPass(self).run(self.func_ir.blocks) + if self.options.numpy: + ConvertNumpyPass(self).run(self.func_ir.blocks) + if self.options.reduction: + ConvertReducePass(self).run(self.func_ir.blocks) + if self.options.prange: + ConvertLoopPass(self).run(self.func_ir.blocks) + + # setup diagnostics now parfors are found + self.diagnostics.setup(self.func_ir, self.options.fusion) + + dprint_func_ir(self.func_ir, "after parfor pass") + + # simplify CFG of parfor body loops since nested parfors with extra + # jumps can be created with prange conversion + simplify_parfor_body_CFG(self.func_ir.blocks) + # simplify before fusion + simplify(self.func_ir, self.typemap, self.calltypes) + # need two rounds of copy propagation to enable fusion of long sequences + # of parfors like test_fuse_argmin (some PYTHONHASHSEED values since + # apply_copies_parfor depends on set order for creating dummy assigns) + simplify(self.func_ir, self.typemap, self.calltypes) + + if self.options.fusion: + self.func_ir._definitions = build_definitions(self.func_ir.blocks) + self.array_analysis.equiv_sets = dict() + self.array_analysis.run(self.func_ir.blocks) + # reorder statements to maximize fusion + # push non-parfors down + maximize_fusion(self.func_ir, self.func_ir.blocks, self.typemap, + up_direction=False) + dprint_func_ir(self.func_ir, "after maximize fusion down") + self.fuse_parfors(self.array_analysis, self.func_ir.blocks) + # push non-parfors up + maximize_fusion(self.func_ir, self.func_ir.blocks, self.typemap) + dprint_func_ir(self.func_ir, "after maximize fusion up") + # try fuse again after maximize + self.fuse_parfors(self.array_analysis, self.func_ir.blocks) + dprint_func_ir(self.func_ir, "after fusion") + # simplify again + simplify(self.func_ir, self.typemap, self.calltypes) + # push function call variables inside parfors so gufunc function + # wouldn't need function variables as argument + push_call_vars(self.func_ir.blocks, {}, {}, self.typemap) + dprint_func_ir(self.func_ir, "after push call vars") + # simplify again + simplify(self.func_ir, self.typemap, self.calltypes) + dprint_func_ir(self.func_ir, "after optimization") + if config.DEBUG_ARRAY_OPT >= 1: + print("variable types: ", sorted(self.typemap.items())) + print("call types: ", self.calltypes) + + if config.DEBUG_ARRAY_OPT >= 3: + for(block_label, block) in self.func_ir.blocks.items(): + new_block = [] + scope = block.scope + for stmt in block.body: + new_block.append(stmt) + if isinstance(stmt, ir.Assign): + loc = stmt.loc + lhs = stmt.target + rhs = stmt.value + lhs_typ = self.typemap[lhs.name] + print("Adding print for assignment to ", lhs.name, lhs_typ, type(lhs_typ)) + if lhs_typ in types.number_domain or isinstance(lhs_typ, types.Literal): + str_var = ir.Var(scope, mk_unique_var("str_var"), loc) + self.typemap[str_var.name] = types.StringLiteral(lhs.name) + lhs_const = ir.Const(lhs.name, loc) + str_assign = ir.Assign(lhs_const, str_var, loc) + new_block.append(str_assign) + str_print = ir.Print([str_var], None, loc) + self.calltypes[str_print] = signature(types.none, self.typemap[str_var.name]) + new_block.append(str_print) + ir_print = ir.Print([lhs], None, loc) + self.calltypes[ir_print] = signature(types.none, lhs_typ) + new_block.append(ir_print) + block.body = new_block + + # run post processor again to generate Del nodes + post_proc = postproc.PostProcessor(self.func_ir) + post_proc.run() + if self.func_ir.is_generator: + fix_generator_types(self.func_ir.generator_info, self.return_type, + self.typemap) + if sequential_parfor_lowering: + lower_parfor_sequential( + self.typingctx, self.func_ir, self.typemap, self.calltypes) + else: + # prepare for parallel lowering + # add parfor params to parfors here since lowering is destructive + # changing the IR after this is not allowed + parfor_ids, parfors = get_parfor_params(self.func_ir.blocks, + self.options.fusion, + self.nested_fusion_info) + for p in parfors: + get_parfor_reductions(self.func_ir, p, p.params, self.calltypes) + if config.DEBUG_ARRAY_OPT_STATS: + name = self.func_ir.func_id.func_qualname + n_parfors = len(parfor_ids) + if n_parfors > 0: + after_fusion = ("After fusion" if self.options.fusion + else "With fusion disabled") + print(('{}, function {} has ' + '{} parallel for-loop(s) #{}.').format( + after_fusion, name, n_parfors, parfor_ids)) + else: + print('Function {} has no Parfor.'.format(name)) + + return + def _find_mask(self, arr_def): """check if an array is of B[...M...], where M is a boolean array, and other indices (if available) are ints. @@ -2543,78 +2639,6 @@ def _find_mask(self, arr_def): return _find_mask(self.typemap, self.func_ir, arr_def) - def _get_prange_init_block(self, entry_block, call_table, prange_args): - """ - If there is init_prange, find the code between init_prange and prange - calls. Remove the code from entry_block and return it. - """ - init_call_ind = -1 - prange_call_ind = -1 - init_body = [] - for i, inst in enumerate(entry_block.body): - # if init_prange call - if (isinstance(inst, ir.Assign) and isinstance(inst.value, ir.Expr) - and inst.value.op == 'call' - and self._is_prange_init(inst.value.func.name, call_table)): - init_call_ind = i - if (isinstance(inst, ir.Assign) and isinstance(inst.value, ir.Expr) - and inst.value.op == 'call' - and self._is_parallel_loop(inst.value.func.name, call_table)): - prange_call_ind = i - if init_call_ind != -1 and prange_call_ind != -1: - # we save instructions that are used to calculate prange call args - # in the entry block. The rest go to parfor init_block - arg_related_vars = {v.name for v in prange_args} - saved_nodes = [] - for i in reversed(range(init_call_ind+1, prange_call_ind)): - inst = entry_block.body[i] - inst_vars = {v.name for v in inst.list_vars()} - if arg_related_vars & inst_vars: - arg_related_vars |= inst_vars - saved_nodes.append(inst) - else: - init_body.append(inst) - - init_body.reverse() - saved_nodes.reverse() - entry_block.body = (entry_block.body[:init_call_ind] - + saved_nodes + entry_block.body[prange_call_ind+1:]) - - return init_body - - def _is_prange_init(self, func_var, call_table): - if func_var not in call_table: - return False - call = call_table[func_var] - return len(call) > 0 and (call[0] == 'init_prange' or call[0] == init_prange) - - def _is_parallel_loop(self, func_var, call_table): - # prange can be either getattr (numba.prange) or global (prange) - if func_var not in call_table: - return False - call = call_table[func_var] - return len(call) > 0 and (call[0] == 'prange' or call[0] == prange - or call[0] == 'internal_prange' or call[0] == internal_prange - or call[0] == 'pndindex' or call[0] == pndindex) - - def _get_loop_kind(self, func_var, call_table): - """see if prange is user prange or internal""" - # prange can be either getattr (numba.prange) or global (prange) - assert func_var in call_table - call = call_table[func_var] - assert len(call) > 0 - kind = 'user', '' - if call[0] == 'internal_prange' or call[0] == internal_prange: - try: - kind = 'internal', (self.swapped_fns[func_var][0], self.swapped_fns[func_var][-1]) - except KeyError: - # FIXME: Fix this issue... the code didn't manage to trace the - # swapout for func_var so set the kind as internal so that the - # transform can occur, it's just not tracked - kind = 'internal', ('', '') - elif call[0] == 'pndindex' or call[0] == pndindex: - kind = 'pndindex', '' - return kind def _mk_parfor_loops(self, size_vars, scope, loc): """ diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py index 81aebbbe21e..ea523371e22 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_components.py @@ -6,7 +6,7 @@ import numpy as np -from numba import njit, typeof +from numba import njit, typeof, prange, pndindex import numba.parfors.parfor from numba.core import ( typing, @@ -123,7 +123,7 @@ def run_parallel_check_output_array(self, func, *args, **kwargs): def check_records(self, records): for rec in records: - self.assertIsInstance(rec['new'], numba.parfors.parfor.Parfor) + self.assertIsInstance(rec["new"], numba.parfors.parfor.Parfor) class TestConvertSetItemPass(BaseTest): @@ -240,18 +240,13 @@ def test_impl(): self.run_parallel_check_output_array(test_impl) def test_numpy_allocators(self): - fns = [ - np.ones, - np.zeros, - ] + fns = [np.ones, np.zeros] for fn in fns: with self.subTest(fn.__name__): self.check_numpy_allocators(fn) def test_numpy_random(self): - fns = [ - np.random.random, - ] + fns = [np.random.random] for fn in fns: with self.subTest(fn.__name__): self.check_numpy_random(fn) @@ -310,5 +305,172 @@ def test_impl(arr): self.run_parallel(test_impl, *args) +class TestConvertLoopPass(BaseTest): + sub_pass_class = numba.parfors.parfor.ConvertLoopPass + + def test_prange_reduce_simple(self): + def test_impl(): + n = 20 + c = 0 + for i in prange(n): + c += i + return c + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "prange") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) + + def test_prange_map_simple(self): + def test_impl(): + n = 20 + arr = np.ones(n) + for i in prange(n): + arr[i] += i + return arr + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "prange") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) + + def test_prange_two_args(self): + def test_impl(): + n = 20 + arr = np.ones(n) + for i in prange(3, n): + arr[i] += i + return arr + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "prange") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) + + def test_prange_three_args(self): + def test_impl(): + n = 20 + arr = np.ones(n) + for i in prange(3, n, 2): + arr[i] += i + return arr + + with self.assertRaises(NotImplementedError) as raises: + self.run_parfor_sub_pass(test_impl, ()) + self.assertIn( + "Only constant step size of 1 is supported for prange", + str(raises.exception), + ) + + def test_prange_map_inner_loop(self): + def test_impl(): + n = 20 + arr = np.ones((n, n)) + for i in prange(n): + for j in range(i): + arr[i, j] += i + j * n + return arr + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "prange") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl) + + def test_prange_map_nested_prange(self): + def test_impl(): + n = 20 + arr = np.ones((n, n)) + for i in prange(n): + for j in prange(i): + arr[i, j] += i + j * n + return arr + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 2) + self.check_records(sub_pass.rewritten) + for record in sub_pass.rewritten: + self.assertEqual(record["reason"], "prange") + + self.run_parallel(test_impl) + + def test_prange_map_none_index(self): + def test_impl(): + n = 20 + arr = np.ones(n) + for i in prange(n): + inner = arr[i : i + 1] + inner[()] += 1 + return arr + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + self.check_records(sub_pass.rewritten) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "prange") + + self.run_parallel(test_impl) + + def test_prange_map_overwrite_index(self): + def test_impl(): + n = 20 + arr = np.ones(n) + for i in prange(n): + i += 1 + arr[i] = i + return arr + + with self.assertRaises(ValueError) as raises: + self.run_parfor_sub_pass(test_impl, ()) + self.assertIn("Overwrite of parallel loop index", str(raises.exception)) + + def test_init_prange(self): + def test_impl(): + n = 20 + arr = np.ones(n) + numba.parfors.parfor.init_prange() + val = 0 + for i in numba.parfors.parfor.internal_prange(len(arr)): + val += arr[i] + return val + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + self.check_records(sub_pass.rewritten) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "prange") + + self.run_parallel(test_impl) + + def test_pndindex(self): + def test_impl(): + n = 20 + arr = np.ones((n, n)) + val = 0 + for idx in pndindex(arr.shape): + val += idx[0] * idx[1] + return val + + sub_pass = self.run_parfor_sub_pass(test_impl, ()) + self.assertEqual(len(sub_pass.rewritten), 1) + self.check_records(sub_pass.rewritten) + + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "prange") + + self.run_parallel(test_impl) + + if __name__ == "__main__": unittest.main() From 2065ea8919b7461a32d7d36b91c6b82315d46a7e Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 19 Feb 2020 16:56:28 -0600 Subject: [PATCH 555/595] Improving coverage --- numba/parfors/parfor.py | 59 +++----------- numba/tests/test_parfors_components.py | 107 +++++++++++++++++++++++-- 2 files changed, 112 insertions(+), 54 deletions(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index a8ee55791b1..b083c9304c6 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -1363,6 +1363,7 @@ def replace_func(): func_def = get_definition(self.func_ir, expr.func) callname = find_callname(self.func_ir, expr) repl_func = replace_functions_map.get(callname, None) + # Handle method on array type if (repl_func is None and len(callname) == 2 and isinstance(callname[1], ir.Var) and @@ -1947,7 +1948,8 @@ def _reduce_to_parfor(self, equiv_set, lhs, args, loc): index_vars, loopnests = _mk_parfor_loops(pass_states.typemap, size_vars, scope, loc) mask_index = index_vars if mask_indices: - assert False, "DEAD" + # the following is never tested + raise AssertionError("unreachable") index_vars = tuple(x if x else index_vars[0] for x in mask_indices) acc_var = lhs @@ -1960,7 +1962,8 @@ def _reduce_to_parfor(self, equiv_set, lhs, args, loc): index_var, loop_body = self._mk_reduction_body(call_name, scope, loc, index_vars, in_arr, acc_var) if mask_indices: - assert False, "DEAD" + # the following is never tested + raise AssertionError("unreachable") index_var = mask_index[0] if mask_var != None: @@ -2294,7 +2297,7 @@ def find_mask_from_size(size_var): self.rewritten.append(dict( old_loop=loop, new=parfor, - reason='prange', + reason='loop', )) # remove loop blocks from top level dict blocks.pop(loop.header) @@ -2479,19 +2482,25 @@ def _find_mask(typemap, func_ir, arr_def): mask_var = None for ind in seq: index_typ = typemap[ind.name] + # Handle boolean mask if (isinstance(index_typ, types.npytypes.Array) and isinstance(index_typ.dtype, types.Boolean)): mask_var = ind mask_typ = index_typ.dtype mask_indices.append(None) + # Handle integer array selector elif (isinstance(index_typ, types.npytypes.Array) and isinstance(index_typ.dtype, types.Integer)): mask_var = ind mask_typ = index_typ.dtype mask_indices.append(None) + # Handle integer index elif isinstance(index_typ, types.Integer): + # The follow is never tested + raise AssertionError('unreachable') count_consts += 1 mask_indices.append(ind) + require(mask_var and count_consts == ndim - 1) return value, mask_var, mask_typ, mask_indices raise GuardException @@ -2638,55 +2647,12 @@ def _find_mask(self, arr_def): """ return _find_mask(self.typemap, self.func_ir, arr_def) - - def _mk_parfor_loops(self, size_vars, scope, loc): """ Create loop index variables and build LoopNest objects for a parfor. """ return _mk_parfor_loops(self.typemap, size_vars, scope, loc) - def _mk_reduction_body(self, call_name, scope, loc, - index_vars, in_arr, acc_var): - """ - Produce the body blocks for a reduction function indicated by call_name. - """ - from numba.core.inline_closurecall import check_reduce_func - reduce_func = get_definition(self.func_ir, call_name) - fcode = check_reduce_func(self.func_ir, reduce_func) - - arr_typ = self.typemap[in_arr.name] - in_typ = arr_typ.dtype - body_block = ir.Block(scope, loc) - index_var, index_var_type = _make_index_var( - self.typemap, scope, index_vars, body_block) - - tmp_var = ir.Var(scope, mk_unique_var("$val"), loc) - self.typemap[tmp_var.name] = in_typ - getitem_call = ir.Expr.getitem(in_arr, index_var, loc) - self.calltypes[getitem_call] = signature( - in_typ, arr_typ, index_var_type) - body_block.append(ir.Assign(getitem_call, tmp_var, loc)) - - reduce_f_ir = compile_to_numba_ir(fcode, - self.func_ir.func_id.func.__globals__, - self.typingctx, - (in_typ, in_typ), - self.typemap, - self.calltypes) - loop_body = reduce_f_ir.blocks - end_label = next_label() - end_block = ir.Block(scope, loc) - loop_body[end_label] = end_block - first_reduce_label = min(reduce_f_ir.blocks.keys()) - first_reduce_block = reduce_f_ir.blocks[first_reduce_label] - body_block.body.extend(first_reduce_block.body) - first_reduce_block.body = body_block.body - replace_arg_nodes(first_reduce_block, [acc_var, tmp_var]) - replace_returns(loop_body, acc_var, end_label) - return index_var, loop_body - - def fuse_parfors(self, array_analysis, blocks): for label, block in blocks.items(): equiv_set = array_analysis.get_equiv_set(label) @@ -2731,6 +2697,7 @@ def fuse_recursive_parfor(self, parfor, equiv_set): self.fuse_parfors(arr_analysis, blocks) unwrap_parfor_blocks(parfor) + def _remove_size_arg(call_name, expr): "remove size argument from args or kws" # remove size kwarg diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py index ea523371e22..0929a429ffc 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_components.py @@ -319,7 +319,7 @@ def test_impl(): sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.check_records(sub_pass.rewritten) self.run_parallel(test_impl) @@ -335,7 +335,7 @@ def test_impl(): sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.check_records(sub_pass.rewritten) self.run_parallel(test_impl) @@ -351,7 +351,7 @@ def test_impl(): sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.check_records(sub_pass.rewritten) self.run_parallel(test_impl) @@ -383,7 +383,7 @@ def test_impl(): sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.check_records(sub_pass.rewritten) self.run_parallel(test_impl) @@ -401,7 +401,7 @@ def test_impl(): self.assertEqual(len(sub_pass.rewritten), 2) self.check_records(sub_pass.rewritten) for record in sub_pass.rewritten: - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.run_parallel(test_impl) @@ -418,7 +418,7 @@ def test_impl(): self.assertEqual(len(sub_pass.rewritten), 1) self.check_records(sub_pass.rewritten) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.run_parallel(test_impl) @@ -449,7 +449,7 @@ def test_impl(): self.assertEqual(len(sub_pass.rewritten), 1) self.check_records(sub_pass.rewritten) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.run_parallel(test_impl) @@ -467,10 +467,101 @@ def test_impl(): self.check_records(sub_pass.rewritten) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "prange") + self.assertEqual(record["reason"], "loop") self.run_parallel(test_impl) + def test_numpy_sum(self): + def test_impl(arr): + return np.sum(arr) + + shape = 11, 13 + arr = np.arange(np.prod(shape)).reshape(shape) + args = (arr,) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "loop") + self.check_records(sub_pass.rewritten) + self.run_parallel(test_impl, *args) + + def test_numpy_sum_bool_array_masked(self): + def test_impl(arr): + sliced = arr[:, 0] + return np.sum(arr[sliced >= 3, 1:2]) + + shape = 11, 13 + arr = np.arange(np.prod(shape)).reshape(shape) + args = (arr,) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "loop") + self.check_records(sub_pass.rewritten) + self.run_parallel(test_impl, *args) + + def test_numpy_sum_int_array_masked(self): + def test_impl(arr): + sel = np.arange(arr.shape[1]) + return np.sum(arr[:, sel]) + + shape = 11, 13 + arr = np.arange(np.prod(shape)).reshape(shape) + args = (arr,) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + # 1 for arange; 1 for sum + self.assertEqual(len(sub_pass.rewritten), 2) + for record in sub_pass.rewritten: + self.assertEqual(record["reason"], "loop") + self.check_records(sub_pass.rewritten) + self.run_parallel(test_impl, *args) + + def test_numpy_fill_method(self): + def test_impl(arr): + arr.fill(3) + return arr + + shape = 11, 13 + arr = np.arange(np.prod(shape)).reshape(shape) + args = (arr,) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + # 1 for arange; 1 for sum + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "loop") + self.check_records(sub_pass.rewritten) + self.run_parallel(test_impl, *args) + + +class TestPreParforPass(BaseTest): + class sub_pass_class: + def __init__(self, pass_states): + pass + + def run(self, blocks): + pass + + def test_dtype_conversion(self): + # array.dtype are converted to np.dtype(array) in the PreParforPass + def test_impl(a): + b = np.ones(20, dtype=a.dtype) + return b + + arr = np.arange(10) + args = (arr,) + argtypes = [typeof(x) for x in args] + + self.run_parfor_sub_pass(test_impl, argtypes) + self.run_parallel(test_impl, *args) + if __name__ == "__main__": unittest.main() From 14a1a04e3634d4d9f27dd35ae11a99f93f7be8ce Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 19 Feb 2020 17:47:02 -0600 Subject: [PATCH 556/595] Improving coverage --- numba/parfors/parfor.py | 3 ++ numba/tests/test_parfors_components.py | 54 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index b083c9304c6..8d5f5a2b88f 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -2908,6 +2908,7 @@ def _gen_arrayexpr_getitem( num_indices = len(all_parfor_indices) size_vars = equiv_set.get_shape(var) or [] size_consts = [equiv_set.get_equiv_const(x) for x in size_vars] + # Handle array-scalar if ndims == 0: # call np.ravel ravel_var = ir.Var(var.scope, mk_unique_var("$ravel"), loc) @@ -2923,9 +2924,11 @@ def _gen_arrayexpr_getitem( const_assign = ir.Assign(const_node, const_var, loc) out_ir.append(const_assign) index_var = const_var + # Handle 1d array elif ndims == 1: # Use last index for 1D arrays index_var = all_parfor_indices[-1] + # Handle known constant size elif any([x != None for x in size_consts]): # Need a tuple as index ind_offset = num_indices - ndims diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py index 0929a429ffc..d8361ae3002 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_components.py @@ -268,6 +268,60 @@ def test_impl(a, b): self.run_parallel(test_impl, *args) + def test_numpy_arrayexpr_ufunc(self): + def test_impl(a, b): + return np.sin(-a) + np.float64(1) / np.sqrt(b) + + a = b = np.ones(10) + + args = (a, b) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "arrayexpr") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl, *args) + + def test_numpy_arrayexpr_boardcast(self): + def test_impl(a, b): + return a + b + np.array(1) + + a = np.ones(10) + b = np.ones((3, 10)) + + args = (a, b) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "arrayexpr") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl, *args) + + def test_numpy_arrayexpr_reshaped(self): + def test_impl(a, b): + a = a.reshape(1, a.size) # shape[0] is now constant + return a + b + + a = np.ones(10) + b = np.ones(10) + + args = (a, b) + argtypes = [typeof(x) for x in args] + + sub_pass = self.run_parfor_sub_pass(test_impl, argtypes) + self.assertEqual(len(sub_pass.rewritten), 1) + [record] = sub_pass.rewritten + self.assertEqual(record["reason"], "arrayexpr") + self.check_records(sub_pass.rewritten) + + self.run_parallel(test_impl, *args) + class TestConvertReducePass(BaseTest): sub_pass_class = numba.parfors.parfor.ConvertReducePass From e7a2c40fdbce49e49373c254028232e4abb709dd Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 19 Feb 2020 18:02:21 -0600 Subject: [PATCH 557/595] Add test for PreParforPass --- numba/parfors/parfor.py | 7 +++ numba/tests/test_parfors_components.py | 67 ++++++++++++++++++-------- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 8d5f5a2b88f..cfb38bdd187 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -1329,7 +1329,12 @@ def __init__(self, func_ir, typemap, calltypes, typingctx, options, self.calltypes = calltypes self.typingctx = typingctx self.options = options + # diagnostics self.swapped = swapped + self.stats = { + 'replaced_func': 0, + 'replaced_dtype': 0, + } def run(self): """Run pre-parfor processing pass. @@ -1405,6 +1410,7 @@ def replace_func(): break return True if guard(replace_func): + self.stats['replaced_func'] += 1 break elif (isinstance(expr, ir.Expr) and expr.op == 'getattr' and expr.attr == 'dtype'): @@ -1464,6 +1470,7 @@ def replace_func(): block.body.insert(0, dtype_attr_assign) block.body.insert(0, typ_var_assign) block.body.insert(0, g_np_assign) + self.stats['replaced_dtype'] += 1 break def find_template(op): diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_components.py index d8361ae3002..c7444bb84b0 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_components.py @@ -1,5 +1,6 @@ """ Tests for sub-components of parfors. +These tests are aimed to produce a good coverage of parfor passes. """ import unittest from functools import reduce @@ -34,16 +35,13 @@ def __init__(self, typingctx, targetctx, args, test_ir): class BaseTest(TestCase): @classmethod - def run_parfor_sub_pass(cls, test_func, args, **kws): + def _run_parfor(cls, test_func, args): # TODO: refactor this with get_optimized_numba_ir() where this is # copied from typingctx = typing.Context() targetctx = cpu.CPUContext(typingctx) test_ir = compiler.run_frontend(test_func) - if kws: - options = cpu.ParallelOptions(kws) - else: - options = cpu.ParallelOptions(True) + options = cpu.ParallelOptions(True) tp = MyPipeline(typingctx, targetctx, args, test_ir) @@ -79,25 +77,37 @@ def run_parfor_sub_pass(cls, test_func, args, **kws): preparfor_pass.run() rewrites.rewrite_registry.apply("after-inference", tp.state) + return tp, options, diagnostics, preparfor_pass - flags = compiler.Flags() - parfor_pass = numba.parfors.parfor.ParforPass( - tp.state.func_ir, - tp.state.typemap, - tp.state.calltypes, - tp.state.return_type, - tp.state.typingctx, - options, - flags, - diagnostics=diagnostics, - ) - parfor_pass._pre_run() - # Run subpass - sub_pass = cls.sub_pass_class(parfor_pass) - sub_pass.run(parfor_pass.func_ir.blocks) + @classmethod + def run_parfor_sub_pass(cls, test_func, args): + tp, options, diagnostics, _ = cls._run_parfor(test_func, args) + + flags = compiler.Flags() + parfor_pass = numba.parfors.parfor.ParforPass( + tp.state.func_ir, + tp.state.typemap, + tp.state.calltypes, + tp.state.return_type, + tp.state.typingctx, + options, + flags, + diagnostics=diagnostics, + ) + parfor_pass._pre_run() + # Run subpass + sub_pass = cls.sub_pass_class(parfor_pass) + sub_pass.run(parfor_pass.func_ir.blocks) return sub_pass + @classmethod + def run_parfor_pre_pass(cls, test_func, args): + tp, options, diagnostics, preparfor_pass = cls._run_parfor( + test_func, args + ) + return preparfor_pass + def _run_parallel(self, func, *args, **kwargs): cfunc = njit(parallel=True)(func) expect = func(*args, **kwargs) @@ -613,7 +623,22 @@ def test_impl(a): args = (arr,) argtypes = [typeof(x) for x in args] - self.run_parfor_sub_pass(test_impl, argtypes) + pre_pass = self.run_parfor_pre_pass(test_impl, argtypes) + self.assertEqual(pre_pass.stats["replaced_func"], 0) + self.assertEqual(pre_pass.stats["replaced_dtype"], 1) + self.run_parallel(test_impl, *args) + + def test_sum_replacement(self): + def test_impl(a): + return np.sum(a) + + arr = np.arange(10) + args = (arr,) + argtypes = [typeof(x) for x in args] + + pre_pass = self.run_parfor_pre_pass(test_impl, argtypes) + self.assertEqual(pre_pass.stats["replaced_func"], 1) + self.assertEqual(pre_pass.stats["replaced_dtype"], 0) self.run_parallel(test_impl, *args) From 328cfacb126ee6523b518690c79e0e19d3820c51 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 19 Feb 2020 18:09:07 -0600 Subject: [PATCH 558/595] Rename file --- .../{test_parfors_components.py => test_parfors_passes.py} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename numba/tests/{test_parfors_components.py => test_parfors_passes.py} (99%) diff --git a/numba/tests/test_parfors_components.py b/numba/tests/test_parfors_passes.py similarity index 99% rename from numba/tests/test_parfors_components.py rename to numba/tests/test_parfors_passes.py index c7444bb84b0..0e1af63e95e 100644 --- a/numba/tests/test_parfors_components.py +++ b/numba/tests/test_parfors_passes.py @@ -1,6 +1,7 @@ """ Tests for sub-components of parfors. -These tests are aimed to produce a good coverage of parfor passes. +These tests are aimed to produce a good-enough coverage of parfor passes +so that refactoring on these passes are easier with faster testing turnaround. """ import unittest from functools import reduce From ca446a36e34a2324abcff8f663758c0887f053d2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 20 Feb 2020 10:22:03 +0000 Subject: [PATCH 559/595] Simple changes from review feedback. As title. --- numba/core/ir_utils.py | 6 +----- numba/core/postproc.py | 10 ++-------- numba/tests/test_ir.py | 4 +++- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py index a09dac8c61d..68ae3f15251 100644 --- a/numba/core/ir_utils.py +++ b/numba/core/ir_utils.py @@ -2060,15 +2060,11 @@ def enforce_no_dels(func_ir): """ Enforce there being no ir.Del nodes in the IR. """ - strict = True for blk in func_ir.blocks.values(): dels = [x for x in blk.find_insts(ir.Del)] if dels: msg = "Illegal IR, del found at: %s" % dels[0] - if strict: - raise CompilerError(msg, loc=dels[0].loc) - else: - warnings.warn(NumbaWarning(msg)) + raise CompilerError(msg, loc=dels[0].loc) def check_and_legalize_ir(func_ir): diff --git a/numba/core/postproc.py b/numba/core/postproc.py index 4ffd522ab6f..27b372e781d 100644 --- a/numba/core/postproc.py +++ b/numba/core/postproc.py @@ -1,4 +1,4 @@ -from numba.core import utils, ir, analysis, transforms +from numba.core import utils, ir, analysis, transforms, ir_utils class YieldPoint(object): @@ -219,10 +219,4 @@ def remove_dels(self): """ Strips the IR of Del nodes """ - for block in self.func_ir.blocks.values(): - new_body = [] - for stmt in block.body: - if not isinstance(stmt, ir.Del): - new_body.append(stmt) - block.body = new_body - return + ir_utils.remove_dels(self.func_ir.blocks) diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index a07acef9422..82350f0e4b8 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -436,7 +436,9 @@ def check_diffstr(string, pointing_at=[]): b[idx], b[idx + 1] = b[idx + 1], b[idx] break - assert change_set + # ensure that a mutation occurred. + self.asserTrue(change_set) + self.assertFalse(x_ir.equal_ir(z_ir)) self.assertEqual(len(change_set), 2) for item in change_set: From e9771378b64c9aa159eb6594007876dce34b311c Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 20 Feb 2020 11:25:40 +0000 Subject: [PATCH 560/595] Add tests for IR del enforcement --- .flake8 | 1 - numba/tests/test_pipeline.py | 79 ++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/.flake8 b/.flake8 index 657acca04b5..dbefed7e126 100644 --- a/.flake8 +++ b/.flake8 @@ -312,7 +312,6 @@ exclude = numba/tests/test_withlifting.py numba/tests/test_errorhandling.py numba/tests/test_parfors.py - numba/tests/test_pipeline.py numba/tests/test_sets.py numba/tests/test_dyn_array.py numba/tests/test_objects.py diff --git a/numba/tests/test_pipeline.py b/numba/tests/test_pipeline.py index e7091a5f104..98174aa0fa5 100644 --- a/numba/tests/test_pipeline.py +++ b/numba/tests/test_pipeline.py @@ -1,6 +1,10 @@ -from numba.core.compiler import Compiler -from numba import jit, generated_jit, objmode -from numba.core import types +from numba.core.compiler import Compiler, DefaultPassBuilder +from numba.core.compiler_machinery import (FunctionPass, AnalysisPass, + register_pass) +from numba.core.untyped_passes import InlineInlinables +from numba.core.typed_passes import IRLegalization +from numba import jit, generated_jit, objmode, njit +from numba.core import types, postproc, errors from numba.core.ir import FunctionIR from numba.tests.support import TestCase @@ -72,3 +76,72 @@ def foo(x): second = self.pipeline_class.custom_pipeline_cache[1] self.assertIsInstance(second, FunctionIR) + +class TestPassManagerFunctionality(TestCase): + + def _create_pipeline_w_del(self, base=None, inject_after=None): + """ + Creates a new compiler pipeline with the _InjectDelsPass injected after + the pass supplied in kwarg 'inject_after'. + """ + self.assertTrue(inject_after is not None) + self.assertTrue(base is not None) + + @register_pass(mutates_CFG=False, analysis_only=False) + class _InjectDelsPass(base): + """ + This pass injects ir.Del nodes into the IR + """ + _name = "inject_dels_%s" % str(base) + + def __init__(self): + base.__init__(self) + + def run_pass(self, state): + pp = postproc.PostProcessor(state.func_ir) + pp.run(emit_dels=True) + return True + + class TestCompiler(Compiler): + + def define_pipelines(self): + pm = DefaultPassBuilder.define_nopython_pipeline(self.state) + pm.add_pass_after(_InjectDelsPass, inject_after) + pm.finalize() + return [pm] + + return TestCompiler + + def test_compiler_error_on_ir_del_from_functionpass(self): + new_compiler = self._create_pipeline_w_del(FunctionPass, + InlineInlinables) + + @njit(pipeline_class=new_compiler) + def foo(x): + return x + 1 + + with self.assertRaises(errors.CompilerError) as raises: + foo(10) + + errstr = str(raises.exception) + + self.assertIn("Illegal IR, del found at:", errstr) + self.assertIn("del x", errstr) + + def test_no_compiler_error_on_ir_del_after_legalization(self): + # Legalization should be the last FunctionPass to execute so it's fine + # for it to emit ir.Del nodes as no further FunctionPasses will run and + # therefore the checking routine in the PassManager won't execute. + # This test adds a new pass that is an AnalysisPass into the pipeline + # after legalisation, this pass will return with already existing dels + # in the IR but by virtue of it being an AnalysisPass the checking + # routine won't execute. + + new_compiler = self._create_pipeline_w_del(AnalysisPass, + IRLegalization) + + @njit(pipeline_class=new_compiler) + def foo(x): + return x + 1 + + self.assertTrue(foo(10), foo.py_func(10)) From f4b8267967c0a305a9c7f22f554035deff5c5653 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 20 Feb 2020 11:31:50 +0000 Subject: [PATCH 561/595] Fix up test relying on ir.Del presence --- numba/tests/test_ir_utils.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/numba/tests/test_ir_utils.py b/numba/tests/test_ir_utils.py index 83e0d778160..6091a1092a7 100644 --- a/numba/tests/test_ir_utils.py +++ b/numba/tests/test_ir_utils.py @@ -39,7 +39,7 @@ def test_func(): typemap, _, _ = type_inference_stage( typingctx, test_ir, (), None) matched_call = ir_utils.find_callname( - test_ir, test_ir.blocks[0].body[14].value, typemap) + test_ir, test_ir.blocks[0].body[8].value, typemap) self.assertTrue(isinstance(matched_call, tuple) and len(matched_call) == 2 and matched_call[0] == 'append') @@ -87,16 +87,13 @@ def check_initial_ir(the_ir): # dead stuff: # a const int value 0xdead # an assign of above into to variable `dead` - # del of both of the above # a const int above 0xdeaddead # an assign of said int to variable `deaddead` - # del of both of the above - # this is 8 things to remove + # this is 4 things to remove self.assertEqual(len(the_ir.blocks), 1) block = the_ir.blocks[0] deads = [] - dels = [x for x in block.find_insts(ir.Del)] for x in block.find_insts(ir.Assign): if isinstance(getattr(x, 'target', None), ir.Var): if 'dead' in getattr(x.target, 'name', ''): @@ -105,7 +102,6 @@ def check_initial_ir(the_ir): expect_removed = [] self.assertEqual(len(deads), 2) expect_removed.extend(deads) - del_names = [x.value for x in dels] for d in deads: # check the ir.Const is the definition and the value is expected const_val = the_ir.get_definition(d.value) @@ -113,16 +109,7 @@ def check_initial_ir(the_ir): const_val.value) expect_removed.append(const_val) - # check there is a del for both sides of the assignment, one for - # the dead variable and one for which to it the const gets - # assigned - self.assertIn(d.value.name, del_names) - self.assertIn(d.target.name, del_names) - - for x in dels: - if x.value in (d.value.name, d.target.name): - expect_removed.append(x) - self.assertEqual(len(expect_removed), 8) + self.assertEqual(len(expect_removed), 4) return expect_removed def check_dce_ir(the_ir): @@ -130,7 +117,6 @@ def check_dce_ir(the_ir): block = the_ir.blocks[0] deads = [] consts = [] - dels = [x for x in block.find_insts(ir.Del)] for x in block.find_insts(ir.Assign): if isinstance(getattr(x, 'target', None), ir.Var): if 'dead' in getattr(x.target, 'name', ''): @@ -138,8 +124,6 @@ def check_dce_ir(the_ir): if isinstance(getattr(x, 'value', None), ir.Const): consts.append(x) self.assertEqual(len(deads), 0) - # check there's no mention of dead in dels - self.assertTrue(all(['dead' not in x.value for x in dels])) # check the consts to make sure there's no reference to 0xdead or # 0xdeaddead From 1312bba43b24ad179e934b3d4dacb7db06b6e5c8 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Thu, 20 Feb 2020 11:59:48 +0000 Subject: [PATCH 562/595] Fix typo As title. --- numba/tests/test_ir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/tests/test_ir.py b/numba/tests/test_ir.py index 82350f0e4b8..4c98caf3f0c 100644 --- a/numba/tests/test_ir.py +++ b/numba/tests/test_ir.py @@ -437,7 +437,7 @@ def check_diffstr(string, pointing_at=[]): break # ensure that a mutation occurred. - self.asserTrue(change_set) + self.assertTrue(change_set) self.assertFalse(x_ir.equal_ir(z_ir)) self.assertEqual(len(change_set), 2) From ae6a54e1d4de7fa14a4e487ee14719055c555f98 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Thu, 20 Feb 2020 12:20:59 -0600 Subject: [PATCH 563/595] Line wrap to 80 characters. --- docs/source/extending/entrypoints.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/source/extending/entrypoints.rst b/docs/source/extending/entrypoints.rst index 200a8e6db44..143c2e09015 100644 --- a/docs/source/extending/entrypoints.rst +++ b/docs/source/extending/entrypoints.rst @@ -48,12 +48,18 @@ extensions is undefined. Testing your Entry Point ------------------------ -Numba loads all entry points when the first function is compiled. To test your entry point, it is not sufficient to just ``import numba``; you have to define and run a small function, like this: +Numba loads all entry points when the first function is compiled. To test your +entry point, it is not sufficient to just ``import numba``; you have to define +and run a small function, like this: .. code-block:: python import numba; numba.njit(lambda x: x + 1)(123) -It is not necessary to import your module: entry points are identified by the ``entry_points.txt`` file in your library's ``*.egg-info`` directory. +It is not necessary to import your module: entry points are identified by the +``entry_points.txt`` file in your library's ``*.egg-info`` directory. -The ``setup.py build`` command does not create eggs, but ``setup.py sdist`` (for testing in a local directory) and ``setup.py install`` do. All entry points registered in eggs that are on the Python path are loaded. Be sure to check for stale ``entry_points.txt`` when debugging. +The ``setup.py build`` command does not create eggs, but ``setup.py sdist`` +(for testing in a local directory) and ``setup.py install`` do. All entry points +registered in eggs that are on the Python path are loaded. Be sure to check for +stale ``entry_points.txt`` when debugging. From f9b5d0dca7b91ce76d51c349879ddc1cb016e999 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 20 Feb 2020 16:00:51 -0600 Subject: [PATCH 564/595] Apply suggestions from code review Co-Authored-By: stuartarchibald --- numba/parfors/parfor.py | 4 ++-- numba/tests/test_parfors_passes.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index e13490265f7..9887cb2843a 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -1539,7 +1539,7 @@ def run(self, blocks): loc, target, index, value) self.rewritten.append( dict(old=instr, new=new_instr, - reason='masked_assign_boardcast_scalar'), + reason='masked_assign_broadcast_scalar'), ) instr = new_instr # RHS is an @@ -2514,7 +2514,7 @@ def _find_mask(typemap, func_ir, arr_def): class ParforPass(ParforPassStates): - """ParforPass class is responsible for converting Numpy + """ParforPass class is responsible for converting NumPy calls in Numba intermediate representation to Parfors, which will lower into either sequential or parallel loops during lowering stage. diff --git a/numba/tests/test_parfors_passes.py b/numba/tests/test_parfors_passes.py index 0e1af63e95e..c759333bafb 100644 --- a/numba/tests/test_parfors_passes.py +++ b/numba/tests/test_parfors_passes.py @@ -196,7 +196,7 @@ def test_impl(): sub_pass = self.run_parfor_sub_pass(test_impl, ()) self.assertEqual(len(sub_pass.rewritten), 1) [record] = sub_pass.rewritten - self.assertEqual(record["reason"], "masked_assign_boardcast_scalar") + self.assertEqual(record["reason"], "masked_assign_broadcast_scalar") self.check_records(sub_pass.rewritten) self.run_parallel(test_impl) From ee1385ecf9efd6fea78ff3a2bf21731203e99491 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 20 Feb 2020 16:00:57 -0600 Subject: [PATCH 565/595] Add docstrings --- numba/parfors/parfor.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py index 9887cb2843a..d0438aff769 100644 --- a/numba/parfors/parfor.py +++ b/numba/parfors/parfor.py @@ -1479,6 +1479,8 @@ def find_template(op): class ParforPassStates: + """This class encapsulates all internal states of the ParforPass. + """ def __init__(self, func_ir, typemap, calltypes, return_type, typingctx, options, flags, diagnostics=ParforDiagnostics()): @@ -1502,7 +1504,14 @@ def __init__(self, func_ir, typemap, calltypes, return_type, typingctx, class ConvertSetItemPass: + """Parfor subpass to convert setitem on Arrays + """ def __init__(self, pass_states): + """ + Parameters + ---------- + pass_states : ParforPassStates + """ self.pass_states = pass_states self.rewritten = [] @@ -1542,7 +1551,7 @@ def run(self, blocks): reason='masked_assign_broadcast_scalar'), ) instr = new_instr - # RHS is an + # RHS is an array elif isinstance(value_typ, types.npytypes.Array): val_def = guard(get_definition, pass_states.func_ir, value.name) From 51cdc7c36ac75f539e0c3f1d4a688a7396152493 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 20 Feb 2020 16:19:09 -0600 Subject: [PATCH 566/595] Move disabled_test --- numba/tests/support.py | 2 ++ numba/tests/test_parfors.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/numba/tests/support.py b/numba/tests/support.py index 14af940700f..dce1a91d5f8 100644 --- a/numba/tests/support.py +++ b/numba/tests/support.py @@ -78,6 +78,8 @@ _is_armv7l = platform.machine() == 'armv7l' +disabled_test = unittest.skipIf(True, 'Test disabled') + try: import scipy.linalg.cython_lapack has_lapack = True diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index 6dadf4c4ba4..eed32ad8452 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -38,12 +38,11 @@ from numba.tests.support import (TestCase, captured_stdout, MemoryLeakMixin, override_env_config, linux_only, tag, skip_parfors_unsupported, _32bit, needs_blas, - needs_lapack) + needs_lapack, disabled_test) import cmath import unittest -disabled_test = unittest.skipIf(True, 'Test disabled') x86_only = unittest.skipIf(platform.machine() not in ('i386', 'x86_64'), 'x86 only test') _GLOBAL_INT_FOR_TESTING1 = 17 From f4e5d1b0ad4dd1cbb2fb1c1776789f4a0b0094fe Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 28 Oct 2019 21:48:22 +0000 Subject: [PATCH 567/595] Add branch pruning based on raw predicates. As title. --- numba/core/analysis.py | 31 +++++ numba/tests/test_analysis.py | 235 ++++++++++++++++++++++++++++++++++- 2 files changed, 265 insertions(+), 1 deletion(-) diff --git a/numba/core/analysis.py b/numba/core/analysis.py index ad57b0f9b03..7a8363ffec3 100644 --- a/numba/core/analysis.py +++ b/numba/core/analysis.py @@ -347,6 +347,21 @@ def prune_by_value(branch, condition, blk, *conds): taken = do_prune(take_truebr, blk) return True, taken + def prune_by_predicate(branch, pred, blk): + try: + # Just to prevent accidents, whilst already guarded, ensure this + # is an ir.Const + if not isinstance(pred, (ir.Const, ir.FreeVar, ir.Global)): + raise TypeError + take_truebr = bool(pred.value) + except Exception: + return False, None + if DEBUG > 0: + kill = branch.falsebr if take_truebr else branch.truebr + print("Pruning %s" % kill, branch, pred) + taken = do_prune(take_truebr, blk) + return True, taken + class Unknown(object): pass @@ -383,6 +398,7 @@ def resolve_input_arg_const(input_arg_idx): # if the condition is met it will replace the branch with a jump branch_info = find_branches(func_ir) nullified_conditions = [] # stores conditions that have no impact post prune + for branch, condition, blk in branch_info: const_conds = [] if isinstance(condition, ir.Expr) and condition.op == 'binop': @@ -414,6 +430,21 @@ def resolve_input_arg_const(input_arg_idx): if(prune_stat): # add the condition to the list of nullified conditions nullified_conditions.append((condition, taken)) + else: + # see if this is a branch on a constant value predicate + resolved_const = Unknown() + try: + resolved_const = find_const(func_ir, branch.cond) + if resolved_const is None: + resolved_const = types.NoneType('none') + except GuardException: + pass + + if not isinstance(resolved_const, Unknown): + prune_stat, taken = prune_by_predicate(branch, condition, blk) + if(prune_stat): + # add the condition to the list of nullified conditions + nullified_conditions.append((condition, taken)) # 'ERE BE DRAGONS... # It is the evaluation of the condition expression that often trips up type diff --git a/numba/tests/test_analysis.py b/numba/tests/test_analysis.py index 2ab5682c5f1..89336d3b8ac 100644 --- a/numba/tests/test_analysis.py +++ b/numba/tests/test_analysis.py @@ -1,10 +1,11 @@ # Tests numba.analysis functions import collections +import types as pytypes import numpy as np from numba.core.compiler import compile_isolated, run_frontend, Flags, StateDict from numba import jit, njit -from numba.core import types, errors, ir, rewrites, ir_utils +from numba.core import types, errors, ir, rewrites, ir_utils, utils from numba.tests.support import TestCase, MemoryLeakMixin, SerialMixin from numba.core.analysis import dead_branch_prune, rewrite_semantic_constants @@ -563,6 +564,238 @@ def impl(array, x=None, a=None): np.zeros((2, 3)), 1.2, None) +class TestBranchPrunePredicates(TestBranchPruneBase, SerialMixin): + # Really important thing to remember... the branch on predicates end up as + # POP_JUMP_IF_ and the targets are backwards compared to normal, i.e. + # the true condition is far jump and the false the near i.e. `if x` would + # end up in Numba IR as e.g. `branch x 10, 6`. + + _TRUTHY = (1, "String", True, 7.4, 3j) + _FALSEY = (0, "", False, 0.0, 0j, None) + + def _literal_const_sample_generator(self, pyfunc, consts): + """ + This takes a python function, pyfunc, and manipulates its co_const + __code__ member to create a new function with different co_consts as + supplied in argument consts. + + consts is a dict {index: value} of co_const tuple index to constant + value used to update a pyfunc clone's co_const. + """ + pyfunc_code = pyfunc.__code__ + + # translate consts spec to update the constants + co_consts = {k: v for k, v in enumerate(pyfunc_code.co_consts)} + for k, v in consts.items(): + co_consts[k] = v + new_consts = tuple([v for _, v in sorted(co_consts.items())]) + + # create new code parts + co_args = [pyfunc_code.co_argcount] + + if utils.PYVERSION >= (3, 8): + co_args.append(pyfunc_code.co_posonlyargcount) + co_args.append(pyfunc_code.co_kwonlyargcount) + co_args.extend([pyfunc_code.co_nlocals, + pyfunc_code.co_stacksize, + pyfunc_code.co_flags, + pyfunc_code.co_code, + new_consts, + pyfunc_code.co_names, + pyfunc_code.co_varnames, + pyfunc_code.co_filename, + pyfunc_code.co_name, + pyfunc_code.co_firstlineno, + pyfunc_code.co_lnotab, + pyfunc_code.co_freevars, + pyfunc_code.co_cellvars + ]) + + # create code object with mutation + new_code = pytypes.CodeType(*co_args) + + # get function + return pytypes.FunctionType(new_code, globals()) + + def test_literal_const_code_gen(self): + def impl(x): + _CONST1 = "PLACEHOLDER1" + if _CONST1: + return 3.14159 + else: + _CONST2 = "PLACEHOLDER2" + return _CONST2 + 4 + + new = self._literal_const_sample_generator(impl, {1:0, 3:20}) + iconst = impl.__code__.co_consts + nconst = new.__code__.co_consts + self.assertEqual(iconst, (None, "PLACEHOLDER1", 3.14159, + "PLACEHOLDER2", 4)) + self.assertEqual(nconst, (None, 0, 3.14159, 20, 4)) + self.assertEqual(impl(None), 3.14159) + self.assertEqual(new(None), 24) + + def test_single_if_const(self): + + def impl(x): + _CONST1 = "PLACEHOLDER1" + if _CONST1: + return 3.14159 + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + func = self._literal_const_sample_generator(impl, {1: const}) + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_negate_const(self): + + def impl(x): + _CONST1 = "PLACEHOLDER1" + if not _CONST1: + return 3.14159 + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + func = self._literal_const_sample_generator(impl, {1: const}) + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_else_const(self): + + def impl(x): + _CONST1 = "PLACEHOLDER1" + if _CONST1: + return 3.14159 + else: + return 1.61803 + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + func = self._literal_const_sample_generator(impl, {1: const}) + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_else_negate_const(self): + + def impl(x): + _CONST1 = "PLACEHOLDER1" + if not _CONST1: + return 3.14159 + else: + return 1.61803 + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + func = self._literal_const_sample_generator(impl, {1: const}) + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_freevar(self): + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + + def func(x): + if const: + return 3.14159 + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_negate_freevar(self): + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + + def func(x): + if not const: + return 3.14159 + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_else_freevar(self): + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + + def func(x): + if const: + return 3.14159 + else: + return 1.61803 + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_else_negate_freevar(self): + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for const in c_inp: + + def func(x): + if not const: + return 3.14159 + else: + return 1.61803 + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + # globals in this section have absurd names after their test usecase names + # so as to prevent collisions and permit tests to run in parallel + def test_single_if_global(self): + global c_test_single_if_global + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for c in c_inp: + c_test_single_if_global = c + + def func(x): + if c_test_single_if_global: + return 3.14159 + + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_negate_global(self): + global c_test_single_if_negate_global + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for c in c_inp: + c_test_single_if_negate_global = c + + def func(x): + if c_test_single_if_negate_global: + return 3.14159 + + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_else_global(self): + global c_test_single_if_else_global + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for c in c_inp: + c_test_single_if_else_global = c + + def func(x): + if c_test_single_if_else_global: + return 3.14159 + else: + return 1.61803 + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + def test_single_if_else_negate_global(self): + global c_test_single_if_else_negate_global + + for c_inp, prune in (self._TRUTHY, False), (self._FALSEY, True): + for c in c_inp: + c_test_single_if_else_negate_global = c + + def func(x): + if not c_test_single_if_else_negate_global: + return 3.14159 + else: + return 1.61803 + self.assert_prune(func, (types.NoneType('none'),), [prune], + None) + + class TestBranchPrunePostSemanticConstRewrites(TestBranchPruneBase): # Tests that semantic constants rewriting works by virtue of branch pruning From 3af05ab81c0af1006b0d0121f98601ede06452b0 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Mon, 24 Feb 2020 20:26:19 +0000 Subject: [PATCH 568/595] Respond to feedback. As title. --- numba/core/analysis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba/core/analysis.py b/numba/core/analysis.py index 7a8363ffec3..54342b48878 100644 --- a/numba/core/analysis.py +++ b/numba/core/analysis.py @@ -352,9 +352,9 @@ def prune_by_predicate(branch, pred, blk): # Just to prevent accidents, whilst already guarded, ensure this # is an ir.Const if not isinstance(pred, (ir.Const, ir.FreeVar, ir.Global)): - raise TypeError + raise TypeError('Expected constant Numba IR node') take_truebr = bool(pred.value) - except Exception: + except TypeError: return False, None if DEBUG > 0: kill = branch.falsebr if take_truebr else branch.truebr From c7ad57dfbc5d730c02b313e03a70088aa3342809 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 7 Feb 2020 09:51:29 +0000 Subject: [PATCH 569/595] Remove more unsupported Python versions from build tooling. As title. --- buildscripts/condarecipe.local/meta.yaml | 5 ----- buildscripts/incremental/setup_conda_environment.cmd | 4 ---- buildscripts/incremental/setup_conda_environment.sh | 11 ----------- requirements.txt | 2 -- 4 files changed, 22 deletions(-) diff --git a/buildscripts/condarecipe.local/meta.yaml b/buildscripts/condarecipe.local/meta.yaml index 53a51f5961d..40a411e6341 100644 --- a/buildscripts/condarecipe.local/meta.yaml +++ b/buildscripts/condarecipe.local/meta.yaml @@ -33,8 +33,6 @@ requirements: - setuptools # On channel https://anaconda.org/numba/ - llvmlite 0.31.* - - funcsigs # [py27] - - singledispatch # [py27] # TBB devel version is to match TBB libs - tbb-devel >=2019.5 # [not (armv6l or armv7l or aarch64 or linux32)] run: @@ -43,8 +41,6 @@ requirements: - setuptools # On channel https://anaconda.org/numba/ - llvmlite 0.31.* - - funcsigs # [py27] - - singledispatch # [py27] run_constrained: # If TBB is present it must be at least this version from Anaconda due to # build flag issues triggering UB @@ -64,7 +60,6 @@ test: - scipy # [not (armv6l or armv7l)] - ipython # [not (armv6l or armv7l or aarch64)] - setuptools - - faulthandler # [py27 and (not (armv6l or armv7l or aarch64))] - tbb >=2019.5 # [not (armv6l or armv7l or aarch64 or linux32)] - intel-openmp # [osx] # Need these for AOT. Do not init msvc as it may not be present diff --git a/buildscripts/incremental/setup_conda_environment.cmd b/buildscripts/incremental/setup_conda_environment.cmd index 911b5720fe5..a264147f47c 100644 --- a/buildscripts/incremental/setup_conda_environment.cmd +++ b/buildscripts/incremental/setup_conda_environment.cmd @@ -28,10 +28,6 @@ conda create -n %CONDA_ENV% -q -y python=%PYTHON% numpy=%NUMPY% cffi pip scipy j call activate %CONDA_ENV% @rem Install latest llvmlite build %CONDA_INSTALL% -c numba llvmlite -@rem Install required backports for older Pythons -if %PYTHON% LSS 3.4 (%CONDA_INSTALL% enum34) -if %PYTHON% LSS 3.4 (%PIP_INSTALL% singledispatch) -if %PYTHON% LSS 3.3 (%CONDA_INSTALL% -c numba funcsigs) @rem Install dependencies for building the documentation if "%BUILD_DOC%" == "yes" (%CONDA_INSTALL% sphinx pygments) if "%BUILD_DOC%" == "yes" (%PIP_INSTALL% sphinx_bootstrap_theme) diff --git a/buildscripts/incremental/setup_conda_environment.sh b/buildscripts/incremental/setup_conda_environment.sh index 9fe9d605c32..f44d1ec7dc0 100755 --- a/buildscripts/incremental/setup_conda_environment.sh +++ b/buildscripts/incremental/setup_conda_environment.sh @@ -77,11 +77,6 @@ fi # Install latest llvmlite build $CONDA_INSTALL -c numba llvmlite -# Install enum34 and singledispatch for Python < 3.4 -if [ $PYTHON \< "3.4" ]; then $CONDA_INSTALL enum34; fi -if [ $PYTHON \< "3.4" ]; then $PIP_INSTALL singledispatch; fi -# Install funcsigs for Python < 3.3 -if [ $PYTHON \< "3.3" ]; then $CONDA_INSTALL -c numba funcsigs; fi # Install dependencies for building the documentation if [ "$BUILD_DOC" == "yes" ]; then $CONDA_INSTALL sphinx pygments numpydoc; fi if [ "$BUILD_DOC" == "yes" ]; then $PIP_INSTALL sphinx_bootstrap_theme rstcheck; fi @@ -91,12 +86,6 @@ if [ "$RUN_COVERAGE" == "yes" ]; then $PIP_INSTALL codecov; fi if [ "$TEST_SVML" == "yes" ]; then $CONDA_INSTALL -c numba icc_rt; fi # Install Intel TBB parallel backend if [ "$TEST_THREADING" == "tbb" ]; then $CONDA_INSTALL tbb tbb-devel; fi -# install the faulthandler for Python 2.x, but not on armv7l as it doesn't exist -# in berryconda -archstr=`uname -m` -if [[ "$archstr" != 'armv7l' ]]; then - if [ $PYTHON \< "3.0" ]; then $CONDA_INSTALL faulthandler; fi -fi # environment dump for debug echo "DEBUG ENV:" diff --git a/requirements.txt b/requirements.txt index 95b9e0a7c1d..aa53a4f5a2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,3 @@ setuptools numpy>=1.10 llvmlite>=0.31 argparse -funcsigs ; python_version < '3.4' -singledispatch ; python_version < '3.4' From 0f43a3a41a020ef7292f385a1e02d2e9488c3914 Mon Sep 17 00:00:00 2001 From: Greg Jennings Date: Fri, 22 Mar 2019 22:21:31 -0400 Subject: [PATCH 570/595] Fixes numba#3888. Modified the np.random.choice implementation inside of numba to match the implementation used in numpy, which uses np.random.permutation. Not using np.random.permutation previously resulted in different values for np.random.choice inside of numba vs outside of numba, when using the same np.random.seed value. Using this approach, the following now match, when replace=False: @numba.njit def new_numba_random_choice(a, size, replace): np.random.seed(3) return np.random.choice(a, size, replace) def np_random_choice(a, size, replace): np.random.seed(3) return np.random.choice(a, size, replace) Previously, np.random.choice inside of numba only matched output with numpy under the same np.random.seed when replace=True --- numba/cpython/randomimpl.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index 450301ed0ad..672c4ce9fe1 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -1413,14 +1413,12 @@ def choice_impl(a, size=None, replace=True): if out.size > n: raise ValueError("Cannot take a larger sample than " "population when 'replace=False'") - # Get a contiguous copy of the source so as to permute it - src = copy_source(a) - fl = out.flat - for i in range(len(fl)): - j = np.random.randint(i, n) - fl[i] = src[j] - # Move away selected element - src[j] = src[i] + + # we need this implementation in order to get the + # np.random.choice inside numba to match the output + # of np.random.choice outside numba when np.random.seed + # is set to the same value + out[:] = np.random.permutation(a)[:size] return out return choice_impl From 0cdee831f0a28efbc5c8f3cca04f0576e9ae96d7 Mon Sep 17 00:00:00 2001 From: Greg Jennings Date: Sat, 23 Mar 2019 09:25:54 -0400 Subject: [PATCH 571/595] updating assignment into out array --- numba/cpython/randomimpl.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index 672c4ce9fe1..82e4f645609 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -1409,16 +1409,15 @@ def choice_impl(a, size=None, replace=True): else: # Note we have to construct the array to compute out.size # (`size` can be an arbitrary int or tuple of ints) - out = np.empty(size, dtype) - if out.size > n: + if size > n: raise ValueError("Cannot take a larger sample than " "population when 'replace=False'") - + # we need this implementation in order to get the # np.random.choice inside numba to match the output # of np.random.choice outside numba when np.random.seed # is set to the same value - out[:] = np.random.permutation(a)[:size] + out = np.random.permutation(a)[:size] return out return choice_impl From ced46b48cd677ef2266cdb908148fbb096d6887e Mon Sep 17 00:00:00 2001 From: Greg Jennings Date: Sat, 23 Mar 2019 10:18:18 -0400 Subject: [PATCH 572/595] handling case where incoming size is a tuple --- numba/cpython/randomimpl.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index 82e4f645609..1c38c026fa1 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -1409,7 +1409,8 @@ def choice_impl(a, size=None, replace=True): else: # Note we have to construct the array to compute out.size # (`size` can be an arbitrary int or tuple of ints) - if size > n: + out = np.empty(size, dtype) + if out.size > n: raise ValueError("Cannot take a larger sample than " "population when 'replace=False'") @@ -1417,7 +1418,7 @@ def choice_impl(a, size=None, replace=True): # np.random.choice inside numba to match the output # of np.random.choice outside numba when np.random.seed # is set to the same value - out = np.random.permutation(a)[:size] + out = np.random.permutation(a)[:out.size] return out return choice_impl From 24441852644a197040b32bb4f19b921094b0ca91 Mon Sep 17 00:00:00 2001 From: Greg Jennings Date: Sun, 24 Mar 2019 13:45:23 -0400 Subject: [PATCH 573/595] combining use of np.random.permutation with original approach using an iterator over the output array in order to account for alternate shapes of the `size` argument --- numba/cpython/randomimpl.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index 1c38c026fa1..cf402b558a6 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -1408,17 +1408,20 @@ def choice_impl(a, size=None, replace=True): return out else: # Note we have to construct the array to compute out.size - # (`size` can be an arbitrary int or tuple of ints) + # (`size` can be an arbitrary int or tuple of ints) out = np.empty(size, dtype) if out.size > n: raise ValueError("Cannot take a larger sample than " "population when 'replace=False'") - + # Get a permuted copy of the source array # we need this implementation in order to get the # np.random.choice inside numba to match the output # of np.random.choice outside numba when np.random.seed # is set to the same value - out = np.random.permutation(a)[:out.size] + permuted_a = np.random.permutation(a) + fl = out.flat + for i in range(len(fl)): + fl[i] = permuted_a[i] return out return choice_impl From 2e4fa5419e4680a2e6844d5f6eaa2b3efbaea382 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 25 Feb 2020 14:13:09 +0000 Subject: [PATCH 574/595] Add test As title --- numba/tests/test_random.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/numba/tests/test_random.py b/numba/tests/test_random.py index 758916d26db..871d20e5a9a 100644 --- a/numba/tests/test_random.py +++ b/numba/tests/test_random.py @@ -1202,6 +1202,27 @@ def test_choice_array_3(self): pop = np.arange(50) * 2 + 100 self._check_choice_3(pop, pop) + def test_choice_follows_seed(self): + # See issue #3888, np.random.choice must acknowledge the seed + + @jit(nopython=True) + def numba_rands(n_to_return, choice_array): + np.random.seed(1337) + out = np.empty((n_to_return, 2), np.int32) + for i in range(n_to_return): + out[i] = np.random.choice(choice_array, 2, False) + return out + + choice_array = np.random.randint(300, size=1000).astype(np.int32) + tmp_np = choice_array.copy() + expected = numba_rands.py_func(5, tmp_np) + tmp_nb = choice_array.copy() + got = numba_rands(5, tmp_nb) + np.testing.assert_allclose(expected, got) + # check no mutation + np.testing.assert_allclose(choice_array, tmp_np) + np.testing.assert_allclose(choice_array, tmp_nb) + class TestRandomMultinomial(BaseTest): """ From d908dd97ed8ee240cc2c50e8c0d38bb50a03428f Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 25 Feb 2020 14:52:50 +0000 Subject: [PATCH 575/595] Remove more files/code for Py2.7 As title --- .binstar.yml | 79 ---------------------------- .travis.yml | 60 --------------------- buildscripts/azure/azure-windows.yml | 8 --- setup.py | 4 -- 4 files changed, 151 deletions(-) delete mode 100644 .binstar.yml delete mode 100644 .travis.yml diff --git a/.binstar.yml b/.binstar.yml deleted file mode 100644 index 9268cba5188..00000000000 --- a/.binstar.yml +++ /dev/null @@ -1,79 +0,0 @@ - -## The package attribure specifies a binstar package namespace to build the package to. -## This can be specified here or on the command line -package: numba - -## You can also specify the account to upload to, -## you must be an admin of that account, this -## defaults to your user account -# user: USERNAME - -#=============================================================================== -# Build Matrix Options -# These options may be a single item, a list or empty -# The resulting number of builds is [platform * engine * env] -#=============================================================================== - -# The platforms to build on. -# platform defaults to linux-64 -platform: - - linux-64 - - linux-32 - - win-32 - - win-64 - - osx-64 - -# The engine are the initial conda packages you want to run with -engine: - - python=2.6 argparse funcsigs unittest2 - #- python=2.7 funcsigs - #- python=3.3 - - python=3.4 - -## The env param is an environment variable list -#env: - #- MY_ENV=A CC=gcc - #- MY_ENV=B - -#=============================================================================== -# Scrip options -# These options may be broken out into the before_script, script and after_script -# or not, that is up to you -#=============================================================================== - -# Run before the script -before_script: - - conda config --add channels numba - - conda install -q --yes numpy llvmlite jinja2 - -# Put your main computations here! -script: - - python setup.py build - - python setup.py build_ext --inplace - - python -m numba.testing -v -b -m - -## This will run after the script regardless of the result of script -## BINSTAR_BUILD_RESULT=[succcess|failure] -# after_script: -# - echo "The build was a $BINSTAR_BUILD_RESULT" | tee artifact1.txt -## This will be run only after a successful build -# after_success: -# - echo "after_success!" -## This will be run only after a build failure -# after_failure: -# - echo "after_failure!" - -#=============================================================================== -# Build Results -# Build results are split into two categories: artifacts and targets -# You may omit either key and stiff have a successful build -# They may be a string, list and contain any bash glob -#=============================================================================== - -## Build Targets: Upload these files to your binstar package -## build targets may be a list of files (globs allows) to upload -## The special build targets 'conda' and 'pypi' may be used to -## upload conda builds -## e.g. conda is an alias for /opt/anaconda/conda-bld//*.tar.bz2 -#build_targets: - #- conda diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4d1e0469542..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,60 +0,0 @@ -# References https://gist.github.com/dan-blanchard/7045057 -# and https://docs.travis-ci.com/user/trusty-ci-environment/ - -dist: trusty - -matrix: - include: - # Parametrize the conda env name so multiple builds can - # work with multiple environments on the same machine in parallel. - # Try and cover all supported pythons and NumPy's in some combination - - os: osx - env: PYTHON=3.7 NUMPY=1.16 CONDA_ENV=travisci BUILD_DOC=yes - - env: PYTHON=3.7 NUMPY=1.16 CONDA_ENV=travisci TEST_THREADING=tbb - - env: PYTHON=2.7 NUMPY=1.16 CONDA_ENV=travisci - - env: PYTHON=2.7 NUMPY=1.9 CONDA_ENV=travisci - - env: PYTHON=3.5 NUMPY=1.10 CONDA_ENV=travisci - - env: PYTHON=3.5 NUMPY=1.11 CONDA_ENV=travisci - - env: PYTHON=3.6 NUMPY=1.12 CONDA_ENV=travisci - - env: PYTHON=3.6 NUMPY=1.13 CONDA_ENV=travisci - - env: PYTHON=3.7 NUMPY=1.14 CONDA_ENV=travisci - - env: PYTHON=3.7 NUMPY=1.15 CONDA_ENV=travisci - - env: PYTHON=3.7 NUMPY=1.16 CONDA_ENV=travisci TEST_SVML=yes - - env: PYTHON=3.7 NUMPY=1.16 CONDA_ENV=travisci VANILLA_INSTALL=yes - - env: PYTHON=2.7 NUMPY=1.11 CONDA_ENV=travisci BITS32=yes - - env: PYTHON=3.7 NUMPY=1.15 CONDA_ENV=travisci BITS32=yes - - env: PYTHON=3.7 NUMPY=1.16 CONDA_ENV=travisci TEST_THREADING=omp - - env: PYTHON=3.7 NUMPY=1.16 CONDA_ENV=travisci TEST_THREADING=workqueue - - -branches: - only: - - master - - travis - -before_install: - - if [ "$(uname)" == "Linux" ] && [[ "$CONDA_SUBDIR" == "linux-32" || "$BITS32" == "yes" ]]; then sudo apt-get install libc6-dev-i386; fi - - buildscripts/incremental/install_miniconda.sh - - export PATH=$HOME/miniconda3/bin:$PATH - - buildscripts/incremental/setup_conda_environment.sh -install: - - buildscripts/incremental/build.sh - -script: - - buildscripts/incremental/test.sh - -after_success: - - buildscripts/incremental/after_success.sh - -notifications: - email: false - on_success: "change" - on_failure: "always" # "change" - slack: - secure: SGgsT4DevPiF/u4y3HBorUYCVWan7EjSnEBmuGPnGkepv8JxfOnbbeM3ca2TSWa601J4OP2K2JhehUGZSn6YkTx5XKOzqF2pddZQX8j0B4htDgV2qvcY/aIUFz8UW2uQAuguP6OlHPmAj5KgF5raJ34rkmTd8UgObL6jAan2Kzg= - webhooks: - urls: - - secure: "IpSOubapaCybPfQc/XRaFTB7nry+wSN0dGkU/m4aBclLiEx8Op+mAH8rm9N58U6TG5jhcNBmv7RCjs6k3Pi0Ra3Bt0x6fjB/46Xj93k0tftcfIn+0jLjujbmJym0efTxhj4ip+b0awh8f/LKY/U46PfEBSJmxUppY84YhRU23kI=" - on_success: change - on_failure: always - on_start: false diff --git a/buildscripts/azure/azure-windows.yml b/buildscripts/azure/azure-windows.yml index d9b82d8c0ab..63b7137b7c6 100644 --- a/buildscripts/azure/azure-windows.yml +++ b/buildscripts/azure/azure-windows.yml @@ -25,14 +25,6 @@ jobs: updateConda: no packageSpecs: '' - # Need to install VC 9.0 only for Python 2.7 - - powershell: | - $wc = New-Object net.webclient - $wc.Downloadfile("https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi", "VCForPython27.msi") - Start-Process "VCForPython27.msi" /qn -Wait - displayName: 'Install VC 9.0' - condition: eq(variables['PYTHON'], '2.7') - - script: | buildscripts\\incremental\\setup_conda_environment.cmd displayName: 'Before Install' diff --git a/setup.py b/setup.py index 32b3d96fd06..b48b868252c 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,3 @@ -# NOTE: for building under Windows. -# Use setuptools so as to enable support of the special -# "Microsoft Visual C++ Compiler for Python 2.7" (http://aka.ms/vcpython27) -# Note setuptools >= 6.0 is required for this. from setuptools import setup, Extension, find_packages from distutils.command import build from distutils.spawn import spawn From c14e2d2bf1ee57e7f3ddec8bbfa06e1bd382a5d5 Mon Sep 17 00:00:00 2001 From: Ravi Teja Gutta Date: Fri, 26 Jul 2019 11:24:11 -0700 Subject: [PATCH 576/595] [WIP] initial commit for numpy's flip functionalty --- numba/np/arrayobj.py | 56 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 7b0e9b1b3a8..7cbf997fbb1 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -30,7 +30,7 @@ from numba.core.extending import register_jitable, overload, overload_method from numba.misc import quicksort, mergesort from numba.cpython import slicing - +from numba.cpython.unsafe.tuple import tuple_setitem def set_range_metadata(builder, load, lower_bound, upper_bound): """ @@ -4874,7 +4874,59 @@ def dot_impl(arr, other): return dot_impl -# ------------------------------------------------------------------------------ +@overload(np.fliplr) +def np_flip_lr(a): + def impl(a): + return a[::, ::-1, ...] + return impl + + +@overload(np.flipud) +def np_flip_ud(a): + def impl(a): + return a[::-1, ...] + return impl + + +@intrinsic +def _build_slice_tuple(tyctx, sz): + """ Creates a tuple of slices for np.flip indexing like + `(slice(None, None, -1),) * sz` """ + size = int(sz.literal_value) + tuple_type = types.UniTuple(dtype=types.slice3_type, count=size) + sig = tuple_type(sz) + + def codegen(context, builder, signature, args): + def impl(length, empty_tuple): + out = empty_tuple + for i in range(length): + out = tuple_setitem(out, i, slice(None, None, -1)) + return out + + inner_argtypes = [types.intp, tuple_type] + inner_sig = typing.signature(tuple_type, *inner_argtypes) + ll_idx_type = context.get_value_type(types.intp) + # Allocate an empty tuple + empty_tuple = context.get_constant_undef(tuple_type) + inner_args = [ll_idx_type(size), empty_tuple] + + res = context.compile_internal(builder, impl, inner_sig, inner_args) + return res + + return sig, codegen + + +@overload(np.flip) +def np_flip(a): + ndim = a.ndim + + def impl(a): + sl = _build_slice_tuple(ndim) + return a[sl] + return impl + + +# ----------------------------------------------------------------------------- # Sorting _sorts = {} From 6324fbe110ce0c0849855bb84426af42d9310558 Mon Sep 17 00:00:00 2001 From: Ravi Teja Gutta Date: Thu, 1 Aug 2019 23:53:20 -0700 Subject: [PATCH 577/595] input to fliplr must be >= 2-d --- numba/np/arrayobj.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 7cbf997fbb1..a02764c053e 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -4876,6 +4876,9 @@ def dot_impl(arr, other): @overload(np.fliplr) def np_flip_lr(a): + if len(a.shape) < 2: + raise ValueError('Input must be >= 2-d.') + def impl(a): return a[::, ::-1, ...] return impl From 9ae6ff3d53e986078c31b7cf5110ea12732d24a2 Mon Sep 17 00:00:00 2001 From: Ravi Teja Gutta Date: Fri, 2 Aug 2019 00:04:17 -0700 Subject: [PATCH 578/595] add tests for fliplr, flipud and flip --- numba/tests/test_np_functions.py | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index 64ffc1c9fc2..ca42f973dbd 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -104,6 +104,18 @@ def finfo_machar(*args): return np.finfo(*args).machar +def fliplr(a): + return np.fliplr(a) + + +def flipud(a): + return np.flipud(a) + + +def flip(a): + return np.flip(a) + + def correlate(a, v): return np.correlate(a, v) @@ -288,6 +300,14 @@ def np_cross(a, b): return np.cross(a, b) +def flip_lr(a): + return np.fliplr(a) + + +def flip_ud(a): + return np.flipud(a) + + class TestNPFunctions(MemoryLeakMixin, TestCase): """ Tests for various Numpy functions. @@ -2060,6 +2080,62 @@ def test_ediff1d_exceptions(self): msg = "Boolean dtype is unsupported (as per NumPy)" assert msg in str(e.exception) + def test_fliplr_basic(self): + pyfunc = fliplr + cfunc = jit(nopython=True)(pyfunc) + + def a_variations(): + yield np.arange(10).reshape(5,2) + yield np.arange(20).reshape(5, 2, 2) + + for a in a_variations(): + expected = pyfunc(a) + got = cfunc(a) + self.assertPreciseEqual(expected, got) + + def test_fliplr_exception(self): + pyfunc = fliplr + cfunc = jit(nopython=True)(pyfunc) + + # Exceptions leak references + self.disable_leak_check() + + with self.assertRaises(ValueError) as raises: + cfunc([1,2]) + + self.assertIn("Input must be >= 2-d.", str(raises.exception)) + + + def test_flipud_basic(self): + pyfunc = flipud + cfunc = jit(nopython=True)(pyfunc) + + def a_variations(): + yield [1] + yield np.arange(10) + yield np.arange(10).reshape(5,2) + yield np.arange(20).reshape(5, 2, 2) + + for a in a_variations(): + expected = pyfunc(a) + got = cfunc(a) + self.assertPreciseEqual(expected, got) + + def test_flip_basic(self): + pyfunc = flip + cfunc = jit(nopython=True)(pyfunc) + + def a_variations(): + yield [1] + yield np.arange(10) + yield np.arange(10).reshape(5,2) + yield np.arange(20).reshape(5, 2, 2) + + for a in a_variations(): + expected = pyfunc(a) + got = cfunc(a) + self.assertPreciseEqual(expected, got) + def test_roll_basic(self): pyfunc = roll cfunc = jit(nopython=True)(pyfunc) From 3cbf33fb33c92d8d17f5c754ec3b3fed18fd9db3 Mon Sep 17 00:00:00 2001 From: Ravi Teja Gutta Date: Fri, 2 Aug 2019 00:05:20 -0700 Subject: [PATCH 579/595] add in docs that flip doesn't support axis argument --- docs/source/reference/numpysupported.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index 520aa6cf60b..967a0ddb5b3 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -355,6 +355,9 @@ The following top-level functions are supported: * :func:`numpy.fill_diagonal` * :func:`numpy.flatten` (no order argument; 'C' order only) * :func:`numpy.flatnonzero` +* :func:`numpy.fliplr` +* :func:`numpy.flipud` +* :func:`numpy.flip` (no axis argument) * :func:`numpy.frombuffer` (only the 2 first arguments) * :func:`numpy.full` (only the 3 first arguments) * :func:`numpy.full_like` (only the 3 first arguments) From e17d484321521a6863754551d78144882ce24de6 Mon Sep 17 00:00:00 2001 From: VP5785 Date: Sun, 28 Jul 2019 14:14:48 -0700 Subject: [PATCH 580/595] initial commit --- numba/np/arrayobj.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index a02764c053e..42f159ed9b3 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -31,6 +31,8 @@ from numba.misc import quicksort, mergesort from numba.cpython import slicing from numba.cpython.unsafe.tuple import tuple_setitem +from . import quicksort, mergesort, slicing + def set_range_metadata(builder, load, lower_bound, upper_bound): """ @@ -4876,6 +4878,7 @@ def dot_impl(arr, other): @overload(np.fliplr) def np_flip_lr(a): + if len(a.shape) < 2: raise ValueError('Input must be >= 2-d.') From d54a70eea7f2e88f60a2427a63a3710ba1f31a06 Mon Sep 17 00:00:00 2001 From: Ravi Teja Gutta Date: Fri, 2 Aug 2019 15:54:27 -0700 Subject: [PATCH 581/595] convert any iterable into numpy array --- numba/np/arrayobj.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 42f159ed9b3..05c25688a69 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -4878,6 +4878,8 @@ def dot_impl(arr, other): @overload(np.fliplr) def np_flip_lr(a): + if not isinstance(a, types.Array): + a = np.array(a) if len(a.shape) < 2: raise ValueError('Input must be >= 2-d.') @@ -4889,6 +4891,9 @@ def impl(a): @overload(np.flipud) def np_flip_ud(a): + if not isinstance(a, types.Array): + a = np.array(a) + def impl(a): return a[::-1, ...] return impl @@ -4924,6 +4929,8 @@ def impl(length, empty_tuple): @overload(np.flip) def np_flip(a): + if not isinstance(a, types.Array): + a = np.array(a) ndim = a.ndim def impl(a): From 130dfa2c76d949f960af1ea0b56ef7e04c23fd84 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 25 Feb 2020 15:06:30 +0000 Subject: [PATCH 582/595] Remove dead references in docs --- docs/source/developer/repomap.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/source/developer/repomap.rst b/docs/source/developer/repomap.rst index edd475eeafa..9d2c4e58ba8 100644 --- a/docs/source/developer/repomap.rst +++ b/docs/source/developer/repomap.rst @@ -32,13 +32,10 @@ Build and Packaging Continuous Integration '''''''''''''''''''''' -- :ghfile:`.binstar.yml` - Binstar Build CI config (inactive) - :ghfile:`azure-pipelines.yml` - Azure Pipelines CI config (active: Win/Mac/Linux) - :ghfile:`buildscripts/azure/` - Azure Pipeline configuration for specific platforms -- :ghfile:`.travis.yml` - Travis CI config (active: Mac/Linux, will be - dropped in the future) - :ghfile:`buildscripts/appveyor/` - Appveyor build scripts - :ghfile:`buildscripts/incremental/` - Generic scripts for building Numba on various CI systems From 5236d858298305e31ecfcce65e8f9e946aef2ce4 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 25 Feb 2020 15:50:57 +0000 Subject: [PATCH 583/595] Fix up and add tests --- docs/source/reference/numpysupported.rst | 2 +- numba/np/arrayobj.py | 39 ++++++++++----- numba/tests/test_np_functions.py | 62 ++++++++++++++++++------ 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index 967a0ddb5b3..fc831b983c4 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -355,9 +355,9 @@ The following top-level functions are supported: * :func:`numpy.fill_diagonal` * :func:`numpy.flatten` (no order argument; 'C' order only) * :func:`numpy.flatnonzero` +* :func:`numpy.flip` (no axis argument) * :func:`numpy.fliplr` * :func:`numpy.flipud` -* :func:`numpy.flip` (no axis argument) * :func:`numpy.frombuffer` (only the 2 first arguments) * :func:`numpy.full` (only the 3 first arguments) * :func:`numpy.full_like` (only the 3 first arguments) diff --git a/numba/np/arrayobj.py b/numba/np/arrayobj.py index 05c25688a69..49c98d3ecbb 100644 --- a/numba/np/arrayobj.py +++ b/numba/np/arrayobj.py @@ -27,11 +27,11 @@ impl_ret_new_ref, impl_ret_untracked, RefType) from numba.core.typing import signature -from numba.core.extending import register_jitable, overload, overload_method +from numba.core.extending import (register_jitable, overload, overload_method, + intrinsic) from numba.misc import quicksort, mergesort from numba.cpython import slicing from numba.cpython.unsafe.tuple import tuple_setitem -from . import quicksort, mergesort, slicing def set_range_metadata(builder, load, lower_bound, upper_bound): @@ -4878,24 +4878,35 @@ def dot_impl(arr, other): @overload(np.fliplr) def np_flip_lr(a): - if not isinstance(a, types.Array): - a = np.array(a) - if len(a.shape) < 2: - raise ValueError('Input must be >= 2-d.') + if not type_can_asarray(a): + raise errors.TypingError("Cannot np.fliplr on %s type" % a) def impl(a): - return a[::, ::-1, ...] + A = np.asarray(a) + # this handling is superfluous/dead as < 2d array cannot be indexed as + # present below and so typing fails. If the typing doesn't fail due to + # some future change, this will catch it. + if A.ndim < 2: + raise ValueError('Input must be >= 2-d.') + return A[::, ::-1, ...] return impl @overload(np.flipud) def np_flip_ud(a): - if not isinstance(a, types.Array): - a = np.array(a) + + if not type_can_asarray(a): + raise errors.TypingError("Cannot np.flipud on %s type" % a) def impl(a): - return a[::-1, ...] + A = np.asarray(a) + # this handling is superfluous/dead as a 0d array cannot be indexed as + # present below and so typing fails. If the typing doesn't fail due to + # some future change, this will catch it. + if A.ndim < 1: + raise ValueError('Input must be >= 1-d.') + return A[::-1, ...] return impl @@ -4929,13 +4940,15 @@ def impl(length, empty_tuple): @overload(np.flip) def np_flip(a): + # a constant value is needed for the tuple slice, types.Array.ndim can + # provide this and so at presnet only type.Array is support if not isinstance(a, types.Array): - a = np.array(a) - ndim = a.ndim + raise errors.TypingError("Cannot np.flip on %s type" % a) def impl(a): - sl = _build_slice_tuple(ndim) + sl = _build_slice_tuple(a.ndim) return a[sl] + return impl diff --git a/numba/tests/test_np_functions.py b/numba/tests/test_np_functions.py index ca42f973dbd..3d53f94a15d 100644 --- a/numba/tests/test_np_functions.py +++ b/numba/tests/test_np_functions.py @@ -2083,16 +2083,24 @@ def test_ediff1d_exceptions(self): def test_fliplr_basic(self): pyfunc = fliplr cfunc = jit(nopython=True)(pyfunc) - + def a_variations(): - yield np.arange(10).reshape(5,2) + yield np.arange(10).reshape(5, 2) yield np.arange(20).reshape(5, 2, 2) - + yield ((1, 2),) + yield ([1, 2], [3, 4],) + for a in a_variations(): expected = pyfunc(a) got = cfunc(a) self.assertPreciseEqual(expected, got) + with self.assertRaises(TypingError) as raises: + cfunc("abc") + + self.assertIn("Cannot np.fliplr on %s type" % types.unicode_type, + str(raises.exception)) + def test_fliplr_exception(self): pyfunc = fliplr cfunc = jit(nopython=True)(pyfunc) @@ -2100,42 +2108,68 @@ def test_fliplr_exception(self): # Exceptions leak references self.disable_leak_check() - with self.assertRaises(ValueError) as raises: - cfunc([1,2]) - - self.assertIn("Input must be >= 2-d.", str(raises.exception)) + with self.assertRaises(TypingError) as raises: + cfunc(np.arange(3)) + self.assertIn("cannot index array", str(raises.exception)) + self.assertIn("with 2 indices", str(raises.exception)) def test_flipud_basic(self): pyfunc = flipud cfunc = jit(nopython=True)(pyfunc) - + def a_variations(): yield [1] yield np.arange(10) - yield np.arange(10).reshape(5,2) + yield np.arange(10).reshape(5, 2) yield np.arange(20).reshape(5, 2, 2) - + yield ((1, 2),) + yield ([1, 2], [3, 4],) + for a in a_variations(): expected = pyfunc(a) got = cfunc(a) self.assertPreciseEqual(expected, got) + with self.assertRaises(TypingError) as raises: + cfunc("abc") + + self.assertIn("Cannot np.flipud on %s type" % types.unicode_type, + str(raises.exception)) + + def test_flipud_exception(self): + pyfunc = flipud + cfunc = jit(nopython=True)(pyfunc) + + # Exceptions leak references + self.disable_leak_check() + + with self.assertRaises(TypingError) as raises: + cfunc(1) + + self.assertIn("cannot index array", str(raises.exception)) + self.assertIn("with 1 indices", str(raises.exception)) + def test_flip_basic(self): pyfunc = flip cfunc = jit(nopython=True)(pyfunc) - + def a_variations(): - yield [1] + yield np.array(1) yield np.arange(10) - yield np.arange(10).reshape(5,2) + yield np.arange(10).reshape(5, 2) yield np.arange(20).reshape(5, 2, 2) - + for a in a_variations(): expected = pyfunc(a) got = cfunc(a) self.assertPreciseEqual(expected, got) + with self.assertRaises(TypingError) as raises: + cfunc((1, 2, 3)) + + self.assertIn("Cannot np.flip on UniTuple", str(raises.exception)) + def test_roll_basic(self): pyfunc = roll cfunc = jit(nopython=True)(pyfunc) From fb98c33255b2587115fbf6ac8563b3768972b5cd Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Wed, 26 Feb 2020 09:12:07 +0100 Subject: [PATCH 584/595] changes after review --- docs/source/reference/numpysupported.rst | 2 +- numba/core/rewrites/static_getitem.py | 19 +++++++++++-------- numba/core/typeinfer.py | 15 ++++++--------- numba/core/typing/arraydecl.py | 8 +++++++- numba/tests/test_mixed_tuple_unroller.py | 4 ++-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/docs/source/reference/numpysupported.rst b/docs/source/reference/numpysupported.rst index 509bcf6727a..80472165104 100644 --- a/docs/source/reference/numpysupported.rst +++ b/docs/source/reference/numpysupported.rst @@ -128,7 +128,7 @@ It is also possible to use local or global tuples together with ``literal_unroll ... def get_field_sum(rec): ... out = 0 ... for f in literal_unroll(fields_gl): - ... out += arr[f] + ... out += rec[f] ... return out ... >>> get_field_sum(arr[0]) diff --git a/numba/core/rewrites/static_getitem.py b/numba/core/rewrites/static_getitem.py index d61aaba4f41..8f49554c8b7 100644 --- a/numba/core/rewrites/static_getitem.py +++ b/numba/core/rewrites/static_getitem.py @@ -47,29 +47,32 @@ def apply(self): @register_rewrite('after-inference') -class RewriteLiteralGetitems(Rewrite): +class RewriteStringLiteralGetitems(Rewrite): """ Rewrite IR expressions of the kind `getitem(value=arr, index=$XX)` - where `$XX` is a Literal value as + where `$XX` is a StringLiteral value as `static_getitem(value=arr, index=)`. """ def match(self, func_ir, block, typemap, calltypes): + """ + Detect all getitem expressions and find which ones have + string literal indexes + """ self.getitems = getitems = {} self.block = block - # Detect all getitem expressions and find which ones can be - # rewritten for expr in block.find_exprs(op='getitem'): if expr.op == 'getitem': - if isinstance(typemap[expr.index.name], types.StringLiteral): - literal_value = typemap[expr.index.name].literal_value - getitems[expr] = (expr.index, literal_value) + index_ty = typemap[expr.index.name] + if isinstance(index_ty, types.StringLiteral): + getitems[expr] = (expr.index, index_ty.literal_value) return len(getitems) > 0 def apply(self): """ - Rewrite all matching getitems as static_getitems. + Rewrite all matching getitems as static_getitems where the index + is the literal value of the string. """ new_block = self.block.copy() new_block.clear() diff --git a/numba/core/typeinfer.py b/numba/core/typeinfer.py index b4488554ee2..614cac7b598 100644 --- a/numba/core/typeinfer.py +++ b/numba/core/typeinfer.py @@ -1479,15 +1479,12 @@ def typeof_global(self, inst, target, gvar): # Global array in nopython mode is constant typ = typ.copy(readonly=True) - if isinstance(typ, types.Tuple): - if all(isinstance(ty, (types.Integer, types.UnicodeType)) - for ty in typ): - typ = types.Tuple([types.literal(val) for val in gvar.value]) - - if isinstance(typ, types.UniTuple): - # since this test makes typ into a Tuple, it must be placed after - # the test for types.Tuple to prevent double-triggering - if isinstance(typ.dtype, (types.Integer, types.UnicodeType)): + if isinstance(typ, types.BaseAnonymousTuple): + types_w_literals = (types.Integer, types.UnicodeType) + types_in_tuple = (typ.dtype.types + if isinstance(typ.dtype, types.UnionType) + else (typ.dtype,)) + if all(isinstance(ty, types_w_literals) for ty in types_in_tuple): typ = types.Tuple([types.literal(val) for val in gvar.value]) self.sentry_modified_builtin(inst, gvar) diff --git a/numba/core/typing/arraydecl.py b/numba/core/typing/arraydecl.py index de98c2312d1..119bbdec89e 100644 --- a/numba/core/typing/arraydecl.py +++ b/numba/core/typing/arraydecl.py @@ -540,17 +540,23 @@ def generic(self, args, kws): # Resolution of members for records record, idx = args if isinstance(record, types.Record) and isinstance(idx, str): + if idx not in record.fields: + raise KeyError(f"Field '{idx}' was not found in record with " + f"fields {tuple(record.fields.keys())}") ret = record.typeof(idx) assert ret return signature(ret, *args) @infer_global(operator.getitem) -class GetItemRecord(AbstractTemplate): +class StaticGetItemLiteralRecord(AbstractTemplate): def generic(self, args, kws): # Resolution of members for records record, idx = args if isinstance(record, types.Record) and isinstance(idx, types.StringLiteral): + if idx.literal_value not in record.fields: + raise KeyError(f"Field '{idx.literal_value}' was not found in record with " + f"fields {tuple(record.fields.keys())}") ret = record.typeof(idx.literal_value) assert ret return signature(ret, *args) diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 5db1ef410dd..4efa8ad19ca 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -17,7 +17,7 @@ NoPythonBackend, PartialTypeInference) from numba.core.ir_utils import (compute_cfg_from_blocks, flatten_labels) -x_global = (10, 11) +_X_GLOBAL = (10, 11) class TestLiteralTupleInterpretation(MemoryLeakMixin, TestCase): @@ -1655,7 +1655,7 @@ def test_unroll_global_tuple(self): @njit def foo(): out = 0 - for i in literal_unroll(x_global): + for i in literal_unroll(_X_GLOBAL): out += i return out From 3a9b7a6ea0e139b4535bd3dbcb9f09e1dae5b592 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Wed, 26 Feb 2020 09:17:32 +0100 Subject: [PATCH 585/595] added test for unrolling of functions --- numba/tests/test_mixed_tuple_unroller.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 4efa8ad19ca..7ed0e423383 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -1673,6 +1673,25 @@ def foo(): self.assertEqual(foo(), foo.py_func()) + def test_unroll_function_tuple(self): + @njit + def a(): + return 1 + + @njit + def b(): + return 2 + + x = (a, b) + + @njit + def foo(): + out = 0 + for f in literal_unroll(x): + out += f() + return out + + self.assertEqual(foo(), foo.py_func()) def capture(real_pass): """ Returns a compiler pass that captures the mutation state reported From 89ed7e7ea9aaafd5834cbb82e70ce0c8e2c843ca Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Wed, 26 Feb 2020 09:23:16 +0100 Subject: [PATCH 586/595] flake8 fix --- numba/tests/test_mixed_tuple_unroller.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba/tests/test_mixed_tuple_unroller.py b/numba/tests/test_mixed_tuple_unroller.py index 7ed0e423383..0c3099276e6 100644 --- a/numba/tests/test_mixed_tuple_unroller.py +++ b/numba/tests/test_mixed_tuple_unroller.py @@ -1693,6 +1693,7 @@ def foo(): self.assertEqual(foo(), foo.py_func()) + def capture(real_pass): """ Returns a compiler pass that captures the mutation state reported by the pass used in the argument""" From 60e23c31eee43b0efa6b6d13c87a5dfec7aaa0a2 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 26 Feb 2020 09:05:57 +0000 Subject: [PATCH 587/595] Remove AUTHORS file reference from MANIFEST.in As title --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index bc21816e6b2..449dab31c5c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include MANIFEST.in -include README.rst setup.py runtests.py versioneer.py CHANGE_LOG AUTHORS LICENSE +include README.rst setup.py runtests.py versioneer.py CHANGE_LOG LICENSE recursive-include numba *.c *.cpp *.h *.hpp *.inc recursive-include docs *.ipynb *.txt *.py Makefile *.rst From 193168c1139f36b190e5107b99653e0fca41e8ba Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Tue, 25 Feb 2020 17:46:56 +0000 Subject: [PATCH 588/595] Update the image used in Azure CI for OSX. 10.13 is being retired, move to 10.14. --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 30de3753557..4fd21e78539 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ jobs: - template: buildscripts/azure/azure-linux-macos.yml parameters: name: macOS - vmImage: xcode9-macos10.13 + vmImage: macOS-10.14 matrix: py38_np117: PYTHON: '3.8' From c2688339faf796ff8ff009836b664f07853a07f8 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Wed, 26 Feb 2020 13:47:08 +0100 Subject: [PATCH 589/595] avoiding UnionType --- numba/core/typeinfer.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/numba/core/typeinfer.py b/numba/core/typeinfer.py index 614cac7b598..03cebde3bc1 100644 --- a/numba/core/typeinfer.py +++ b/numba/core/typeinfer.py @@ -1480,11 +1480,8 @@ def typeof_global(self, inst, target, gvar): typ = typ.copy(readonly=True) if isinstance(typ, types.BaseAnonymousTuple): - types_w_literals = (types.Integer, types.UnicodeType) - types_in_tuple = (typ.dtype.types - if isinstance(typ.dtype, types.UnionType) - else (typ.dtype,)) - if all(isinstance(ty, types_w_literals) for ty in types_in_tuple): + types_with_literals = (types.Integer, types.UnicodeType) + if all(isinstance(ty, types_with_literals) for ty in typ): typ = types.Tuple([types.literal(val) for val in gvar.value]) self.sentry_modified_builtin(inst, gvar) From 569e38f3c01e962053430003a0245688091bcf52 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 26 Feb 2020 13:28:48 +0000 Subject: [PATCH 590/595] Remove extra spaces --- numba/cpython/randomimpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cpython/randomimpl.py b/numba/cpython/randomimpl.py index cf402b558a6..7936ad7ce7e 100644 --- a/numba/cpython/randomimpl.py +++ b/numba/cpython/randomimpl.py @@ -1408,7 +1408,7 @@ def choice_impl(a, size=None, replace=True): return out else: # Note we have to construct the array to compute out.size - # (`size` can be an arbitrary int or tuple of ints) + # (`size` can be an arbitrary int or tuple of ints) out = np.empty(size, dtype) if out.size > n: raise ValueError("Cannot take a larger sample than " From 5c3274ec51663a486931f175fc2a107613f00383 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 26 Feb 2020 14:24:06 +0000 Subject: [PATCH 591/595] Make user facing error string use abs path not rel. This fixes a bug that appeared on windows where the installation and CWD were on different drives and as a result `os.path.relpath` raises a ValueError. `os.path.abspath` will produce a longer but more OS situation tolerant string. --- numba/cuda/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py index 98edc28d70e..69a65b873d2 100644 --- a/numba/cuda/compiler.py +++ b/numba/cuda/compiler.py @@ -632,7 +632,7 @@ def load_symbol(name): locinfo = '' else: sym, filepath, lineno = loc - filepath = os.path.relpath(filepath) + filepath = os.path.abspath(filepath) locinfo = 'In function %r, file %s, line %s, ' % ( sym, filepath, lineno, ) From 4490e59bfe54874e17d3afd00ede0ad410dc7957 Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Wed, 26 Feb 2020 14:58:46 +0000 Subject: [PATCH 592/595] Add in windows drive pattern match. As title. --- numba/cuda/tests/cudapy/test_userexc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba/cuda/tests/cudapy/test_userexc.py b/numba/cuda/tests/cudapy/test_userexc.py index f1862f362d4..7e68a65643a 100644 --- a/numba/cuda/tests/cudapy/test_userexc.py +++ b/numba/cuda/tests/cudapy/test_userexc.py @@ -8,7 +8,7 @@ class MyError(Exception): regex_pattern = ( - r'In function [\'"]test_exc[\'"], file [\.\/\\\-a-zA-Z_0-9]+, line \d+' + r'In function [\'"]test_exc[\'"], file [\:\.\/\\\-a-zA-Z_0-9]+, line \d+' ) From fbbad5f60a161cd35050b4ab72486449fc57a313 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Wed, 26 Feb 2020 16:47:24 +0100 Subject: [PATCH 593/595] adding test for content of error being raised --- numba/tests/test_record_dtype.py | 48 ++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 488585222a0..9e424228768 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -7,11 +7,14 @@ from numba.core.compiler import compile_isolated from numba.core.itanium_mangler import mangle_type from numba.core.config import IS_WIN32 +from numba.core.errors import TypingError from numba.np.numpy_support import numpy_version import unittest from numba.np import numpy_support +_FS = ('e', 'f') + def get_a(ary, i): return ary[i].a @@ -265,17 +268,14 @@ def get_field2(rec): return out -fs = ('e', 'f') - - def get_field3(rec): - f = fs[1] + f = _FS[1] return rec[f] def get_field4(rec): out = 0 - for f in literal_unroll(fs): + for f in literal_unroll(_FS): out += rec[f] return out @@ -1013,11 +1013,16 @@ class TestRecordArrayGetItem(unittest.TestCase): """ Test getitem when index is Literal[str] """ + def get_cfunc(self, pyfunc, rec_dtype): + rectype = numpy_support.from_dtype(rec_dtype) + cres = compile_isolated(pyfunc, (rectype,)) + return cres.entry_point + def test_literal_variable(self): arr = np.array([1, 2], dtype=recordtype2) pyfunc = get_field1 - jitfunc = njit(pyfunc) - self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) + cfunc = self.get_cfunc(pyfunc, rec_dtype=recordtype2) + self.assertEqual(pyfunc(arr[0]), cfunc(arr[0])) def test_literal_unroll(self): arr = np.array([1, 2], dtype=recordtype2) @@ -1027,7 +1032,7 @@ def test_literal_unroll(self): def test_literal_variable_global_tuple(self): """ - this tests the getitem of record array when the indexes come from a + This tests the getitem of record array when the indexes come from a global tuple. It tests getitem behaviour but also tests that a global tuple is being typed as a tuple of constants. """ @@ -1038,7 +1043,7 @@ def test_literal_variable_global_tuple(self): def test_literal_unroll_global_tuple(self): """ - this tests the getitem of record array when the indexes come from a + This tests the getitem of record array when the indexes come from a global tuple and are being unrolled. It tests getitem behaviour but also tests that literal_unroll accepts a global tuple as argument @@ -1048,6 +1053,31 @@ def test_literal_unroll_global_tuple(self): jitfunc = njit(pyfunc) self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) + def test_literal_unroll_free_var_tuple(self): + """ + This tests the getitem of record array when the indexes come from a + free variable tuple (not local, not global) and are being unrolled. + It tests getitem behaviour but also tests that literal_unroll accepts + a free variable tuple as argument + """ + fs = ('e', 'f') + arr = np.array([1, 2], dtype=recordtype2) + + def get_field(rec): + out = 0 + for f in literal_unroll(fs): + out += rec[f] + return out + + jitfunc = njit(get_field) + self.assertEqual(get_field(arr[0]), jitfunc(arr[0])) + + def test_error_w_invalid_field(self): + arr = np.array([1, 2], dtype=recordtype3) + with self.assertRaises(TypingError) as raises: + cfunc = self.get_cfunc(get_field1, rec_dtype=recordtype3) + self.assertIn("Field 'f' was not found in record with fields " + "('first', 'second')", str(raises.exception)) if __name__ == '__main__': unittest.main() From 632204b40fc1500bca26c507319a69b0bb802127 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Wed, 26 Feb 2020 16:51:52 +0100 Subject: [PATCH 594/595] minor consistency fix on tests --- numba/tests/test_record_dtype.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 9e424228768..5f81fd148da 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -1013,16 +1013,11 @@ class TestRecordArrayGetItem(unittest.TestCase): """ Test getitem when index is Literal[str] """ - def get_cfunc(self, pyfunc, rec_dtype): - rectype = numpy_support.from_dtype(rec_dtype) - cres = compile_isolated(pyfunc, (rectype,)) - return cres.entry_point - def test_literal_variable(self): arr = np.array([1, 2], dtype=recordtype2) pyfunc = get_field1 - cfunc = self.get_cfunc(pyfunc, rec_dtype=recordtype2) - self.assertEqual(pyfunc(arr[0]), cfunc(arr[0])) + jitfunc = njit(pyfunc) + self.assertEqual(pyfunc(arr[0]), jitfunc(arr[0])) def test_literal_unroll(self): arr = np.array([1, 2], dtype=recordtype2) @@ -1074,8 +1069,9 @@ def get_field(rec): def test_error_w_invalid_field(self): arr = np.array([1, 2], dtype=recordtype3) + jitfunc = njit(get_field1) with self.assertRaises(TypingError) as raises: - cfunc = self.get_cfunc(get_field1, rec_dtype=recordtype3) + jitfunc(arr[0]) self.assertIn("Field 'f' was not found in record with fields " "('first', 'second')", str(raises.exception)) From 268e8c49972061b6169601a5a03371902dadde75 Mon Sep 17 00:00:00 2001 From: luk-f-a Date: Wed, 26 Feb 2020 17:07:54 +0100 Subject: [PATCH 595/595] flake8 fix --- numba/tests/test_record_dtype.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index 5f81fd148da..92c6cdf438d 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -15,6 +15,7 @@ _FS = ('e', 'f') + def get_a(ary, i): return ary[i].a @@ -1075,5 +1076,6 @@ def test_error_w_invalid_field(self): self.assertIn("Field 'f' was not found in record with fields " "('first', 'second')", str(raises.exception)) + if __name__ == '__main__': unittest.main()