[Numpy-svn] r8515 - in branches/1.5.x/numpy/core: src/multiarray tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Sat Jul 24 06:40:54 EDT 2010
Author: ptvirtan
Date: 2010-07-24 05:40:54 -0500 (Sat, 24 Jul 2010)
New Revision: 8515
Modified:
branches/1.5.x/numpy/core/src/multiarray/calculation.c
branches/1.5.x/numpy/core/tests/test_regression.py
Log:
BUG: core: make .std() and .var() respect the out= keyword (#1434)
(cherry picked from commit r8505)
Modified: branches/1.5.x/numpy/core/src/multiarray/calculation.c
===================================================================
--- branches/1.5.x/numpy/core/src/multiarray/calculation.c 2010-07-24 09:39:13 UTC (rev 8514)
+++ branches/1.5.x/numpy/core/src/multiarray/calculation.c 2010-07-24 10:40:54 UTC (rev 8515)
@@ -393,11 +393,14 @@
ret = PyArray_GenericUnaryFunction((PyAO *)obj1, n_ops.sqrt);
Py_DECREF(obj1);
}
- if (ret == NULL || PyArray_CheckExact(self)) {
- return ret;
+ if (ret == NULL) {
+ return NULL;
}
+ if (PyArray_CheckExact(self)) {
+ goto finish;
+ }
if (PyArray_Check(self) && Py_TYPE(self) == Py_TYPE(ret)) {
- return ret;
+ goto finish;
}
obj1 = PyArray_EnsureArray(ret);
if (obj1 == NULL) {
@@ -405,6 +408,8 @@
}
ret = PyArray_View((PyAO *)obj1, NULL, Py_TYPE(self));
Py_DECREF(obj1);
+
+finish:
if (out) {
if (PyArray_CopyAnyInto(out, (PyArrayObject *)ret) < 0) {
Py_DECREF(ret);
Modified: branches/1.5.x/numpy/core/tests/test_regression.py
===================================================================
--- branches/1.5.x/numpy/core/tests/test_regression.py 2010-07-24 09:39:13 UTC (rev 8514)
+++ branches/1.5.x/numpy/core/tests/test_regression.py 2010-07-24 10:40:54 UTC (rev 8515)
@@ -1324,5 +1324,18 @@
assert_equal(type(getattr(x, name)), np.float32,
err_msg=name)
+ def test_ticket_1434(self):
+ # Check that the out= argument in var and std has an effect
+ data = np.array(((1,2,3),(4,5,6),(7,8,9)))
+ out = np.zeros((3,))
+
+ ret = data.var(axis=1, out=out)
+ assert_(ret is out)
+ assert_array_equal(ret, data.var(axis=1))
+
+ ret = data.std(axis=1, out=out)
+ assert_(ret is out)
+ assert_array_equal(ret, data.std(axis=1))
+
if __name__ == "__main__":
run_module_suite()
More information about the Numpy-svn
mailing list