【问题标题】:Cython function returning pointer without GIL errorCython 函数返回没有 GIL 错误的指针
【发布时间】:2015-07-23 19:08:10
【问题描述】:

我不明白为什么这不能编译。 _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 的情况下调用它。

【问题讨论】:

    标签: python c++ cython


    【解决方案1】:

    试试这个

    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)
    

    【讨论】:

    • 请补充说明
    • 谢谢!我现在意识到我做错了什么; A_f、m 和 n 都是 python 对象。在释放 GIL 之前,我需要将它们转换为 cython 对象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 2013-07-28
    • 2014-09-25
    相关资源
    最近更新 更多