summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2017-06-10 12:23:04 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2017-06-17 17:45:57 +0200
commit7bd7283ce3325ccae4ae2f5628166b605af773cb (patch)
tree93c3df226a05f7f441be944199b4a784d93828b8 /numpy
parent3abc112883aa7f381b722f9f2e02bdb4ba5749f9 (diff)
downloadnumpy-7bd7283ce3325ccae4ae2f5628166b605af773cb.tar.gz
BUG: don't elide into readonly and updateifcopy temporaries
Closes gh-9232, gh-9245
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/temp_elide.c2
-rw-r--r--numpy/core/tests/test_multiarray.py11
2 files changed, 13 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/temp_elide.c b/numpy/core/src/multiarray/temp_elide.c
index c4673bd4b..f885fe218 100644
--- a/numpy/core/src/multiarray/temp_elide.c
+++ b/numpy/core/src/multiarray/temp_elide.c
@@ -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;
}
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 98981c8b6..3c07902a7 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -3151,6 +3151,17 @@ class TestTemporaryElide(TestCase):
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):