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]: <MemoryView of 'ndarray' at 0x8ae14e0> > > In [44]: x.flags['WRITEABLE'] = False > ...: return_one(x) > ValueError: buffer source array is read-only > > > Any help, esp. in regards to a workaround would be greatly appreciated! > > Thanks, > Dave > >
It seems using the numpy buffer interface works but I guess it would still be good if this worked for memviews too: %%cython cimport cython import numpy as np cimport numpy as np ctypedef np.float64_t float64_t @cython.boundscheck(False) @cython.wraparound(False) @cython.cdivision(True) cpdef double[:] return_one_np(np.ndarray[float64_t, ndim=1] x): return np.array([1.0]) In [203]: return_one_np(x) Out[203]: <MemoryView of 'ndarray' at 0x7d2d558> Cheers, Dave _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel