[PyQt] Returning a numpy.ndarray

Hans Meine meine at informatik.uni-hamburg.de
Fri May 9 17:10:26 BST 2008


Hi,

I am trying to return a numpy array from one of my member functions.  I got it 
worked out, but I have one remaining, sip-related problem:

As e.g. explained on http://numpy.scipy.org/numpydoc/numpy-13.html, I need to 
call import_array() in my module initialization code.  I am using

%PostInitialisationCode
import_array();
%End

for that.  However, import_array is defined in the numpy header files, so care 
must be taken not to produce clashing symbols in every compilation unit.  
This should be done by defining PY_ARRAY_UNIQUE_SYMBOL to a unique name and 
defining NO_IMPORT_ARRAY in all but the modules' main compilation unit in 
which the function is being called.  (Don't know where this is properly 
explained ATM.)

However, I cannot get this to work; %UnitCode would be included in every unit, 
so it cannot be used becase NO_IMPORT_ARRAY must not be defined in 
sipfoocmodule.cpp.  Similarly, I tried %ModuleCode and %ModuleHeaderCode.
I used %TypeHeaderCode to #define NO_IMPORT_ARRAY, but the sipfooBar.h header 
files are all included at the very beginning of sipfoocmodule.cpp, so it is 
defined there, too, before the %ModuleCode.  The only temporary solution I 
found is to manually move the code inserted by %ModuleCode above the 
mentioned #includes.  (Note that it cannot simply be #undef'ed, because it is 
used in conjunction with a subsequent #include which immediately evaluates 
the setting.)

Is this impossible with sip (BTW: I am using sip 4.5.2 and PyQt 4.1.1), and/or 
has anybody else tried using numpy together with SIP/PyQt?

-- 
Ciao, /  /
     /--/
    /  / ANS


More information about the PyQt mailing list