Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this import_umath function?

When compiling a bunch of Cython-generated C files that interface with Numpy, I get the warning:

/usr/lib/pymodules/python2.7/numpy/core/include/numpy/__ufunc_api.h:226:1: warning: ‘_import_umath’ defined but not used [-Wunused-function]

I can't seem to get rid of that. Figuring this might be similar to np.import_array(), which gets rid of a related warning (and is actually required for using the Numpy C API), I tried np.import_umath() at top level, but the warning persists. How do I get rid of it?

(Cython 0.17.4, Numpy 1.6.2.)

like image 875
Fred Foo Avatar asked Jan 07 '13 17:01

Fred Foo


1 Answers

There's a thread on the Cython mailing list that discusses this a little bit. I believe that the discussion was concerning the Cython test suite, but I think the same ideas can be applied to generated files.

In essence, the issue involved a hack that was done in order to avoid C compiler warnings about unused functions.

The code file in question currently looks like this:

cdef extern from *:
   bint FALSE "0"
   void import_array()
#   void import_umath()

if FALSE:
    import_array()
#    import_umath()

In the past, the import_umath() portions were uncommented, but as it turns out, this was causing errors when building in C++ mode. So it appears that it was decided that a compiler warning is much better than a broken build.

In short, it seems this particular warning exists for the sake of C++ compatibility, and can be safely ignored. I suppose if you really dislike it, and if you're building in C mode, then you could try to do the same hack, by importing a similar .pxi file with a call to import_umath() inside of your Cython code.

like image 121
voithos Avatar answered Oct 14 '22 21:10

voithos