Passing memoryview to C function

后端 未结 1 1339
情深已故
情深已故 2020-12-10 11:47

I have a C function declared as follows:

void getIndexOfState(long *p, long C, long G, long B, long *state);

Nowadays my cython wrapper cod

相关标签:
1条回答
  • 2020-12-10 12:21

    If the underlying data is properly contiguous/strided and there is at least one element in the memory, then it should suffice to pass a pointer to the first element (and maybe the length):

    getIndexOfState(&out, self.C, self.G, self.B, &s[0])
    

    EDIT:

    One way to ensure "properly contiguous" should be the addition of "[::1]".

    cpdef int getIndexOfState(self, long[::1] s):
        cdef long out
        getIndexOfState(&out, self.C, self.G, self.B, &s[0])
        return out
    
    0 讨论(0)
提交回复
热议问题