Numba is a just-in-time, type-specializing, function compiler.
import numba
numba.__version__
the main API:
numba.jit?
numba.njit?
both are decorators that compile functions into native code
A simple example:
@numba.njit
def plus1(x):
return x + 1
plus1(1)
look at the generated assembly:
print(plus1.inspect_asm(plus1.signatures[0]))
decorated functions remember their compiled signatures
plus1.signatures
new argument types triggers new compilation
using plus1()
with float64
plus1(1.2)
plus1.signatures
using plus1()
with NumPy array
import numpy as np
plus1(np.arange(10))
plus1.signatures
Inspect the LLVM controlflow graph each of call signature.
plus1.inspect_cfg(plus1.signatures[0]).display()
plus1.inspect_cfg(plus1.signatures[1]).display()
plus1.inspect_cfg(plus1.signatures[2]).display()