Cython 函数返回没有 GIL 错误的指针
Cython function returning pointer without GIL error
我不明白为什么这不能编译。 _svd returns a 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)
我不明白为什么这不能编译。 _svd returns a 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)