I have a function in C like this:
source file
// foo.cpp
int foo(int input1, double *output1, int size1, int* output2, int size2)
{
// does stuff and allocate space for output1 and output2
return 0;
}
header file
// foo.h
int foo(int input1, double *output1, int size1, int* output2, int size2);
In Cython I need to convert output1 and output2 to a numpy array, so in my foo.pyx I do the following steps:
cdef extern from "foo.h":
cdef int foo(int input1, double* output1, int size1, double* output2, int size2)
cdef double* ptnOutput1
cdef int* ptnOutput2
foo(1, ptnOutput1, 10, ptnOutput2, 10)
but now I'm not able to get the output in form of two np.array. How should I align the pointers ptnOutput1 and ptnOutput2 to two numpy arrays?
I've tried np.frombuffer as well as np.PyArray_SimpleNewFromData but with no luck. I always get segmentation fault.
Any idea how to do it correctly?
ptnOutput1andptnOutput2need to already be allocated when you callfoo(which then fills in their contents)?