[Numpy-svn] r8220 - trunk/numpy/core/src/multiarray

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 20:52:20 CST 2010


Author: ptvirtan
Date: 2010-02-20 20:52:20 -0600 (Sat, 20 Feb 2010)
New Revision: 8220

Modified:
   trunk/numpy/core/src/multiarray/arraytypes.c.src
Log:
3K: ENH: core: void.item() -> byte array; simple memoryview -> Bytes

Modified: trunk/numpy/core/src/multiarray/arraytypes.c.src
===================================================================
--- trunk/numpy/core/src/multiarray/arraytypes.c.src	2010-02-21 02:52:02 UTC (rev 8219)
+++ trunk/numpy/core/src/multiarray/arraytypes.c.src	2010-02-21 02:52:20 UTC (rev 8220)
@@ -440,7 +440,7 @@
         temp = PyUnicode_AsASCIIString(op);
         if (temp == NULL) return -1;
     }
-    else if (PyBytes_Check(op)) {
+    else if (PyBytes_Check(op) || PyMemoryView_Check(op)) {
         temp = PyObject_Bytes(op);
         if (temp == NULL) {
             return -1;
@@ -616,31 +616,38 @@
         return NULL;
     }
     itemsize = ap->descr->elsize;
-    if (PyArray_ISWRITEABLE(ap)) {
 #if defined(NPY_PY3K)
-#warning XXX -- needs implementation
-        PyErr_SetString(PyExc_RuntimeError, "XXX -- not implemented");
-        u = NULL;
+    /*
+     * Return a byte array; there are no plain buffer objects on Py3
+     */
+    {
+        intp dims[1], strides[1];
+        PyArray_Descr *descr;
+        dims[0] = itemsize;
+        strides[0] = 1;
+        descr = PyArray_DescrNewFromType(PyArray_BYTE);
+        u = PyArray_NewFromDescr(&PyArray_Type, descr, 1, dims, strides,
+                                 ip,
+                                 PyArray_ISWRITEABLE(ap) ? NPY_WRITEABLE : 0,
+                                 NULL);
+        ((PyArrayObject*)u)->base = ap;
+        Py_INCREF(ap);
+    }
 #else
+    /*
+     * default is to return buffer object pointing to
+     * current item a view of it
+     */
+    if (PyArray_ISWRITEABLE(ap)) {
         u = PyBuffer_FromReadWriteMemory(ip, itemsize);
-#endif
     }
     else {
-#if defined(NPY_PY3K)
-#warning XXX -- needs implementation
-        PyErr_SetString(PyExc_RuntimeError, "XXX -- not implemented");
-        u = NULL;
-#else
         u = PyBuffer_FromMemory(ip, itemsize);
+    }
 #endif
-    }
     if (u == NULL) {
         goto fail;
     }
-    /*
-     * default is to return buffer object pointing to
-     * current item a view of it
-     */
     return u;
 
 fail:



More information about the Numpy-svn mailing list