import_array weird behavior
Hi all, I've just changed to cython and old numpy module with a raw C API. The C module init is removed, and I've put the import_array in the 'pure-cython' part of the module init. Usual tutorial examples have these lines: import numpy as NPY cimport numpy as NPY NPY.import_array() But this fails (first numpy API call core dump) in my module, if I put back the import_array() in the C part of the module everything turns ok again. Now if I remove again this C API import_array and I write: import numpy as NPY cimport numpy as CNPY CNPY.import_array() all is ok. Do I miss something? It sounds good to me to have to separate scopes but I wonder if it's a common practice with potential side-effects or if it is the right way to use numpy with cython. And then, what about my core dump? cython 1.15.1 python 2.7.2 numpy 1.6.1 scons 2.1.0 linux x86 64 with gcc 4.3.4 -MP- ----------------------------------------------------------------------- Marc POINOT [ONERA/DSNA] Tel:+33.1.46.73.42.84 Fax:+33.1.46.73.41.66 Avertissement/disclaimer http://www.onera.fr/onera-en/emails-terms
On Tue, Dec 20, 2011 at 10:31, Marc POINOT <Marc.Poinot@onera.fr> wrote:
Hi all,
I've just changed to cython and old numpy module with a raw C API. The C module init is removed, and I've put the import_array in the 'pure-cython' part of the module init. Usual tutorial examples have these lines:
import numpy as NPY cimport numpy as NPY
NPY.import_array()
But this fails (first numpy API call core dump) in my module, if I put back the import_array() in the C part of the module everything turns ok again. Now if I remove again this C API import_array and I write:
import numpy as NPY cimport numpy as CNPY
CNPY.import_array()
all is ok. Do I miss something? It sounds good to me to have to separate scopes but I wonder if it's a common practice with potential side-effects or if it is the right way to use numpy with cython.
Yes, it is the right way to do it. Cython can *mostly* tell from context whether to resolve NPY.<whatever> from either the C side or the Python side, but sometimes it's ambiguous. It's more often ambiguous to the human reader, too, so I try to be explicit about it. I don't really know why the tutorials do it the confusing way. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (2)
-
Marc POINOT
-
Robert Kern