How to fix compiler error: cannot convert to a pointer type with Cython + numpy?

How to fix compiler error: cannot convert to a pointer type with Cython + numpy?

我正在尝试使用 Cython 和 numpy 包装一个 C 函数以便在 Python 中使用。

编译时出现以下错误:

_fastlp.c: In function ‘__pyx_pf_6fastlp_fastlp_func’:
_fastlp.c:1351:3: error: cannot convert to a pointer type
   fastlp(((double *)PyArray_DATA(((PyArrayObject *)__pyx_v_obj))), 
   ((double *)PyArray_DATA(((PyArrayObject *)__pyx_v_mat))), 
   ((double *)PyArray_DATA(((PyArrayObject *)__pyx_v_rhs))), (&__pyx_v_m0), 
   (&__pyx_v_n0), ((double *)PyArray_DATA(__pyx_v_opt)), 
   (&__pyx_v_status), ((double *)__pyx_v_lam));
      ^

箭头^指向(&__pyx_v_status)

我的 .pyx 文件是:

import numpy as np
cimport numpy as np

np.import_array()

# cdefine the signature of the c function
cdef extern from "fastlp.h":
    void fastlp(double *obj, double *mat, double *rhs, int *m0 , int *n0, 
                double *opt, int *status, double *lam)

def fastlp_func(np.ndarray[double, ndim=1, mode="c"] obj not None,
                np.ndarray[double, ndim=2, mode="c"] mat not None,
                np.ndarray[double, ndim=1, mode="c"] rhs not None,
                double lam):   

    #Define output
    cdef np.ndarray opt = np.zeros((len(obj),), dtype = np.float64)
    cdef int status = 0

    #Call external C function
    cdef int m0 = mat.shape[0]
    cdef int n0 = mat.shape[1]

    fastlp(<double*> np.PyArray_DATA(obj),
           <double*> np.PyArray_DATA(mat),
           <double*> np.PyArray_DATA(rhs),
           &m0,
           &n0,
           <double*> np.PyArray_DATA(opt),
           &status,
           <double*> lam)

    return (opt,status)

非常感谢任何帮助!我已经为此工作了很长时间,我想我已经接近了。谢谢!

原来我只需要在调用外部函数时使用<double*> &lam。我试图将一个变量转换为一个指针......当我不应该这样做时。