Bases: object
partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.
tuple of arguments to future partial calls
function object to use in future partial calls
dictionary of keyword arguments to future partial calls
Bases: numba.typesystem.types._NumbaType
Base for numba types.
Bases: numba.typesystem.types.known_value
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.ContainerListType
tuple(base_type, size)
Bases: object
imap(func, *iterables) –> imap object
Make an iterator that computes the function using arguments from each of the iterables. Like map() except that it returns an iterator instead of a list and that it stops when the shortest iterable is exhausted instead of filling in None for shorter iterables.
x.next() -> the next value, or raise StopIteration
Bases: numba.typesystem.types.NumbaType
Bases: object
Conser: constructs new objects only when not already available. Objects are weakreffed to sanitize memory consumption.
This allows the objects to be compared by and hashed on identity.
Bases: numba.typesystem.types.NumbaType
Type for autojit functions
Bases: numba.typesystem.types.NumbaType
Cons calls to the constructor.
Bases: numba.typesystem.types.NumbaType
A reference to an (primitive or Python) object. This is passed as a pointer and dereferences automatically.
Currently only supported for structs.
Bases: numba.typesystem.types.NumbaType
Type of numpy dtypes
Bases: numba.typesystem.types.NumbaType
A type instance in user code. e.g. double(value). The Name node will have a cast-type with dst_type ‘double’.
Bases: numba.typesystem.types.NumbaType
Bases: object
Base of all types.
Add defaults to a given args tuple for type construction
Nullary type constructor creating the most elementary of types. Does not compose any other type.
Bases: numba.typesystem.types.NumbaType
Method of something.
base_type: the object type the attribute was accessed on
Bases: numba.typesystem.types.MapContainerType
dict(key, value, size)
Bases: numba.typesystem.types.NumbaType
Parameters: |
|
---|---|
Returns: | a tuple type representation |
Bases: numba.typesystem.types.NumbaType
Parameters: |
|
---|---|
Returns: | an array type representation |
Bases: numba.typesystem.types.known_value
Global type
Bases: numba.typesystem.types.NumbaType
Passing structs by value is not properly supported for different calling conventions in LLVM, so we take an extra argument pointing to a caller-allocated struct value.
Bases: numba.typesystem.types.NumbaType
An array type. array_ may be sliced to obtain a subtype:
>>> double[:, :, ::1][1:]
double[:, ::1]
>>> double[:, :, ::1][:-1]
double[:, :]
>>> double[::1, :, :][:-1]
double[::1, :]
>>> double[::1, :, :][1:]
double[:, :]
Bases: numba.typesystem.types.known_value
Represents a type for modules.
Bases: numba.typesystem.types.NumbaType
Type for jit functions
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.ContainerListType
list(base_type, size)
Bases: type
Metaclass for numba types, conses immutable types.
Create a mutable struct type
Bases: numba.typesystem.types.NumbaType
Type which is associated with a known value or well-defined symbolic expression:
np.add => np.add np.add.reduce => (np.add, “reduce”)
Bases: numba.typesystem.types.pointer
Bases: numba.typesystem.types.NumbaType
Compute the offset of a field. Must be used only after mutation has finished.
Parameters: | np_dtype – the NumPy dtype (e.g. np.dtype(np.double)) |
---|---|
Returns: | a dtype type representation |
Bases: object
Function types may be called with Python functions to create a Function object. This may be used to minivect users for their own purposes. e.g.
@double(double, double) def myfunc(...):
...
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
A pointer with knowledge of its range.
E.g. an array’s ‘shape’ or ‘strides’ attribute. This also allow tuple unpacking.
Types for closures and inner functions.
Bases: numba.exttypes.types.extensiontype.ExtensionType
Type of the enclosing scope for closures. This is always passed in as first argument to the function.
Bases: numba.typesystem.types.NumbaType
Type of closures and inner functions.
Default rules for the typing of constants.
Get a function mapping values to types, which returns None if unsuccessful.
Get a matcher table: { (type -> bool) : (value -> type) }
Get a table mapping Python classes to handlers (value -> type)
Parameters: | u – The type universe |
---|
Get a simple table mapping Python classes to types.
Parameters: | u – The type universe |
---|
Type defaults
Inferface for our typesystems.
Some requirements:
The typesystem must allow us to switch between low-level representations. For instance, we may want to represent an array as a NumPy ndarray, a Py_buffer, or some other representation.
The sizes of atom types (e.g. int) must be easily customizable. This allows an interpreter to switch sizes to simulate different platforms.
Type representations and sizes, must be overridable without reimplementing the type. E.g. an atom type can be sliced to create an array type, which should be separate from its low-level representation.
Types should map easily between type domains of the same level, e.g. between the low-level numba and llvm types. Ideally this forms an isomorphism, which is precluded by ctypes and numpy type systems:
>>> ctypes.c_longlong <class 'ctypes.c_long'>No type system but our own should be entrenched in any part of the codebase, including the code generator.
Sets of type constructors (type universes) must be composable. For instance, we may want to extend a low-level type systems of ints and pointers with objects to yield a type universe supporting both constructs.
Universes must be re-usable across type-systems. Types of universes represent abstract type concepts, and the type-systems give meaning and representation to values of those types.
Types must be immutable and consed, i.e. ts.pointer(base) is ts.pointer(base) must always be True
The use of a certain typesystem must suggest at which level the corresponding terms operate.
Conversion code should be written with minimal effort:
- unit types should map immediately between domains of the same level
- parametric types should naturally re-construct in domains of the same level
Converting a type to a lower-level domain constitutes a one-way conversion. This should, where possible, constitute a lowering in the same domain followed by a conversion. E.g.:
- def numba_complex_to_llvm(type):
return to_llvm(lower_complex(type))
Type constructors must be substitutable. E.g. an external user may want to construct a universe where type construction is logged, or where special type checking is performed, disallowing certain compositions.
Bases: object
Bases: object
Base of all types.
Add defaults to a given args tuple for type construction
Nullary type constructor creating the most elementary of types. Does not compose any other type.
Bases: object
Get a concrete type given a python value. Return None f this ConstantTyper cannot type the constant
Bases: object
Conser: constructs new objects only when not already available. Objects are weakreffed to sanitize memory consumption.
This allows the objects to be compared by and hashed on identity.
Kinds for numba types.
x.__getitem__(y) <==> x[y]
Type lowering from a higher-level domain to a lower-level domain.
Create a type lowerer from a domain to a codomain given a lowering table.
Get a function form the table by resolving any indirections
Find a lowering function from the flags of the type
Shorthands for type constructing, promotions, etc.
Bases: object
partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.
tuple of arguments to future partial calls
function object to use in future partial calls
dictionary of keyword arguments to future partial calls
Bases: numba.typesystem.types._NumbaType
Base for numba types.
Bases: numba.typesystem.types.known_value
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.ContainerListType
tuple(base_type, size)
Bases: object
imap(func, *iterables) –> imap object
Make an iterator that computes the function using arguments from each of the iterables. Like map() except that it returns an iterator instead of a list and that it stops when the shortest iterable is exhausted instead of filling in None for shorter iterables.
x.next() -> the next value, or raise StopIteration
Bases: numba.typesystem.types.NumbaType
Bases: object
Conser: constructs new objects only when not already available. Objects are weakreffed to sanitize memory consumption.
This allows the objects to be compared by and hashed on identity.
Bases: numba.typesystem.types.NumbaType
Type for autojit functions
Bases: numba.typesystem.types.NumbaType
Cons calls to the constructor.
Bases: numba.typesystem.types.NumbaType
A reference to an (primitive or Python) object. This is passed as a pointer and dereferences automatically.
Currently only supported for structs.
Bases: numba.typesystem.types.NumbaType
Type of numpy dtypes
Bases: numba.typesystem.types.NumbaType
A type instance in user code. e.g. double(value). The Name node will have a cast-type with dst_type ‘double’.
Bases: numba.typesystem.types.NumbaType
Bases: object
Base of all types.
Add defaults to a given args tuple for type construction
Nullary type constructor creating the most elementary of types. Does not compose any other type.
Bases: numba.typesystem.types.NumbaType
Method of something.
base_type: the object type the attribute was accessed on
Bases: numba.typesystem.types.MapContainerType
dict(key, value, size)
Bases: numba.typesystem.types.NumbaType
Parameters: |
|
---|---|
Returns: | a tuple type representation |
Bases: numba.typesystem.types.NumbaType
Parameters: |
|
---|---|
Returns: | an array type representation |
Bases: numba.typesystem.types.known_value
Global type
Bases: numba.typesystem.types.NumbaType
Passing structs by value is not properly supported for different calling conventions in LLVM, so we take an extra argument pointing to a caller-allocated struct value.
Bases: numba.typesystem.types.NumbaType
An array type. array_ may be sliced to obtain a subtype:
>>> double[:, :, ::1][1:]
double[:, ::1]
>>> double[:, :, ::1][:-1]
double[:, :]
>>> double[::1, :, :][:-1]
double[::1, :]
>>> double[::1, :, :][1:]
double[:, :]
Bases: numba.typesystem.types.known_value
Represents a type for modules.
Bases: numba.typesystem.types.NumbaType
Type for jit functions
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.ContainerListType
list(base_type, size)
Bases: type
Metaclass for numba types, conses immutable types.
Create a mutable struct type
Bases: numba.typesystem.types.NumbaType
Type which is associated with a known value or well-defined symbolic expression:
np.add => np.add np.add.reduce => (np.add, “reduce”)
Bases: numba.typesystem.types.pointer
Bases: numba.typesystem.types.NumbaType
Compute the offset of a field. Must be used only after mutation has finished.
Parameters: | np_dtype – the NumPy dtype (e.g. np.dtype(np.double)) |
---|---|
Returns: | a dtype type representation |
Bases: object
Function types may be called with Python functions to create a Function object. This may be used to minivect users for their own purposes. e.g.
@double(double, double) def myfunc(...):
...
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
A pointer with knowledge of its range.
E.g. an array’s ‘shape’ or ‘strides’ attribute. This also allow tuple unpacking.
D.__contains__(k) -> True if D has a key k, else False
Map a NumPy dtype to a minitype.
>>> map_dtype(np.dtype(np.int32))
int32
>>> map_dtype(np.dtype(np.int64))
int64
>>> map_dtype(np.dtype(np.object))
PyObject *
>>> map_dtype(np.dtype(np.float64))
float64
>>> map_dtype(np.dtype(np.complex128))
complex128
Bases: object
Promote two arbitrary types
Return whether the two types satisfy the two properties:
>>> have_properties(int32, int32.pointer(), "is_pointer", "is_int")
True
Promote two array types in an expression to a new array type
Promote two integer types. We have to remain portable at this point, e.g. promote_int(Py_ssize_t, int) should be Py_ssize_t, and not int64 or int32.
Promote two numeric types
This module provides deferred types used for type dependences that haven’t been processed yet, or circular dependences.
Types participating in statements that are deferred until later:
x = 0 # x_0 for i in range(10):
# x_1 = phi(x_0, x_2) print x x = i # x_2
Here x_2 is not resolved yet when we encounter the print statement.
Types participating in type graph cycles:
x = 0 # x_0 for i in range(10):
# x_1 = phi(x_0, x_2) print x x = x + i # x_2
Here we have:
type(x_1) = promote(type(x_0) = int, type(x_2)) type(x_2) = promote(type(x_1), type(i) = Py_ssize_t)
This is a simple cycle that will constitute the following graph:
- x_0 (int)
x_1 __
- X_2
i_0 (Py_ssize_t)
Bases: numba.typesystem.ssatypes.ReanalyzeCircularType
Used when we don’t know the type of the expression being called, or when we have an autojitting function and don’t know all the argument types.
Bases: numba.typesystem.ssatypes.ReanalyzeCircularType
Used when we don’t know the type of the variable being indexed.
Bases: numba.typesystem.ssatypes.UnresolvedType
We don’t know what the type is at the point we need a type, so we create a deferred type.
Depends on: self.variable.type
Example:
- def func():
- for i in range(10):
# type(x) = phi(undef, deferred(x_1)) = phi(deferred(x_1)) if i > 1:
print x # type is deferred(x_1)x = ... # resolve deferred(x_1) to type(...)
Bases: numba.typesystem.ssatypes.UnresolvedType
Bases: numba.typesystem.ssatypes.UnresolvedType
This is useful when there is a circular dependence on yourself. e.g.
s = “hello” for i in range(5):
s = s[1:]
The type of ‘s’ depends on the result of the slice, and on the input to the loop. But to determine the output, we need to assume the input, and unify the output with the input, and see the result for a subsequent slice. e.g.
a = np.empty((10, 10, 10)) for i in range(3):
a = a[0]
Here the type would change on each iteration. Arrays do not demote to object, but other types do. The same goes for a call:
error_circular(result_type.variable)
- for i in range(n):
- f = f(i)
but also
x = 0 for i in range(n):
x = f(x)
or linked-list traversal
current = ... while current:
current = current.next
Retry inferring the type with the new type set
Resolve the reanalyzable statement by setting the already resolved dependences for the type inference code.
Try substituting resolved parts of promotions and reinfer the types.
Try to set the new variables and retry type inference
Update the graph after having updated the dependences
Bases: numba.typesystem.ssatypes.UnresolvedType
Circular type dependence. This can be a strongly connected component of just promotions, or a mixture of promotions and re-inferable statements.
If we have only re-inferable statements, but no promotions, we have nothing to feed into the re-inference process, so we issue an error.
Bases: numba.typesystem.ssatypes.UnresolvedType
A type that indicates the statement cannot be analyzed without first analysing its dependencies.
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
The directed type graph works as follows:
if type x depends on type y, then y is a parent of x.
we construct a condensation graph by contracting strongly connected components to single nodes
- we resolve types in topological order
-> types in SCCs are handled specially
Find the strongly connected components in the connected graph starting at start_type.
This promotes arrays for assignments. Arrays must have a single consistent type in an assignment (phi). Any promotion of delayed types are immediately resolved.
Promote a list of types for assignment (e.g. in a phi node).
if there are any objects, the result will always be an object
(minus any contiguity constraints)
Some types to aid in type-based alias analysis. See numba/metadata.py.
Autojit template types.
Bases: numba.typesystem.templatetypes._TemplateType
Bases: numba.typesystem.templatetypes._TemplateType
This function matches up T in the example below with a concrete type like double when a double pointer is passed in as argument:
- def f(T.pointer() pointer):
- scalar = T(...)
We can go two ways with this, e.g.
- def f(T.base_type scalar):
- pointer = T(...)
Which could work for things like pointers, though not for things like arrays, since we can’t infer the dimensionality.
We mandate that each Template type be resolved through a concrete type, i.e.:
- def f(T scalar):
- pointer = T.pointer(...)
template_context:
Dict mapping template types to concrete types:
T1 -> double * T2 -> float[:]
After the template context is known, resolve functions on template types E.g.
T[:] -> array_(dtype=T) void(T) -> function(args=[T]) Struct { T arg } -> struct(fields={‘arg’: T}) T * -> pointer(base_type=T)
Any other compound types?
Resolve template types given a signature with concrete types.
Bases: numba.typesystem.templatetypes._TemplateType
Match a type pattern to a type.
>>> type = list_(object_, 2)
>>> typematch("list(*, 2)", type)
True
>>> typematch("list(*)", type)
True
>>> typematch("list(*)", type)
True
>>> typematch("tuple(*)", type)
False
>>> typematch("object_", type)
True
User-facing numba types.
Bases: numba.typesystem.types.NumbaType
Parameters: |
|
---|---|
Returns: | a tuple type representation |
Bases: object
Function types may be called with Python functions to create a Function object. This may be used to minivect users for their own purposes. e.g.
@double(double, double) def myfunc(...):
...
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types._NumbaType
Base for numba types.
Bases: type
Metaclass for numba types, conses immutable types.
Parameters: |
|
---|---|
Returns: | an array type representation |
Bases: numba.typesystem.types.NumbaType
An array type. array_ may be sliced to obtain a subtype:
>>> double[:, :, ::1][1:]
double[:, ::1]
>>> double[:, :, ::1][:-1]
double[:, :]
>>> double[::1, :, :][:-1]
double[::1, :]
>>> double[::1, :, :][1:]
double[:, :]
Bases: numba.typesystem.types.NumbaType
Type for autojit functions
Bases: numba.typesystem.types.known_value
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
Cons calls to the constructor.
Bases: numba.typesystem.types.MapContainerType
dict(key, value, size)
Parameters: | np_dtype – the NumPy dtype (e.g. np.dtype(np.double)) |
---|---|
Returns: | a dtype type representation |
Bases: numba.typesystem.types.NumbaType
Passing structs by value is not properly supported for different calling conventions in LLVM, so we take an extra argument pointing to a caller-allocated struct value.
Bases: numba.typesystem.types.known_value
Global type
Bases: numba.typesystem.types.NumbaType
Compute the offset of a field. Must be used only after mutation has finished.
Bases: numba.typesystem.types.NumbaType
Type for jit functions
Bases: numba.typesystem.types.pointer
Bases: numba.typesystem.types.NumbaType
Type which is associated with a known value or well-defined symbolic expression:
np.add => np.add np.add.reduce => (np.add, “reduce”)
Bases: numba.typesystem.types.ContainerListType
list(base_type, size)
Bases: numba.typesystem.types.NumbaType
A type instance in user code. e.g. double(value). The Name node will have a cast-type with dst_type ‘double’.
Bases: numba.typesystem.types.NumbaType
Method of something.
base_type: the object type the attribute was accessed on
Bases: numba.typesystem.types.known_value
Represents a type for modules.
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
Type of numpy dtypes
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
Bases: numba.typesystem.types.NumbaType
A reference to an (primitive or Python) object. This is passed as a pointer and dereferences automatically.
Currently only supported for structs.
Bases: numba.typesystem.types.NumbaType
A pointer with knowledge of its range.
E.g. an array’s ‘shape’ or ‘strides’ attribute. This also allow tuple unpacking.
Create a mutable struct type
Defines the typeset class and a number of builtin type sets.
Bases: numba.typesystem.types.NumbaType
Holds a set of types that can be used to specify signatures for type inference.
Result type of iterating over something
Parameters: | ast_node – a Numba or Python AST expression node |
---|---|
Returns: | the type of the expression node |
Result of indexing a value of the given type with an integer index
D.__contains__(k) -> True if D has a key k, else False
Signature of a python function with N arguments
Assert that the types of the given nodes meets a certain requirement
Universes of type constructors for numba.
D.__contains__(k) -> True if D has a key k, else False