Tracing np.add: From Python to SIMD
Tracing np.add, all the way down
NumPy's np.add is among the most executed lines of numerical Python, yet most users treat it as a black box. This deep dive traces a single call with float64 arrays from the Python entry point down to the SIMD kernel, revealing the machinery in between: argument parsing, __array_ufunc__ overrides, type promotion and dispatch, the trivial loop fast path versus NpyIter, and finally the inner loop itself. Along the way, we see how caching accelerates repeated calls, how the GIL is released for performance, and how strides affect execution.
The inner loop itself never checks anything, it just computes and sets CPU flags.
- aadyachinubhai
The `.c.src` files with the @arch@ like dispatching logic is specific to numpy. Also, they are currently making efforst to shift to C++ templates using Google's Highway project. I worked on porting `np.negative` to it!
- bobmarleybiceps
I sort of wish they used c++ for some of the template stuff, especially since the code base already seems to have some C++ iirc.
I also contributed a tiny bit in the past, and their C template system was a surprise. (but this is cool and I love numpy anyway lol)
- brcmthrowaway
I don't understand, I thought numpy hooked into the fortran stuff :|