这个import_umath函数是什么? [英] What is this import_umath function?
问题描述
当编译一堆由Cython生成的与Numpy接口的C文件时,我得到警告:
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]
我似乎无法摆脱这一点.弄清楚这可能类似于np.import_array()
,它摆脱了相关警告(实际上是必填 (使用Numpy C API),我在顶层尝试了np.import_umath()
,但警告仍然存在.我如何摆脱它?
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.)
(Cython 0.17.4, Numpy 1.6.2.)
推荐答案
有一个 Cython邮件列表上的主题,对此进行了一些讨论.我相信讨论是关于Cython测试套件的,但是我认为相同的想法也可以应用于生成的文件.
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.
从本质上讲,该问题涉及黑客攻击,目的是避免C编译器有关未使用功能的警告.
In essence, the issue involved a hack that was done in order to avoid C compiler warnings about unused functions.
相关代码文件当前如下所示:
cdef extern from *:
bint FALSE "0"
void import_array()
# void import_umath()
if FALSE:
import_array()
# import_umath()
过去,import_umath()
部分没有注释,但事实证明,在C ++模式下构建时会导致错误.因此,似乎已决定,编译器警告比破碎的构建.
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.
简而言之,看来此特殊警告是出于C ++兼容性的考虑而存在的,可以安全地忽略.我想如果您真的不喜欢它,并且如果您在C模式下构建,那么您可以尝试通过导入类似的.pxi
文件并调用import_umath()
来进行相同的破解.在您的Cython代码中.
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.
这篇关于这个import_umath函数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!