[Numpy-svn] r2795 - in trunk/numpy/core: . code_generators include/numpy src

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Jul 10 19:05:18 EDT 2006


Author: oliphant
Date: 2006-07-10 18:05:09 -0500 (Mon, 10 Jul 2006)
New Revision: 2795

Added:
   trunk/numpy/core/include/numpy/old_defines.h
Modified:
   trunk/numpy/core/_internal.py
   trunk/numpy/core/code_generators/array_api_order.txt
   trunk/numpy/core/code_generators/generate_array_api.py
   trunk/numpy/core/include/numpy/arrayobject.h
   trunk/numpy/core/records.py
   trunk/numpy/core/src/arraymethods.c
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/src/arraytypes.inc.src
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/core/src/scalartypes.inc.src
Log:
MADE NPY_ versions of all PyArray_ prefixes corresponding to CONSTANTS.  Created a names member of PyArray_Descr and changed usages that extracted -1 out of the fields dict.

Modified: trunk/numpy/core/_internal.py
===================================================================
--- trunk/numpy/core/_internal.py	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/_internal.py	2006-07-10 23:05:09 UTC (rev 2795)
@@ -5,16 +5,36 @@
 import re
 from multiarray import dtype, ndarray
 
-# make sure the tuple entries are PyArray_Descr
-#          or convert them
-#
-# make sure offsets are all interpretable
-#          as positive integers and
-#          convert them to positive integers if so
-#
-#
-# return totalsize from last offset and size
+def _makenames_list(adict):
+    allfields = []
+    fnames = adict.keys()
+    for fname in fnames:
+        obj = adict[fname]
+        n = len(obj)
+        if not isinstance(obj, tuple) or n not in [2,3]:
+            raise ValueError, "entry not a 2- or 3- tuple"
+        if (n > 2) and (obj[2] == fname):
+            continue
+        num = int(obj[1])
+        if (num < 0):
+            raise ValueError, "invalid offset."
+        format = dtype(obj[0])
+        if (format.itemsize == 0):
+            raise ValueError, "all itemsizes must be fixed."
+        if (n > 2):
+            title = obj[2]
+        else:
+            title = None
+        allfields.append((fname, format, num, title))
+    # sort by offsets
+    allfields.sort(lambda x,y: cmp(x[2],y[2]))
+    names = [x[0] for x in allfields]
+    formats = [x[1] for x in allfields]
+    offsets = [x[2] for x in allfields]
+    titles = [x[3] for x in allfields]
 
+    return names, formats, offsets, titles
+    
 # Called in PyArray_DescrConverter function when
 #  a dictionary without "names" and "formats"
 #  fields is used as a data-type descriptor.
@@ -24,32 +44,7 @@
     except KeyError:
         names = None
     if names is None:
-        allfields = []
-        fnames = adict.keys()
-        for fname in fnames:
-            obj = adict[fname]
-            n = len(obj)
-            if not isinstance(obj, tuple) or n not in [2,3]:
-                raise ValueError, "entry not a 2- or 3- tuple"
-            if (n > 2) and (obj[2] == fname):
-                continue
-            num = int(obj[1])
-            if (num < 0):
-                raise ValueError, "invalid offset."
-            format = dtype(obj[0])
-            if (format.itemsize == 0):
-                raise ValueError, "all itemsizes must be fixed."
-            if (n > 2):
-                title = obj[2]
-            else:
-                title = None
-            allfields.append((fname, format, num, title))
-        # sort by offsets
-        allfields.sort(lambda x,y: cmp(x[2],y[2]))
-        names = [x[0] for x in allfields]
-        formats = [x[1] for x in allfields]
-        offsets = [x[2] for x in allfields]
-        titles = [x[3] for x in allfields]
+        names, formats, offsets, titles = _makenames_list(adict)
     else:
         formats = []
         offsets = []
@@ -80,7 +75,8 @@
     if fields is None:
         return descriptor.str
 
-    ordered_fields = [fields[x] + (x,) for x in fields[-1]]
+    names = descriptor.names
+    ordered_fields = [fields[x] + (x,) for x in names]
     result = []
     offset = 0
     for field in ordered_fields:

Modified: trunk/numpy/core/code_generators/array_api_order.txt
===================================================================
--- trunk/numpy/core/code_generators/array_api_order.txt	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/code_generators/array_api_order.txt	2006-07-10 23:05:09 UTC (rev 2795)
@@ -80,3 +80,4 @@
 PyArray_ElementStrides
 PyArray_Item_INCREF
 PyArray_Item_XDECREF
+PyArray_FieldNames

Modified: trunk/numpy/core/code_generators/generate_array_api.py
===================================================================
--- trunk/numpy/core/code_generators/generate_array_api.py	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/code_generators/generate_array_api.py	2006-07-10 23:05:09 UTC (rev 2795)
@@ -76,10 +76,10 @@
   Py_DECREF(numpy);
   if (PyArray_API == NULL) return -1;
   /* Perform runtime check of C API version */
-  if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {
+  if (NPY_VERSION != PyArray_GetNDArrayCVersion()) {
     PyErr_Format(PyExc_RuntimeError, "module compiled against "\
         "version %%x of C-API but this version of numpy is %%x", \
-        (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());
+        (int) NPY_VERSION, (int) PyArray_GetNDArrayCVersion());
     return -1;
   }
   return 0;

Modified: trunk/numpy/core/include/numpy/arrayobject.h
===================================================================
--- trunk/numpy/core/include/numpy/arrayobject.h	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/include/numpy/arrayobject.h	2006-07-10 23:05:09 UTC (rev 2795)
@@ -36,8 +36,7 @@
 #define NPY_SUCCEED 1
 
         /* Helpful to distinguish what is installed */
-#define NDARRAY_VERSION 0x00090909
-#define NPY_VERSION NDARRAY_VERSION
+#define NPY_VERSION 0x0009090A
 
 	/* Some platforms don't define bool, long long, or long double.
 	   Handle that here.
@@ -101,108 +100,107 @@
 typedef int npy_int;
 typedef long npy_long;
 
-
 typedef struct { float real, imag; } npy_cfloat;
 typedef struct { double real, imag; } npy_cdouble;
 typedef struct {npy_longdouble real, imag;} npy_clongdouble;
 
-enum PyArray_TYPES {    PyArray_BOOL=0,
-                        PyArray_BYTE, PyArray_UBYTE,
-		        PyArray_SHORT, PyArray_USHORT,
-		        PyArray_INT, PyArray_UINT,
-			PyArray_LONG, PyArray_ULONG,
-                        PyArray_LONGLONG, PyArray_ULONGLONG,
-			PyArray_FLOAT, PyArray_DOUBLE, PyArray_LONGDOUBLE,
-			PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CLONGDOUBLE,
-			PyArray_OBJECT=17,
-                        PyArray_STRING, PyArray_UNICODE,
-			PyArray_VOID,
-			PyArray_NTYPES,
-			PyArray_NOTYPE,
-			PyArray_CHAR,      /* special flag */
-			PyArray_USERDEF=256  /* leave room for characters */
+enum NPY_TYPES {    NPY_BOOL=0,
+                    NPY_BYTE, NPY_UBYTE,
+                    NPY_SHORT, NPY_USHORT,
+                    NPY_INT, NPY_UINT,
+                    NPY_LONG, NPY_ULONG,
+                    NPY_LONGLONG, NPY_ULONGLONG,
+                    NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
+                    NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE,
+                    NPY_OBJECT=17,
+                    NPY_STRING, NPY_UNICODE,
+                    NPY_VOID,
+                    NPY_NTYPES,
+                    NPY_NOTYPE,
+                    NPY_CHAR,      /* special flag */
+                    NPY_USERDEF=256  /* leave room for characters */
 };
 
-	/* basetype array priority */
-#define PyArray_PRIORITY 0.0
-	/* default subtype priority */
-#define PyArray_SUBTYPE_PRIORITY 1.0
+/* basetype array priority */
+#define NPY_PRIORITY 0.0
 
-	/* How many floating point types are there */
-#define PyArray_NUM_FLOATTYPE 3
+/* default subtype priority */
+#define NPY_SUBTYPE_PRIORITY 1.0
 
+/* How many floating point types are there */
+#define NPY_NUM_FLOATTYPE 3
 
-	/* We need to match npy_intp to a signed integer of the same size as
-	   a pointer variable. npy_uintp to the equivalent unsigned integer
-	*/
+/* We need to match npy_intp to a signed integer of the same size as
+   a pointer variable. npy_uintp to the equivalent unsigned integer
+*/
 
 
-	/* These characters correspond to the array type and the
-	   struct module */
+/* These characters correspond to the array type and the
+   struct module */
 
-	/*  except 'p' -- signed integer for pointer type */
+/*  except 'p' -- signed integer for pointer type */
 
-enum PyArray_TYPECHAR { PyArray_BOOLLTR = '?',
-			PyArray_BYTELTR = 'b',
-			PyArray_UBYTELTR = 'B',
-			PyArray_SHORTLTR = 'h',
-			PyArray_USHORTLTR = 'H',
-			PyArray_INTLTR = 'i',
-			PyArray_UINTLTR = 'I',
-			PyArray_LONGLTR = 'l',
-			PyArray_ULONGLTR = 'L',
-			PyArray_LONGLONGLTR = 'q',
-			PyArray_ULONGLONGLTR = 'Q',
-			PyArray_FLOATLTR = 'f',
-			PyArray_DOUBLELTR = 'd',
-			PyArray_LONGDOUBLELTR = 'g',
-			PyArray_CFLOATLTR = 'F',
-			PyArray_CDOUBLELTR = 'D',
-			PyArray_CLONGDOUBLELTR = 'G',
-			PyArray_OBJECTLTR = 'O',
-			PyArray_STRINGLTR = 'S',
-			PyArray_STRINGLTR2 = 'a',
-			PyArray_UNICODELTR = 'U',
-		        PyArray_VOIDLTR = 'V',
-			PyArray_CHARLTR = 'c',
+enum NPY_TYPECHAR { NPY_BOOLLTR = '?',
+			NPY_BYTELTR = 'b',
+			NPY_UBYTELTR = 'B',
+			NPY_SHORTLTR = 'h',
+			NPY_USHORTLTR = 'H',
+			NPY_INTLTR = 'i',
+			NPY_UINTLTR = 'I',
+			NPY_LONGLTR = 'l',
+			NPY_ULONGLTR = 'L',
+			NPY_LONGLONGLTR = 'q',
+			NPY_ULONGLONGLTR = 'Q',
+			NPY_FLOATLTR = 'f',
+			NPY_DOUBLELTR = 'd',
+			NPY_LONGDOUBLELTR = 'g',
+			NPY_CFLOATLTR = 'F',
+			NPY_CDOUBLELTR = 'D',
+			NPY_CLONGDOUBLELTR = 'G',
+			NPY_OBJECTLTR = 'O',
+			NPY_STRINGLTR = 'S',
+			NPY_STRINGLTR2 = 'a',
+			NPY_UNICODELTR = 'U',
+		        NPY_VOIDLTR = 'V',
+			NPY_CHARLTR = 'c',
 
 			/* No Descriptor, just a define -- this let's
 			 Python users specify an array of integers
 			 large enough to hold a pointer on the platform*/
-			PyArray_INTPLTR = 'p',
-			PyArray_UINTPLTR = 'P',
+			NPY_INTPLTR = 'p',
+			NPY_UINTPLTR = 'P',
 
-			PyArray_GENBOOLLTR ='b',
-			PyArray_SIGNEDLTR = 'i',
-			PyArray_UNSIGNEDLTR = 'u',
-			PyArray_FLOATINGLTR = 'f',
-			PyArray_COMPLEXLTR = 'c'
+			NPY_GENBOOLLTR ='b',
+			NPY_SIGNEDLTR = 'i',
+			NPY_UNSIGNEDLTR = 'u',
+			NPY_FLOATINGLTR = 'f',
+			NPY_COMPLEXLTR = 'c'
 };
 
 typedef enum {
-	PyArray_QUICKSORT=0,
-	PyArray_HEAPSORT=1,
-	PyArray_MERGESORT=2,
-} PyArray_SORTKIND;
-#define PyArray_NSORTS PyArray_MERGESORT + 1
+	NPY_QUICKSORT=0,
+	NPY_HEAPSORT=1,
+	NPY_MERGESORT=2,
+} NPY_SORTKIND;
+#define NPY_NSORTS NPY_MERGESORT + 1
 
 
 typedef enum {
-	PyArray_NOSCALAR=-1,
-	PyArray_BOOL_SCALAR,
-	PyArray_INTPOS_SCALAR,
-	PyArray_INTNEG_SCALAR,
-	PyArray_FLOAT_SCALAR,
-	PyArray_COMPLEX_SCALAR,
-	PyArray_OBJECT_SCALAR,
-} PyArray_SCALARKIND;
-#define PyArray_NSCALARKINDS PyArray_OBJECT_SCALAR+1
+	NPY_NOSCALAR=-1,
+	NPY_BOOL_SCALAR,
+	NPY_INTPOS_SCALAR,
+	NPY_INTNEG_SCALAR,
+	NPY_FLOAT_SCALAR,
+	NPY_COMPLEX_SCALAR,
+	NPY_OBJECT_SCALAR,
+} NPY_SCALARKIND;
+#define NPY_NSCALARKINDS NPY_OBJECT_SCALAR+1
 
 typedef enum {
-        PyArray_ANYORDER=-1,
-        PyArray_CORDER=0,
-        PyArray_FORTRANORDER=1
-} PyArray_ORDER;
+        NPY_ANYORDER=-1,
+        NPY_CORDER=0,
+        NPY_FORTRANORDER=1
+} NPY_ORDER;
 
 
 	/* Define bit-width array types and typedefs */
@@ -277,37 +275,37 @@
 #define NPY_BITSOF_LONGDOUBLE (NPY_SIZEOF_LONGDOUBLE*CHAR_BIT)
 
 #if NPY_BITSOF_LONG == 8
-#define PyArray_INT8 PyArray_LONG
-#define PyArray_UINT8 PyArray_ULONG
+#define NPY_INT8 NPY_LONG
+#define NPY_UINT8 NPY_ULONG
 	typedef long npy_int8;
 	typedef unsigned long npy_uint8;
 #elif NPY_BITSOF_LONG == 16
-#define PyArray_INT16 PyArray_LONG
-#define PyArray_UINT16 PyArray_ULONG
+#define NPY_INT16 NPY_LONG
+#define NPY_UINT16 NPY_ULONG
 	typedef long npy_int16;
 	typedef unsigned long npy_uint16;
 #elif NPY_BITSOF_LONG == 32
-#define PyArray_INT32 PyArray_LONG
-#define PyArray_UINT32 PyArray_ULONG
+#define NPY_INT32 NPY_LONG
+#define NPY_UINT32 NPY_ULONG
 	typedef long npy_int32;
 	typedef unsigned long npy_uint32;
 	typedef unsigned long npy_ucs4;
 #elif NPY_BITSOF_LONG == 64
-#define PyArray_INT64 PyArray_LONG
-#define PyArray_UINT64 PyArray_ULONG
+#define NPY_INT64 NPY_LONG
+#define NPY_UINT64 NPY_ULONG
 	typedef long npy_int64;
 	typedef unsigned long npy_uint64;
 #elif NPY_BITSOF_LONG == 128
-#define PyArray_INT128 PyArray_LONG
-#define PyArray_UINT128 PyArray_ULONG
+#define NPY_INT128 NPY_LONG
+#define NPY_UINT128 NPY_ULONG
 	typedef long npy_int128;
 	typedef unsigned long npy_uint128;
 #endif
 
 #if NPY_BITSOF_LONGLONG == 8
-#  ifndef PyArray_INT8
-#    define PyArray_INT8 PyArray_LONGLONG
-#    define PyArray_UINT8 PyArray_ULONGLONG
+#  ifndef NPY_INT8
+#    define NPY_INT8 NPY_LONGLONG
+#    define NPY_UINT8 NPY_ULONGLONG
 	typedef npy_longlong npy_int8;
 	typedef npy_ulonglong npy_uint8;
 #  endif
@@ -315,9 +313,9 @@
 #  define NPY_MIN_LONGLONG NPY_MIN_INT8
 #  define NPY_MAX_ULONGLONG NPY_MAX_UINT8
 #elif NPY_BITSOF_LONGLONG == 16
-#  ifndef PyArray_INT16
-#    define PyArray_INT16 PyArray_LONGLONG
-#    define PyArray_UINT16 PyArray_ULONGLONG
+#  ifndef NPY_INT16
+#    define NPY_INT16 NPY_LONGLONG
+#    define NPY_UINT16 NPY_ULONGLONG
 	typedef npy_longlong npy_int16;
 	typedef npy_ulonglong npy_uint16;
 #  endif
@@ -325,9 +323,9 @@
 #  define NPY_MIN_LONGLONG NPY_MIN_INT16
 #  define NPY_MAX_ULONGLONG NPY_MAX_UINT16
 #elif NPY_BITSOF_LONGLONG == 32
-#  ifndef PyArray_INT32
-#    define PyArray_INT32 PyArray_LONGLONG
-#    define PyArray_UINT32 PyArray_ULONGLONG
+#  ifndef NPY_INT32
+#    define NPY_INT32 NPY_LONGLONG
+#    define NPY_UINT32 NPY_ULONGLONG
 	typedef npy_longlong npy_int32;
 	typedef npy_ulonglong npy_uint32;
 	typedef npy_ulonglong npy_ucs4;
@@ -336,9 +334,9 @@
 #  define NPY_MIN_LONGLONG NPY_MIN_INT32
 #  define NPY_MAX_ULONGLONG NPY_MAX_UINT32
 #elif NPY_BITSOF_LONGLONG == 64
-#  ifndef PyArray_INT64
-#    define PyArray_INT64 PyArray_LONGLONG
-#    define PyArray_UINT64 PyArray_ULONGLONG
+#  ifndef NPY_INT64
+#    define NPY_INT64 NPY_LONGLONG
+#    define NPY_UINT64 NPY_ULONGLONG
 	typedef npy_longlong npy_int64;
 	typedef npy_ulonglong npy_uint64;
 #  endif
@@ -346,9 +344,9 @@
 #  define NPY_MIN_LONGLONG NPY_MIN_INT64
 #  define NPY_MAX_ULONGLONG NPY_MAX_UINT64
 #elif NPY_BITSOF_LONGLONG == 128
-#  ifndef PyArray_INT128
-#    define PyArray_INT128 PyArray_LONGLONG
-#    define PyArray_UINT128 PyArray_ULONGLONG
+#  ifndef NPY_INT128
+#    define NPY_INT128 NPY_LONGLONG
+#    define NPY_UINT128 NPY_ULONGLONG
 	typedef npy_longlong npy_int128;
 	typedef npy_ulonglong npy_uint128;
 #  endif
@@ -356,8 +354,8 @@
 #  define NPY_MIN_LONGLONG NPY_MIN_INT128
 #  define NPY_MAX_ULONGLONG NPY_MAX_UINT128
 #elif NPY_BITSOF_LONGLONG == 256
-#  define PyArray_INT256 PyArray_LONGLONG
-#  define PyArray_UINT256 PyArray_ULONGLONG
+#  define NPY_INT256 NPY_LONGLONG
+#  define NPY_UINT256 NPY_ULONGLONG
 	typedef npy_longlong npy_int256;
 	typedef npy_ulonglong npy_uint256;
 #  define NPY_MAX_LONGLONG NPY_MAX_INT256
@@ -366,76 +364,76 @@
 #endif
 
 #if NPY_BITSOF_INT == 8
-#ifndef PyArray_INT8
-#define PyArray_INT8 PyArray_INT
-#define PyArray_UINT8 PyArray_UINT
+#ifndef NPY_INT8
+#define NPY_INT8 NPY_INT
+#define NPY_UINT8 NPY_UINT
 	typedef int npy_int8;
 	typedef unsigned int npy_uint8;
 #endif
 #elif NPY_BITSOF_INT == 16
-#ifndef PyArray_INT16
-#define PyArray_INT16 PyArray_INT
-#define PyArray_UINT16 PyArray_UINT
+#ifndef NPY_INT16
+#define NPY_INT16 NPY_INT
+#define NPY_UINT16 NPY_UINT
 	typedef int npy_int16;
 	typedef unsigned int npy_uint16;
 #endif
 #elif NPY_BITSOF_INT == 32
-#ifndef PyArray_INT32
-#define PyArray_INT32 PyArray_INT
-#define PyArray_UINT32 PyArray_UINT
+#ifndef NPY_INT32
+#define NPY_INT32 NPY_INT
+#define NPY_UINT32 NPY_UINT
 	typedef int npy_int32;
 	typedef unsigned int npy_uint32;
         typedef unsigned int npy_ucs4;
 #endif
 #elif NPY_BITSOF_INT == 64
-#ifndef PyArray_INT64
-#define PyArray_INT64 PyArray_INT
-#define PyArray_UINT64 PyArray_UINT
+#ifndef NPY_INT64
+#define NPY_INT64 NPY_INT
+#define NPY_UINT64 NPY_UINT
 	typedef int npy_int64;
 	typedef unsigned int npy_uint64;
 #endif
 #elif NPY_BITSOF_INT == 128
-#ifndef PyArray_INT128
-#define PyArray_INT128 PyArray_INT
-#define PyArray_UINT128 PyArray_UINT
+#ifndef NPY_INT128
+#define NPY_INT128 NPY_INT
+#define NPY_UINT128 NPY_UINT
 	typedef int npy_int128;
 	typedef unsigned int npy_uint128;
 #endif
 #endif
 
 #if NPY_BITSOF_SHORT == 8
-#ifndef PyArray_INT8
-#define PyArray_INT8 PyArray_SHORT
-#define PyArray_UINT8 PyArray_USHORT
+#ifndef NPY_INT8
+#define NPY_INT8 NPY_SHORT
+#define NPY_UINT8 NPY_USHORT
 	typedef short npy_int8;
 	typedef unsigned short npy_uint8;
 #endif
 #elif NPY_BITSOF_SHORT == 16
-#ifndef PyArray_INT16
-#define PyArray_INT16 PyArray_SHORT
-#define PyArray_UINT16 PyArray_USHORT
+#ifndef NPY_INT16
+#define NPY_INT16 NPY_SHORT
+#define NPY_UINT16 NPY_USHORT
 	typedef short npy_int16;
 	typedef unsigned short npy_uint16;
 #endif
 #elif NPY_BITSOF_SHORT == 32
-#ifndef PyArray_INT32
-#define PyArray_INT32 PyArray_SHORT
-#define PyArray_UINT32 PyArray_USHORT
+#ifndef NPY_INT32
+#define NPY_INT32 NPY_SHORT
+#define NPY_UINT32 NPY_USHORT
 	typedef short npy_int32;
 	typedef unsigned short npy_uint32;
 	typedef unsigned short npy_ucs4;
 #endif
 #elif NPY_BITSOF_SHORT == 64
-#ifndef PyArray_INT64
-#define PyArray_INT64 PyArray_SHORT
-#define PyArray_UINT64 PyArray_USHORT
+#ifndef NPY_INT64
+#define NPY_INT64 NPY_SHORT
+#define NPY_UINT64 NPY_USHORT
 	typedef short npy_int64;
 	typedef unsigned short npy_uint64;
 #endif
 #elif NPY_BITSOF_SHORT == 128
-#ifndef PyArray_INT128
-#define PyArray_INT128 PyArray_SHORT
-#define PyArray_UINT128 PyArray_USHORT
+#ifndef NPY_INT128
+#define NPY_INT128 NPY_SHORT
+#define NPY_UINT128 NPY_USHORT
 	typedef short npy_int128;
 	typedef unsigned short npy_uint128;
 #endif
@@ -443,38 +441,38 @@
 
 
 #if NPY_BITSOF_CHAR == 8
-#ifndef PyArray_INT8
-#define PyArray_INT8 PyArray_BYTE
-#define PyArray_UINT8 PyArray_UBYTE
+#ifndef NPY_INT8
+#define NPY_INT8 NPY_BYTE
+#define NPY_UINT8 NPY_UBYTE
 	typedef signed char npy_int8;
 	typedef unsigned char npy_uint8;
 #endif
 #elif NPY_BITSOF_CHAR == 16
-#ifndef PyArray_INT16
-#define PyArray_INT16 PyArray_BYTE
-#define PyArray_UINT16 PyArray_UBYTE
+#ifndef NPY_INT16
+#define NPY_INT16 NPY_BYTE
+#define NPY_UINT16 NPY_UBYTE
 	typedef signed char npy_int16;
 	typedef unsigned char npy_uint16;
 #endif
 #elif NPY_BITSOF_CHAR == 32
-#ifndef PyArray_INT32
-#define PyArray_INT32 PyArray_BYTE
-#define PyArray_UINT32 PyArray_UBYTE
+#ifndef NPY_INT32
+#define NPY_INT32 NPY_BYTE
+#define NPY_UINT32 NPY_UBYTE
 	typedef signed char npy_int32;
 	typedef unsigned char npy_uint32;
 	typedef unsigned char npy_ucs4;
 #endif
 #elif NPY_BITSOF_CHAR == 64
-#ifndef PyArray_INT64
-#define PyArray_INT64 PyArray_BYTE
-#define PyArray_UINT64 PyArray_UBYTE
+#ifndef NPY_INT64
+#define NPY_INT64 NPY_BYTE
+#define NPY_UINT64 NPY_UBYTE
 	typedef signed char npy_int64;
 	typedef unsigned char npy_uint64;
 #endif
 #elif NPY_BITSOF_CHAR == 128
-#ifndef PyArray_INT128
-#define PyArray_INT128 PyArray_BYTE
-#define PyArray_UINT128 PyArray_UBYTE
+#ifndef NPY_INT128
+#define NPY_INT128 NPY_BYTE
+#define NPY_UINT128 NPY_UBYTE
 	typedef signed char npy_int128;
 	typedef unsigned char npy_uint128;
 #endif
@@ -483,44 +481,44 @@
 
 
 #if NPY_BITSOF_DOUBLE == 16
-#ifndef PyArray_FLOAT16
-#define PyArray_FLOAT16 PyArray_DOUBLE
-#define PyArray_COMPLEX32 PyArray_CDOUBLE
+#ifndef NPY_FLOAT16
+#define NPY_FLOAT16 NPY_DOUBLE
+#define NPY_COMPLEX32 NPY_CDOUBLE
 	typedef  double npy_float16;
 	typedef npy_cdouble npy_complex32;
 #endif
 #elif NPY_BITSOF_DOUBLE == 32
-#ifndef PyArray_FLOAT32
-#define PyArray_FLOAT32 PyArray_DOUBLE
-#define PyArray_COMPLEX64 PyArray_CDOUBLE
+#ifndef NPY_FLOAT32
+#define NPY_FLOAT32 NPY_DOUBLE
+#define NPY_COMPLEX64 NPY_CDOUBLE
 	typedef double npy_float32;
 	typedef npy_cdouble npy_complex64;
 #endif
 #elif NPY_BITSOF_DOUBLE == 64
-#ifndef PyArray_FLOAT64
-#define PyArray_FLOAT64 PyArray_DOUBLE
-#define PyArray_COMPLEX128 PyArray_CDOUBLE
+#ifndef NPY_FLOAT64
+#define NPY_FLOAT64 NPY_DOUBLE
+#define NPY_COMPLEX128 NPY_CDOUBLE
 	typedef double npy_float64;
 	typedef npy_cdouble npy_complex128;
 #endif
 #elif NPY_BITSOF_DOUBLE == 80
-#ifndef PyArray_FLOAT80
-#define PyArray_FLOAT80 PyArray_DOUBLE
-#define PyArray_COMPLEX160 PyArray_CDOUBLE
+#ifndef NPY_FLOAT80
+#define NPY_FLOAT80 NPY_DOUBLE
+#define NPY_COMPLEX160 NPY_CDOUBLE
 	typedef double npy_float80;
 	typedef npy_cdouble npy_complex160;
 #endif
 #elif NPY_BITSOF_DOUBLE == 96
-#ifndef PyArray_FLOAT96
-#define PyArray_FLOAT96 PyArray_DOUBLE
-#define PyArray_COMPLEX192 PyArray_CDOUBLE
+#ifndef NPY_FLOAT96
+#define NPY_FLOAT96 NPY_DOUBLE
+#define NPY_COMPLEX192 NPY_CDOUBLE
 	typedef double npy_float96;
 	typedef npy_cdouble npy_complex192;
 #endif
 #elif NPY_BITSOF_DOUBLE == 128
-#ifndef PyArray_FLOAT128
-#define PyArray_FLOAT128 PyArray_DOUBLE
-#define PyArray_COMPLEX256 PyArray_CDOUBLE
+#ifndef NPY_FLOAT128
+#define NPY_FLOAT128 NPY_DOUBLE
+#define NPY_COMPLEX256 NPY_CDOUBLE
 	typedef double npy_float128;
 	typedef npy_cdouble npy_complex256;
 #endif
@@ -529,44 +527,44 @@
 
 
 #if NPY_BITSOF_FLOAT == 16
-#ifndef PyArray_FLOAT16
-#define PyArray_FLOAT16 PyArray_FLOAT
-#define PyArray_COMPLEX32 PyArray_CFLOAT
+#ifndef NPY_FLOAT16
+#define NPY_FLOAT16 NPY_FLOAT
+#define NPY_COMPLEX32 NPY_CFLOAT
 	typedef float npy_float16;
 	typedef npy_cfloat npy_complex32;
 #endif
 #elif NPY_BITSOF_FLOAT == 32
-#ifndef PyArray_FLOAT32
-#define PyArray_FLOAT32 PyArray_FLOAT
-#define PyArray_COMPLEX64 PyArray_CFLOAT
+#ifndef NPY_FLOAT32
+#define NPY_FLOAT32 NPY_FLOAT
+#define NPY_COMPLEX64 NPY_CFLOAT
 	typedef float npy_float32;
 	typedef npy_cfloat npy_complex64;
 #endif
 #elif NPY_BITSOF_FLOAT == 64
-#ifndef PyArray_FLOAT64
-#define PyArray_FLOAT64 PyArray_FLOAT
-#define PyArray_COMPLEX128 PyArray_CFLOAT
+#ifndef NPY_FLOAT64
+#define NPY_FLOAT64 NPY_FLOAT
+#define NPY_COMPLEX128 NPY_CFLOAT
 	typedef float npy_float64;
 	typedef npy_cfloat npy_complex128;
 #endif
 #elif NPY_BITSOF_FLOAT == 80
-#ifndef PyArray_FLOAT80
-#define PyArray_FLOAT80 PyArray_FLOAT
-#define PyArray_COMPLEX160 PyArray_CFLOAT
+#ifndef NPY_FLOAT80
+#define NPY_FLOAT80 NPY_FLOAT
+#define NPY_COMPLEX160 NPY_CFLOAT
 	typedef float npy_float80;
 	typedef npy_cfloat npy_complex160;
 #endif
 #elif NPY_BITSOF_FLOAT == 96
-#ifndef PyArray_FLOAT96
-#define PyArray_FLOAT96 PyArray_FLOAT
-#define PyArray_COMPLEX192 PyArray_CFLOAT
+#ifndef NPY_FLOAT96
+#define NPY_FLOAT96 NPY_FLOAT
+#define NPY_COMPLEX192 NPY_CFLOAT
 	typedef float npy_float96;
 	typedef npy_cfloat npy_complex192;
 #endif
 #elif NPY_BITSOF_FLOAT == 128
-#ifndef PyArray_FLOAT128
-#define PyArray_FLOAT128 PyArray_FLOAT
-#define PyArray_COMPLEX256 PyArray_CFLOAT
+#ifndef NPY_FLOAT128
+#define NPY_FLOAT128 NPY_FLOAT
+#define NPY_COMPLEX256 NPY_CFLOAT
 	typedef float npy_float128;
 	typedef npy_cfloat npy_complex256;
 #endif
@@ -574,50 +572,50 @@
 
 
 #if NPY_BITSOF_LONGDOUBLE == 16
-#ifndef PyArray_FLOAT16
-#define PyArray_FLOAT16 PyArray_LONGDOUBLE
-#define PyArray_COMPLEX32 PyArray_CLONGDOUBLE
+#ifndef NPY_FLOAT16
+#define NPY_FLOAT16 NPY_LONGDOUBLE
+#define NPY_COMPLEX32 NPY_CLONGDOUBLE
 	typedef npy_longdouble npy_float16;
 	typedef npy_clongdouble npy_complex32;
 #endif
 #elif NPY_BITSOF_LONGDOUBLE == 32
-#ifndef PyArray_FLOAT32
-#define PyArray_FLOAT32 PyArray_LONGDOUBLE
-#define PyArray_COMPLEX64 PyArray_CLONGDOUBLE
+#ifndef NPY_FLOAT32
+#define NPY_FLOAT32 NPY_LONGDOUBLE
+#define NPY_COMPLEX64 NPY_CLONGDOUBLE
 	typedef npy_longdouble npy_float32;
 	typedef npy_clongdouble npy_complex64;
 #endif
 #elif NPY_BITSOF_LONGDOUBLE == 64
-#ifndef PyArray_FLOAT64
-#define PyArray_FLOAT64 PyArray_LONGDOUBLE
-#define PyArray_COMPLEX128 PyArray_CLONGDOUBLE
+#ifndef NPY_FLOAT64
+#define NPY_FLOAT64 NPY_LONGDOUBLE
+#define NPY_COMPLEX128 NPY_CLONGDOUBLE
 	typedef npy_longdouble npy_float64;
 	typedef npy_clongdouble npy_complex128;
 #endif
 #elif NPY_BITSOF_LONGDOUBLE == 80
-#ifndef PyArray_FLOAT80
-#define PyArray_FLOAT80 PyArray_LONGDOUBLE
-#define PyArray_COMPLEX160 PyArray_CLONGDOUBLE
+#ifndef NPY_FLOAT80
+#define NPY_FLOAT80 NPY_LONGDOUBLE
+#define NPY_COMPLEX160 NPY_CLONGDOUBLE
 	typedef npy_longdouble npy_float80;
 	typedef npy_clongdouble npy_complex160;
 #endif
 #elif NPY_BITSOF_LONGDOUBLE == 96
-#ifndef PyArray_FLOAT96
-#define PyArray_FLOAT96 PyArray_LONGDOUBLE
-#define PyArray_COMPLEX192 PyArray_CLONGDOUBLE
+#ifndef NPY_FLOAT96
+#define NPY_FLOAT96 NPY_LONGDOUBLE
+#define NPY_COMPLEX192 NPY_CLONGDOUBLE
 	typedef npy_longdouble npy_float96;
 	typedef npy_clongdouble npy_complex192;
 #endif
 #elif NPY_BITSOF_LONGDOUBLE == 128
-#ifndef PyArray_FLOAT128
-#define PyArray_FLOAT128 PyArray_LONGDOUBLE
-#define PyArray_COMPLEX256 PyArray_CLONGDOUBLE
+#ifndef NPY_FLOAT128
+#define NPY_FLOAT128 NPY_LONGDOUBLE
+#define NPY_COMPLEX256 NPY_CLONGDOUBLE
 	typedef npy_longdouble npy_float128;
 	typedef npy_clongdouble npy_complex256;
 #endif
 #elif NPY_BITSOF_LONGDOUBLE == 256
-#define PyArray_FLOAT256 PyArray_LONGDOUBLE
-#define PyArray_COMPLEX512 PyArray_CLONGDOUBLE
+#define NPY_FLOAT256 NPY_LONGDOUBLE
+#define NPY_COMPLEX512 NPY_CLONGDOUBLE
 	typedef npy_longdouble npy_float256;
 	typedef npy_clongdouble npy_complex512;
 #endif
@@ -638,8 +636,8 @@
 #endif
 
 #if SIZEOF_PY_INTPTR_T == SIZEOF_INT
-	#define PyArray_INTP PyArray_INT
-	#define PyArray_UINTP PyArray_UINT
+	#define NPY_INTP NPY_INT
+	#define NPY_UINTP NPY_UINT
         #define PyIntpArrType_Type PyIntArrType_Type
         #define PyUIntpArrType_Type PyUIntArrType_Type
 	#define NPY_MAX_INTP NPY_MAX_INT
@@ -647,8 +645,8 @@
 	#define NPY_MAX_UINTP NPY_MAX_UINT
         #define NPY_INTP_FMT "d"
 #elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG
-	#define PyArray_INTP PyArray_LONG
-	#define PyArray_UINTP PyArray_ULONG
+	#define NPY_INTP NPY_LONG
+	#define NPY_UINTP NPY_ULONG
         #define PyIntpArrType_Type PyLongArrType_Type
         #define PyUIntpArrType_Type PyULongArrType_Type
 	#define NPY_MAX_INTP NPY_MAX_LONG
@@ -656,8 +654,8 @@
 	#define NPY_MAX_UINTP NPY_MAX_ULONG
         #define NPY_INTP_FMT "ld"
 #elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)
-	#define PyArray_INTP PyArray_LONGLONG
-	#define PyArray_UINTP PyArray_ULONGLONG
+	#define NPY_INTP NPY_LONGLONG
+	#define NPY_UINTP NPY_ULONGLONG
         #define PyIntpArrType_Type PyLongLongArrType_Type
         #define PyUIntpArrType_Type PyULongLongArrType_Type
 	#define NPY_MAX_INTP NPY_MAX_LONGLONG
@@ -683,9 +681,9 @@
   /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */
 #define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size))
 
-#define PyArray_USE_PYMEM 0
+#define NPY_USE_PYMEM 0
 
-#if PyArray_USE_PYMEM == 1
+#if NPY_USE_PYMEM == 1
 #define npy_malloc PyObject_Malloc
 #define npy_free PyObject_Free
 #define npy_realloc PyObject_Realloc
@@ -738,7 +736,7 @@
 typedef struct {
 	/* Functions to cast to all other standard types*/
 	/* Can have some NULL entries */
-	PyArray_VectorUnaryFunc *cast[PyArray_NTYPES];
+	PyArray_VectorUnaryFunc *cast[NPY_NTYPES];
 
 	/* The next four functions *cannot* be NULL */
 
@@ -789,8 +787,8 @@
 	PyArray_FillWithScalarFunc *fillwithscalar;
 
 	/* Sorting functions; Can be NULL*/
-	PyArray_SortFunc *sort[PyArray_NSORTS];
-	PyArray_ArgSortFunc *argsort[PyArray_NSORTS];
+	PyArray_SortFunc *sort[NPY_NSORTS];
+	PyArray_ArgSortFunc *argsort[NPY_NSORTS];
 
 	/* Dictionary of additional casting functions
 	   PyArray_VectorUnaryFuncs
@@ -836,6 +834,9 @@
 	                        /* For statically defined descr this
 				   is always Py_None */
 
+        PyObject *names;        /* An ordered tuple of field names or NULL
+                                   if no fields are defined */
+
 	PyArray_ArrFuncs *f;     /* a table of functions specific for each
 				    basic data descriptor */
 } PyArray_Descr;
@@ -961,10 +962,11 @@
 /* Size of internal buffers used for alignment */
 /* Make BUFSIZE a multiple of sizeof(cdouble) -- ususally 16 */
 /* So that ufunc buffers are aligned */
-#define PyArray_MIN_BUFSIZE sizeof(cdouble)
-#define PyArray_MAX_BUFSIZE sizeof(cdouble)*1000000
-#define PyArray_BUFSIZE 10000
+#define NPY_MIN_BUFSIZE sizeof(cdouble)
+#define NPY_MAX_BUFSIZE sizeof(cdouble)*1000000
+#define NPY_BUFSIZE 10000
 
+#include "old_defines.h"
 
 /*
  * C API:  consists of Macros and functions.  The MACROS are defined here.
@@ -977,8 +979,8 @@
 #define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, NPY_WRITEABLE)
 #define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, NPY_ALIGNED)
 
-#define NPY_MAX(a,b) (((a)>(b))?(a):(b))
-#define NPY_MIN(a,b) (((a)<(b))?(a):(b))
+#define PyArray_MAX(a,b) (((a)>(b))?(a):(b))
+#define PyArray_MIN(a,b) (((a)<(b))?(a):(b))
 
 #if defined(ALLOW_THREADS)
 #define NPY_BEGIN_THREADS_DEF PyThreadState *_save;
@@ -1204,7 +1206,8 @@
 
 /* The default array type
  */
-#define PyArray_DEFAULT PyArray_DOUBLE
+#define NPY_DEFAULT_TYPE NPY_DOUBLE
+#define PyArray_DEFAULT NPY_DEFAULT_TYPE
 /* All sorts of useful ways to look into a PyArrayObject.
    These are the recommended over casting to PyArrayObject and accessing
    the members directly.
@@ -1214,7 +1217,8 @@
 #define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || PyArray_CHKFLAGS(m, NPY_CONTIGUOUS) || \
 				 PyArray_CHKFLAGS(m, NPY_FORTRAN))
 #define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_FORTRAN) && (PyArray_NDIM(m) > 1))
-#define FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_FORTRAN) ? NPY_FORTRAN : 0))
+#define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_FORTRAN) ? NPY_FORTRAN : 0))
+#define FORTRAN_IF PyArray_FORTRAN_IF
 #define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))
 #define PyArray_BYTES(obj) (((PyArrayObject *)(obj))->data)
 #define PyArray_DIMS(obj) (((PyArrayObject *)(obj))->dimensions)
@@ -1279,21 +1283,20 @@
 
 #define PyTypeNum_ISOBJECT(type) ((type) == PyArray_OBJECT)
 
-#define PyDescr_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))
-#define PyDescr_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)obj)->type_num )
-#define PyDescr_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISPYTHON(obj) PyTypeNum_ISPYTHON(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)obj)->type_num)
-#define PyDescr_HASFIELDS(obj) (((PyArray_Descr *)obj)->fields && \
-                                ((PyArray_Descr *)obj)->fields != Py_None)
+#define PyDataType_ISBOOL(obj) PyTypeNum_ISBOOL(_PyADt(obj))
+#define PyDataType_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)obj)->type_num )
+#define PyDataType_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISPYTHON(obj) PyTypeNum_ISPYTHON(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)obj)->type_num)
+#define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)obj)->names)
 
 #define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))
 #define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))
@@ -1308,20 +1311,20 @@
 #define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))
 #define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))
 #define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))
-#define PyArray_HASFIELDS(obj) PyDescr_HASFIELDS(PyArray_DESCR(obj))
+#define PyArray_HASFIELDS(obj) PyDataType_HASFIELDS(PyArray_DESCR(obj))
 
-#define PyArray_LITTLE '<'
-#define PyArray_BIG '>'
-#define PyArray_NATIVE '='
-#define PyArray_SWAP 's'
-#define PyArray_IGNORE '|'
+#define NPY_LITTLE '<'
+#define NPY_BIG '>'
+#define NPY_NATIVE '='
+#define NPY_SWAP 's'
+#define NPY_IGNORE '|'
 
 #ifdef WORDS_BIGENDIAN
-#define PyArray_NATBYTE PyArray_BIG
-#define PyArray_OPPBYTE PyArray_LITTLE
+#define NPY_NATBYTE NPY_BIG
+#define NPY_OPPBYTE NPY_LITTLE
 #else
-#define PyArray_NATBYTE PyArray_LITTLE
-#define PyArray_OPPBYTE PyArray_BIG
+#define NPY_NATBYTE NPY_LITTLE
+#define NPY_OPPBYTE NPY_BIG
 #endif
 
 #define PyArray_ISNBO(arg) ((arg) != PyArray_OPPBYTE)
@@ -1425,7 +1428,8 @@
 
 #define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), (val), PyArray_NBYTES(obj))
 
-#define NPY_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
+#define PyArray_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
+#define NPY_REFCOUNT PyArray_REFCOUNT
 #define NPY_MAX_ELSIZE 2*SIZEOF_LONGDOUBLE
 
 #define PyArray_ContiguousFromAny(op, type, min_depth, max_depth)   \

Added: trunk/numpy/core/include/numpy/old_defines.h
===================================================================
--- trunk/numpy/core/include/numpy/old_defines.h	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/include/numpy/old_defines.h	2006-07-10 23:05:09 UTC (rev 2795)
@@ -0,0 +1,167 @@
+#define NDARRAY_VERSION NPY_VERSION
+
+#define PyArray_MIN_BUFSIZE NPY_MIN_BUFSIZE
+#define PyArray_MAX_BUFSIZE NPY_MAX_BUFSIZE
+#define PyArray_BUFSIZE NPY_BUFSIZE
+
+#define PyArray_PRIORITY NPY_PRIORITY
+#define PyArray_SUBTYPE_PRIORITY NPY_PRIORITY
+#define PyArray_NUM_FLOATTYPE NPY_NUM_FLOATTYPE
+
+#define NPY_MAX PyArray_MAX
+#define NPY_MIN PyArray_MIN
+
+#define PyArray_TYPES       NPY_TYPES
+#define PyArray_BOOL        NPY_BOOL
+#define PyArray_BYTE        NPY_BYTE        
+#define PyArray_UBYTE       NPY_UBYTE       
+#define PyArray_SHORT       NPY_SHORT       
+#define PyArray_USHORT      NPY_USHORT      
+#define PyArray_INT         NPY_INT         
+#define PyArray_UINT        NPY_UINT        
+#define PyArray_LONG        NPY_LONG        
+#define PyArray_ULONG       NPY_ULONG       
+#define PyArray_LONGLONG    NPY_LONGLONG    
+#define PyArray_ULONGLONG   NPY_ULONGLONG   
+#define PyArray_FLOAT       NPY_FLOAT       
+#define PyArray_DOUBLE      NPY_DOUBLE      
+#define PyArray_LONGDOUBLE  NPY_LONGDOUBLE  
+#define PyArray_CFLOAT      NPY_CFLOAT      
+#define PyArray_CDOUBLE     NPY_CDOUBLE     
+#define PyArray_CLONGDOUBLE NPY_CLONGDOUBLE 
+#define PyArray_OBJECT      NPY_OBJECT      
+#define PyArray_STRING      NPY_STRING      
+#define PyArray_UNICODE     NPY_UNICODE     
+#define PyArray_VOID        NPY_VOID        
+#define PyArray_NTYPES      NPY_NTYPES      
+#define PyArray_NOTYPE      NPY_NOTYPE      
+#define PyArray_CHAR        NPY_CHAR        
+#define PyArray_USERDEF     NPY_USERDEF     
+
+#define PyArray_INTP        NPY_INTP
+#define PyArray_UINTP       NPY_UINTP
+
+#define PyArray_INT8    NPY_INT8   
+#define PyArray_UINT8   NPY_UINT8  
+#define PyArray_INT16   NPY_INT16  
+#define PyArray_UINT16  NPY_UINT16 
+#define PyArray_INT32   NPY_INT32  
+#define PyArray_UINT32  NPY_UINT32 
+
+#ifdef NPY_INT64
+#define PyArray_INT64   NPY_INT64  
+#define PyArray_UINT64  NPY_UINT64 
+#endif
+
+#ifdef NPY_INT128
+#define PyArray_INT128 NPY_INT128
+#define PyArray_UINT128 NPY_UINT128
+#endif
+
+#ifdef NPY_FLOAT16
+#define PyArray_FLOAT16  NPY_FLOAT16
+#define PyArray_COMPLEX32  NPY_COMPLEX32
+#endif
+
+#ifdef NPY_FLOAT80
+#define PyArray_FLOAT80  NPY_FLOAT80
+#define PyArray_COMPLEX160  NPY_COMPLEX160
+#endif
+
+#ifdef NPY_FLOAT96
+#define PyArray_FLOAT96  NPY_FLOAT96
+#define PyArray_COMPLEX192  NPY_COMPLEX192
+#endif
+
+#ifdef NPY_FLOAT128
+#define PyArray_FLOAT128  NPY_FLOAT128
+#define PyArray_COMPLEX256  NPY_COMPLEX256
+#endif
+
+#define PyArray_FLOAT32    NPY_FLOAT32
+#define PyArray_COMPLEX64  NPY_COMPLEX64
+#define PyArray_FLOAT64    NPY_FLOAT64
+#define PyArray_COMPLEX128 NPY_COMPLEX128
+
+
+#define PyArray_TYPECHAR        NPY_TYPECHAR
+#define PyArray_BOOLLTR         NPY_BOOLLTR        
+#define PyArray_BYTELTR         NPY_BYTELTR        
+#define PyArray_UBYTELTR        NPY_UBYTELTR       
+#define PyArray_SHORTLTR        NPY_SHORTLTR       
+#define PyArray_USHORTLTR       NPY_USHORTLTR      
+#define PyArray_INTLTR          NPY_INTLTR         
+#define PyArray_UINTLTR         NPY_UINTLTR        
+#define PyArray_LONGLTR         NPY_LONGLTR        
+#define PyArray_ULONGLTR        NPY_ULONGLTR       
+#define PyArray_LONGLONGLTR     NPY_LONGLONGLTR    
+#define PyArray_ULONGLONGLTR    NPY_ULONGLONGLTR   
+#define PyArray_FLOATLTR        NPY_FLOATLTR       
+#define PyArray_DOUBLELTR       NPY_DOUBLELTR      
+#define PyArray_LONGDOUBLELTR   NPY_LONGDOUBLELTR  
+#define PyArray_CFLOATLTR       NPY_CFLOATLTR      
+#define PyArray_CDOUBLELTR      NPY_CDOUBLELTR     
+#define PyArray_CLONGDOUBLELTR  NPY_CLONGDOUBLELTR 
+#define PyArray_OBJECTLTR       NPY_OBJECTLTR      
+#define PyArray_STRINGLTR       NPY_STRINGLTR      
+#define PyArray_STRINGLTR2      NPY_STRINGLTR2     
+#define PyArray_UNICODELTR      NPY_UNICODELTR     
+#define PyArray_VOIDLTR         NPY_VOIDLTR        
+#define PyArray_CHARLTR         NPY_CHARLTR        
+#define PyArray_INTPLTR         NPY_INTPLTR        
+#define PyArray_UINTPLTR        NPY_UINTPLTR       
+#define PyArray_GENBOOLLTR      NPY_GENBOOLLTR     
+#define PyArray_SIGNEDLTR       NPY_SIGNEDLTR      
+#define PyArray_UNSIGNEDLTR     NPY_UNSIGNEDLTR    
+#define PyArray_FLOATINGLTR     NPY_FLOATINGLTR    
+#define PyArray_COMPLEXLTR      NPY_COMPLEXLTR     
+
+#define PyArray_QUICKSORT   NPY_QUICKSORT
+#define PyArray_HEAPSORT    NPY_HEAPSORT
+#define PyArray_MERGESORT   NPY_MERGESORT
+#define PyArray_SORTKIND    NPY_SORTKIND
+#define PyArray_NSORTS      NPY_NSORTS
+
+#define PyArray_NOSCALAR       NPY_NOSCALAR       
+#define PyArray_BOOL_SCALAR    NPY_BOOL_SCALAR    
+#define PyArray_INTPOS_SCALAR  NPY_INTPOS_SCALAR  
+#define PyArray_INTNEG_SCALAR  NPY_INTNEG_SCALAR  
+#define PyArray_FLOAT_SCALAR   NPY_FLOAT_SCALAR   
+#define PyArray_COMPLEX_SCALAR NPY_COMPLEX_SCALAR 
+#define PyArray_OBJECT_SCALAR  NPY_OBJECT_SCALAR  
+#define PyArray_SCALARKIND     NPY_SCALARKIND     
+#define PyArray_NSCALARKINDS   NPY_NSCALARKINDS 
+
+#define PyArray_ANYORDER     NPY_ANYORDER     
+#define PyArray_CORDER       NPY_CORDER       
+#define PyArray_FORTRANORDER NPY_FORTRANORDER 
+#define PyArray_ORDER        NPY_ORDER        
+
+#define PyDescr_ISBOOL      PyDataType_ISBOOL      
+#define PyDescr_ISUNSIGNED  PyDataType_ISUNSIGNED  
+#define PyDescr_ISSIGNED    PyDataType_ISSIGNED    
+#define PyDescr_ISINTEGER   PyDataType_ISINTEGER   
+#define PyDescr_ISFLOAT     PyDataType_ISFLOAT     
+#define PyDescr_ISNUMBER    PyDataType_ISNUMBER    
+#define PyDescr_ISSTRING    PyDataType_ISSTRING    
+#define PyDescr_ISCOMPLEX   PyDataType_ISCOMPLEX   
+#define PyDescr_ISPYTHON    PyDataType_ISPYTHON    
+#define PyDescr_ISFLEXIBLE  PyDataType_ISFLEXIBLE  
+#define PyDescr_ISUSERDEF   PyDataType_ISUSERDEF   
+#define PyDescr_ISEXTENDED  PyDataType_ISEXTENDED  
+#define PyDescr_ISOBJECT    PyDataType_ISOBJECT    
+#define PyDescr_HASFIELDS   PyDataType_HASFIELDS   
+
+#define PyArray_LITTLE NPY_LITTLE
+#define PyArray_BIG NPY_BIG
+#define PyArray_NATIVE NPY_NATIVE
+#define PyArray_SWAP NPY_SWAP
+#define PyArray_IGNORE NPY_IGNORE
+
+#define PyArray_NATBYTE NPY_NATBYTE
+#define PyArray_OPPBYTE NPY_OPPBYTE
+
+#define NPY_REFCOUNT PyArray_REFCOUNT
+#define PyArray_MAX_ELSIZE NPY_MAX_ELSIZE 
+
+#define PyArray_USE_PYMEM NPY_USE_PYMEM

Modified: trunk/numpy/core/records.py
===================================================================
--- trunk/numpy/core/records.py	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/records.py	2006-07-10 23:05:09 UTC (rev 2795)
@@ -53,7 +53,7 @@
         if fields is None:
             dtype = sb.dtype([formats], aligned)
             fields = dtype.fields
-        keys = fields[-1]
+        keys = dtype.names
         self._f_formats = [fields[key][0] for key in keys]
         self._offsets = [fields[key][1] for key in keys]
         self._nfields = len(keys)
@@ -206,11 +206,12 @@
         return obj
 
     def field(self,attr, val=None):
+        if isinstance(attr,int):
+            names = sb.ndarray.__getattribute__(self,'dtype').names
+            attr=names[attr]
+
         fielddict = sb.ndarray.__getattribute__(self,'dtype').fields
 
-        if isinstance(attr,int):
-            attr=fielddict[-1][attr]
-
         res = fielddict[attr][:2]
 
         if val is None:

Modified: trunk/numpy/core/src/arraymethods.c
===================================================================
--- trunk/numpy/core/src/arraymethods.c	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/src/arraymethods.c	2006-07-10 23:05:09 UTC (rev 2795)
@@ -773,8 +773,6 @@
                 PyArray_Descr *new;
                 int offset, pos=0;
                 while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) return;
                         _deepcopy_call(iptr + offset, optr + offset, new,

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/src/arrayobject.c	2006-07-10 23:05:09 UTC (rev 2795)
@@ -164,8 +164,6 @@
                 PyArray_Descr *new;
                 int offset, pos=0;
                 while (PyDict_Next(descr->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) return;
                         PyArray_Item_INCREF(data + offset, new);
@@ -193,8 +191,6 @@
                 PyArray_Descr *new;
                 int offset, pos=0;
                 while (PyDict_Next(descr->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) return;
                         PyArray_Item_XDECREF(data + offset, new);
@@ -1341,7 +1337,7 @@
 			vobj->ob_size = itemsize;
 			vobj->flags = BEHAVED | OWNDATA;
 			swap = 0;
-			if (descr->fields) {
+			if (descr->names) {
 				if (base) {
 					Py_INCREF(base);
 					vobj->base = base;
@@ -2562,7 +2558,7 @@
 	PyArrayMapIterObject *mit;
 
 	if (PyString_Check(op) || PyUnicode_Check(op)) {
-		if (self->descr->fields) {
+		if (self->descr->names) {
 			PyObject *obj;
 			obj = PyDict_GetItem(self->descr->fields, op);
 			if (obj != NULL) {
@@ -2731,7 +2727,7 @@
 	}
 
 	if (PyString_Check(index) || PyUnicode_Check(index)) {
-		if (self->descr->fields) {
+                if (self->descr->names) {
 			PyObject *obj;
 			obj = PyDict_GetItem(self->descr->fields, index);
 			if (obj != NULL) {
@@ -4248,7 +4244,6 @@
 		op = (cmp_op == Py_EQ ? n_ops.equal : n_ops.not_equal);
 		op2 = (cmp_op == Py_EQ ? n_ops.logical_and : n_ops.logical_or);
                 while (PyDict_Next(self->descr->fields, &pos, &key, &value)) {
-			if (!PyString_Check(key)) continue;
 			a = array_subscript(self, key);
 			if (a==NULL) {Py_XDECREF(res); return NULL;}
 			b = array_subscript(other, key);
@@ -5118,8 +5113,6 @@
                 PyArray_Descr *new;
                 int offset, pos=0;
                 while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) return;
                         _putzero(optr + offset, zero, new);
@@ -5290,8 +5283,6 @@
                 PyArray_Descr *new;
                 int offset, pos=0;
                 while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) return;
                         _fillobject(optr + offset, obj, new);
@@ -6018,7 +6009,7 @@
 		inter->strides = NULL;
 	}
         inter->data = self->data;
-	if (self->descr->fields && self->descr->fields != Py_None) {
+	if (self->descr->names) {
 		inter->descr = arraydescr_protocol_descr_get(self->descr);
 		if (inter->descr == NULL) PyErr_Clear();
 		else inter->flags &= ARR_HAS_DESCR;
@@ -6597,6 +6588,8 @@
 			outtype->elsize = testsize;
 			Py_XDECREF(outtype->fields);
 			outtype->fields = NULL;
+			Py_XDECREF(outtype->names);
+			outtype->names = NULL;
 		}
 	}
 	return outtype;
@@ -6865,9 +6858,8 @@
 			  (type == PyArray_UNICODE) ||  \
 			  (type == PyArray_VOID));
 
-	stop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&	\
-						   typecode->fields!=Py_None) \
-						  || (typecode->subarray)));
+	stop_at_tuple = (type == PyArray_VOID && (typecode->names       \
+						  || typecode->subarray));
 
         if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,
 				 stop_at_tuple)) > 0)) {
@@ -10016,6 +10008,7 @@
 
 	if (new->fields == Py_None) new->fields = NULL;
 	Py_XINCREF(new->fields);
+        Py_XINCREF(new->names);
 	if (new->subarray) {
 		new->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));
 		memcpy(new->subarray, base->subarray,
@@ -10034,6 +10027,7 @@
 arraydescr_dealloc(PyArray_Descr *self)
 {
 	Py_XDECREF(self->typeobj);
+        Py_XDECREF(self->names);
 	Py_XDECREF(self->fields);
 	if (self->subarray) {
 		Py_DECREF(self->subarray->shape);
@@ -10056,6 +10050,7 @@
 	{"itemsize", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},
 	{"alignment", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},
         {"hasobject", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},
+        {"names", T_OBJECT, offsetof(PyArray_Descr, names), RO, NULL},
 	{NULL},
 };
 
@@ -10139,7 +10134,7 @@
 {
 	PyObject *dobj, *res;
 
-	if (self->fields == NULL || self->fields == Py_None) {
+	if (self->names == NULL) {
 		/* get default */
 		dobj = PyTuple_New(2);
 		if (dobj == NULL) return NULL;
@@ -10183,7 +10178,7 @@
 static PyObject *
 arraydescr_fields_get(PyArray_Descr *self)
 {
-	if (self->fields == NULL || self->fields == Py_None) {
+	if (self->names == NULL) {
 		Py_INCREF(Py_None);
 		return Py_None;
 	}
@@ -10308,7 +10303,7 @@
         /* version number of this pickle type. Increment if we need to
            change the format. Be sure to handle the old versions in
            arraydescr_setstate. */
-        const int version = 1;
+        const int version = 2;
 	PyObject *ret, *mod, *obj;
 	PyObject *state;
 	char endian;
@@ -10344,17 +10339,21 @@
 		endian = '<';
 		if (!PyArray_IsNativeByteOrder(endian)) endian = '>';
 	}
-	state = PyTuple_New(6);
+	state = PyTuple_New(7);
         PyTuple_SET_ITEM(state, 0, PyInt_FromLong(version));
 	PyTuple_SET_ITEM(state, 1, PyString_FromFormat("%c", endian));
 	PyTuple_SET_ITEM(state, 2, arraydescr_subdescr_get(self));
-	if (self->fields && self->fields != Py_None) {
+	if (self->names) {
+                Py_INCREF(self->names);
 		Py_INCREF(self->fields);
-		PyTuple_SET_ITEM(state, 3, self->fields);
+		PyTuple_SET_ITEM(state, 3, self->names);
+                PyTuple_SET_ITEM(state, 4, self->fields);
 	}
 	else {
 		PyTuple_SET_ITEM(state, 3, Py_None);
+		PyTuple_SET_ITEM(state, 4, Py_None);
 		Py_INCREF(Py_None);
+                Py_INCREF(Py_None);
 	}
 
 	/* for extended types it also includes elsize and alignment */
@@ -10364,8 +10363,8 @@
 	}
 	else {elsize = -1; alignment = -1;}
 
-	PyTuple_SET_ITEM(state, 4, PyInt_FromLong(elsize));
-	PyTuple_SET_ITEM(state, 5, PyInt_FromLong(alignment));
+	PyTuple_SET_ITEM(state, 5, PyInt_FromLong(elsize));
+	PyTuple_SET_ITEM(state, 6, PyInt_FromLong(alignment));
 
 	PyTuple_SET_ITEM(ret, 2, state);
 	return ret;
@@ -10380,32 +10379,61 @@
 arraydescr_setstate(PyArray_Descr *self, PyObject *args)
 {
 	int elsize = -1, alignment = -1;
-        int version = 1;
+        int version = 2;
 	char endian;
-	PyObject *subarray, *fields;
-
+	PyObject *subarray, *fields, *names=NULL;
+        int incref_names = 1;
+        
 	if (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}
-
-	if (!PyArg_ParseTuple(args, "(icOOii)", &version, &endian, &subarray,
-                              &fields, &elsize, &alignment)) {
+        
+        if (!PyArg_ParseTuple(args, "(icOOOii)", &version, &endian, &subarray,
+                              &names, &fields, &elsize, &alignment)) {
             PyErr_Clear();
-            version = 0;
-	    if (!PyArg_ParseTuple(args, "(cOOii)", &endian, &subarray,
+            if (!PyArg_ParseTuple(args, "(icOOii)", &version, &endian, &subarray,
                                   &fields, &elsize, &alignment)) {
-                return NULL;
+                PyErr_Clear();
+                version = 0;
+                if (!PyArg_ParseTuple(args, "(cOOii)", &endian, &subarray,
+                                      &fields, &elsize, &alignment)) {
+                    return NULL;
+                }
             }
         }
 
+        if (version == 1 || version == 0) {
+            if (fields != Py_None) {
+                PyObject *key, *list;
+                key = PyInt_FromLong(-1);
+                list = PyDict_GetItem(fields, key);
+                if (!list) return NULL;
+                    Py_INCREF(list);
+                    names = list;
+                    PyDict_DelItem(fields, key);
+                    incref_names = 0;
+            }
+            else {
+                names = Py_None;
+            }
+            version = 2;
+        }
+        
         /* If we ever need another pickle format, increment the version
            number. But we should still be able to handle the old versions.
-           We've only got one right now. */
-        if (version != 1 && version != 0) {
+        */
+        if (version != 2) {
             PyErr_Format(PyExc_ValueError,
                          "can't handle version %d of numpy.dtype pickle",
-                          version);
+                         version);
             return NULL;
         }
-
+        
+        if ((fields == Py_None && names != Py_None) ||  \
+            (names == Py_None && fields != Py_None)) {
+            PyErr_Format(PyExc_ValueError,
+                         "inconsistent fields and names");
+            return NULL;
+        }
+        
 	if (endian != '|' &&
 	    PyArray_IsNativeByteOrder(endian)) endian = '=';
 
@@ -10429,6 +10457,10 @@
 		Py_XDECREF(self->fields);
 		self->fields = fields;
 		Py_INCREF(fields);
+                Py_XDECREF(self->names);
+                self->names = names;
+                if (incref_names)
+                    Py_INCREF(names);
 	}
 
 	if (PyTypeNum_ISEXTENDED(self->type_num)) {
@@ -10476,7 +10508,7 @@
 			new->byteorder = newendian;
 		}
 	}
-	if (new->fields) {
+	if (new->names) {
 		PyObject *newfields;
 		PyObject *key, *value;
 		PyObject *newvalue;
@@ -10487,11 +10519,6 @@
 		/* make new dictionary with replaced */
 		/* PyArray_Descr Objects */
 		while(PyDict_Next(self->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) &&			\
-			    PyInt_AsLong(key) == -1) {
-				PyDict_SetItem(newfields, key, value);
-				continue;
-			}
 			if (!PyString_Check(key) ||	     \
 			    !PyTuple_Check(value) ||			\
 			    ((len=PyTuple_GET_SIZE(value)) < 2))
@@ -10563,7 +10590,7 @@
 {
 	PyObject *sub;
 
-	if (self->fields && self->fields != Py_None) {
+	if (self->names) {
 		PyObject *lst;
 		lst = arraydescr_protocol_descr_get(self);
 		if (!lst) {
@@ -10689,9 +10716,8 @@
 	
 	PyArray_Descr *self = (PyArray_Descr *)self0;
 
-	if (self->fields && self->fields != Py_None)
-		/* Remove the last entry (root) */
-		return PyDict_Size(self->fields) - 1;
+	if (self->names) 
+                return PyDict_Size(self->fields);
 	else return 0;
 }
 
@@ -10699,7 +10725,7 @@
 descr_subscript(PyArray_Descr *self, PyObject *op)
 {
 
-	if (self->fields) {
+	if (self->names) {
 		if (PyString_Check(op) || PyUnicode_Check(op)) {
 			PyObject *obj;
 			obj = PyDict_GetItem(self->fields, op);
@@ -10716,15 +10742,33 @@
 			}
 		}
 		else {
-		  PyErr_SetString(PyExc_ValueError,
-				  "only strings or unicode values allowed " \
-				  "for getting fields.");
-		}
-	}
+                        PyObject *name;
+                        int value;
+                        value = PyArray_PyIntAsInt(op);
+                        if (!PyErr_Occurred()) {
+                                int size;
+                                size = PyTuple_GET_SIZE(self->names);
+                                if (value < 0) value += size;
+                                if (value < 0 || value >= size) {
+                                        PyErr_Format(PyExc_IndexError,
+                                                     "0<=index<%d not %d",
+                                                     size, value);
+                                }
+                                name = PyTuple_GET_ITEM(self->names, value);
+                                return descr_subscript(self, name);
+                        }
+                }
+                PyErr_SetString(PyExc_ValueError,
+                                "only integers, strings or unicode values allowed " \
+                                "for getting fields.");
+        }
 	else {
+                PyObject *astr;
+                astr = arraydescr_str(self);
 		PyErr_Format(PyExc_KeyError,
 			     "there are no fields in dtype %s.",
-			     PyString_AsString(arraydescr_str(self)));
+			     PyString_AsString(astr));
+                Py_DECREF(astr);
 	}
 	return NULL;
 }

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/src/arraytypes.inc.src	2006-07-10 23:05:09 UTC (rev 2795)
@@ -383,7 +383,7 @@
         int itemsize;
 
 	descr = ap->descr;
-	if (descr->fields && descr->fields != Py_None) {
+	if (descr->names) {
 		PyObject *key;
 		PyObject *names;
 		int i, n;
@@ -394,9 +394,7 @@
 		int savedflags;
 
 		/* get the names from the fields dictionary*/
-		key = PyInt_FromLong(-1);
-		names = PyDict_GetItem(descr->fields, key);
-		Py_DECREF(key);
+                names = descr->names;
 		if (!names) goto finish;
 		n = PyTuple_GET_SIZE(names);
 		ret = PyTuple_New(n);
@@ -478,8 +476,7 @@
 	int res;
 
 	descr = ap->descr;
-	if (descr->fields && (descr->fields != Py_None) && \
-	    PyTuple_Check(op)) {
+	if (descr->names && PyTuple_Check(op)) {
 		PyObject *key;
 		PyObject *names;
 		int i, n;
@@ -489,10 +486,7 @@
 		int savedflags;
 		res = -1;
 		/* get the names from the fields dictionary*/
-		key = PyInt_FromLong(-1);
-		names = PyDict_GetItem(descr->fields, key);
-		Py_DECREF(key);
-		if (!names) goto finish;
+                names = descr->names;
 		n = PyTuple_GET_SIZE(names);
 		if (PyTuple_GET_SIZE(op) != n) {
 			PyErr_SetString(PyExc_ValueError, 
@@ -552,7 +546,6 @@
 		return res;
 	}
 
- finish:
 	/* Default is to use buffer interface to set item */
 	{
 		const void *buffer;
@@ -1218,8 +1211,6 @@
                 int offset, pos=0;
                 descr = arr->descr;
                 while (PyDict_Next(descr->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) {arr->descr=descr;return;}
                         arr->descr = new;
@@ -1244,8 +1235,6 @@
                 int offset, pos=0;
                 descr = arr->descr;  /* Save it */
                 while (PyDict_Next(descr->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) {arr->descr=descr;return;}
                         arr->descr = new;
@@ -1466,8 +1455,6 @@
 		descr = ap->descr;
 		savedflags = ap->flags;
                 while (PyDict_Next(descr->fields, &pos, &key, &value)) {
-			if (PyInt_Check(key) && PyInt_AsLong(key) == -1) 
-				continue;
  			if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, 
 					      &title)) {PyErr_Clear(); continue;}
                         ap->descr = new;
@@ -1926,6 +1913,7 @@
 	_ALIGN(@align@),
 	NULL,
 	NULL,
+        NULL,
 	&_Py at NAME@_ArrFuncs,
 };
 
@@ -2003,6 +1991,7 @@
 	_ALIGN(@fromtyp@),
 	NULL,
 	NULL,
+        NULL,
 	&_Py at NAME@_ArrFuncs,
 };
 

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-07-10 23:05:09 UTC (rev 2795)
@@ -3655,9 +3655,11 @@
 		goto fail;
 	}
 	new->elsize = conv->elsize;
-	if (conv->fields != Py_None) {
+	if (conv->names) {
 		new->fields = conv->fields;
 		Py_XINCREF(new->fields);
+                new->names = conv->names;
+                Py_XINCREF(new->names);
 	}
 	Py_DECREF(conv);
         if (conv->hasobject)
@@ -3742,7 +3744,9 @@
 		Py_INCREF(val);
 		newdescr->subarray->shape = val;
 		Py_XDECREF(newdescr->fields);
+                Py_XDECREF(newdescr->names);
 		newdescr->fields = NULL;
+                newdescr->names = NULL;
 		type = newdescr;
 	}
 	return type;
@@ -3763,7 +3767,7 @@
 	int n, i, totalsize;
 	int ret;
 	PyObject *fields, *item, *newobj;
-	PyObject *name, *key, *tup, *title;
+	PyObject *name, *tup, *title;
 	PyObject *nameslist;
 	PyArray_Descr *new;
 	PyArray_Descr *conv;
@@ -3838,12 +3842,9 @@
 		totalsize += conv->elsize;
 		Py_DECREF(tup);
 	}
-	key = PyInt_FromLong(-1);
-	PyDict_SetItem(fields, key, nameslist);
-	Py_DECREF(key);
-	Py_DECREF(nameslist);
 	new = PyArray_DescrNewFromType(PyArray_VOID);
 	new->fields = fields;
+        new->names = nameslist;
 	new->elsize = totalsize;
         new->hasobject=hasobject;
 	return new;
@@ -3908,12 +3909,9 @@
 		PyTuple_SET_ITEM(nameslist, i, key);
 		totalsize += conv->elsize;
 	}
-	key = PyInt_FromLong(-1);
-	PyDict_SetItem(fields, key, nameslist);
-	Py_DECREF(key);
-	Py_DECREF(nameslist);
 	new = PyArray_DescrNewFromType(PyArray_VOID);
 	new->fields = fields;
+        new->names = nameslist;
         new->hasobject=hasobject;
 	if (maxalign > 1) {
 		totalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;
@@ -4013,7 +4011,7 @@
 {
 	PyArray_Descr *new;
 	PyObject *fields=NULL;
-	PyObject *names, *offsets, *descrs, *titles, *key;
+	PyObject *names, *offsets, *descrs, *titles;
 	int n, i;
 	int totalsize;
 	int maxalign=0;
@@ -4125,14 +4123,13 @@
 		totalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;
 	if (align) new->alignment = maxalign;
 	new->elsize = totalsize;
-	key = PyInt_FromLong(-1);
         if (!PyTuple_Check(names)) {
                 names = PySequence_Tuple(names);
-                PyDict_SetItem(fields, key, names);
-                Py_DECREF(names);
         }
-        else PyDict_SetItem(fields, key, names);
-	Py_DECREF(key);
+        else {
+                Py_INCREF(names);
+        }
+        new->names = names;
 	new->fields = fields;
         new->hasobject=hasobject;
 	return new;

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2006-07-10 23:00:58 UTC (rev 2794)
+++ trunk/numpy/core/src/scalartypes.inc.src	2006-07-10 23:05:09 UTC (rev 2795)
@@ -1416,17 +1416,11 @@
 static Py_ssize_t
 voidtype_length(PyVoidScalarObject *self) 
 {
-	if (!self->descr->fields || self->descr->fields == Py_None) {
+	if (!self->descr->names) {
 		return 0;
 	}
 	else { /* return the number of fields */
-		PyObject *key;
-		PyObject *flist;
-		key = PyInt_FromLong(-1);
-		flist = PyDict_GetItem(self->descr->fields, key);
-		Py_DECREF(key);
-		if (!flist) return 0;
-		return PyTuple_GET_SIZE(flist);
+                return (Py_ssize_t) PyTuple_GET_SIZE(self->descr->names);
 	}
 }
 
@@ -1434,16 +1428,14 @@
 voidtype_item(PyVoidScalarObject *self, Py_ssize_t n)
 {
 	intp m;
-	PyObject *flist=NULL, *key, *fieldinfo;
+	PyObject *flist=NULL, *fieldinfo;
 
 	if (!(PyDescr_HASFIELDS(self->descr))) {
 		PyErr_SetString(PyExc_IndexError, 
 				"can't index void scalar without fields");
 		return NULL;	
 	}
-	key = PyInt_FromLong(-1);
-	flist = PyDict_GetItem(self->descr->fields, key);
-	Py_DECREF(key);
+        flist = self->descr->names;
 	m = PyTuple_GET_SIZE(flist);
 	if (n < 0) n += m;
 	if (n < 0 || n >= m) {
@@ -1463,7 +1455,7 @@
 	intp n;
 	PyObject *fieldinfo;
 
-	if (!self->descr->fields || self->descr->fields == Py_None) {
+	if (!(PyDescr_HASFIELDS(self->descr))) {
 		PyErr_SetString(PyExc_IndexError, 
 				"can't index void scalar without fields");
 		return NULL;
@@ -1492,7 +1484,7 @@
 voidtype_ass_item(PyVoidScalarObject *self, Py_ssize_t n, PyObject *val)
 {
 	intp m;
-	PyObject *flist=NULL, *key, *fieldinfo, *newtup;
+	PyObject *flist=NULL, *fieldinfo, *newtup;
 	PyObject *res;
 
 	if (!(PyDescr_HASFIELDS(self->descr))) {
@@ -1501,9 +1493,7 @@
 		return -1;
 	}
 
-	key = PyInt_FromLong(-1);
-	flist = PyDict_GetItem(self->descr->fields, key);
-	Py_DECREF(key);
+        flist = self->descr->names;
 	m = PyTuple_GET_SIZE(flist);
 	if (n < 0) n += m;
 	if (n < 0 || n >= m) goto fail;
@@ -1532,7 +1522,7 @@
 	PyObject *fieldinfo, *newtup;
 	PyObject *res;
 
-	if (!self->descr->fields || self->descr->fields == Py_None) {
+	if (!PyDescr_HASFIELDS(self->descr)) {
 		PyErr_SetString(PyExc_IndexError, 
 				"can't index void scalar without fields");
 		return -1;
@@ -2509,6 +2499,8 @@
 	if (conv) {
 		new->fields = conv->fields;
 		Py_INCREF(new->fields);
+                new->names = conv->names;
+                Py_INCREF(new->names);
 		new->elsize = conv->elsize;
 		new->subarray = conv->subarray;
 		conv->subarray = NULL;
@@ -2520,6 +2512,27 @@
 	return new;
 }
 
+/*OBJECT_API
+  Return the tuple of ordered field names from a dictionary.
+*/
+static PyObject *
+PyArray_FieldNames(PyObject *fields)
+{
+        PyObject *tup;
+        PyObject *ret;
+        if (!PyDict_Check(fields)) {
+                PyErr_SetString(PyExc_TypeError,
+                                "Fields must be a dictionary");
+                return NULL;
+        }
+	tup = PyObject_CallMethod(_numpy_internal, "_makenames_list", "O", fields);
+        if (tup == NULL) return NULL;
+        ret = PyTuple_GET_ITEM(tup, 0);
+        ret = PySequence_Tuple(ret);
+        Py_DECREF(tup);
+        return ret;
+}
+
 /* New reference */
 /*OBJECT_API
  Return descr object from array scalar.
@@ -2556,6 +2569,8 @@
 				Py_XDECREF(descr->fields);
 				descr->fields = NULL;
 			}
+                        if (descr->fields) 
+                                descr->names = PyArray_FieldNames(descr->fields);
 			PyErr_Clear();
 		}
         }




More information about the Numpy-svn mailing list