[Cython] BUG: assignment to typed memoryview

Daniele Nicolodi daniele at grinta.net
Tue Nov 26 16:18:51 CET 2013


I believe there is a bug in how assignment to typed memoryviews is
handled in the compiler.  I think the following code should be valid code:

  cdef double[::1] a = np.arange(10, dtype=np.double)
  cdef double[::1] b = np.empty(a.size // 2)
  b[:] = a[::2]

However, the Cython compiler complains with:

  Memoryview 'double[:]' not conformable to memoryview 'double[::1]'.

A similar thing happens with memoryview copies:

  cdef double[::1] a = np.arange(10, dtype=np.double)
  cdef double[::1] b
  b = a[::2].copy()

In both cases I would expect Cython to copy the non contiguous elements
of the source array to the destination array (or to a newly created
array in the second case).  The copy() method is defined here
and (while I haven't spent much time analyzing it in detail) it seems to
do the right thing.

Indeed, if I short-circuit the src_conforms_to_dst() function
the code compiles and runs correctly in both cases.

I don't know much about how the Cython compiler works, therefore I don't
know where to dig for the source of this problem.  Can someone point me
in the right direction?

Thanks. Cheers,

More information about the cython-devel mailing list