diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2017-09-18 17:35:07 -0600 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2017-09-21 10:22:56 -0600 |
| commit | 0dc06b36dc3567e9bb79d9ba404c85fec7e7f799 (patch) | |
| tree | 6f83d1550e36f5880f64f76f3dd48a7c15bc7967 | |
| parent | 8344c2cfcb6f46224f64106a5d5aa6c62ab38a24 (diff) | |
| download | numpy-0dc06b36dc3567e9bb79d9ba404c85fec7e7f799.tar.gz | |
BUG: Make scalar function elision check writeable.
Add checks for writeable and updateifcopy in the can_elide_temp_unary
function.
Closes #9679.
| -rw-r--r-- | numpy/core/src/multiarray/temp_elide.c | 2 | ||||
| -rw-r--r-- | numpy/core/tests/test_multiarray.py | 9 |
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 31868026b..4d085a340 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -3172,6 +3172,15 @@ class TestTemporaryElide(TestCase): 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 |
