[Cython] MemoryViews require writeable arrays?
Dave Hirschfeld
dave.hirschfeld at gmail.com
Thu Feb 28 15:55:15 CET 2013
Sturla Molden <sturla at ...> writes:
>
> On 27.02.2013 20:05, Dave Hirschfeld wrote:
>
> > Is this a required restriction? Is there any workaround?
>
> http://www.python.org/dev/peps/pep-3118/
>
> What you should consider is the "readonly" field in "struct bufferinfo"
> or the access flag "PyBUF_WRITEABLE".
>
> In short:
>
> A PEP3118 buffer can be readonly, and then you shouldn't write to it!
> When you set the readonly flag, Cython cannot retrieve the buffer with
> PyBUF_WRITEABLE. Thus, Cython helps you not to shoot yourself in the
> foot. I don't think you can declare a read-only memoryview in Cython.
> (Well, not by any means I know of.)
>
> Sturla
>
>
So the issue is that at present memoryviews can't be readonly? Presumably
because this works for numpy arrays it would be possible to also make readonly
memoryviews? I think that would certainly be nice to have, but maybe it's a
niche use case.
Certainly, for IPython.parallel use it's easy enough to write a shim which sets
the array to writeable with the understanding that changes don't get propagated
back.
Thanks,
Dave
More information about the cython-devel
mailing list