I am facing a problem, yesterday I made a post asking how to import a C++ funtion in Python: Post. In this post they suggested me to use Boost Python. So I started to learn it. However all the tutorials are really complicated for me. I know Python language but I am learing C++ so I found it difficult to understand. The other point is that in all the posts that I have found here they talk about 1D vectors in C++, but my function takes 2D vectors.
Indeed all the posts usually employ a C++ class instead of a function. And I don't know anything about classes in C++. But I found it useless in my case since I only whant to evaluate a function and return the result (double) to python. So the first question is. Is It completaley necessary to employ classes instead of functions for Boost python?
As you can see in the other post my function have the following structure:
double many_body_pot(
std::vector< std::vector<double> > &par,
std::vector< std::vector<double> > &geometry,
double x, double y, double z)
{
// ...
}
So it takes 2 2D vectors and 3 doubles as parameters. So what I have learned until now is I have to use #include <boost/python.hpp>
in my C++ script and I have to include something like this:
BOOST_PYTHON_MODULE(many_body_pot) {
using namespace boost::python;
def("many_body_pot", many_body_pot);
}
I Python have to send rather 2D ndarrays or 2D lists to the function to be converted to 2D vectors. And if I use 2D ndarrays I will have to use numpy Boost. In my case I don't mind to use one or the other. But I don't understand how to do the conversion to 2D vectors. Could you please give me an easy-to-understand solution for this? It would be really appreciated.
Thank you