I understand a basic C++ function wrapped for Python looks like this:
int square(int n)
{
return n*n;
}
static PyObject* square_wrapper(PyObject* self, PyObject* args)
{
int n = 0;
if(!PyArg_ParseTuple(args, "i", &n))
return Py_RETURN_NONE;
return Py_BuildValue("i", square(n));
}
Some of the C++ functions I'd like to wrap take in double arrays and modify them. This isn't a supported type by PyArg_ParseTuple. After doing some searching it is my understanding that using PyArg_ParseTuple to get a PyObject and then making that a PyArray_DOUBLE is an option. How would I go about doing this and how would I traverse such an array. I assume if I modify the array in the C++ extension that the Python version will be modified as well. Also, is NumPy the best way to make a double/float array to pass to my C++ extension?