【发布时间】:2018-07-26 18:18:00
【问题描述】:
我有一个包含以下代码的 pyx 文件:
cimport cython
from libc.math cimport sqrt, abs
from libc.stdio cimport printf
from cython.parallel import prange
cdef double my_abs(double a):
return sqrt(a*a)
cpdef loop(int a):
cdef int i
cdef int sum = 0
for i in prange(a, nogil=True):
printf("%s %i %s %f\n", "The square root of ", i, " is ", sqrt(i))
#printf("%s %i %s %f\n", "The absolute value of ", i, " is ", abs(i))
#printf("%s %i %s %f\n", "The absolute value of ", i, " is ", my_abs(i))
return
当我取消注释循环中的两行中的任何一行时,编译失败。
- 为什么 libc.math abs 函数不能与 nogil 配合得很好,而 sqrt、pow 等其他函数似乎可以?
- 我必须在我的函数(和 .pxd 文件)中添加什么才能使它成为 nogil?我已尝试在此页面后添加https://lbolla.info/python-threads-cython-gil,但仍然无法编译。
这个问题类似于:
提前致谢!
【问题讨论】: