On Fri, May 21, 2010 at 12:24 PM, Lisandro Dalcin <[email protected]> wrote: > On 20 May 2010 17:40, jah <[email protected]> wrote: >> Hi, >> >> I'm reading through numpy.pxd and trying to understand the following: >> >> ctypedef class numpy.ndarray [object PyArrayObject] >> > >> Probably, I have made some wrong conclusions and was hoping for an >> explanation. Sorry if these are simple questions, but I wasn't able >> to find info on this in the docs (links are appreciated). >> >> 0) What does the above statement mean, in words? >> > > 1) There is an extension type called "ndarray" in module "numpy" > > 2) The object structure (i.e. a C struct that has extra slots > extending the core Python's PyObject structure) is called > PyArrayObject > > 3) the "ctypedef" bit means that generated C code will use plain > "PyArrayObject" for declaring structs, whild if you do cdef class > ...., the generated C code will use "struct PyArrayObject". In the > specific case of numpy, look at the header "numpy/arrayobject.h", you > should see "typedef struct PyArrayObject { ...} PyArrayObject"... As > PyArrayObject end-up being a C typedef, in Cython side you have > declare with "ctypedef". > > Pretty obvious, right? ;-) >
Very helpful. I was able to figure out the third point by looking at the generated code. But I'm still confused on one other issue. In numpy.pxd, the ctypedef used "numpy.ndarray" in the declaration, but in the same file, "ndarray" is used without qualification (inside the ctypedef block). Is this just how it is? It seemed a bit like magic that "ndarray" can be used without the namespace before the ctypedef has been fully defined. For example, I see: def __getbuffer__(ndarray self, Py_buffer* info, int flags): rather than def __getbuffer__(numpy.ndarray self, Py_buffer* info, int flags): I'm not too worried about it, but it was a sticking point for me that caused mental confusion. _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
