【发布时间】:2017-02-15 13:43:21
【问题描述】:
尝试编译以下 MCE:
from libc.math import fabs
cdef inline double fmax(double x, double y) nogil:
return x if x > y else y
cdef inline double fsign(double x) nogil :
if x == 0.:
return 0.
elif x > 0.:
return 1.
else:
return - 1.
cdef inline double ST(double u, double x) nogil:
return fsign(x) * fmax(fabs(x) - u, 0.)
除其他错误外,我得到:
Error compiling Cython file:
------------------------------------------------------------
...
else:
return - 1.
cdef inline double ST(double u, double x) nogil:
return fsign(x) * fmax(fabs(x) - u, 0.)
^
------------------------------------------------------------
test.pyx:18:35: Coercion from Python not allowed without the GIL
我不知道发生了什么,因为从我的角度来看,所有值都是双精度的(可能 0 除外。它可能是浮点数,但可以安全地提升为双精度)
setup.py 是:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("*.pyx"),
)
编辑:实际上,与这一行相关的错误有很多,例如:
test.pyx:18:35: Operation not allowed without gil
test.pyx:18:31: Calling gil-requiring function not allowed without gil
test.pyx:18:31: Accessing Python global or builtin not allowed without gil
test.pyx:18:33: Converting to Python object not allowed without gil
test.pyx:18:31: Constructing Python tuple not allowed without gil
【问题讨论】: