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:  [email protected] |
> +----------------------+------------------------------+
> 
> _______________________________________________
> NumPy-Discussion mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to