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

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Sep 15 13:05:32 CDT 2006


Author: oliphant
Date: 2006-09-15 13:05:27 -0500 (Fri, 15 Sep 2006)
New Revision: 3160

Modified:
   trunk/numpy/core/code_generators/multiarray_api_order.txt
   trunk/numpy/core/include/numpy/ndarrayobject.h
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/src/multiarraymodule.c
Log:
Add DescrAlignConverter

Modified: trunk/numpy/core/code_generators/multiarray_api_order.txt
===================================================================
--- trunk/numpy/core/code_generators/multiarray_api_order.txt	2006-09-15 17:24:44 UTC (rev 3159)
+++ trunk/numpy/core/code_generators/multiarray_api_order.txt	2006-09-15 18:05:27 UTC (rev 3160)
@@ -78,3 +78,5 @@
 PyArray_BroadcastToShape
 _PyArray_SigintHandler
 _PyArray_GetSigintBuf
+PyArray_DescrAlignConverter
+PyArray_DescrAlignConverter2
\ No newline at end of file

Modified: trunk/numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- trunk/numpy/core/include/numpy/ndarrayobject.h	2006-09-15 17:24:44 UTC (rev 3159)
+++ trunk/numpy/core/include/numpy/ndarrayobject.h	2006-09-15 18:05:27 UTC (rev 3160)
@@ -1478,6 +1478,7 @@
 #define PyArray_ToScalar(data, arr) \
         PyArray_Scalar(data, PyArray_DESCR(arr), (PyObject *)arr)
 
+
 /* These might be faster without the dereferencing of obj
    going on inside -- of course an optimizing compiler should
    inline the constants inside a for loop making it a moot point

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-09-15 17:24:44 UTC (rev 3159)
+++ trunk/numpy/core/src/arrayobject.c	2006-09-15 18:05:27 UTC (rev 3160)
@@ -10729,32 +10729,10 @@
                 return NULL;
 
         if (align) {
-                conv = NULL;
-                if PyDict_Check(odescr)
-                        conv =  _convert_from_dict(odescr, 1);
-                else if PyList_Check(odescr) {
-			PyErr_SetString(PyExc_ValueError,
-					"align cannot be True"		\
-					" with array_descriptor "	\
-					"specification.");
-			return NULL;
-		}
-                else if PyString_Check(odescr)
-                        conv = _convert_from_commastring(odescr, 1);
-                else {
-                        PyErr_SetString(PyExc_ValueError,
-                                        "align can only be non-zero for " \
-                                        "dictionary, list, and string objects.");
-                }
-                if (conv) return (PyObject *)conv;
-                if (!PyErr_Occurred()) {
-                        PyErr_SetString(PyExc_ValueError,
-                                        "data-type-descriptor not understood");
-                }
-                return NULL;
+                if (!PyArray_DescrAlignConverter(odescr, &conv))
+                        return NULL;
         }
-
-        if (!PyArray_DescrConverter(odescr, &conv))
+        else if (!PyArray_DescrConverter(odescr, &conv))
                 return NULL;
         /* Get a new copy of it unless it's already a copy */
         if (copy && conv->fields == Py_None) {

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-09-15 17:24:44 UTC (rev 3159)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-09-15 18:05:27 UTC (rev 3160)
@@ -4661,6 +4661,57 @@
 
 
 /*MULTIARRAY_API
+ Get type-descriptor from an object forcing alignment if possible
+ None goes to DEFAULT type.
+*/
+static int
+PyArray_DescrAlignConverter(PyObject *obj, PyArray_Descr **at)
+{
+        if PyDict_Check(obj) {
+                *at =  _convert_from_dict(obj, 1);
+        }
+        else if PyString_Check(obj)
+                *at = _convert_from_commastring(obj, 1);
+        else {
+                return PyArray_DescrConverter(obj, at);
+        }
+        if (*at == NULL) {
+                if (!PyErr_Occurred()) {
+                        PyErr_SetString(PyExc_ValueError,
+                                        "data-type-descriptor not understood");
+                }
+                return PY_FAIL;
+        } 
+        return PY_SUCCEED;
+}
+
+/*MULTIARRAY_API
+ Get type-descriptor from an object forcing alignment if possible
+ None goes to NULL.
+*/
+static int
+PyArray_DescrAlignConverter2(PyObject *obj, PyArray_Descr **at)
+{
+        if PyDict_Check(obj) {
+                *at =  _convert_from_dict(obj, 1);
+        }
+        else if PyString_Check(obj)
+                *at = _convert_from_commastring(obj, 1);
+        else {
+                return PyArray_DescrConverter2(obj, at);
+        }
+        if (*at == NULL) {
+                if (!PyErr_Occurred()) {
+                        PyErr_SetString(PyExc_ValueError,
+                                        "data-type-descriptor not understood");
+                }
+                return PY_FAIL;
+        } 
+        return PY_SUCCEED;
+}
+
+
+/*MULTIARRAY_API
  Get typenum from an object -- None goes to NULL
 */
 static int



More information about the Numpy-svn mailing list