2.4. Supported Python features

Apart from the Language part below, which applies to both object mode and nopython mode, this page only lists the features supported in nopython mode.

2.4.1. Language

2.4.1.1. Constructs

Numba strives to support as much of the Python language as possible, but some language features are not available inside Numba-compiled functions:

  • Function definition
  • Class definition
  • Exception handling (try .. except, try .. finally)
  • Context management (the with statement)
  • Comprehensions (either list, dict, set or generator comprehensions)
  • Generator delegation (yield from)

The raise statement is supported in several forms:

Similarly, the assert statement is supported with or without an error message.

2.4.1.2. Function calls

Numba supports function calls using positional and named arguments, as well as arguments with default values. Explicit *args and **kwargs are not supported.

2.4.1.3. Generators

Numba supports generator functions and is able to compile them in object mode and nopython mode. The returned generator can be used both from Numba-compiled code and from regular Python code.

Coroutine features of generators are not supported (i.e. the generator.send(), generator.throw(), generator.close() methods).

2.4.2. Built-in types

2.4.2.1. int, bool

Arithmetic operations as well as truth values are supported.

The following attributes and methods are supported:

  • .conjugate()
  • .real
  • .imag

2.4.2.2. float, complex

Arithmetic operations as well as truth values are supported.

The following attributes and methods are supported:

  • .conjugate()
  • .real
  • .imag

2.4.2.3. tuple

Tuple construction and unpacking is supported.

2.4.2.4. None

The None value is supported for identity testing (when using an optional type).

2.4.2.5. bytes, bytearray, memoryview

The bytearray type and, on Python 3, the bytes type support indexing, iteration and retrieving the len().

The memoryview type supports indexing, slicing, iteration, retrieving the len(), and also the following attributes:

2.4.3. Built-in functions

The following built-in functions are supported:

2.4.4. Standard library modules

2.4.4.1. array

Limited support for the array.array type is provided through the buffer protocol. Indexing, iteration and taking the len() is supported. All type codes are supported except for "u".

2.4.4.3. ctypes

Numba is able to call ctypes-declared functions with the following argument and return types:

2.4.4.6. random

Numba supports top-level functions from the random module, but does not allow you to create individual Random instances. A Mersenne-Twister generator is used, with a dedicated internal state. It is initialized at startup with entropy drawn from the operating system.

Note

Calling random.seed() from non-Numba code (or from object mode code) will seed the Python random generator, not the Numba random generator.

Note

The generator is not thread-safe when releasing the GIL.

Also, under Unix, if creating a child process using os.fork() or the multiprocessing module, the child’s random generator will inherit the parent’s state and will therefore produce the same sequence of numbers (except when using the “forkserver” start method under Python 3.4 and later).

See also

Numba also supports most additional distributions from the Numpy random module.

2.4.5. Third-party modules

2.4.5.1. cffi

Similarly to ctypes, Numba is able to call into cffi-declared external functions, using the following C types:

  • char
  • short
  • int
  • long
  • long long
  • unsigned char
  • unsigned short
  • unsigned int
  • unsigned long
  • unsigned long long
  • int8_t
  • uint8_t
  • int16_t
  • uint16_t
  • int32_t
  • uint32_t
  • int64_t
  • uint64_t
  • float
  • double
  • char *
  • void *
  • uint8_t *
  • ssize_t
  • size_t
  • void