[Numpy-discussion] How to call import_array() properly?
Bruce Sherwood
Bruce_Sherwood@ncsu....
Mon Dec 27 13:51:35 CST 2010
The module I'm working with, which uses Boost, doesn't have a function
"initcvisual". Rather there's a section headed with
BOOST_PYTHON_MODULE( cvisual). Placing the import_array macro directly
in this section causes an unwanted return.
I guess it doesn't matter, since what I've done works okay. And I
realized that I could collapse init_numpy a bit:
#if PY_MAJOR_VERSION >= 3
int
#else
void
#endif
init_numpy()
{
import_array();
}
Bruce Sherwood
On Mon, Dec 27, 2010 at 12:15 PM, Robert Kern <robert.kern@gmail.com> wrote:
> On Mon, Dec 27, 2010 at 13:09, Bruce Sherwood <Bruce_Sherwood@ncsu.edu> wrote:
>> Thanks for the good suggestion. I now see that it was purely
>> historical that import_array was driven (indirectly through
>> init_numpy) from the pure Python component of the module rather than
>> in the import of the C++ component, and I've changed that. However,
>> I'm still curious as to whether there's a more intelligent or elegant
>> way to drive import_array than the following code:
>>
>> #if PY_MAJOR_VERSION >= 3
>> int
>> init_numpy()
>> {
>> import_array();
>> }
>> #else
>> void
>> init_numpy()
>> {
>> import_array();
>> }
>> #endif
>
> Just put "import_array();" into initcvisual(). You should not put it
> in any other function.
>
> --
> 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
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list