gpt4 book ai didi

python - Cython 函数返回没有 GIL 错误的指针

转载 作者:行者123 更新时间:2023-11-30 05:40:32 24 4
gpt4 key购买 nike

我不明白为什么这不能编译。 _svd 返回一个 double*,我将它分配给一个 double*。

错误信息:没有 GIL 不允许来自 Python 的强制转换

cpdef svd(A_f, m, n):
cdef double *S_p

with nogil:
S_p = _svd(A_f, m, n)

return <double[:min(m, n)]> S_p

cdef double* _svd(double[:] A_f, int m, int n) nogil:
#code removed bc it is long

编辑:它适用于 GIL,但我想在没有 GIL 的情况下调用它。

最佳答案

试试这个

cpdef svd(A_f, int m, int n):

cdef double *S_p

cdef double[:] abc = A_f

with nogil:
S_p = _svd(abc , m, n)

关于python - Cython 函数返回没有 GIL 错误的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31568303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com