[Cython] Bug Report: can't assign zero length array to contiguous 2D memoryview

Josh Ayers josh.ayers at gmail.com
Wed Nov 6 19:35:39 CET 2013


Assigning a NumPy array with a zero length dimension to a memoryview fails
if the memoryview is declared contiguous in the zero-length dimension.  I'm
getting a run-time error that the buffer is not C-contiguous or Fortran
contiguous.

See examples below.

Thanks,
Josh Ayers


cdef float [:, :] arr1 = numpy.empty((2, 0), 'f4') # works
cdef float [:, :] arr2 = numpy.empty((0, 2), 'f4') # works
cdef float [:, ::1] arr3 = numpy.empty((2, 0), 'f4') # fails (buffer not
C-contiguous)
cdef float [:, ::1] arr4 = numpy.empty((0, 2), 'f4') # works

cdef float [:, :] arr5 = numpy.empty((2, 0), 'f4', order='F') # works
cdef float [:, :] arr6 = numpy.empty((0, 2), 'f4', order='F') # works
cdef float [::1, :] arr7 = numpy.empty((2, 0), 'f4', order='F') # works
cdef float [::1, :] arr8 = numpy.empty((0, 2), 'f4', order='F') # fails
(buffer not Fortran contiguous)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20131106/52460a43/attachment.html>


More information about the cython-devel mailing list