开发者

Cython code doesn't work

I wrote some Python code and it worked fine when using the "python". I then converted it to C using "Cython" and used distutils to compile it to a shared library. I then changed some of the code to Cython so it would run faster. But when I imported the .so module and tried to use the command I had "cdef"ed it said that the command didn't exist. Original code:

import time as t
def time(function):
    t1 = t.time()
    function()
    t2 = t.time()
    return t2 - t1

New code:

import time as t
cdef time(function):
    t1 = t.tim开发者_StackOverflow中文版e()
    function()
    t2 = t.time()
    return t2 - t1

I tried using "cdef int time" but I got the same result. Any advice?


cdef functions are not exposed to Python. cpdef is provided to provide a Python wrapper to a C function defined in Cython.

Also, you're probably better off using timeit than bothering with implementing this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜