summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-06-17 13:19:14 -0600
committerGitHub <noreply@github.com>2017-06-17 13:19:14 -0600
commit733df1c955ba58e835a46bb7bd2af7f313decaca (patch)
tree108227f05751105888d2272a7b17bcce95ac2565
parent6e2c42df11b42832036f999a924b088210702524 (diff)
parent7bd7283ce3325ccae4ae2f5628166b605af773cb (diff)
downloadnumpy-733df1c955ba58e835a46bb7bd2af7f313decaca.tar.gz
Merge pull request #9261 from juliantaylor/readonly-temp
BUG: don't elide into readonly and updateifcopy temporaries for 1.13
-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 b93f4e67e..abca0ecd6 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_ISNUMBER(alhs) ||
!(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 3575ecc8e..385b1d4d5 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -3172,6 +3172,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):