How to resolve Cython numpy compilation warnings?

I ran into the problem described here ( What is the import_umath function? ) And wanted to know if there is a fix for this? I have the same case where a Cython code is compiled that uses numpy with the following code:

import numpy as np cimport numpy as np np.import_array() 

generates many _import_umath that are not used:

 /usr/local/lib/python2.7/dist-packages/numpy-1.6.2-py2.7-linux-x86_64.egg/numpy/core/include/numpy/__ufunc_api.h:226:1: warning: '_import_umath' defined but not used [-Wunused-function] 

removing np.import_array() does not change the result. As one of the posters suggested in the above thread, I tried adding this to my .pxd/.pyx :

 cdef extern from *: import_umath() 

it didn't matter either. How can I eliminate these warnings?

+6
source share
2 answers

You can pass arguments to the C compiler using the extra_compile_args in setup.py . For example, this will not result in warnings:

 from distutils.core import setup from Cython.Build import cythonize from distutils.extension import Extension import numpy extensions=[ Extension("abc", ["abc.pyx"], include_dirs=[numpy.get_include()], extra_compile_args=["-w"] ) ] setup( ext_modules=cythonize(extensions), ) 
+3
source

In Cython Tricks and Tips, they explain what you need:

 cdef extern from *: pass 

when importing extern packages. I already need this trick to write a wrapper , maybe this will work for you too ...

+1
source

All Articles