Skip to content

Commit

Permalink
BUG: don't elide into readonly and updateifcopy temporaries
Browse files Browse the repository at this point in the history
  • Loading branch information
juliantaylor committed Jun 17, 2017
1 parent 3abc112 commit 7bd7283
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions numpy/core/src/multiarray/temp_elide.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ can_elide_temp(PyArrayObject * alhs, PyObject * orhs, int * cannot)
if (Py_REFCNT(alhs) != 1 || !PyArray_CheckExact(alhs) ||
PyArray_DESCR(alhs)->type_num >= NPY_OBJECT ||
!(PyArray_FLAGS(alhs) & NPY_ARRAY_OWNDATA) ||
!PyArray_ISWRITEABLE(alhs) ||
PyArray_CHKFLAGS(alhs, NPY_ARRAY_UPDATEIFCOPY) ||
PyArray_NBYTES(alhs) < NPY_MIN_ELIDE_BYTES) {
return 0;
}
Expand Down
11 changes: 11 additions & 0 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3151,6 +3151,17 @@ def test_elide_scalar(self):
a = np.bool_()
assert_(type(~(a & a)) is np.bool_)

def test_elide_readonly(self):
# don't try to elide readonly temporaries
r = np.asarray(np.broadcast_to(np.zeros(1), 100000).flat) * 0.0
assert_equal(r, 0)

def test_elide_updateifcopy(self):
a = np.ones(2**20)[::2]
b = a.flat.__array__() + 1
del b
assert_equal(a, 1)


class TestCAPI(TestCase):
def test_IsPythonScalar(self):
Expand Down

0 comments on commit 7bd7283

Please sign in to comment.