Jump to content

Numba

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 2003:7a:8509:d00:5cf8:7af2:e3d7:9aee (talk) at 04:34, 1 April 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Original author(s)Continuum Analytics
Developer(s)Community project
Initial release2012 (2012)
Stable release
0.24.0 / March 2016; 8 years ago (2016-03)
Repository
Written inPython, C
Operating systemCross-platform
TypeTechnical computing
Websitenumba.pydata.org

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

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.[1]

References