user248237
user248237

Reputation:

way to eliminate Cython numpy compilation warnings?

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

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

generates many warnings about _import_umath not being 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. Like one of the posters suggested in the above thread, I tried adding this in my .pxd/.pyx file:

cdef extern from *:
    import_umath()

this also made no difference. How can this warnings be eliminated?

Upvotes: 8

Views: 1326

Answers (2)

Jishnu
Jishnu

Reputation: 779

You can pass arguments to the C compiler using the keyword extra_compile_args in your setup.py. For example, this will not generate 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),
)

Upvotes: 6

Saullo G. P. Castro
Saullo G. P. Castro

Reputation: 58955

In Cython Tricks and Tips they explain that you need:

cdef extern from *:
    pass

when you import extern packages. I already needed this trick to write a wrapper, maybe it will work for you too...

Upvotes: 1

Related Questions