I am trying to pass a numpy array to C++ using Boost.Python.
The C++ code is:
#include <boost/python.hpp>
#include <boost/python/numpy.hpp>
void f(boost::python::numpy::ndarray& x){}
BOOST_PYTHON_MODULE(libtest)
{
boost::python::def("f", f);
}
The Python code is:
import libtest
import numpy
x=numpy.array(range(3))
libtest.f(x)
This gives a segmentation fault. This happens when passing the variable by value and by reference.
I have found a way to do what I needed. However the purpose of using Boost.Python was to be able to simply call the functions from the module without having to write a wrapper on the Python side as is the case with ctypes where certain types or return values have to be dealt with.
Is is possible to simply pass a reference to a numpy array?
Thanks!