[Numpy-svn] r8361 - trunk/numpy/core/src/multiarray

numpy-svn@scip... numpy-svn@scip...
Sun Apr 25 09:50:14 CDT 2010


Author: charris
Date: 2010-04-25 09:50:14 -0500 (Sun, 25 Apr 2010)
New Revision: 8361

Modified:
   trunk/numpy/core/src/multiarray/methods.c
Log:
BUG: Fix the fix so resize works like it is supposed to.

Modified: trunk/numpy/core/src/multiarray/methods.c
===================================================================
--- trunk/numpy/core/src/multiarray/methods.c	2010-04-25 09:57:19 UTC (rev 8360)
+++ trunk/numpy/core/src/multiarray/methods.c	2010-04-25 14:50:14 UTC (rev 8361)
@@ -904,23 +904,42 @@
     return PyArray_NewCopy(self, fortran);
 }
 
-
+#include <stdio.h>
 static PyObject *
 array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds)
 {
     static char *kwlist[] = {"refcheck", NULL};
+    intp size = PyTuple_Size(args);
+    int refcheck = 1;
     PyArray_Dims newshape;
     PyObject *ret;
-    int refcheck = 1;
 
-    if (PyTuple_GET_ITEM(args, 0) == Py_None) {
+
+    if (kwds != NULL) {
+        PyObject *tmp = PyTuple_New(0);
+        if (!PyArg_ParseTupleAndKeywords(tmp, kwds, "|i", kwlist,  &refcheck)) {
+            Py_XDECREF(tmp);
+            return NULL;
+        }
+        Py_DECREF(tmp);
+    }
+
+    if (size == 0) {
         Py_INCREF(Py_None);
         return Py_None;
     }
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist,
-                PyArray_IntpConverter, &newshape, &refcheck)) {
-        return NULL;
+    else if (size == 1) {
+        PyObject *obj = PyTuple_GET_ITEM(args, 0);
+        if (obj == Py_None) {
+            Py_INCREF(Py_None);
+            return Py_None;
+        }
+        PyArray_IntpConverter(obj, &newshape);
     }
+    else {
+        PyArray_IntpConverter(args, &newshape);
+    }
+
     ret = PyArray_Resize(self, &newshape, refcheck, PyArray_CORDER);
     PyDimMem_FREE(newshape.ptr);
     if (ret == NULL) {



More information about the Numpy-svn mailing list