Trisha Shetty (Editor)

Numba

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Original author(s)
  
Continuum Analytics

Initial release
  
2012 (2012)

Developer(s)
  
Community project

Repository
  
github.com/numba/numba

Stable release
  
0.31.0 / 17 February 2017; 29 days ago (2017-02-17)

Preview release
  
0.31.0.dev / 22 December 2016; 2 months ago (2016-12-22)

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.

According to its project page:

"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:

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).

To make the above example work for any compatible input types automatically, we can create a function that specializes automatically:

@autojit is deprecated in newer versions and @jit() is the recommended use.

References

Numba Wikipedia