[Cython] contiguous array access
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Wed Nov 12 11:25:26 CET 2008
Dag Sverre Seljebotn wrote:
> Or if you do not know the number of dimensions:
>
> cdef np.ndarray Xc = X
> if Xc.dtype != np.float or not Xc.flags["C_CONTIGUOUS"]:
> raise something
> cdef float* buf = <float*>Xc.data
>
I'm changing my recommondation to this instead:
if X.dtype != np.float or not X.flags["C_CONTIGUOUS"]:
raise something
cdef float* buf = <float*>np.PyArray_DATA(X)
(I suppose the "X.data" could be removed in the future because it might
be potentially confusing that it does something different if X is typed
as ndarray rather than if not:
cdef ndarray Xc = X
X.data # is a Python buffer instance
Xc.data # is a char*
PyArray_DATA can always be used if you want the latter one. Opinions?)
--
Dag Sverre
More information about the Cython-dev
mailing list