8000 TST: split long ufunc.at test by mattip · Pull Request #22918 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TST: split long ufunc.at test #22918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions numpy/core/tests/test_ufunc.py
9002
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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)
Expand Down Expand Up @@ -2034,23 +2034,21 @@ 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)

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
Expand All @@ -2062,6 +2060,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]
Expand All @@ -2085,7 +2084,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
Expand Down
0