This document attempts to specify the Python subset supported by the numba compiler, and attempts to clarify which constructs are supported natively without help of the object layer.
Note
[1] with reference counting
Note
[2] indexing, slicing and len()
The following types are currently boxed in PyObjects:
All operations on these types go through the object layer.
Tuple unpacking is supported for:
- arrays of known size, e.g. m, n = array.shape
- syntactic assignment, e.g. x, y = a, b
Anything else goes through the object layer.
Supported:
Not Supported:
Runtime introspection with type, isinstance, issubclass, id, dir, callable, getattr, hash, hasattr, super and vars are supported only through the object layer.
globals, locals are not supported.
The implementation of the len function is polymorphic and container specific.
len :: [a] -> int
Variable and element destruction is not supported. The del operator is not part of the syntax and ``delattr` is not supported.
compile, eval and exec, execfile are not supported
Pass is ignored.
file, open and quit, raw_input, reload, help and input are are supported only through the object layer.
print is supported through the object layer (default) or through printf (nopython mode).
String formatting is supported through the object layer.
Generator definitions are not supported. Generator and iterator iteration is supported through the object layer.
Range iterators are syntactic sugar for looping constructs. Custom iterators are not supported. The iter and next functions are are supported only through the object layer.
for i in xrange(start, stop, step):
foo()
Is lowered into some equivalent low-level looping construct that roughly corresponds to the following C code:
for (i = start; i < stop; i += step) {
foo();
}
The value of i after the loop block follows the Python semantics and is set to the last value in the iterator instead of the C semantics.
xrange and range` are lowered into the same constructs.
enumerate is supported through the object layer.
List comprehensions are rewritten into equivalent loops with list appending. Generator comprehensions are not supported.
Named slicing is not supported. Slice types are supported only through the object layer. Slicing as an indexing operation is supported.
a = slice(0, 1, 2)
Classes are supported through extension types.
int :: a -> int
bool :: a -> bool
complex :: a -> bool
The coerce function is not supported.
The str, list and tuple casts are not supported.
The chr, ord are supported for the integer and character types. unichr, hex, bin, oct functions are supported through the object layer.
Nested functions and closures are supported. Construction goes through the object layer. Calling from numba does not.
The nonlocal keyword is not supported.
Global variables are not supported and resolved as constants. The global keyword is not supported.
Variadic and keyword arguments are not supported.
Assertions are not supported.
Comparison operator chaining is supported and is desugared into boolean conjunctions of the comparison operators:
(x > y > z)
(x > y) and (y > z)
Not supported:
Division follows the Python semantics for distinction between floordiv and truediv but operates over unboxed types with no error checking.
Constants such as math.e and math.pi are resolved as constants.