> There seems to be a lot of misunderstanding over what a pxd vs. pxi > file is. A pxd file is a declaration file, it just says "these things > will be available." A .pxi file is an include file, it is simply > textually included at that point in the program. The confusion comes > because cdef extern from blocks work the same for both. Perhaps we > should get rid of .pxi files altogether and just call them .pyx > files, because that's really what they are.
I sure have been confused about this multiple times. In my head, I know the difference in how they are handled, but sometimes I still don't know where to put things. I do like the name pxi to help us remember that they are simply textually included. In some ways include files is very anti-python in the first place. Not sure what to think, but I will start using c_numpy.pxd. Brian > - Robert > > > > > On Apr 24, 2008, at 1:16 PM, Brian Granger wrote: > > Hi, > > > > Previously, in numpy shipped with a numpy.pxd. But, at the last Sage > > days, all the Sage folks said "no, no, you should use a .pxi file for > > numpy, not a pxd file." Recently, Fernando updated the numpy example > > to work with cython and renamed the file to numpy.pxi. For simple > > things this works fine, but I am running into huge problems using the > > renamed numpy.pxi: > > > > 1) In numpy,pxi, there are extension types defined: > > > > ctypedef extern class numpy.dtype [object PyArray_Descr]: > > cdef int type_num, elsize, alignment > > cdef char type, kind, byteorder, hasobject > > cdef object fields, typeobj > > > > The problem is that when I include this .pxi file, I get the symbol > > dtype dumped into my global namespace. This makes it impossible to > > write functions like: > > > > def foo(a, dtype=float): > > ^^^^^ Cython complains that this is a not a valid C > > variable declaration > > > > So, then I thought I would get smart and do: > > > > ctypedef extern class numpy.dtype as DType [object PyArray_Descr]: > > cdef int type_num, elsize, alignment > > cdef char type, kind, byteorder, hasobject > > cdef object fields, typeobj > > > > But, this doesn't work because in numpy.pxi there are other extern > > classes defined that use dtype. Even when I change those references > > to DType, Cython complains that it doesn't know what DType is. > > > > 2) I have various files that are independent that need to include > > numpy.pxi. This works fine. But, when I use a file that includes > > numpy.pxi (through an include or cimport) in another file that > > includes numpy.pxi, I get lots of problems. It looks like Cython > > tries to include numpy.pxi twice. The second time it sees it, it > > thinks it is finding the actual implementation of the classes and > > complains that I can't add new C attributes in the implmentation. > >> From this, it looks like Cython has problems with double includes of > > pxi files that define extern classes. > > > > So.... > > > > The only way I can get all this to work is the rename numpy.pxi -> > > c_numpy.pxd and use cimport. Then all works well. But, this seems to > > go against the recommendation that pxd files should not be used for > > this purpose. Also, it seems like there are bugs or misfeatures in > > Cython's handling of pxi files. > > > > Thoughts? Thanks > > > > Brian > > _______________________________________________ > > Cython-dev mailing list > > Cython-dev@codespeak.net > > http://codespeak.net/mailman/listinfo/cython-dev > > _______________________________________________ > Cython-dev mailing list > Cython-dev@codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > _______________________________________________ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev