How to include numpy headers in C across versions 1.1, 1.2, and 1.3
Hey guys, I've got a small C extension that uses isnan() and (in numpy 1.1) had been importing it from ufuncobject.h. I see that it has now moved into npy_math.h in 1.3. What is the best way to ensure that I can reliably include this function across versions 1.1, 1.2, and 1.3? (Checking NPY_FEATURE_VERSION won't work, since it did not change from 1.2 to 1.3, although the location of the function definition did.) My best idea right now is to simply do a numpy version check in my setup.py, and hard-code some macros at the top of my C extension to #include the appropriate headers for each version. Any help or suggestions would be appreciated! Thanks, Peter
On Mon, May 11, 2009 at 4:49 PM, Peter Wang
Hey guys,
I've got a small C extension that uses isnan() and (in numpy 1.1) had been importing it from ufuncobject.h. I see that it has now moved into npy_math.h in 1.3.
What is the best way to ensure that I can reliably include this function across versions 1.1, 1.2, and 1.3? (Checking NPY_FEATURE_VERSION won't work, since it did not change from 1.2 to 1.3, although the location of the function definition did.)
My best idea right now is to simply do a numpy version check in my setup.py, and hard-code some macros at the top of my C extension to #include the appropriate headers for each version.
Any help or suggestions would be appreciated!
Oops, looks like we broke the ABI ;) For numpy itself we should fix things by including npy_math in ufuncobject.h. Looks like a fixup release might be in offing here. Otherwise there might be a workaround that would work. <looks> In 1.1.x it looks like isnan is defined in ufuncobject iff it is compiled on windows. Try #include ufuncobject.h #ifdef _MSC_VER #ifndef isnan #define isnan(x) ((x) != (x)) #endif #endif Chuck
Charles R Harris wrote:
On Mon, May 11, 2009 at 4:49 PM, Peter Wang
mailto:pwang@enthought.com> wrote: Hey guys,
I've got a small C extension that uses isnan() and (in numpy 1.1) had been importing it from ufuncobject.h. I see that it has now moved into npy_math.h in 1.3.
isnan is a C99 function (more exactly a macro), so we should not have defined it in the first place in public header, strictly speaking. The replacement in numpy 1.3 is npy_nan (and for every math function, replaced with the npy_ prefix).
My best idea right now is to simply do a numpy version check in my setup.py, and hard-code some macros at the top of my C extension to #include the appropriate headers for each version.
Any help or suggestions would be appreciated!
You could just reproduce the logic used for numpy 1.3: check whether isnan is declared in math.h, and if not, use a replacement (the replacement are in npy_math.h - they are guaranteed to work on most platforms where numpy runs). It avoids hardcoding versions, which is often problematic if you need to support many platforms. cheers, David
participants (3)
-
Charles R Harris
-
David Cournapeau
-
Peter Wang