8000 TST: fix inplace case of alignment data generator · numpy/numpy@d555a0a · GitHub
[go: up one dir, main page]

Skip to content

Commit d555a0a

Browse files
committed
TST: fix inplace case of alignment data generator
Due to the lambdas used it didn't actually generate inplace cases. Fix a few tests that now break due to assuming that the cases are always out of place. Also update some numbers to make it more likely to find issues like loading from wrong array.
1 parent fd298a3 commit d555a0a

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

numpy/core/tests/test_scalarmath.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_blocked(self):
7373
inp1[...] = np.ones_like(inp1)
7474
inp2[...] = np.zeros_like(inp2)
7575
assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg)
76-
assert_almost_equal(np.add(inp1, 1), exp1 + 1, err_msg=msg)
76+
assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg)
7777
assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg)
7878

7979
np.add(inp1, inp2, out=out)
@@ -88,11 +88,11 @@ def test_blocked(self):
8888
np.divide(1, inp2), err_msg=msg)
8989

9090
inp1[...] = np.ones_like(inp1)
91-
inp2[...] = np.zeros_like(inp2)
92-
np.add(inp1, 1, out=out)
93-
assert_almost_equal(out, exp1 + 1, err_msg=msg)
94-
np.add(1, inp2, out=out)
95-
assert_almost_equal(out, exp1, err_msg=msg)
91+
np.add(inp1, 2, out=out)
92+
assert_almost_equal(out, exp1 + 2, err_msg=msg)
93+
inp2[...] = np.ones_like(inp2)
94+
np.add(2, inp2, out=out)
95+
assert_almost_equal(out, exp1 + 2, err_msg=msg)
9696

9797
def test_lower_align(self):
9898
# check data that is not aligned to element size

numpy/core/tests/test_umath.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,9 @@ def test_abs_neg_blocked(self):
12021202
assert_array_equal(out, d, err_msg=msg)
12031203

12041204
assert_array_equal(-inp, -1*inp, err_msg=msg)
1205+
d = -1 * inp
12051206
np.negative(inp, out=out)
1206-
assert_array_equal(out, -1*inp, err_msg=msg)
1207+
assert_array_equal(out, d, err_msg=msg)
12071208

12081209
def test_lower_align(self):
12091210
# check data that is not aligned to element size

numpy/testing/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,8 @@ def _gen_alignment_data(dtype=float32, type='binary', max_size=24):
17941794
inp = lambda: arange(s, dtype=dtype)[o:]
17951795
out = empty((s,), dtype=dtype)[o:]
17961796
yield out, inp(), ufmt % (o, o, s, dtype, 'out of place')
1797-
yield inp(), inp(), ufmt % (o, o, s, dtype, 'in place')
1797+
d = inp()
1798+
yield d, d, ufmt % (o, o, s, dtype, 'in place')
17981799
yield out[1:], inp()[:-1], ufmt % \
17991800
(o + 1, o, s - 1, dtype, 'out of place')
18001801
yield out[:-1], inp()[1:], ufmt % \
@@ -1809,9 +1810,11 @@ def _gen_alignment_data(dtype=float32, type='binary', max_size=24):
18091810
out = empty((s,), dtype=dtype)[o:]
18101811
yield out, inp1(), inp2(), bfmt % \
18111812
(o, o, o, s, dtype, 'out of place')
1812-
yield inp1(), inp1(), inp2(), bfmt % \
1813+
d = inp1()
1814+
yield d, d, inp2(), bfmt % \
18131815
(o, o, o, s, dtype, 'in place1')
1814-
yield inp2(), inp1(), inp2(), bfmt % \
1816+
d = inp2()
1817+
yield d, inp1(), d, bfmt % \
18151818
(o, o, o, s, dtype, 'in place2')
18161819
yield out[1:], inp1()[:-1], inp2()[:-1], bfmt % \
18171820
(o + 1, o, o, s - 1, dtype, 'out of place')

0 commit comments

Comments
 (0)
0