Reputation: 59
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.
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.
Upvotes: 2
Views: 2595
Reputation: 88977
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?)
Declare it as cdef
instead.
Upvotes: 7