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

Reply via email to