Let's suppose I am given a function that looks like this
void myFunc(int *a){
a[0]++;
a[1]++;
}
I tried to bind this function with the below
#include "pybind11/numpy.h"
#include "pybind11/pybind11.h"
namespace py = pybind11;
PYBIND11_MODULE(pybindtest, m) {
m.def("myFunc", [](py::array_t<int> buffer){
py::buffer_info info = buffer.request();
myFunc(static_cast<int *>(info.ptr));
});
}
and use the below python code to test
import pybindtest
a=[1,2];
pybindtest.myFunc(a);
print(a)
This shows [1, 2] instead of [2, 3]. Given that myFunc is written by other people, so I am not allowed to change the API. Is it possible to bind this function into python? If yes, what am I doing wrong?
ints, so this really shouldn't work.