r/cpp • u/emilios_tassios • Apr 24 '26
Parallel C++ for Scientific Applications: Integrating C++ and Python
https://www.youtube.com/watch?v=qlLgtSCw0ZAIn this week’s lecture, Dr. Hartmut Kaiser focuses on the seamless integration of C++ and Python. The lecture highlights essential foundational concepts by exploring how to combine the user-friendliness and extensive library ecosystem of Python with the raw performance of C++, setting the stage for highly efficient scientific computing.
A core discussion demonstrates how to utilize the Pybind11 library as a lightweight solution for creating Python bindings, specifically addressing the practical challenges of mapping C++ functions, classes, and diverse data types. Finally, critical strategies for integrating NumPy arrays are explored, offering a comprehensive approach to maximizing performance in advanced mathematical and data-driven applications.
If you want to keep up with more news from the Stellar group and watch the lectures of Parallel C++ for Scientific Applications and these tutorials a week earlier please follow our page on LinkedIn https://www.linkedin.com/company/ste-ar-group/
Also, you can find our GitHub page below:
https://github.com/TheHPXProject/hpx
View all comments
Show parent comment
1
u/TopIdler Apr 25 '26 edited Apr 25 '26
I don’t have any experience with pybind11. The built in numpy array to C++ in nanobind converts it to an Eigen matrix. The most complex thing I did was make my own binding to convert dense numpy and sparse scipy matrices to unmanaged Kokkos views instead without copying data. And also routines to return new views in a way that the python garbage collector would handle it (nb::capsule).
It was all very simple and transparent after the implementation. I don’t know how hard it would be in pybind11.
I was able to generate 90% of it with an llm. Just had to double check that there wasn’t some copies being snuck in.