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