[Numpy-svn] r8505 - in trunk/numpy/core: src/multiarray tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Sun Jul 18 12:52:48 EDT 2010
Author: ptvirtan
Date: 2010-07-18 11:52:48 -0500 (Sun, 18 Jul 2010)
New Revision: 8505
Modified:
trunk/numpy/core/src/multiarray/calculation.c
trunk/numpy/core/tests/test_regression.py
Log:
BUG: core: make .std() and .var() respect the out= keyword (#1434)
Modified: trunk/numpy/core/src/multiarray/calculation.c
===================================================================
--- trunk/numpy/core/src/multiarray/calculation.c 2010-07-18 14:58:06 UTC (rev 8504)
+++ trunk/numpy/core/src/multiarray/calculation.c 2010-07-18 16:52:48 UTC (rev 8505)
@@ -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: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py 2010-07-18 14:58:06 UTC (rev 8504)
+++ trunk/numpy/core/tests/test_regression.py 2010-07-18 16:52:48 UTC (rev 8505)
@@ -1325,5 +1325,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