[Numpy-discussion] Updating cython directory to pxd usage: objections?

Fernando Perez fperez.net at gmail.com
Fri Jun 20 13:51:53 EDT 2008


On Thu, Jun 19, 2008 at 9:18 PM, Fernando Perez <fperez.net at gmail.com> wrote:
> On Thu, Jun 19, 2008 at 5:29 PM, Robert Kern <robert.kern at gmail.com> wrote:
>
>>> I just tested the changes and there seem to be no ill effects.  Should
>>> I  go ahead and commit it? I'll do it in a single commit with no other
>>> changes so it's easy to revert should it prove to be a bad idea.
>>
>> Sure.
>
> Thanks.  Done in r5301.

Well, the simplistic test script we had in didn't show any problems,
but Matthew Brett was more careful than me and went looking into the
generated code:

On Fri, Jun 20, 2008 at 1:32 AM, Matthew Brett <matthew.brett at gmail.com> wrote:
> Hi,
>
>>>> I just tested the changes and there seem to be no ill effects.  Should
>>>> I  go ahead and commit it? I'll do it in a single commit with no other
>>>> changes so it's easy to revert should it prove to be a bad idea.
>>>
>>> Sure.
>>
>> Thanks.  Done in r5301.
>
> Hmm - but does import_array() get called when it's in the pxd file?  I
> just updated svn and generated the numpyx.c file, and can't see
> import_array() there.  Isn't the pxd file just definitions?

And indeed, it was my fault for not RTFM:

http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/sharing.html#mozTocId411233

which says:

It [the .pxd file] cannot contain the implementations of any C or
Python functions, or any Python class definitions, or **any executable
statements**. (emphasis mine).


I verified further by putting the import_array() back into  the .pyx
file and indeed:

- i_a() in .pxd -> missing from .c file.
- i_a() in .pyx -> OK in .c file.

It thus seems that  we must keep the import_array call out of the .pxd
and users still need to remember to make it themselves.

I'll go ahead and clean up, since the mess was my fault.

Many thanks to Matthew for catching it!

Cheers,

f



More information about the NumPy-Discussion mailing list