From ebe86acfd1aa898a559a37dd489d98c182f8bde6 Mon Sep 17 00:00:00 2001 From: mattip Date: Tue, 3 Jan 2023 18:19:05 +0200 Subject: [PATCH 1/2] TST: split long ufunc.at test --- numpy/core/tests/test_ufunc.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 85c90c129265..dcfa372d21ab 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -1927,7 +1927,7 @@ def __rmul__(self, other): np.arange(10, dtype=int), np.arange(10, dtype=_rational_tests.rational), )) - def test_ufunc_at(self, a): + def test_ufunc_at_basic(self, a): aa = a.copy() np.add.at(aa, [2, 5, 2], 1) @@ -1941,6 +1941,11 @@ def test_ufunc_at(self, a): np.negative.at(aa, [2, 5, 3]) assert_equal(aa, [0, 1, -2, -3, 4, -5, 6, 7, 8, 9]) + aa = a.copy() + b = np.array([100, 100, 100]) + np.add.at(aa, [2, 5, 2], b) + assert_equal(aa, [0, 1, 202, 3, 4, 105, 6, 7, 8, 9]) + with pytest.raises(ValueError): # extraneous second operand np.negative.at(a, [2, 5, 3], [1, 2, 3]) @@ -1949,12 +1954,7 @@ def test_ufunc_at(self, a): # second operand cannot be converted to an array np.add.at(a, [2, 5, 3], [[1, 2], 1]) - # reset a - a = np.arange(10) - b = np.array([100, 100, 100]) - np.add.at(a, [2, 5, 2], b) - assert_equal(a, [0, 1, 202, 3, 4, 105, 6, 7, 8, 9]) - + def test_ufunc_at_multiD(self): a = np.arange(9).reshape(3, 3) b = np.array([[100, 100, 100], [200, 200, 200], [300, 300, 300]]) np.add.at(a, (slice(None), [1, 2, 1]), b) @@ -2034,11 +2034,8 @@ def test_ufunc_at(self, a): [121, 222, 323], [124, 225, 326]]]) - a = np.arange(10) - np.negative.at(a, [2, 5, 2]) - assert_equal(a, [0, 1, 2, 3, 4, -5, 6, 7, 8, 9]) - # Test 0-dim array + def test_ufunc_at_0D(self): a = np.array(0) np.add.at(a, (), 1) assert_equal(a, 1) @@ -2046,11 +2043,13 @@ def test_ufunc_at(self, a): assert_raises(IndexError, np.add.at, a, 0, 1) assert_raises(IndexError, np.add.at, a, [], 1) + def test_ufunc_at_dtypes(self): # Test mixed dtypes a = np.arange(10) np.power.at(a, [1, 2, 3, 2], 3.5) assert_equal(a, np.array([0, 1, 4414, 46, 4, 5, 6, 7, 8, 9])) + def test_ufunc_at_boolean(self): # Test boolean indexing and boolean ufuncs a = np.arange(10) index = a % 2 == 0 @@ -2062,6 +2061,7 @@ def test_ufunc_at(self, a): np.invert.at(a, [2, 5, 2]) assert_equal(a, [0, 1, 2, 3, 4, 5 ^ 0xffffffff, 6, 7, 8, 9]) + def test_ufunc_at_advanced(self): # Test empty subspace orig = np.arange(4) a = orig[:, None][:, 0:0] @@ -2085,7 +2085,7 @@ def test_ufunc_at(self, a): # Test maximum a = np.array([1, 2, 3]) np.maximum.at(a, [0], 0) - assert_equal(np.array([1, 2, 3]), a) + assert_equal(a, np.array([1, 2, 3])) def test_at_not_none_signature(self): # Test ufuncs with non-trivial signature raise a TypeError From 7762920e88a3f44bcc9c4a22d8d243716abc16c6 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Tue, 3 Jan 2023 17:38:19 +0100 Subject: [PATCH 2/2] Update numpy/core/tests/test_ufunc.py --- numpy/core/tests/test_ufunc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index dcfa372d21ab..34cdd88c6497 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -2034,7 +2034,6 @@ def test_ufunc_at_multiD(self): [121, 222, 323], [124, 225, 326]]]) - def test_ufunc_at_0D(self): a = np.array(0) np.add.at(a, (), 1)