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

Cython function returning pointer without GIL error

本文关键字:错误 指针 GIL 函数 返回 python      更新时间:2023-10-16

我不明白为什么这不能编译。_svd返回双精度*,我将其赋值为双精度*。

错误信息:如果没有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)