diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2018-07-25 21:55:52 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2018-07-27 00:09:39 +0200 |
commit | c6c7f1eaf9833f2dbca27c26521060ec6a48b959 (patch) | |
tree | 15d58201ddd684da6d3b5ec02be97477b1efc5cf /numpy/core | |
parent | 210f07f2e91727f7f2f687beb36e7d53445d1e72 (diff) | |
download | numpy-c6c7f1eaf9833f2dbca27c26521060ec6a48b959.tar.gz |
BUG: Clip uses wrong memory order in output
Also fixes two smaller typos in the test where the wrong
arrays were compared
Closes gh-11605
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/calculation.c | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_numeric.py | 12 |
2 files changed, 13 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/calculation.c b/numpy/core/src/multiarray/calculation.c index e47dd81b9..f30e0441d 100644 --- a/numpy/core/src/multiarray/calculation.c +++ b/numpy/core/src/multiarray/calculation.c @@ -1103,6 +1103,8 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o outgood = 1; } if (!outgood && PyArray_ISONESEGMENT(out) && + /* Both are contiguous, but must be identically so */ + PyArray_ISFORTRAN(out) == PyArray_ISFORTRAN(self) && PyArray_CHKFLAGS(out, NPY_ARRAY_ALIGNED) && PyArray_ISNOTSWAPPED(out) && PyArray_EquivTypes(PyArray_DESCR(out), indescr)) { @@ -1115,7 +1117,7 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o */ if (!outgood) { int oflags; - if (PyArray_ISFORTRAN(out)) + if (PyArray_ISFORTRAN(self)) oflags = NPY_ARRAY_FARRAY; else oflags = NPY_ARRAY_CARRAY; diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 53486dc51..62aec1433 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -1530,7 +1530,7 @@ class TestClip(object): m = -0.5 M = 0.6 self.fastclip(a, m, M, a) - self.clip(a, m, M, ac) + self.clip(ac, m, M, ac) assert_array_strict_equal(a, ac) def test_noncontig_inplace(self): @@ -1543,7 +1543,7 @@ class TestClip(object): m = -0.5 M = 0.6 self.fastclip(a, m, M, a) - self.clip(a, m, M, ac) + self.clip(ac, m, M, ac) assert_array_equal(a, ac) def test_type_cast_01(self): @@ -1722,6 +1722,14 @@ class TestClip(object): self.clip(a, m, M, act) assert_array_strict_equal(ac, act) + def test_clip_with_out_transposed(self): + # Test that the out argument works when tranposed + a = np.arange(16).reshape(4, 4) + out = np.empty_like(a).T + a.clip(4, 10, out=out) + expected = self.clip(a, 4, 10) + assert_array_equal(out, expected) + def test_clip_inplace_array(self): # Test native double input with array min/max a = self._generate_data(self.nr, self.nc) |