robertwb / issues-import-test

0 stars 0 forks source link

buffer shape incompatible with memoryview shape #938

Open robertwb opened 12 years ago

robertwb commented 12 years ago

This code fails to compile for me:

def test(double[a, object[double, ndim=2](:,:]) b):
    if a.shape != b.shape:
        print("shape differs")
Error compiling Cython file:
------------------------------------------------------------
def test(double[a, object[double, ndim=2](:,:]) b):
    if a.shape != b.shape:
       ^
------------------------------------------------------------
mvtest.pyx:2:8: Cannot convert 'Py_ssize_t [8]' to Python object

The error is that the shape field of the memory view is a C array that cannot be converted to a Python object in order to compare it to the shape of the buffer, which is a Python tuple.

The underlying problem is that Cython does not know that the shape field of a buffer is just a C array as well. Instead, it looks it up as a Python attribute and unpacks it as a Python tuple.

Migrated from http://trac.cython.org/ticket/780

robertwb commented 12 years ago

scoder changed milestone from wishlist to 0.17