summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-09-21 11:20:28 -0500
committerGitHub <noreply@github.com>2017-09-21 11:20:28 -0500
commit54232da2f1c1d65f01c747eb7d1dda8fd46d6a63 (patch)
treec6be6f055ddb93f88a513120b6c1afa74de332d8
parent80f0a0a9c25584dd431e7a253446bff8ce0da379 (diff)
parent2549adf90c95ec700fced0049f440207858081c5 (diff)
downloadnumpy-54232da2f1c1d65f01c747eb7d1dda8fd46d6a63.tar.gz
Merge pull request #9711 from charris/fix-scalar-elision
BUG: Make scalar function elision check writeable.
-rw-r--r--numpy/core/src/multiarray/temp_elide.c2
-rw-r--r--numpy/core/tests/test_multiarray.py9
2 files changed, 11 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/temp_elide.c b/numpy/core/src/multiarray/temp_elide.c
index abca0ecd6..3822f5d0d 100644
--- a/numpy/core/src/multiarray/temp_elide.c
+++ b/numpy/core/src/multiarray/temp_elide.c
@@ -363,6 +363,8 @@ can_elide_temp_unary(PyArrayObject * m1)
if (Py_REFCNT(m1) != 1 || !PyArray_CheckExact(m1) ||
!PyArray_ISNUMBER(m1) ||
!(PyArray_FLAGS(m1) & NPY_ARRAY_OWNDATA) ||
+ !PyArray_ISWRITEABLE(m1) ||
+ PyArray_CHKFLAGS(m1, NPY_ARRAY_UPDATEIFCOPY) ||
PyArray_NBYTES(m1) < NPY_MIN_ELIDE_BYTES) {
return 0;
}
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index e19087540..bbdf4dbfa 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -3246,6 +3246,15 @@ class TestTemporaryElide(object):
a = np.bool_()
assert_(type(~(a & a)) is np.bool_)
+ def test_elide_scalar_readonly(self):
+ # The imaginary part of a real array is readonly. This needs to go
+ # through fast_scalar_power which is only called for powers of
+ # +1, -1, 0, 0.5, and 2, so use 2. Also need valid refcount for
+ # elision which can be gotten for the imaginary part of a real
+ # array. Should not error.
+ a = np.empty(100000, dtype=np.float64)
+ a.imag ** 2
+
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