8000 ENH: add inplace cases to fast ufunc loop macros by juliantaylor · Pull Request #7999 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: add inplace cases to fast ufunc loop macros #7999

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
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
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.
  • Loading branch information
juliantaylor committed Sep 1, 2016
commit d555a0ad0f1191daf8ae83e10933da5556b2510e
12 changes: 6 additions & 6 deletions numpy/core/tests/test_scalarmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_blocked(self):
inp1[...] = np.ones_like(inp1)
inp2[...] = np.zeros_like(inp2)
assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg)
assert_almost_equal(np.add(inp1, 1), exp1 + 1, err_msg=msg)
assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg)
assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg)

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

inp1[...] = np.ones_like(inp1)
inp2[...] = np.zeros_like(inp2)
np.add(inp1, 1, out=out)
assert_almost_equal(out, exp1 + 1, err_msg=msg)
np.add(1, inp2, out=out)
assert_almost_equal(out, exp1, err_msg=msg)
np.add(inp1, 2, out=out)
assert_almost_equal(out, exp1 + 2, err_msg=msg)
inp2[...] = np.ones_like(inp2)
np.add(2, inp2, out=out)
assert_almost_equal(out, exp1 + 2, err_msg=msg)

def test_lower_align(self):
# check data that is not aligned to element size
Expand Down
3 changes: 2 additions & 1 deletion numpy/core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,8 +1202,9 @@ def test_abs_neg_blocked(self):
assert_array_equal(out, d, err_msg=msg)

assert_array_equal(-inp, -1*inp, err_msg=msg)
d = -1 * inp
np.negative(inp, out=out)
assert_array_equal(out, -1*inp, err_msg=msg)
assert_array_equal(out, d, err_msg=msg)

def test_lower_align(self):
# check data that is not aligned to element size
Expand Down
9 changes: 6 additions & 3 deletions numpy/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,8 @@ def _gen_alignment_data(dtype=float32, type='binary', max_size=24):
inp = lambda: arange(s, dtype=dtype)[o:]
out = empty((s,), dtype=dtype)[o:]
yield out, inp(), ufmt % (o, o, s, dtype, 'out of place')
yield inp(), inp(), ufmt % (o, o, s, dtype, 'in place')
d = inp()
yield d, d, ufmt % (o, o, s, dtype, 'in place')
yield out[1:], inp()[:-1], ufmt % \
(o + 1, o, s - 1, dtype, 'out of place')
yield out[:-1], inp()[1:], ufmt % \
Expand All @@ -1809,9 +1810,11 @@ def _gen_alignment_data(dtype=float32, type='binary', max_size=24):
out = empty((s,), dtype=dtype)[o:]
yield out, inp1(), inp2(), bfmt % \
(o, o, o, s, dtype, 'out of place')
yield inp1(), inp1(), inp2(), bfmt % \
d = inp1()
yield d, d, inp2(), bfmt % \
(o, o, o, s, dtype, 'in place1')
yield inp2(), inp1(), inp2(), bfmt % \
d = inp2()
yield d, inp1(), d, bfmt % \
(o, o, o, s, dtype, 'in place2')
yield out[1:], inp1()[:-1], inp2()[:-1], bfmt % \
(o + 1, o, o, s - 1, dtype, 'out of place')
Expand Down
0