Re: [Cython] MemoryViews require writeable arrays?

2013-02-28 Thread Sturla Molden
On 28.02.2013 15:55, Dave Hirschfeld wrote: So the issue is that at present memoryviews can't be readonly? https://github.com/cython/cython/blob/master/Cython/Compiler/MemoryView.py#L33 Typed memoryviews are thus acquired with the PyBUF_WRITEABLE flag. If the the assigned buffer is readonly,

Re: [Cython] MemoryViews require writeable arrays?

2013-02-28 Thread Dave Hirschfeld
Sturla Molden 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"

Re: [Cython] MemoryViews require writeable arrays?

2013-02-28 Thread Sturla Molden
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 r

Re: [Cython] MemoryViews require writeable arrays?

2013-02-27 Thread Dave Hirschfeld
Dave Hirschfeld writes: > > cpdef double[:] return_one(double[:] x): > return np.array([1.0]) > > In [43]: x = randn(3) > ...: return_one(x) > Out[43]: > > In [44]: x.flags['WRITEABLE'] = False > ...: return_one(x) > ValueError: buffer source array is read-only > > > Any help, e

[Cython] MemoryViews require writeable arrays?

2013-02-27 Thread Dave Hirschfeld
%%cython cimport cython import numpy as np cimport numpy as np @cython.boundscheck(False) @cython.wraparound(False) @cython.cdivision(True) cpdef double[:] return_one(double[:] x): return np.array([1.0]) In [43]: x = randn(3) ...: return_one(x) Out[43]: In [44]: x.flags['WRITEABLE'] =