summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-07-29 20:07:57 +0000
committerPauli Virtanen <pav@iki.fi>2010-07-29 20:07:57 +0000
commita761330ef68caeadd73e6d01068fa81d2f9dc07c (patch)
tree35f35ca0ac4ba60c7530c700d78ee719243b9a6d /numpy/core
parentd13f75802ebb5ee38a178d06c891a632f3102d89 (diff)
downloadnumpy-a761330ef68caeadd73e6d01068fa81d2f9dc07c.tar.gz
BUG: core/umath: do not create views unnecessarily in ndarray.__array_prepare__ (fixes #1548)
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarray/methods.c6
-rw-r--r--numpy/core/tests/test_regression.py8
2 files changed, 14 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index 0d7180a01..783554965 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -843,6 +843,12 @@ array_preparearray(PyArrayObject *self, PyObject *args)
return NULL;
}
+ if (Py_TYPE(self) == Py_TYPE(arr)) {
+ /* No need to create a new view */
+ Py_INCREF(arr);
+ return arr;
+ }
+
Py_INCREF(PyArray_DESCR(arr));
ret = PyArray_NewFromDescr(Py_TYPE(self),
PyArray_DESCR(arr),
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index bc88eed3c..1257a54c2 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1351,5 +1351,13 @@ class TestRegression(TestCase):
x[(0,)] = 2 # shouldn't raise an exception
assert_equal(x[0], 2)
+ def test_ufunc_no_unnecessary_views(self):
+ # ticket #1548
+ class Subclass(np.ndarray):
+ pass
+ x = np.array([1,2,3]).view(Subclass)
+ y = np.add(x, x, x)
+ assert_equal(id(x), id(y))
+
if __name__ == "__main__":
run_module_suite()