2014-04-03 80 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)