Skip to content Skip to sidebar Skip to footer

Passing Memoryview To C Function

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 arra

Solution 1:

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 longout
    getIndexOfState(&out, self.C, self.G, self.B, &s[0])
    returnout

Post a Comment for "Passing Memoryview To C Function"