Numba
Original author(s) | Continuum Analytics |
---|---|
Developer(s) | Community project |
Initial release | 2012 |
Stable release |
0.29.0
/ 18 October 2016 |
Repository |
github |
Written in | Python, C |
Operating system | Cross-platform |
Type | Technical computing |
Website |
numba |
Numba is an optimizing compiler (just-in-time or import-time or statically) for Python, designed to enhance the running speed of selected bottleneck functions, particularly focusing on "array-oriented (Numpy) and math-heavy" Python code.[1]
According to its project page:[2]
"Numba is an Open Source NumPy-aware optimizing compiler for Python sponsored by Continuum Analytics, Inc. It uses the LLVM compiler infrastructure to compile Python syntax to machine code.
It is aware of NumPy arrays as typed memory regions and so can speed-up code using NumPy arrays. Other, less well-typed code will be translated to Python C-API calls effectively removing the "interpreter" but not removing the dynamic indirection.
Numba is also not a tracing JIT. It compiles code before it gets run either using run-time type information or type information provided in a decorator.
Numba is a mechanism for producing machine code from Python syntax and typed data structures such as those that exist in NumPy."
Traits
Numba compiles Python code with LLVM to code which can be natively executed at runtime. This happens by decorating Python functions, which allows users to create native functions for different input types, or to create them on the fly:
@jit('f8(f8[:])')
def sum1d(my_double_array):
total = 0.0
for i in range(my_double_array.shape[0]):
total += my_double_array[i]
return total
This optimized function runs more than 200 times faster than the interpreted original function on a long NumPy array ; and it is even 30% faster than NumPy's builtin sum()
function (version 0.27.0).[3][4]
To make the above example work for any compatible input types automatically, we can create a function that specializes automatically:
@jit
def sum1d(my_array):
...
@autojit is deprecated in newer versions and @jit() is the recommended use.[5]
See also
References
- ↑ 5 projects that push Python performance, InfoWorld, Feb 9 2015
- ↑ Numba project page on GitHub
- ↑ https://www.ibm.com/developerworks/community/blogs/jfp/entry/A_Comparison_Of_C_Julia_Python_Numba_Cython_Scipy_and_BLAS_on_LU_Factorization?lang=en
- ↑ http://jakevdp.github.io/blog/2013/06/15/numba-vs-cython-take-2/
- ↑ Numba 0.12.0 release notes