2014-04-03 77 views
0

我有以下用Cython模塊:錯誤簽名錯誤

compmech  
    integrate 
     integratev.pxd 
     integratev.pyx 
    conecyl 
     main.pyx 

integratev.pxd我已經聲明:

ctypedef void (*f_type)(int npts, double *xs, double *ts, double *out, 
        double *alphas, double *betas, void *args) nogil 

cdef int trapz2d(f_type f, int fdim, np.ndarray[cDOUBLE, ndim=1] final_out, 
       double xmin, double xmax, int m, 
       double ymin, double ymax, int n, 
       void *args, int num_cores) 

我打電話trapz2dmain.pyx,並通過功能到trapz2d已在main.pyx中聲明,例如:

from compmech.integrate.integratev cimport trapz2d 

cdef void cfk0L(int npts, double *xs, double *ts, double *out, 
       double *alphas, double *betas, void *args) nogil: 
    ... 

trapz2d(<f_type>cfk0L, fdim, k0Lv, xa, xb, nx, ta, tb, nt, &args, num_cores) 

它編譯就好了,但是當我跑我的錯誤:

TypeError: C function compmech.integrate.integratev.trapz2d has wrong signature  
(expected int (__pyx_t_8compmech_9integrate_10integratev_f_type, int, PyArrayObject *, 
       double, double, int, double, double, int, void *, int), 
got int (__pyx_t_10integratev_f_type, int, PyArrayObject *, 
      double, double, int, double, double, int, void *, int)) 

這似乎是我的錯誤,但也許我缺少一些重要的東西在這裏...


注:當我把所有內容都放入main.pyx而不是使用多個模塊時,它可以工作。

回答

0

解決的辦法是在trapz2d()之前,通過所有內容,如void *,並將其轉換爲<f_type>,然後才能實際執行該功能。代碼的最終佈局是:

ctypedef void (*f_type)(int npts, double *xs, double *ts, double *out, 
        double *alphas, double *betas, void *args) nogil 

cdef int trapz2d(void *fin, int fdim, np.ndarray[cDOUBLE, ndim=1] final_out, 
       double xmin, double xmax, int m, 
       double ymin, double ymax, int n, 
       void *args, int num_cores) 
    cdef f_type f 
    f = <f_type>fin 
    ... 

,並在其他的代碼:

from compmech.integrate.integratev cimport trapz2d 

cdef void cfk0L(int npts, double *xs, double *ts, double *out, 
       double *alphas, double *betas, void *args) nogil: 
    ... 

trapz2d(<void *>cfk0L, fdim, k0Lv, xa, xb, nx, ta, tb, nt, &args, num_cores)