我遇到了这里描述的问题(What is this import_umath function?)并想知道是否有修复方法?我有完全相同的情况,编译使用numpy的Cython代码与以下代码:
import numpy as np
cimport numpy as np
np.import_array()
生成许多关于_import_umath
未被使用的警告:
/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]
删除np.import_array()
不会更改结果。就像上面帖子中建议的一个海报一样,我尝试在我的.pxd/.pyx
文件中添加它:
cdef extern from *:
import_umath()
这也没有区别。如何消除这种警告?
答案 0 :(得分:4)
您可以使用extra_compile_args
中的关键字setup.py
将参数传递给C编译器。例如,这不会生成警告:
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),
)
答案 1 :(得分:1)
在Cython Tricks and Tips中,他们解释说您需要:
cdef extern from *:
pass
导入extern包时。 I already needed this trick to write a wrapper,也许它也适合你......