[Numpy-svn] r3358 - in trunk: . numpy/core/src numpy/core/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Oct 18 13:05:40 CDT 2006


Author: oliphant
Date: 2006-10-18 13:05:35 -0500 (Wed, 18 Oct 2006)
New Revision: 3358

Modified:
   trunk/THANKS.txt
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/tests/test_regression.py
Log:
Fix Ticket #352

Modified: trunk/THANKS.txt
===================================================================
--- trunk/THANKS.txt	2006-10-18 07:09:19 UTC (rev 3357)
+++ trunk/THANKS.txt	2006-10-18 18:05:35 UTC (rev 3358)
@@ -24,4 +24,5 @@
     and much help with rooting out nested record array bugs. 
 Tim Hochberg for getting the build working on MSVC, optimization 
     improvements, and code review
-Charles Harris for the sorting code originally written for Numarray and for    improvements to polyfit, many bug fixes, and documentation strings.
+Charles Harris for the sorting code originally written for Numarray and 
+    for improvements to polyfit, many bug fixes, and documentation strings.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-10-18 07:09:19 UTC (rev 3357)
+++ trunk/numpy/core/src/arrayobject.c	2006-10-18 18:05:35 UTC (rev 3358)
@@ -4749,41 +4749,44 @@
 static PyObject *
 _check_axis(PyArrayObject *arr, int *axis, int flags)
 {
-        PyObject *temp;
+        PyObject *temp1, *temp2;
         int n = arr->nd;
 
         if ((*axis >= MAX_DIMS) || (n==0)) {
                 if (n != 1) {
-                        temp = PyArray_Ravel(arr,0);
-                        if (temp) *axis = PyArray_NDIM(temp)-1;
-                        else *axis = 0;
+                        temp1 = PyArray_Ravel(arr,0);
+                        if (temp1 == NULL) {*axis=0; return NULL;}
+                        *axis = PyArray_NDIM(temp1)-1;
                 }
                 else {
-                        temp = (PyObject *)arr;
-                        Py_INCREF(temp);
+                        temp1 = (PyObject *)arr;
+                        Py_INCREF(temp1);
                         *axis = 0;
                 }
-                return temp;
+                if (!flags) return temp1;
         }
         else {
-                if (flags) {
-                        temp = PyArray_CheckFromAny((PyObject *)arr, NULL,
-                                               0, 0, flags, NULL);
-                        if (temp == NULL) return NULL;
-                }
-                else {
-                        Py_INCREF(arr);
-                        temp = (PyObject *)arr;
-                }
+                temp1 = (PyObject *)arr;
+                Py_INCREF(temp1);
         }
+        if (flags) {
+                temp2 = PyArray_CheckFromAny((PyObject *)temp1, NULL,
+                                             0, 0, flags, NULL);
+                Py_DECREF(temp1);
+                if (temp2 == NULL) return NULL;
+        }
+        else {
+                temp2 = (PyObject *)temp1;
+        }
+        n = PyArray_NDIM(temp2);
         if (*axis < 0) *axis += n;
         if ((*axis < 0) || (*axis >= n)) {
                 PyErr_Format(PyExc_ValueError,
                              "axis(=%d) out of bounds", *axis);
-                Py_DECREF(temp);
+                Py_DECREF(temp2);
                 return NULL;
         }
-        return temp;
+        return temp2;
 }
 
 #include "arraymethods.c"

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2006-10-18 07:09:19 UTC (rev 3357)
+++ trunk/numpy/core/tests/test_regression.py	2006-10-18 18:05:35 UTC (rev 3358)
@@ -537,6 +537,12 @@
         a = N.array([[1,2],[3,4],[5,6],[7,8]])
         b = a[:,1]
         assert_equal(b.reshape(2,2,order='F'), [[2,6],[4,8]])
+
+    def check_repeat_discont(self, level=rlevel):
+        """Ticket #352"""
+        a = N.arange(12).reshape(4,3)[:,2]
+        assert_equal(a.repeat(3), [2,2,2,5,5,5,8,8,8,11,11,11])
+        
                 
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list