[Numpy-svn] r5429 - branches/1.1.x/numpy/core/src

numpy-svn@scip... numpy-svn@scip...
Tue Jul 15 22:33:20 CDT 2008


Author: charris
Date: 2008-07-15 22:33:12 -0500 (Tue, 15 Jul 2008)
New Revision: 5429

Modified:
   branches/1.1.x/numpy/core/src/arrayobject.c
Log:
Backport r5255 by copy _zerofill and array_imag_get from trunk.


Modified: branches/1.1.x/numpy/core/src/arrayobject.c
===================================================================
--- branches/1.1.x/numpy/core/src/arrayobject.c	2008-07-16 03:21:08 UTC (rev 5428)
+++ branches/1.1.x/numpy/core/src/arrayobject.c	2008-07-16 03:33:12 UTC (rev 5429)
@@ -6640,6 +6640,27 @@
     }
 }
 
+
+static int
+_zerofill(PyArrayObject *ret)
+{
+    if (PyDataType_REFCHK(ret->descr)) {
+        PyObject *zero = PyInt_FromLong(0);
+        PyArray_FillObjectArray(ret, zero);
+        Py_DECREF(zero);
+        if (PyErr_Occurred()) {
+            Py_DECREF(ret);
+            return -1;
+        }
+    }
+    else {
+        intp n = PyArray_NBYTES(ret);
+        memset(ret->data, 0, n);
+    }
+    return 0;
+}
+
+
 /* Create a view of a complex array with an equivalent data-type
    except it is real instead of complex.
 */
@@ -6721,29 +6742,26 @@
 array_imag_get(PyArrayObject *self)
 {
     PyArrayObject *ret;
-    PyArray_Descr *type;
 
     if (PyArray_ISCOMPLEX(self)) {
         ret = _get_part(self, 1);
-        return (PyObject *) ret;
     }
     else {
-        type = self->descr;
-        Py_INCREF(type);
-        ret = (PyArrayObject *)PyArray_Zeros(self->nd,
-                                             self->dimensions,
-                                             type,
-                                             PyArray_ISFORTRAN(self));
+        Py_INCREF(self->descr);
+	ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,
+						    self->descr,
+						    self->nd,
+						    self->dimensions,
+						    NULL, NULL,
+						    PyArray_ISFORTRAN(self),
+						    (PyObject *)self);
+	if (ret == NULL) return NULL;
+
+	if (_zerofill(ret) < 0) return NULL;
+
         ret->flags &= ~WRITEABLE;
-        if (PyArray_CheckExact(self))
-            return (PyObject *)ret;
-        else {
-            PyObject *newret;
-            newret = PyArray_View(ret, NULL, self->ob_type);
-            Py_DECREF(ret);
-            return newret;
-        }
     }
+    return (PyObject *) ret;
 }
 
 static int



More information about the Numpy-svn mailing list