When and How to Try with Your Own C-Extensions
summary
Claims that beating NumPy is hard and demonstrates a practical C-extension for finding the first True in 1D/2D Boolean arrays, with concrete implementations and timings. It implements a slow PyObject approach (orders of magnitude worse), a faster PyArray_GetPtr cast path, an npy_iter version, contiguous pointer arithmetic with loop unrolling, and a fastest uint64 forward scan that outperforms np.argmax+np.any and np.nonzero in these tests (gains up to ~3 orders of magnitude; advantage narrows at large sizes). Code ships as arraykit wheels and the extension works as measured.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 0:23Speaker background
- 1:20Numpy and performance
- 3:06Finding the first true
- 5:58Performance benchmarks
- 7:21C extension strategy
- 8:52Building a C extension
- 10:42Working with PyObjects
- 13:50Direct C type pointer access
- 15:57Npy_iter evaluation
- 18:20Contiguous memory access
- 20:40SIMD and loop unrolling
- 24:05Final optimization and results
- 27:08Q&A session
