Just-in-time compiling with Numba

The Numba software performs just-in-time compiling using special function decorators. The compilation produces native machine code automatically. The generated code can run on CPUs and GPUs. The main use case for Numba is math-heavy code that uses NumPy arrays.

We can compile the code with the @numba.jit decorator with optional function signature (for instance, int32(int32)). The types correspond with similar NumPy types. Numba operates in the nopython and object modes. The nopython mode is faster but more restricted. We can also release the Global Interpreter Lock (GIL) with the nogil option. You can cache the compilation results by requesting a file cache with the cache argument.

The @vectorize decorator converts ...

Get Python Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.