I have a C function declared as follows:
void getIndexOfState(long *p, long C, long G, long B, long *state);
Nowadays my cython wrapper code uses the buffer syntax from numpy array:
cpdef int getIndexOfState(self, np.ndarray[np.int_t, ndim=1, mode="c"] s):
cdef long out
getIndexOfState(&out, self.C, self.G, self.B, <long*> s.data)
return out
I want to use the new memoryview syntax, my question is, how can I pass the pointer to the data when using a memoryview?
I tried:
cpdef int getIndexOfState(self, long[:] s):
cdef long out
getIndexOfState(&out, self.C, self.G, self.B, s)
return out
which raised the "Cannot assign type 'long[:]' to 'long *'" error when I was trying to compile the module. There is any way to pass that pointer without coercing the memoryview back to a numpy array before calling the C function?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…