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

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Oct 24 02:15:42 CDT 2006


Author: oliphant
Date: 2006-10-24 02:15:28 -0500 (Tue, 24 Oct 2006)
New Revision: 3389

Modified:
   trunk/numpy/core/include/numpy/noprefix.h
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/ctypeslib.py
Log:
Add more keys to _flagdict.  Fix uses of F_CONTIGUOUS and C_CONTIGUOUS up a bit and make sure flags in num_to_flags includes only full flag names.

Modified: trunk/numpy/core/include/numpy/noprefix.h
===================================================================
--- trunk/numpy/core/include/numpy/noprefix.h	2006-10-24 06:52:30 UTC (rev 3388)
+++ trunk/numpy/core/include/numpy/noprefix.h	2006-10-24 07:15:28 UTC (rev 3389)
@@ -136,7 +136,9 @@
 #define LONGDOUBLE_FMT NPY_LONGDOUBLE_FMT
 
 #define CONTIGUOUS         NPY_CONTIGUOUS
+#define C_CONTIGUOUS       NPY_C_CONTIGUOUS
 #define FORTRAN            NPY_FORTRAN
+#define F_CONTIGUOUS       NPY_F_CONTIGUOUS
 #define OWNDATA            NPY_OWNDATA
 #define FORCECAST          NPY_FORCECAST
 #define ENSURECOPY         NPY_ENSURECOPY

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-10-24 06:52:30 UTC (rev 3388)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-10-24 07:15:28 UTC (rev 3389)
@@ -7147,24 +7147,28 @@
 
         newd = PyDict_New();
 
-        PyDict_SetItemString(newd, "OWNDATA", s=PyInt_FromLong(OWNDATA));
-        Py_DECREF(s);
-        PyDict_SetItemString(newd, "FORTRAN", s=PyInt_FromLong(FORTRAN));
-        Py_DECREF(s);
-        PyDict_SetItemString(newd, "F_CONTIGUOUS", s=PyInt_FromLong(FORTRAN));
-        Py_DECREF(s);
-        PyDict_SetItemString(newd, "CONTIGUOUS", s=PyInt_FromLong(CONTIGUOUS));
-        Py_DECREF(s);
-        PyDict_SetItemString(newd, "C_CONTIGUOUS", s=PyInt_FromLong(CONTIGUOUS));
-        Py_DECREF(s);
-        PyDict_SetItemString(newd, "ALIGNED", s=PyInt_FromLong(ALIGNED));
-        Py_DECREF(s);
+#define _addnew(val, one) \
+        PyDict_SetItemString(newd, #val, s=PyInt_FromLong(val)); \
+        Py_DECREF(s); \
+        PyDict_SetItemString(newd, #one, s=PyInt_FromLong(val)); \
+        Py_DECREF(s)
 
-        PyDict_SetItemString(newd, "UPDATEIFCOPY", s=PyInt_FromLong(UPDATEIFCOPY));
-        Py_DECREF(s);
-        PyDict_SetItemString(newd, "WRITEABLE", s=PyInt_FromLong(WRITEABLE));
-        Py_DECREF(s);
+#define _addone(val) \
+        PyDict_SetItemString(newd, #val, s=PyInt_FromLong(val)); \
+        Py_DECREF(s)
 
+        _addnew(OWNDATA, O);
+        _addnew(FORTRAN, F);
+        _addnew(CONTIGUOUS, C);
+        _addnew(ALIGNED, A);
+        _addnew(UPDATEIFCOPY, U);
+        _addnew(WRITEABLE, W);
+        _addone(C_CONTIGUOUS);
+        _addone(F_CONTIGUOUS);
+        
+#undef _addone
+#undef _addnew
+
         PyDict_SetItemString(d, "_flagdict", newd);
         Py_DECREF(newd);
         return;

Modified: trunk/numpy/ctypeslib.py
===================================================================
--- trunk/numpy/ctypeslib.py	2006-10-24 06:52:30 UTC (rev 3388)
+++ trunk/numpy/ctypeslib.py	2006-10-24 07:15:28 UTC (rev 3389)
@@ -51,9 +51,12 @@
         num += _flagdict[val]
     return num
 
+_flagnames = ['C_CONTIGUOUS', 'F_CONTIGUOUS', 'ALIGNED', 'WRITEABLE', 
+              'OWNDATA', 'UPDATEIFCOPY']
 def _flags_fromnum(num):
     res = []
-    for key, value in _flagdict.items():
+    for key in _flagnames:
+        value = _flagdict[key]
         if (num & value):
             res.append(key)
     return res



More information about the Numpy-svn mailing list