[Numpy-discussion] "import numpy" performance
Andrew Dalke
dalke at dalkescientific.com
Mon Jul 2 18:15:46 EDT 2012
On Jul 2, 2012, at 11:38 PM, Fernando Perez wrote:
> No, that's the wrong thing to test, because it effectively amounts to
> 'import numpy', sicne the numpy __init__ file is still executed. As
> David indicated, you must import multarray.so by itself.
I understand that clarification. However, it does not affect me.
I do "import rdkit.Chem". This is all I really care about.
That imports "rdkit.Chem.rdchem" which is a shared library.
That shared library calls the C function/macro "import_array", which appears to be:
#define import_array() { if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); } }
The _import_array looks to be defined via numpy/core/code_generators/generate_numpy_api.py
which contains
static int
_import_array(void)
{
int st;
PyObject *numpy = PyImport_ImportModule("numpy.core.multiarray");
PyObject *c_api = NULL;
...
Thus, I don't see any way that I can import 'multiarray' directly,
because the underlying C code is the one which imports
'numpy.core.multiarray' and by design it is inaccessible to change
from Python code.
Thus, the correct reference benchmark is "import numpy.core.multiarray"
Unless I'm lost in a set of header files?
Cheers,
Andrew
dalke at dalkescientific.com
More information about the NumPy-Discussion
mailing list