[英]Cython int ** and int * types
I am trying to wrap some C code with Cython, but I am running into a error that I don't understand, and despite a lot of searching I cannot seem to find anything on it. 我试图总结与用Cython一些C代码,但我遇到了,我不明白一个错误,尽管有很多搜索的我似乎无法找到它的任何东西。 Here is my c code
这里是我的C代码
void cssor(double *U, int m, int n, double omega, double tol, int maxiters, int *info){
double maxerr, temp, lcf, rcf;
int i, j, k;
lcf = 1.0 - omega;
rcf = 0.25 * omega;
for (k =0; k < maxiters ; k ++){
maxerr = 0.0;
for (j =1; j < n-1; j++) {
for (i =1; i < m-1; i++) {
temp = U[i*n+ j];
U[i*n+j] = lcf * U[i*n+j] + rcf * (U[i*n+j-1] + U [i*n+j+1] + U [(i-1)*n + j] + U [(i+1)*n+j]);
maxerr = fmax(fabs(U[i*n+j] - temp), maxerr);
}
}
if(maxerr < tol){break;}
}
if (maxerr < tol) {*info =0;}
else{*info =1;}
} }
My .pyx file is 我的.pyx文件是
cdef extern from "cssor.h":
void cssor(double *U, int m, int n, double omega, double tol, int maxiters, int *info)
cpdef cyssor(double[:, ::1] U, double omega, double tol, int maxiters, int *info):
cdef int n, m
m = U.shape[0]
n = U.shape[1]
cssor(&U[0, 0], m, n, omega, tol, maxiters, &info)
However, when I try to run the associated setup file I get an error referring to maxiters in the last line of the code that says: 然而,当我尝试运行相关的安装文件,我得到一个错误参照,上面写着代码的最后一行maxiters:
Cannot assign type 'int **' to type 'int *' 无法将类型“ int **”分配给类型“ int *”
Can you tell me how to fix this? 你能告诉我如何解决这个问题吗?
Roy Roth 罗伊·罗斯
The problem comes from here: 问题来自这里:
cpdef cyssor(double[:, ::1] U, double omega, double tol, int maxiters, int *info):
cdef int n, m
m = U.shape[0]
n = U.shape[1]
cssor(&U[0, 0], m, n, omega, tol, maxiters, &info)
You declare info
as type int*
. 您将
info
声明为int*
类型。 But you then pass it into the cssor
function as a reference to an int*
, making it an int**
. 但是您然后将其传递给
cssor
函数作为对int*
的引用,从而使其成为int**
。
The correct code is: 正确的代码是:
cssor(&U[0, 0], m, n, omega, tol, maxiters, info)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.