[Numpy-svn] r3109 - in trunk/numpy/core: include/numpy src

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Sep 4 14:31:35 CDT 2006


Author: oliphant
Date: 2006-09-04 14:31:30 -0500 (Mon, 04 Sep 2006)
New Revision: 3109

Modified:
   trunk/numpy/core/include/numpy/ndarrayobject.h
   trunk/numpy/core/src/arrayobject.c
Log:
Add Index checking for integer conversion and Python 2.5

Modified: trunk/numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- trunk/numpy/core/include/numpy/ndarrayobject.h	2006-09-04 17:06:31 UTC (rev 3108)
+++ trunk/numpy/core/include/numpy/ndarrayobject.h	2006-09-04 19:31:30 UTC (rev 3109)
@@ -645,6 +645,7 @@
 #define PY_SSIZE_T_MIN INT_MIN
 #define NPY_SSIZE_T_PYFMT "i"
 #define constchar const char
+#define PyIndex_Check(op) 0
 #else
 #define NPY_SSIZE_T_PYFMT "n"
 #define constchar char

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-09-04 17:06:31 UTC (rev 3108)
+++ trunk/numpy/core/src/arrayobject.c	2006-09-04 19:31:30 UTC (rev 3109)
@@ -560,6 +560,12 @@
                 Py_DECREF(arr);
                 return ret;
         }
+#if (PY_VERSION_HEX >= 0x02050000)
+	if (PyIndex_Check(op)) {
+		long_value = (longlong) PyNumber_Index(op);
+		goto finish;
+	}
+#endif
         if (o->ob_type->tp_as_number != NULL &&                 \
             o->ob_type->tp_as_number->nb_long != NULL) {
                 obj = o->ob_type->tp_as_number->nb_long(o);
@@ -643,6 +649,12 @@
                 Py_DECREF(arr);
                 return ret;
         }
+#if (PY_VERSION_HEX >= 0x02050000)
+	if (PyIndex_Check(o)) {
+		long_value = (longlong) PyNumber_Index(o);
+		goto finish;
+	}
+#endif
         if (o->ob_type->tp_as_number != NULL &&         \
             o->ob_type->tp_as_number->nb_int != NULL) {
                 obj = o->ob_type->tp_as_number->nb_int(o);
@@ -2679,7 +2691,7 @@
         }
 
         if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) ||
-            PyLong_Check(op)) {
+            PyLong_Check(op) || PyIndex_Check(index)) {
                 intp value;
                 value = PyArray_PyIntAsIntp(op);
                 if (!PyErr_Occurred()) {
@@ -2792,7 +2804,7 @@
         }
 
         if (PyInt_Check(index) || PyArray_IsScalar(index, Integer) ||
-            PyLong_Check(index)) {
+            PyLong_Check(index) || PyIndex_Check(index)) {
                 intp value;
                 value = PyArray_PyIntAsIntp(index);
                 if (PyErr_Occurred())
@@ -2890,6 +2902,7 @@
    Python so that 0-dim arrays are passed as scalars
 */
 
+
 static PyObject *
 array_subscript_nice(PyArrayObject *self, PyObject *op)
 {
@@ -2898,7 +2911,7 @@
         intp vals[MAX_DIMS];
 
         if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) || \
-            PyLong_Check(op)) {
+            PyLong_Check(op) || PyIndex_Check(op)) {
                 intp value;
                 value = PyArray_PyIntAsIntp(op);
                 if (PyErr_Occurred())



More information about the Numpy-svn mailing list