2017-05-01 1 views
3

코드 속도를 높이기 위해 일부 cython을 통합하려고합니다. Jupyter에서 cython 코드를 실행하는 데 문제가 있습니다.Jupyter에서 Cython을 실행합니다. cdef

세포 1 :

%%cython 
cdef fuc(): 
    cdef int a = 0 
    for i in range(10): 
     a += i 
     print(a) 

세포 2 :

fuc() 

오류 :

--------------------------------------------------------------------------- 
NameError         Traceback (most recent call last) 
<ipython-input-48-10789e9d47b8> in <module>() 
----> 1 fuc() 

NameError: name 'fuc' is not defined 

그러나 나는이 작업을 수행 할 경우, 그것은 잘 작동합니다. 내가 Jupyter 노트북에 CDEF 사용할 수있는 방법을 CDEF는 Jupyter에서 다르게 사용하고 같은

%%cython 
def fuc(): 
    cdef int a = 0 
    for i in range(10): 
     a += i 
     print(a) 

은 같은데?

답변

5

cdef functions can only be called from Cython, not Python. 문서는

Within a Cython module, Python functions and C functions can call each other freely, but only Python functions can be called from outside the module by interpreted Python code.

(이미있는 것은 "C 함수는"def으로 cdef와 "파이썬 기능"에 의해 정의됩니다 밝혔다.)라고

대신 사이 썬의 def 기능을 사용합니다. 여전히 Cython에 의해 컴파일됩니다. def 함수 내에서 cdef 유형을 계속 사용할 수 있습니다. cpdef에 CDEF 을 변경하는

0

how could I use cdef in Jupyter notebook?

보십시오.

관련 문제