Python列表到Cython

Python列表到Cython,第1张

Python列表到Cython

您需要将列表的内容显式复制数组。例如…

cimport cythonfrom libc.stdlib cimport malloc, free...def process(a, int len):    cdef int *my_ints    my_ints = <int *>malloc(len(a)*cython.sizeof(int))    if my_ints is NULL:        raise MemoryError()    for i in xrange(len(a)):        my_ints[i] = a[i]    with nogil:        #once you convert all of your Python types to C types, then you can release the GIL and do the real work        ...        free(my_ints)    #convert back to python return type    return value


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5662857.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存