[Cython] [cython-users] Confusing beheavior of memoryview (assigning value to slice fails without any indication)

Stefan Behnel stefan_ml at behnel.de
Tue May 8 15:20:11 CEST 2012

mark florisson, 08.05.2012 11:11:
> On 7 May 2012 13:09, Maxim wrote:
>> Consider the following code:
>>> # a.pyx:
>>> cdef class Base(object):
>>>   cdef public double[:,:] arr
>>> # b.py:
>>> from a import Base
>>> import numpy as np
>>> class MyClass(Base):
>>>   def __init__(self):
>>>     self.arr = np.zeros((10, 10), dtype=np.float64)
>>>     self.arr[1, :] = 10  # this line will execute correctly, but won't
>>> have any effect
>>>     print self.arr[1,5]
>> Is it possible to somehow warn the user here that assigning value to
>> memoryview slice is not supported? Finding this out after some debugging was
>> a little annoying.
> Thanks for the report, that's a silly bug. It works with typed
> memoryviews, but with objects it passes in the wrong ndim, and the
> second dimension is 0, which means it does nothing. It is fixed in the
> cython master branch.
> BTW, using 'self.arr' in the python subclass means you don't get your
> numpy array back, but rather a cython memoryview that is far less
> capable.

I think it would be good to cherry pick this kind of fix directly over into
the release branch so that we can start building up our pile of fixes for
0.16.1 there.


More information about the cython-devel mailing list