2017-02-15 2 views
2

없이 사용할 수 없습니다 :사이 썬 오류 : 파이썬에서 강제 변환은 다음 MCE 컴파일하려고 GIL

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 

내가 단서가 무슨 일하지 않은, 내 관점에서 볼 때 모든 값은 double입니다 (float 일 수는 있지만 0은 float 일 수 있지만 double로 안전하게 승격 될 수 있음).

setup.py

012 3,516,
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 

답변

3

이는 "단순한 오타"하지만 오류 메시지 : 사실, 다른 같은이 라인과 관련된 오류가 많이있다 그래서 나는 이것을 답변으로 올리고있다. cimport fabs 대신 libc.math import fabs에서 사용했다.