2

After experimenting with Pybind11 to create C++ extensions for Python, I was hoping to write C++ sections for computationally heavy parts of my code. In my particular case, I would like to work with numpy arrays and use a mixture of numpy functions and my C++ code for speed.

I can see a way to work with numpy arrays in C++ here and have seen calls to numpy/scipy functions handled in other examples by calling the python interpreter to call the functions. For something like numpy, which is built from C code, is it possible to call the functions without calling the python interpreter and suffering the overhead, or is this the appropriate way of calling numpy functions in pybind11? If this interpreter must be called, could one use C++ multithreading (pthreads) to parallelize code called by the python interpreter, or does the code neccisarily share the same python interpreter and thus GIL?

1
  • 1
    The NumPy C API is described here. However only the basic numpy types and some core functions are implemented in C, and not all the functions are available through the API. In most cases if you really want to call such things from C++ you are better off using Eigen (or whatever). Commented Dec 1, 2021 at 23:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.