You can โcallโ a function directly from Cython by declaring it as extern.
cdef extern from "mylibraryheader.h":
void cfun1(void* indatav, int rowcount, int colcount, void* outdatav)
void cfun2(double** indata, int rowcount, int colcount, doubke** outdata)
Now you can call these functions, as in C / C ++. Please note that in Cython there is no const keyword, you can leave it. Unfortunately, I cannot give you an example of how to convert a NumPy array to a double array. But here is an example of starting from a list of doubles.
cdef extern from "mylibraryheader.h":
void cfun1(void* indatav, int rowcount, int colcount, void* outdatav)
void cfun2(double** indata, int rowcount, int colcount, double** outdata)
cdef extern from "stdlib.h":
ctypedef int size_t
void* malloc(size_t)
void free(void*)
def py_cfunc1(*values):
cdef int i = 0
cdef int size = sizeof(double)*len(values)
cdef double* indatav = <double*> malloc(size)
cdef double* outdatav = <double*> malloc(size)
cdef list outvalues = []
for v in values:
indatav[i] = <double>v
i += 1
cfun1(<void*>indatav, 1, len(values), <void*>outdatav)
for 0 <= i < len(values):
outvalues.append(outdatav[i])
return outvalues
Note: Unverified
source
share