Trying to compile the following 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.)
I get, amongst other errors:
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
I have no clue what is happening, since from my point of view all values are double (except may 0. which could be a float, but can safely be promoted to double)
The setup.py is:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("*.pyx"),
)
EDIT: Actually, there are plenty of different errors associated with this line, such as:
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
This is "just a typo" but the error messages did not help me a lot, so I'm posting this as an answer:
I had used from libc.math import fabs, instead of cimport fabs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With