From 11ba299516ce9f717f89ca863dbdeb8688ee4d3e Mon Sep 17 00:00:00 2001 From: kc611 Date: Wed, 15 Feb 2023 21:34:11 +0530 Subject: [PATCH 1/7] Refactored Fancy Index Selection and Testing --- numba/core/typing/arraydecl.py | 65 +++++++-- numba/tests/test_array_manipulation.py | 4 +- numba/tests/test_fancy_indexing.py | 190 ++++++++++++++++++++++++- numba/tests/test_record_dtype.py | 2 +- 4 files changed, 243 insertions(+), 18 deletions(-) diff --git a/numba/core/typing/arraydecl.py b/numba/core/typing/arraydecl.py index c6d0806f25c..81514cd41f8 100644 --- a/numba/core/typing/arraydecl.py +++ b/numba/core/typing/arraydecl.py @@ -34,50 +34,87 @@ def get_array_index_type(ary, idx): right_indices = [] ellipsis_met = False advanced = False - has_integer = False num_newaxis = 0 if not isinstance(idx, types.BaseTuple): idx = [idx] + # A subspace is a contigous group of advanced indices. + # num_subspaces keeps track of the number of such + # contigous groups. + in_subspace = False + num_subspaces = 0 + array_indices = 0 + # Walk indices for ty in idx: if ty is types.ellipsis: if ellipsis_met: - raise NumbaTypeError("only one ellipsis allowed in array index " - "(got %s)" % (idx,)) + raise NumbaTypeError( + "Only one ellipsis allowed in array indices " + "(got %s)" % (idx,)) ellipsis_met = True + in_subspace = False elif isinstance(ty, types.SliceType): - pass + # If we encounter a non-advanced index while in a + # subspace then that subspace ends. + in_subspace = False + # In advanced indexing, any index broadcastable to an + # array is considered an advanced index. All the + # branches below are hence considered as advanced indices. elif isinstance(ty, types.Integer): # Normalize integer index ty = types.intp if ty.signed else types.uintp # Integer indexing removes the given dimension ndim -= 1 - has_integer = True + # If we're within a subspace/contigous group of + # advanced indices then no action is necessary + # since we've already counted that subspace once. + if not in_subspace: + # If we're not within a subspace and we encounter + # this branch then we have a new subspace/group. + num_subspaces += 1 + in_subspace = True elif (isinstance(ty, types.Array) and ty.ndim == 0 and isinstance(ty.dtype, types.Integer)): # 0-d array used as integer index ndim -= 1 - has_integer = True + if not in_subspace: + num_subspaces += 1 + in_subspace = True elif (isinstance(ty, types.Array) - and ty.ndim == 1 and isinstance(ty.dtype, (types.Integer, types.Boolean))): - if advanced or has_integer: - # We don't support the complicated combination of - # advanced indices (and integers are considered part - # of them by Numpy). - msg = "only one advanced index supported" - raise NumbaNotImplementedError(msg) + if ty.ndim > 1: + # Advanced indexing limitation # 1 + raise NumbaTypeError( + "Multi-dimensional indices are not supported.") + array_indices += 1 + # The condition for activating advanced indexing is simply + # having atleast one array with size > 1. advanced = True + if not in_subspace: + num_subspaces += 1 + in_subspace = True elif (is_nonelike(ty)): ndim += 1 num_newaxis += 1 else: - raise NumbaTypeError("unsupported array index type %s in %s" + raise NumbaTypeError("Unsupported array index type %s in %s" % (ty, idx)) (right_indices if ellipsis_met else left_indices).append(ty) + if advanced: + if array_indices > 1: + # Advanced indexing limitation # 2 + msg = "Using more than one non-scalar array index is unsupported." + raise NumbaTypeError(msg) + + if num_subspaces > 1: + # Advanced indexing limitation # 3 + msg = ("Using more than one indexing subspace (consecutive group " + "of integer or array indices) is unsupported.") + raise NumbaTypeError(msg) + # Only Numpy arrays support advanced indexing if advanced and not isinstance(ary, types.Array): return diff --git a/numba/tests/test_array_manipulation.py b/numba/tests/test_array_manipulation.py index 91a5afe6d5d..e59831011ca 100644 --- a/numba/tests/test_array_manipulation.py +++ b/numba/tests/test_array_manipulation.py @@ -680,13 +680,13 @@ def test_bad_index_npm(self): arraytype2 = types.Array(types.int32, 2, 'C') compile_isolated(bad_index, (arraytype1, arraytype2), flags=no_pyobj_flags) - self.assertIn('unsupported array index type', str(raises.exception)) + self.assertIn('Unsupported array index type', str(raises.exception)) def test_bad_float_index_npm(self): with self.assertTypingError() as raises: compile_isolated(bad_float_index, (types.Array(types.float64, 2, 'C'),)) - self.assertIn('unsupported array index type float64', + self.assertIn('Unsupported array index type float64', str(raises.exception)) def test_fill_diagonal_basic(self): diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index 7bb95c31c6c..56431d5c900 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -6,7 +6,7 @@ from numba import jit, typeof, njit from numba.core import types from numba.core.errors import TypingError -from numba.tests.support import MemoryLeakMixin, TestCase, tag +from numba.tests.support import MemoryLeakMixin, TestCase def getitem_usecase(a, b): @@ -301,5 +301,193 @@ def np_new_axis_setitem(a, idx, item): np.testing.assert_equal(expected, got) +class TestFancyIndexingMultiDim(MemoryLeakMixin, TestCase): + # Every case has exactly one, one-dimensional array, + # Otherwise it's not fancy indexing + shape = (5, 6, 7, 8, 9, 10) + indexing_cases = [ + # Slices + Integers + (slice(4, 5), 3, np.array([0,1,3,4,2]), 1), + (3, np.array([0,1,3,4,2]), slice(None), slice(4)), + + # Ellipsis + Integers + (Ellipsis, 1, np.array([0,1,3,4,2])), + (np.array([0,1,3,4,2]), 3, Ellipsis), + + # Ellipsis + Slices + Integers + (Ellipsis, 1, np.array([0,1,3,4,2]), 3, slice(1,5)), + (np.array([0,1,3,4,2]), 3, Ellipsis, slice(1,5)), + + # Boolean Arrays + Integers + (slice(4, 5), 3, + np.array([True, False, True, False, True, False, False]), + 1), + (3, np.array([True, False, True, False, True, False]), + slice(None), slice(4)), + ] + + rng = np.random.default_rng(1) + + def generate_random_indices(self): + N = min(self.shape) + slice_choices = [slice(None, None, None), + slice(1, N - 1, None), + slice(0, None, 2), + slice(N - 1, None, -2), + slice(-N + 1, -1, None), + slice(-1, -N, -2), + slice(0, N - 1, None), + slice(-1, -N, -2) + ] + integer_choices = list(np.arange(N)) + + indices = [] + + # Generate 20 random slice cases + for i in range(20): + array_idx = self.rng.integers(0, 5, size=15) + # Randomly select 4 slices from our list + curr_idx = self.rng.choice(slice_choices, size=4).tolist() + # Replace one of the slice with the array index + _array_idx = self.rng.choice(4) + curr_idx[_array_idx] = array_idx + indices.append(tuple(curr_idx)) + + # Generate 20 random integer cases + for i in range(20): + array_idx = self.rng.integers(0, 5, size=15) + # Randomly select 4 integers from our list + curr_idx = self.rng.choice(integer_choices, size=4).tolist() + # Replace one of the slice with the array index + _array_idx = self.rng.choice(4) + curr_idx[_array_idx] = array_idx + indices.append(tuple(curr_idx)) + + # Generate 20 random ellipsis cases + for i in range(20): + array_idx = self.rng.integers(0, 5, size=15) + # Randomly select 4 slices from our list + curr_idx = self.rng.choice(slice_choices, size=4).tolist() + # Generate two seperate random indices, replace one with + # array and second with Ellipsis + _array_idx = self.rng.choice(4, size=2, replace=False) + curr_idx[_array_idx[0]] = array_idx + curr_idx[_array_idx[1]] = Ellipsis + indices.append(tuple(curr_idx)) + + # Generate 20 random boolean cases + for i in range(20): + array_idx = self.rng.integers(0, 5, size=15) + # Randomly select 4 slices from our list + curr_idx = self.rng.choice(slice_choices, size=4).tolist() + # Replace one of the slice with the boolean array index + _array_idx = self.rng.choice(4) + bool_arr_shape = self.shape[_array_idx] + curr_idx[_array_idx] = np.array( + self.rng.choice(2, size=bool_arr_shape), + dtype=bool + ) + + indices.append(tuple(curr_idx)) + + return indices + + def check_getitem_indices(self, arr_shape, index): + def get_item(array, idx): + return array[idx] + + arr = np.random.randint(0, 11, size=arr_shape) + get_item_numba = njit(get_item) + orig = arr.copy() + orig_base = arr.base or arr + + expected = get_item(arr, index) + got = get_item_numba(arr, index) + # Sanity check: In advanced indexing, the result is always a copy. + assert expected.base is not orig_base + + # Note: Numba may not return the same array strides and + # contiguity as Numpy + self.assertEqual(got.shape, expected.shape) + self.assertEqual(got.dtype, expected.dtype) + np.testing.assert_equal(got, expected) + + # Check a copy was *really* returned by Numba + assert not np.may_share_memory(got, expected) + + def check_setitem_indices(self, arr_shape, index): + @njit + def set_item(array, idx, item): + array[idx] = item + + arr = np.random.randint(0, 11, size=arr_shape) + src = arr[index] + expected = np.zeros_like(arr) + got = np.zeros_like(arr) + + set_item.py_func(expected, index, src) + set_item(got, index, src) + + # Note: Numba may not return the same array strides and + # contiguity as NumPy + self.assertEqual(got.shape, expected.shape) + self.assertEqual(got.dtype, expected.dtype) + + np.testing.assert_equal(got, expected) + + def test_getitem(self): + # Cases with a combination of integers + other objects + indices = self.indexing_cases + + # Cases with permutations of either integers or objects + indices += self.generate_random_indices() + + for idx in indices: + with self.subTest(idx=idx): + self.check_getitem_indices(self.shape, idx) + + def test_setitem(self): + # Cases with a combination of integers + other objects + indices = self.indexing_cases + + # Cases with permutations of either integers or objects + indices += self.generate_random_indices() + + for idx in indices: + with self.subTest(idx=idx): + self.check_setitem_indices(self.shape, idx) + + def test_unsupported_condition_exceptions(self): + # Cases with multi-dimensional indexing array + idx = (0, 3, np.array([[1, 2], [2, 3]])) + with self.assertRaises(TypingError) as raises: + self.check_getitem_indices(self.shape, idx) + self.assertIn( + 'Multi-dimensional indices are not supported.', + str(raises.exception) + ) + + # Cases with more than one indexing array + idx = (0, 3, np.array([1, 2]), np.array([1, 2])) + with self.assertRaises(TypingError) as raises: + self.check_getitem_indices(self.shape, idx) + self.assertIn( + 'Using more than one non-scalar array index is unsupported.', + str(raises.exception) + ) + + # Cases with more than one indexing subspace + # (The subspaces here are separated by slice(None)) + idx = (0, np.array([1, 2]), slice(None), 3, 4) + with self.assertRaises(TypingError) as raises: + self.check_getitem_indices(self.shape, idx) + msg = "Using more than one indexing subspace (consecutive group " +\ + "of integer or array indices) is unsupported." + self.assertIn( + msg, + str(raises.exception) + ) + + if __name__ == '__main__': unittest.main() diff --git a/numba/tests/test_record_dtype.py b/numba/tests/test_record_dtype.py index bb93a7d61cf..3c551d6ae6e 100644 --- a/numba/tests/test_record_dtype.py +++ b/numba/tests/test_record_dtype.py @@ -1554,7 +1554,7 @@ def test_setitem_whole_array_error(self): nbarr2 = np.recarray(1, dtype=recordwith2darray) args = (nbarr1, nbarr2) pyfunc = record_setitem_array - errmsg = "unsupported array index type" + errmsg = "Unsupported array index type" with self.assertRaisesRegex(TypingError, errmsg): self.get_cfunc(pyfunc, tuple((typeof(arg) for arg in args))) From edc3f5aa64a7912d7c108314b1915dc7a58d248d Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Sat, 25 Feb 2023 20:18:01 +0530 Subject: [PATCH 2/7] Apply suggestions from code review Co-authored-by: stuartarchibald --- numba/core/typing/arraydecl.py | 14 +++++++------- numba/tests/test_fancy_indexing.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/numba/core/typing/arraydecl.py b/numba/core/typing/arraydecl.py index 81514cd41f8..58961ffd008 100644 --- a/numba/core/typing/arraydecl.py +++ b/numba/core/typing/arraydecl.py @@ -39,9 +39,9 @@ def get_array_index_type(ary, idx): if not isinstance(idx, types.BaseTuple): idx = [idx] - # A subspace is a contigous group of advanced indices. + # Here, a subspace is considered as a contiguous group of advanced indices. # num_subspaces keeps track of the number of such - # contigous groups. + # contiguous groups. in_subspace = False num_subspaces = 0 array_indices = 0 @@ -60,19 +60,19 @@ def get_array_index_type(ary, idx): # subspace then that subspace ends. in_subspace = False # In advanced indexing, any index broadcastable to an - # array is considered an advanced index. All the - # branches below are hence considered as advanced indices. + # array is considered an advanced index. Hence all the + # branches below are considered as advanced indices. elif isinstance(ty, types.Integer): # Normalize integer index ty = types.intp if ty.signed else types.uintp # Integer indexing removes the given dimension ndim -= 1 - # If we're within a subspace/contigous group of + # If we're within a subspace/contiguous group of # advanced indices then no action is necessary # since we've already counted that subspace once. if not in_subspace: # If we're not within a subspace and we encounter - # this branch then we have a new subspace/group. + # this branch then we have a new subspace/group. num_subspaces += 1 in_subspace = True elif (isinstance(ty, types.Array) and ty.ndim == 0 @@ -90,7 +90,7 @@ def get_array_index_type(ary, idx): "Multi-dimensional indices are not supported.") array_indices += 1 # The condition for activating advanced indexing is simply - # having atleast one array with size > 1. + # having at least one array with size > 1. advanced = True if not in_subspace: num_subspaces += 1 diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index 56431d5c900..e77f1381d01 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -303,11 +303,11 @@ def np_new_axis_setitem(a, idx, item): class TestFancyIndexingMultiDim(MemoryLeakMixin, TestCase): # Every case has exactly one, one-dimensional array, - # Otherwise it's not fancy indexing + # otherwise it's not fancy indexing. shape = (5, 6, 7, 8, 9, 10) indexing_cases = [ # Slices + Integers - (slice(4, 5), 3, np.array([0,1,3,4,2]), 1), + (slice(4, 5), 3, np.array([0, 1, 3, 4, 2]), 1), (3, np.array([0,1,3,4,2]), slice(None), slice(4)), # Ellipsis + Integers @@ -343,8 +343,10 @@ def generate_random_indices(self): indices = [] - # Generate 20 random slice cases - for i in range(20): + # Generate K random slice cases. The value of K is arbitrary, the intent is + # to create plenty of variation. + K = 20 + for _ in range(K): array_idx = self.rng.integers(0, 5, size=15) # Randomly select 4 slices from our list curr_idx = self.rng.choice(slice_choices, size=4).tolist() @@ -352,7 +354,6 @@ def generate_random_indices(self): _array_idx = self.rng.choice(4) curr_idx[_array_idx] = array_idx indices.append(tuple(curr_idx)) - # Generate 20 random integer cases for i in range(20): array_idx = self.rng.integers(0, 5, size=15) @@ -387,7 +388,6 @@ def generate_random_indices(self): self.rng.choice(2, size=bool_arr_shape), dtype=bool ) - indices.append(tuple(curr_idx)) return indices @@ -407,7 +407,7 @@ def get_item(array, idx): assert expected.base is not orig_base # Note: Numba may not return the same array strides and - # contiguity as Numpy + # contiguity as NumPy self.assertEqual(got.shape, expected.shape) self.assertEqual(got.dtype, expected.dtype) np.testing.assert_equal(got, expected) @@ -416,7 +416,7 @@ def get_item(array, idx): assert not np.may_share_memory(got, expected) def check_setitem_indices(self, arr_shape, index): - @njit + @njit def set_item(array, idx, item): array[idx] = item From 03177c1d3ee71d9e3f2515b0812ec981e00785cf Mon Sep 17 00:00:00 2001 From: kc611 Date: Sat, 25 Feb 2023 20:49:03 +0530 Subject: [PATCH 3/7] Apply suggestions from code reviews --- numba/core/typing/arraydecl.py | 5 ++- numba/tests/test_fancy_indexing.py | 63 +++++++++++++----------------- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/numba/core/typing/arraydecl.py b/numba/core/typing/arraydecl.py index 58961ffd008..def4a5ed177 100644 --- a/numba/core/typing/arraydecl.py +++ b/numba/core/typing/arraydecl.py @@ -111,8 +111,9 @@ def get_array_index_type(ary, idx): if num_subspaces > 1: # Advanced indexing limitation # 3 - msg = ("Using more than one indexing subspace (consecutive group " - "of integer or array indices) is unsupported.") + msg = ("Using more than one indexing subspace is unsupported." + " An indexing subspace is a group of one or more" + " consecutive indices comprising integer or array types.") raise NumbaTypeError(msg) # Only Numpy arrays support advanced indexing diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index e77f1381d01..c0c6b27cbf8 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -393,18 +393,18 @@ def generate_random_indices(self): return indices def check_getitem_indices(self, arr_shape, index): - def get_item(array, idx): + @njit + def numba_get_item(array, idx): return array[idx] arr = np.random.randint(0, 11, size=arr_shape) - get_item_numba = njit(get_item) - orig = arr.copy() + get_item = numba_get_item.py_func orig_base = arr.base or arr expected = get_item(arr, index) - got = get_item_numba(arr, index) + got = numba_get_item(arr, index) # Sanity check: In advanced indexing, the result is always a copy. - assert expected.base is not orig_base + self.assertNotIn(expected.base, orig_base) # Note: Numba may not return the same array strides and # contiguity as NumPy @@ -413,7 +413,7 @@ def get_item(array, idx): np.testing.assert_equal(got, expected) # Check a copy was *really* returned by Numba - assert not np.may_share_memory(got, expected) + self.assertFalse(np.may_share_memory(got, expected)) def check_setitem_indices(self, arr_shape, index): @njit @@ -458,35 +458,28 @@ def test_setitem(self): self.check_setitem_indices(self.shape, idx) def test_unsupported_condition_exceptions(self): - # Cases with multi-dimensional indexing array - idx = (0, 3, np.array([[1, 2], [2, 3]])) - with self.assertRaises(TypingError) as raises: - self.check_getitem_indices(self.shape, idx) - self.assertIn( - 'Multi-dimensional indices are not supported.', - str(raises.exception) - ) - - # Cases with more than one indexing array - idx = (0, 3, np.array([1, 2]), np.array([1, 2])) - with self.assertRaises(TypingError) as raises: - self.check_getitem_indices(self.shape, idx) - self.assertIn( - 'Using more than one non-scalar array index is unsupported.', - str(raises.exception) - ) - - # Cases with more than one indexing subspace - # (The subspaces here are separated by slice(None)) - idx = (0, np.array([1, 2]), slice(None), 3, 4) - with self.assertRaises(TypingError) as raises: - self.check_getitem_indices(self.shape, idx) - msg = "Using more than one indexing subspace (consecutive group " +\ - "of integer or array indices) is unsupported." - self.assertIn( - msg, - str(raises.exception) - ) + err_idx_cases = [ + # Cases with multi-dimensional indexing array + ('Multi-dimensional indices are not supported.', + (0, 3, np.array([[1, 2], [2, 3]]))), + # Cases with more than one indexing array + ('Using more than one non-scalar array index is unsupported.', + (0, 3, np.array([1, 2]), np.array([1, 2]))), + # Cases with more than one indexing subspace + # (The subspaces here are separated by slice(None)) + ("Using more than one indexing subspace is unsupported." + \ + " An indexing subspace is a group of one or more consecutive" + \ + " indices comprising integer or array types.", + (0, np.array([1, 2]), slice(None), 3, 4)) + ] + + for err, idx in err_idx_cases: + with self.assertRaises(TypingError) as raises: + self.check_getitem_indices(self.shape, idx) + self.assertIn( + err, + str(raises.exception) + ) if __name__ == '__main__': From 70e7fc19b3c7f3f5ed4fe998d80e7b9808a0bbcb Mon Sep 17 00:00:00 2001 From: kc611 Date: Mon, 27 Feb 2023 16:07:56 +0530 Subject: [PATCH 4/7] Prevented accidental mutation of indexing cases in fancy indexing tests --- numba/tests/test_fancy_indexing.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index c0c6b27cbf8..edc3edd1856 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -437,7 +437,7 @@ def set_item(array, idx, item): def test_getitem(self): # Cases with a combination of integers + other objects - indices = self.indexing_cases + indices = self.indexing_cases.copy() # Cases with permutations of either integers or objects indices += self.generate_random_indices() @@ -448,7 +448,7 @@ def test_getitem(self): def test_setitem(self): # Cases with a combination of integers + other objects - indices = self.indexing_cases + indices = self.indexing_cases.copy() # Cases with permutations of either integers or objects indices += self.generate_random_indices() @@ -482,5 +482,7 @@ def test_unsupported_condition_exceptions(self): ) -if __name__ == '__main__': - unittest.main() +# if __name__ == '__main__': +# unittest.main() +x = TestFancyIndexingMultiDim() +x.test_getitem() \ No newline at end of file From db062bcbc2d97d957da81072a8492f2b9ea16658 Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Tue, 28 Feb 2023 22:10:57 +0530 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: stuartarchibald --- numba/tests/test_fancy_indexing.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index edc3edd1856..a4dd95fd21d 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -354,8 +354,8 @@ def generate_random_indices(self): _array_idx = self.rng.choice(4) curr_idx[_array_idx] = array_idx indices.append(tuple(curr_idx)) - # Generate 20 random integer cases - for i in range(20): + # Generate K random integer cases + for _ in range(K): array_idx = self.rng.integers(0, 5, size=15) # Randomly select 4 integers from our list curr_idx = self.rng.choice(integer_choices, size=4).tolist() @@ -364,8 +364,8 @@ def generate_random_indices(self): curr_idx[_array_idx] = array_idx indices.append(tuple(curr_idx)) - # Generate 20 random ellipsis cases - for i in range(20): + # Generate K random ellipsis cases + for _ in range(K): array_idx = self.rng.integers(0, 5, size=15) # Randomly select 4 slices from our list curr_idx = self.rng.choice(slice_choices, size=4).tolist() @@ -376,8 +376,8 @@ def generate_random_indices(self): curr_idx[_array_idx[1]] = Ellipsis indices.append(tuple(curr_idx)) - # Generate 20 random boolean cases - for i in range(20): + # Generate K random boolean cases + for _ in range(K): array_idx = self.rng.integers(0, 5, size=15) # Randomly select 4 slices from our list curr_idx = self.rng.choice(slice_choices, size=4).tolist() From 233b1d1b0d2a40c56083cdbfe8e62c9fede67aaa Mon Sep 17 00:00:00 2001 From: kc611 Date: Tue, 28 Feb 2023 22:12:40 +0530 Subject: [PATCH 6/7] Removed unintended changes to testing framework --- numba/tests/test_fancy_indexing.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index a4dd95fd21d..79b64853887 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -482,7 +482,5 @@ def test_unsupported_condition_exceptions(self): ) -# if __name__ == '__main__': -# unittest.main() -x = TestFancyIndexingMultiDim() -x.test_getitem() \ No newline at end of file +if __name__ == '__main__': + unittest.main() From 21f0e917b5c637b71e0eedb6357330ea2d5e4a46 Mon Sep 17 00:00:00 2001 From: kc611 Date: Fri, 10 Mar 2023 17:08:29 +0530 Subject: [PATCH 7/7] Added setup method for new fancy indexing tests --- numba/tests/test_fancy_indexing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numba/tests/test_fancy_indexing.py b/numba/tests/test_fancy_indexing.py index 79b64853887..5d909963fd0 100644 --- a/numba/tests/test_fancy_indexing.py +++ b/numba/tests/test_fancy_indexing.py @@ -326,7 +326,9 @@ class TestFancyIndexingMultiDim(MemoryLeakMixin, TestCase): slice(None), slice(4)), ] - rng = np.random.default_rng(1) + def setUp(self): + super().setUp() + self.rng = np.random.default_rng(1) def generate_random_indices(self): N = min(self.shape)