I saw some previous posts complaining about using numpy and some name
clashes about 'strides', and other stuff like that...
Well, as time pass, I like Cython more and more, because nasty names
and name clashes can be easyly fixed. For example, lest see some code
that uses the convention 'cxxxx' for accession at the Cython C-level
what in python is a 'xxxxx' member (eg. 'cshape' and 'shape'). This is
so easy for me that I will never mind about requiring the numpy
headers to change.
Have fun! I post this directly to F.Perez and B. Granger, I will love
to hear their opinion about this hackery. Any chances to go in for the
'official' numpy.pxy, or a variant shipped with numpy ??
# --------------------------------------------------------------------
cdef extern from "numpy/arrayobject.h":
int import_numpy "_import_array" () except -1
ctypedef int npy_intp
ctypedef extern class numpy.ndarray [object PyArrayObject]:
cdef char *cdata "data"
cdef int cndim "nd"
cdef int *cshape "dimensions"
cdef int *cstrides "strides"
cdef int cflags "flags"
# --------------------------------------------------------------------
import_numpy()
# --------------------------------------------------------------------
def prn(ndarray a):
cdef int i=0
# C-level access
print 'ndim: ', a.cndim
print 'shape: ', [a.cshape[i] for i from 0 <= i < a.cndim]
print 'strides: ', [a.cstrides[i] for i from 0 <= i < a.cndim]
print 'flags: ', a.cflags
#
print
# Python-level access
print 'ndim: ', a.ndim
print 'shape: ', a.shape
print 'strides: ', a.strides
print 'flags: ', a.flags
# --------------------------------------------------------------------
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev