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

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 12:04:27 CST 2010


Author: ptvirtan
Date: 2010-02-20 12:04:27 -0600 (Sat, 20 Feb 2010)
New Revision: 8134

Modified:
   trunk/numpy/core/src/multiarray/buffer.c
Log:
ENH: core: require PEP 3118 buffer contiguity only with ND and not STRIDES

Modified: trunk/numpy/core/src/multiarray/buffer.c
===================================================================
--- trunk/numpy/core/src/multiarray/buffer.c	2010-02-20 18:04:11 UTC (rev 8133)
+++ trunk/numpy/core/src/multiarray/buffer.c	2010-02-20 18:04:27 UTC (rev 8134)
@@ -471,10 +471,6 @@
 
     self = (PyArrayObject*)obj;
 
-    if (view == NULL) {
-        goto fail;
-    }
-
     /* Check whether we can provide the wanted properties */
     if ((flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS &&
         !PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)) {
@@ -492,8 +488,9 @@
         goto fail;
     }
     if ((flags & PyBUF_STRIDES) != PyBUF_STRIDES &&
+        (flags & PyBUF_ND) == PyBUF_ND &&
         !PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)) {
-        /* Non-strided buffers must be C-contiguous */
+        /* Non-strided N-dim buffers must be C-contiguous */
         PyErr_SetString(PyExc_ValueError, "ndarray is not C-contiguous");
         goto fail;
     }
@@ -503,6 +500,11 @@
         goto fail;
     }
 
+    if (view == NULL) {
+        PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer");
+        goto fail;
+    }
+
     /* Fill in information */
     info = _buffer_get_info(obj);
     if (info == NULL) {
@@ -520,9 +522,20 @@
     } else {
         view->format = NULL;
     }
-    view->ndim = info->ndim;
-    view->shape = info->shape;
-    view->strides = info->strides;
+    if ((flags & PyBUF_ND) == PyBUF_ND) {
+        view->ndim = info->ndim;
+        view->shape = info->shape;
+    }
+    else {
+        view->ndim = 0;
+        view->shape = NULL;
+    }
+    if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
+        view->strides = info->strides;
+    }
+    else {
+        view->strides = NULL;
+    }
     view->obj = (PyObject*)self;
 
     Py_INCREF(self);



More information about the Numpy-svn mailing list