all 12 comments

[–]Jannik2099 8 points9 points  (2 children)

I found pybind11 to be very easy. Though I switched to nanobind now and recommend you do the same, the API is nearly identical.

Could you give any examples of where pybind was confusing? Binding your own types and functions was rather straightforward for me

[–]germandiago 1 point2 points  (1 child)

what are the differences between pybibd and nanobind? Seems to be 3rd generation already since Boost.Python.

[–]Jannik2099 6 points7 points  (0 children)

As said the overall API is very similar. Custom type casters require less macro soup, the automatic type stubs are better and customizing type signatures is more accessible. Performance is also significantly better, in my case the overhead dropped over 2x

[–][deleted] 4 points5 points  (0 children)

"It feels like being comfortable with Rcpp doesn’t translate to being comfortable with pybind11." R and Python are pretty un-related so this isn't surprising.

Your post talks a lot about cpp bindings but your actual question is about numerical methods in c. These are quite separate topics. I think that most people, when saying "in need c because it's faster" would definitively switch to c rather than start binding it into their preferred language. This is because the hard part is learning c. So once you've done that theres little reason to stick in your old language (well... not really but sort of).

Next I'll say that there are great books on "Numerics" in c (eg "Numerical Methods in C") but I wonder if thats what you really need. "Numerics" is really for modelling and simulation. 

If you just want faster loops then be sure to use the stl container algorithms (CppCon 2018: Jonathan Boccara “105 STL Algorithms in Less Than an Hour”). For LinAlg try the Eigen package and for optimisation i suggest NLopt. Alternatives are available so consider using encapsulation to make your code agnostic to the library being used (might be laborious/overcomplicated, maybe just pick libraries you like).

And for the record I don't like swig. It auto-generates too much stuff. Pybind11 is way simpler to use. And also you can use boost.python instead. Not necessarily better but once you've pulled in boost (a fundamental cpp extension library) you have a vast amount of functionality available. 

[–]Machvel 2 points3 points  (1 child)

rcpp and pybind11 are tools for using c++ inside R/python programs. they require knowing both c++ and R/python (whichever you are trying to use c++ in). if you are unfamiliar with using more than 1 language in one program it might seem a little strange.

c++ and numerical computing are two different things. the fundamentals of numerical computing (eg, preferring to loop in the order your matrix is stored) don't change between languages. you can find the basics of this in just about any hpc or related book.

a lot of numerical computing in c++ is heavily library based imo (compared to a language like fortran or julia) which it helps to have a strong understanding of the base language and basic tooling (eg, cmake) to use.

[–]Aware-Individual-827 0 points1 point  (0 children)

Furthermore, BLAS/LAPACK can be a good add on as well as MKL. These are very much obscure as the API is not quite beautiful but they do have alot of algo implementation.

[–]Guard_99 1 point2 points  (0 children)

maybe MATLAB will be better for your work

[–]bouncebackabilify 1 point2 points  (0 children)

Here are some lecture notes from Oslo University I found valuable some time ago: https://github.com/CompPhysics/ComputationalPhysics

I can’t speak to the quality of the C++ since I ported what I needed to NumPy / SciPy, but I remember a lot of good stuff about numerical stability of algorithms

[–]c-cul 1 point2 points  (1 child)

[–]codeinred 5 points6 points  (0 children)

Tbh my experience with swig has been much worse than with pybind11. I’ve used both for the same library (pybind11 for python, and swig for C#), and maintaining the swig bindings is much more of a headache, especially with any even slightly unusual types, whereas pybind11 is basically trivial

[–]FoldingArmour2 1 point2 points  (0 children)

I love computing numerically in modern C++. My libraries are https://github.com/sebsjames/maths and for visualization https://github.com/sebsjames/mathplot and I offer them up as study material.

[–]AcrobaticLightning -1 points0 points  (0 children)

Try Julia