[英]Cython error: Cannot convert Python object to type 'int *' error, when passing an Integer array to a function
I am trying to pass an integer array to a function in Cython and I cannot understand why I get the error mentioned in the title. 我试图将整数数组传递给Cython中的函数,但我不明白为什么会出现标题中提到的错误。
A sample code of what I am trying to do is the following: 我正在尝试执行的示例代码如下:
cpdef foo(int *table):
for i in range(10):
table[i] = i
cdef int *temp=<int *>malloc(10*sizeof(int))
foo(temp)
for i in range(10):
print temp[i]
I would appreciate any pointers as to how to pass the array correctly to the function. 我将不胜感激如何将数组正确传递给函数。 Thank you. 谢谢。
The issue here is the function is cpdef
- this means it can be called from both C and Python code, and means all arguments must be Python objects (otherwise how would one call it from Python?) 这里的问题是该函数是cpdef
这意味着可以从C和Python代码中调用它,并且意味着所有参数都必须是Python对象(否则,如何从Python调用它?)
Declare it as cdef
instead. 将其声明为cdef
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.