[Numpy-svn] r3219 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Sep 26 17:39:36 CDT 2006


Author: oliphant
Date: 2006-09-26 17:39:14 -0500 (Tue, 26 Sep 2006)
New Revision: 3219

Modified:
   trunk/numpy/core/src/arraytypes.inc.src
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/core/src/scalartypes.inc.src
Log:
Allow scalars to be constructed with default values of 0.

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2006-09-26 17:01:15 UTC (rev 3218)
+++ trunk/numpy/core/src/arraytypes.inc.src	2006-09-26 22:39:14 UTC (rev 3219)
@@ -341,7 +341,7 @@
 static PyObject *
 OBJECT_getitem(char *ip, PyArrayObject *ap)
 {
-        if (PyArray_ISALIGNED(ap)) {
+        if (!ap || PyArray_ISALIGNED(ap)) {
                 Py_INCREF(*(PyObject **)ip);
                 return *(PyObject **)ip;
         }
@@ -358,7 +358,7 @@
 OBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap)
 {
         Py_INCREF(op);
-        if (PyArray_ISALIGNED(ap)) {
+        if (!ap || PyArray_ISALIGNED(ap)) {
                 Py_XDECREF(*(PyObject **)ov);
                 *(PyObject **)ov = op;
         }

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-09-26 17:01:15 UTC (rev 3218)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-09-26 22:39:14 UTC (rev 3219)
@@ -3661,7 +3661,7 @@
 					 &array, &mask, &values))
 		return NULL;
 
-	return PyArray_PutMask(array, values, mask);
+	return PyArray_PutMask((PyArrayObject *)array, values, mask);
 }
 
 /*MULTIARRAY_API

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2006-09-26 17:01:15 UTC (rev 3218)
+++ trunk/numpy/core/src/scalartypes.inc.src	2006-09-26 22:39:14 UTC (rev 3219)
@@ -1707,6 +1707,7 @@
 #name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#
 #TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#
 #work=0,0,1,1,1,0,0,0,0,0,0,1,0,0,0,0,z,z,1#
+#default=0*16,1*2,2#
 */
 static PyObject *
 @name at _arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
@@ -1717,9 +1718,26 @@
 
         _WORK at work@
 
-        if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
+        if (!PyArg_ParseTuple(args, "|O", &obj)) return NULL;
 
         typecode = PyArray_DescrFromType(PyArray_ at TYPE@);
+        if (obj == NULL) {
+#if @default@ == 0
+                char *mem;
+                PyObject *obj;
+                mem = malloc(sizeof(@name@));
+                memset(mem, 0, sizeof(@name@));
+                obj = PyArray_Scalar(mem, typecode, NULL);
+                free(mem);
+                return obj;
+#elif @default@ == 1
+                return PyArray_Scalar(NULL, typecode, NULL);
+#elif @default@ == 2
+                PyObject *obj = Py_None;
+                return PyArray_Scalar(&obj, typecode, NULL);
+#endif
+        }
+
         arr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);
         return PyArray_Return((PyArrayObject *)arr);
 }
@@ -1737,7 +1755,9 @@
         PyObject *obj=NULL;
         PyObject *arr;
 
-        if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
+        if (!PyArg_ParseTuple(args, "|O", &obj)) return NULL;
+        if (obj == NULL)
+                PyArrayScalar_RETURN_FALSE;
         if (obj == Py_False)
                 PyArrayScalar_RETURN_FALSE;
         if (obj == Py_True)



More information about the Numpy-svn mailing list