[Numpy-discussion] _import_array()
Travis Oliphant
travis@continuum...
Tue Feb 14 03:09:48 CST 2012
Technically, when you write an extension module you really should use import_array(); in the init method of the extensions module. This ensures that the C-API is loaded so that the API -table is available if your C++ code uses the C-API at all.
In this case you are just using some #defines that access the NumPy array structure, so it works without the import_array(). However, this could change in future releases (i.e. PyArray_DIMS and PyArray_DATA could become functions that are looked up in an API-table that must be loaded by import_array() ).
Best regards,
-Travis
On Feb 14, 2012, at 3:03 AM, Mads Ipsen wrote:
> Hi,
>
> I have C++ module (OpenGL) that extracts data from numpy arrays. The interface is pure read-only: It never returns any Python objects but only extracts data from numpy arrays. Eg:
>
> #include "numpy/arrayobject.h"
>
> void PrimitiveManager::deleteAtoms(PyObject * numpy_indices)
> {
> // Extract number of indices
> int const n = static_cast<int>(PyArray_DIMS(numpy_indices)[0]);
> long * const indices = (long *) PyArray_DATA(numpy_indices);
>
> // Delete atoms in buffer
> for (int i = 0; i < n; ++i)
> {
> // Do stuff
> }
> }
>
> Now, when I compile the code with g++, I get the following warning:
>
> numpy/core/include/numpy/__multiarray_api.h:1532: warning: ‘int _import_array()’ defined but not used
>
> Do I need to call '_import_array()' somewhere? Am I doing something potentially nasty?
>
> Best regards,
>
> Mads
>
>
>
>
>
> --
> +-----------------------------------------------------+
> | Mads Ipsen |
> +----------------------+------------------------------+
> | Gåsebæksvej 7, 4. tv | |
> | DK-2500 Valby | phone: +45-29716388 |
> | Denmark | email: mads.ipsen@gmail.com |
> +----------------------+------------------------------+
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120214/f22c1df6/attachment.html
More information about the NumPy-Discussion
mailing list