Robert Kern wrote: > On 2009-04-28 13:10, Dag Sverre Seljebotn wrote: >> Robert Bradshaw wrote: >>> On Apr 28, 2009, at 11:01 AM, Robert Kern wrote: >>> >>>> On 2009-04-28 01:05, Dag Sverre Seljebotn wrote: >>>> [Mike Fletcher wrote:] >>>>>> * You have to call import_array() in your module or many of the >>>>>> Numpy C API entry points will segfault >>>>> Are you sure about this? I never do it. I know you need to do it >>>>> from C >>>>> code, but is it not enough in Cython to do >>>>> >>>>> import numpy >>>>> >>>>> ? >>>> If you call any of the PyArray_* functions, you will need an >>>> import_array() >>>> call. That does not just import numpy; it sets up the function >>>> pointer table in >>>> your extension module such that the PyArray_* #defines reference >>>> the right >>>> functions. >>> So "import numpy" doesn't call import_array() then? > > No, "import numpy" just imports numpy just as in Python. Each numpy-using > extension module has a variable local to it that points to the global table > of > function pointers. import_array() must be called once per extension module in > order to make that module-local variable point to the correct location.
Ahh right. Just as intra-Cython-module calls with __pyx_capi :-) > It would be wise to include it in the tutorial with a comment about when it > is > necessary. People have a wide variety of entry points into the material. They > may start with your tutorial and just need to use a few API functions. They > may > very well skip the parts in the numpy docs about setting up an extension > module > thinking that Cython took care of everything for them. Sounds reasonable to include a C API section prominently there, though I won't have time myself (nor do I know that much about the NumPy C API, to be honest, all I ever use is the ndarray and dtype struct & macros). -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
