I wrote a little C++ Script and used pybind11 to make the C++ function available in python. When called from python, the C++ function takes about 4 seconds to terminate. The C++ functions returns a large array of length 54.346.383. Out of curiosity, I modified the C++ function and returned a different array of length 7373 without changing anything else in the code. Now the C++ function terminates in 1 second. So as I understand this the transfer of an object from C++ to Python becomes a huge bottleneck as size of the object increases.
Is there a smarter approach to handle this issue? Maybe working with pointers? (I am completely new to C++ and pybind11)
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <vector>
#include <numeric>
namespace py = pybind11;
std::vector<double> isoCdf_seq(std::vector<double> array_w, std::vector<double> W, std::vector<double> Y, std::vector<int> posY, std::vector<double> array_y) {
std::vector<double> CDF;
CDF.reserve(m * mY);
// some code
return CDF;