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.
@register(module) def my_type_function(arg1, ..., argN):
...
Creates a function that dispatches to type-specialized LLVM functions based on the input argument types. If no specialized function exists for a set of input argument types, the dispatcher creates and caches a new specialized function at call time.
Compile a function given the input and return types.
There are multiple ways to specify the type signature:
If backend=’bytecode’ the bytecode translator is used, if backend=’ast’ the AST translator is used. By default, the AST translator is used. Note that the bytecode translator is deprecated as of the 0.3 release.
Construct a decorator that takes a function and exports one
A signature is a string with
name ret_type(arg_type, argtype, ...)
A Decorator that exports many signatures for a single function
Get the type of a variable or value.
Used outside of Numba code, infers the type for the object.
Take the address of a compiled jit function.
Parameters: |
|
---|---|
Returns: | ctypes function pointer |
Example of how to use byte-code execution technique to trace accesses to numpy arrays.
This file demonstrates two applications of this technique: * optimize numpy computations for repeated calling * provide automatic differentiation of procedural code
Bases: object
A Class for evaluating a code block of CPython bytecode, and tracking accesses to numpy arrays.
Bases: numba.visitors.NumbaTransformer
Find element-wise expressions and run ElementalMapper to turn it into a minivect AST or a ufunc.
Start the mapping process for the outermost node in the array expression.
Bases: numba.array_expressions.ArrayExpressionRewrite
Compile array expressions to a minivect kernel that calls a Numba scalar kernel with scalar inputs:
a[:, :] = b[:, :] * c[:, :]
becomes
tmp_a = slice(a) tmp_b = slice(b) tmp_c = slice(c) shape = broadcast(tmp_a, tmp_b, tmp_c) call minikernel(shape, tmp_a.data, tmp_a.strides,
tmp_b.data, tmp_b.strides, tmp_c.data, tmp_c.strides)
with
- def numba_kernel(b, c):
- return b * c
- def minikernel(...):
- for (...)
- for(...)
- a[i, j] = numba_kernel(b[i, j], c[i, j])
CAN be used in a nopython context
Bases: numba.array_expressions.ArrayExpressionRewrite
Compile array expressions to ufuncs. Then call the ufunc with the array arguments.
vectorizer_cls: the ufunc vectorizer to use
CANNOT be used in a nopython context
Bases: numba.utils.NumbaContext
Use a static argument list: shape, data1, strides1, data2, strides2, ...
alias of ASTBuilder
This module implements constant folding on the AST. It handles simple cases such as
1 + 2 -> 3
2 ** 10 -> 1024
that’s only assigned once)
from __future__ import print_function, division, absolute_import
Bases: ast.NodeVisitor
Bases: numba.visitors.NumbaTransformer
Perform constant folding on AST.
NOTE: Forbids assignment to True, False, None.
Evaluate the constant expression and return a ast.Num instance containing the result.
Get constant value from AST node.
Store the rhs value so we can inline them in future reference.
TODO: Remove assignment of constant
Bases: numba.visitors.NumbaVisitor
A conservative constant marker. Conservative because we handle the simplest cases only.
Return a set of constant variable names
Bases: exceptions.Exception
Bases: ast.NodeTransformer
Rewrite the With statement.
Python < 3.3:
With(expr context_expr, expr? optional_vars, stmt* body)
Python 3.3:
With(withitem* items, stmt* body) withitem = (expr context_expr, expr? optional_vars)
Bases: _ast.stmt
Node for AST compatibility with python 3.3.
Yield a tuple of (fieldname, value) for each field in node._fields that is present on node.
This module provides support for closures and inner functions.
@autojit def outer():
a = 10 # this is a cellvar
@jit(‘void()’) def inner():
print a # this is a freevarinner() a = 12 return inner
The ‘inner’ function closes over the outer scope. Each function with cellvars packs them into a heap-allocated structure, the closure scope.
The closure scope is passed into ‘inner’ when called from within outer.
The closure scope is an extension type with the cellvars as attributes. Closure scopes are chained together, since multiple inner scopes may need to share a single outer scope. E.g.
- def outer(a):
- def inner(b):
- def inner_inner():
- print a, b
return inner_inner
return inner(1), inner(2)
We have three live closure scopes here:
scope_outer = { ‘a’: a } # call to ‘outer’ scope_inner_1 = { ‘scope_outer’: scope_outer, ‘b’: 1 } # call to ‘inner’ with b=1 scope_inner_2 = { ‘scope_outer’: scope_outer, ‘b’: 2 } # call to ‘inner’ with b=2
Function ‘inner_inner’ defines no new scope, since it contains no cellvars. But it does contain a freevar from scope_outer and scope_inner, so it gets scope_inner passed as first argument. scope_inner has a reference to scope outer, so all variables can be resolved.
These scopes are instances of a numba extension class.
Bases: numba.closures.ClosureTransformer
Lowering of closure instantiation and calling.
- Instantiates the closure scope and makes the necessary assignments
- Rewrites local variable accesses to accesses on the instantiated scope
- Instantiate function with closure scope
Also rewrite calls to closures.
Retrieve the closure scope from ((NumbaFunctionObject *) numba_func).func_closure
Compile the inner function.
Instantiate a closure scope.
After instantiation, assign the parent scope and all function arguments that belong in the scope to the scope.
Resolve cellvars and freevars
Bases: numba.visitors.NumbaTransformer
Bases: numba.closures.ClosureTransformer
Runs just after type inference after the outer variables types are resolved.
Patch closures to get the closure scope as the first argument.
Look up a variable in the closure scope
Process closures recursively and for each variable in each function determine whether it is a freevar, a cellvar, a local or otherwise.
Creates a function that dispatches to type-specialized LLVM functions based on the input argument types. If no specialized function exists for a set of input argument types, the dispatcher creates and caches a new specialized function at call time.
Compile a function given the input and return types.
There are multiple ways to specify the type signature:
If backend=’bytecode’ the bytecode translator is used, if backend=’ast’ the AST translator is used. By default, the AST translator is used. Note that the bytecode translator is deprecated as of the 0.3 release.
Construct a decorator that takes a function and exports one
A signature is a string with
name ret_type(arg_type, argtype, ...)
A Decorator that exports many signatures for a single function
Bases: object
State for a function under translation.
Abstract syntax tree for the function being translated.
Metadata for AST nodes of the function being compiled.
The Control Flow Analysis transform object (control_flow.ControlFlowAnalysis). Set during the cfg pass.
Collective symtol table containing all entries from outer functions.
Map from ast nodes to closures.
Error environment for this function.
Control flow graph. See numba.control_flow.
Function (or similar) being translated.
Target function name.
Type signature for the function being translated.
Globals dict of the function
Inherit from a parent FunctionEnvironment (e.g. to run pipeline stages on a subset of the AST).
Flag indicating if the current function under translation is a closure or not.
Whether this environment is a partially constructed environment
Additional keyword arguments. Deprecated, but kept for backward compatibility.
Compiled, native, Numba function
Pointer to underlying compiled function. Can be used as a callback.
Flag indicating whether the LLVM function needs to be linked into the global fast module from LLVMContextManager
LLVM module for this function. This module is first optimized and then linked into a global module. The Python wrapper function goes directly into the main fat module.
The LLVM wrapper function for the target function. This is a wrapper function that accept python object arguments and returns an object.
A map from local variable names to types. Used to handle the locals keyword argument to the autojit decorator. ({ “local_var_name” : local_var_type } for @autojit(locals=...))
Mangled name of compiled function.
Whether this closure needs a Python wrapper function
Grandparent environment (top-level Numba environment).
The Numba wrapper function (see numbafunction.c) for the target function. This is a wrapper function that accept python object arguments and returns an object.
List of passes that should run on the final llvm ir before linking
Target qualified function name (‘mymodule.myfunc’)
Whether to use refcounting for the function arguments
A map from local variable names to symbol table variables for all local variables. ({ “local_var_name” : numba.symtab.Variable(local_var_type) })
Template signature for @autojit. E.g. T(T[:, :]). See numba.typesystem.templatetypes.
The code generator instance used to generate the target LLVM function. Set during the code generation pass, and used for after-the-fact wrapper generation.
Typesystem for this compilation
Flag that enables control flow warnings on a per-function level.
Warning style, currently available: simple, fancy
Flag indicating whether the function needs a wrapper function to be callable from Python.
Bases: object
Environment for errors or warnings that occurr during translation of a function.
Original Abstract Syntax Tree for the function being translated.
Collection of error and warning messages
Enable post-mortem debugging for the Numba compiler
Function (or similar) being translated.
Merge error messages into another error environment. Useful to propagate error messages for inner functions outwards.
Function source code
Bases: numba.environment._AbstractNumbaEnvironment
Defines global state for a Numba translator.
Bases: object
State for a function under translation.
Abstract syntax tree for the function being translated.
Metadata for AST nodes of the function being compiled.
The Control Flow Analysis transform object (control_flow.ControlFlowAnalysis). Set during the cfg pass.
Collective symtol table containing all entries from outer functions.
Map from ast nodes to closures.
Error environment for this function.
Control flow graph. See numba.control_flow.
Function (or similar) being translated.
Target function name.
Type signature for the function being translated.
Globals dict of the function
Inherit from a parent FunctionEnvironment (e.g. to run pipeline stages on a subset of the AST).
Flag indicating if the current function under translation is a closure or not.
Whether this environment is a partially constructed environment
Additional keyword arguments. Deprecated, but kept for backward compatibility.
Compiled, native, Numba function
Pointer to underlying compiled function. Can be used as a callback.
Flag indicating whether the LLVM function needs to be linked into the global fast module from LLVMContextManager
LLVM module for this function. This module is first optimized and then linked into a global module. The Python wrapper function goes directly into the main fat module.
The LLVM wrapper function for the target function. This is a wrapper function that accept python object arguments and returns an object.
A map from local variable names to types. Used to handle the locals keyword argument to the autojit decorator. ({ “local_var_name” : local_var_type } for @autojit(locals=...))
Mangled name of compiled function.
Whether this closure needs a Python wrapper function
Grandparent environment (top-level Numba environment).
The Numba wrapper function (see numbafunction.c) for the target function. This is a wrapper function that accept python object arguments and returns an object.
List of passes that should run on the final llvm ir before linking
Target qualified function name (‘mymodule.myfunc’)
Whether to use refcounting for the function arguments
A map from local variable names to symbol table variables for all local variables. ({ “local_var_name” : numba.symtab.Variable(local_var_type) })
Template signature for @autojit. E.g. T(T[:, :]). See numba.typesystem.templatetypes.
The code generator instance used to generate the target LLVM function. Set during the code generation pass, and used for after-the-fact wrapper generation.
Typesystem for this compilation
Flag that enables control flow warnings on a per-function level.
Warning style, currently available: simple, fancy
Flag indicating whether the function needs a wrapper function to be callable from Python.
Bases: object
Context manager for handling a translation. Pushes a FunctionEnvironment input onto the given translation environment’s stack, and pops it when leaving the translation context.
Bases: object
State for a given translation.
Flag indicating whether the type of arguments may be overridden for @jit functions. This is always true (except for in tests perhaps!)
The environment corresponding to the current function under translation.
Map from root AST nodes to FunctionEnvironment objects.This allows tracking environments of partially processed ASTs.
A map from target function names that are under compilation to their corresponding FunctionEnvironments
Flag that tells us whether this function is being exported with pycc.
Create a partial environment for a function that only initializes the given attributes.
Later attributes will override existing attributes.
Flag used to indicate if calls to the Python C API are permitted or not during code generation.
Parent environment
A stack consisting of FunctionEnvironment instances. Used to manage lexical closures.
Flag that enables control flow warnings. FunctionEnvironment inherits this unless overridden.
Holds constant values in an LLVM module.
Defines a global typing context for handling promotions and type representations.
Global flag indicating verbose debugging output should be enabled.
Flag for checking type coercions done during late specialization.
Default entry point name. Used to index into the “pipelines” map.
Translation environment for pycc usage
Given an optional key, return the global Numba environment for that key. If no key is given, return the default global environment.
Note that internally, the default environment is mapped to None.
Convenience function for getting a pipeline object (which should be a callable object that accepts (ast, env) arguments, and returns an ast).
Manages the global LLVM module and linkages of new translations.
Name of the environment.
Namespace for pipeline stages. Initially set to the numba.pipeline module.
Map from entry point names to PipelineStages.
Cache for previously specialized functions.
Global flag for enabling detailed checks in translation pipeline stages.
Current translation environment, specific to the current pipeline being run.
Bases: object
pycc environment
Includes flags, and modules for exported functions.
Map from function names to LLVM modules that define the translated function.
Map from function names to type signatures for the translated function (used for header generation).
Map from function names to tuples containing LLVM wrapper functions and LLVM modules that define the wrapper function.
Clear the current set of exported functions.
Boolean flag used to indicate that Python wrappers should be generated for exported functions.
Bases: object
Context manager for handling a translation. Pushes a FunctionEnvironment input onto the given translation environment’s stack, and pops it when leaving the translation context.
Bases: object
State for a given translation.
Flag indicating whether the type of arguments may be overridden for @jit functions. This is always true (except for in tests perhaps!)
The environment corresponding to the current function under translation.
Map from root AST nodes to FunctionEnvironment objects.This allows tracking environments of partially processed ASTs.
A map from target function names that are under compilation to their corresponding FunctionEnvironments
Flag that tells us whether this function is being exported with pycc.
Create a partial environment for a function that only initializes the given attributes.
Later attributes will override existing attributes.
Flag used to indicate if calls to the Python C API are permitted or not during code generation.
Parent environment
A stack consisting of FunctionEnvironment instances. Used to manage lexical closures.
Flag that enables control flow warnings. FunctionEnvironment inherits this unless overridden.
Bases: exceptions.Exception
Some error happened during compilation
Bases: exceptions.Exception
Indicates a compiler bug
Bases: exceptions.Exception
Raised for invalid template type specifications
Build a call node to the specified external function.
context — A numba context llvm_module — A LLVM llvm_module name — Name of the external function args — [optional] argument of for the call temp_name — [optional] Name of the temporary value in LLVM IR.
Bases: object
Cache for compiler functions, declared external functions and constants.
Get the numbawrapper.AutojitFunctionCache that does a quick lookup for the cached case.
Get a compiled function in the the function cache. The function must not be an external function.
For an external function, is_registered() must return False.
Check if a function is registered to the FunctionCache instance.
Register a function to the FunctionCache.
It is necessary before calling compile_function().
Keep an object alive for the lifetime of the translated unit.
This is a HACK. Make live objects part of the function-cache
NOTE: py_func may be None, so we can’t make it a function attribute
llvm_types
Utility module containing common (to Numba) LLVM types.
Hold metadata for instructions.
Bases: object
Type Based Alias Analysis metadata. This defines a type tree where types in different branches are known not to alias each other. Only the ancestors of a type node alias that node.
Find the metadata root of a type. E.g. if we have tbaa(sometype).pointer(), we want to return tbaa(sometype).root.pointer()
Get the TBAA type name
Bases: numba.visitors.NumbaVisitor
Fix missing source position information.
multiarray_api
Defines a utility class for generating LLVM code that retrieves values out of the Numpy array C API PyCObject/capsule.
Bases: object
Convenient access to a the native fields of a NumPy array.
builder: llvmpy IRBuilder pyarray_ptr: pointer to the numpy array tbaa: metadata.TBAAMetadata instance
type: The type to be used for TBAA annotation
Initial AST validation and normalization.
Bases: numba.nodes.basenodes.Node
Wraps an inner function node until the closure code kicks in.
Bases: numba.visitors.NumbaTransformer
Normalize AST
Create assignment code for inner functions and mark the assignment
Inplace assignment.
Resolve a += b to a = a + b. Set ‘inplace_op’ attribute of the Assign node so later stages may recognize inplace assignment.
Do this now, so that we can correctly mark the RHS reference.
Rewrite list comprehensions to the equivalent for loops.
AST syntax:
ListComp(expr elt, comprehension* generators) comprehension = (expr target, expr iter, expr* ifs)
‘ifs’ represent a chain of ANDs
Bases: dict, UserDict.DictMixin
Optimizations module.
Bases: numba.visitors.NumbaTransformer
Pre-load things in order to avoid a potential runtime load instruction. (We also use invariant loads and TBAA).
For each definition of an array variable, which is either a name assignment or a phi, we determine whether to pre-load the data pointer, the strides, and the shape information:
array = np.array(...) for i in range(...):
array[i] # use array->data and array->strides[0]
becomes
array = np.array(...)
temp_data = array->data temp_shape0 = array->shape[0] temp_stride0 = array->strides[0]
- for i in range(...):
- array[i] # use pre-loaded temporaries
This never runs, since we run before late specialization!
Propagate preloading properties through the def-use graph.
If a phi node for an array variable needs preloading, all its incoming variables do too. This means a single property for a phi must propagate through an entire phi cycle:
preload(v) = (initial_condition ∨ (∨ preload(p) for p ∈ incoming(v)))
Ordered Set. See http://code.activestate.com/recipes/576694/
This module contains the Pipeline class which provides a pluggable way to define the transformations and the order in which they run on the AST.
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Sort and issue warnings and errors
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Link the resulting LLVM function into the global fat module.
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: object
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.SimplePipelineStage
alias of ClosureSpecializer
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Bases: numba.pipeline.PipelineStage
Build a wrapper LLVM function around the compiled numba function to call it from Python.
Pop original variables from the symtab
Compile a numba annotated function.
Update the FunctionEnvironment with an LLVM function if the signature is known (try this before type inference to support recursion).
Like run_pipeline, but takes restype and argtypes instead of a function
Postpasses over the LLVM IR. The signature of each postpass is postpass(env, ee, lmod, lfunc) -> lfunc
numba.math.* -> llvmmath.*
Error reporting. Used by the CFA and by each FunctionEnvironment, which can collect errors and warnings and issue them after failed or successful compilation.
Bases: numba.reporting.MessageCollection
Bases: object
Collect error/warnings messages first then sort
Parameters: |
|
---|
scrape_multiarray_api
Utilities for reading the __multiarray_api.h file, and scraping three things: symbolic names of API members, array indices for those members, and LLVM types for those members.
Remove backslashes appearing next to line breaks in a string and strip it after doing so.
Initial prototype for automatically generating multiarray C API call information for llvm-py. Not actually used to generate any Numba modules (dynamically handled by multiarray_api).
Special compiler-recognized numba functions and attributes.
Get the type of a variable or value.
Used outside of Numba code, infers the type for the object.
Take the address of a compiled jit function.
Parameters: |
|
---|---|
Returns: | ctypes function pointer |
alias of LP_c_void_p
Returns file pointers (FILE *) as Python integers for the C stdio stdin, stdout, and stderr streams.
Bases: object
Look up the most recent definition of a variable in this block.
Create a new renamed variable linked to the given variable, which becomes its parent.
Bases: object
Variables placed on the stack. They allow an indirection so, that when used in an operation, the correct LLVM type can be inserted.
The ctypes type for the type of this variable.
The LLVM type for the type of this variable or LLVM Value.
Called when an assignment is made to this variable.
String templating support. The following syntax is supported:
Arbitrary Python code
Placeholders for AST sub-tree substitutions:
{{some_node}}
Typed, untyped and code template variables:
$some_var
Typed and untyped variables are just artificial program (Python) variables.
- Typed variables end up in the jit/autojit locals dict
- Untyped variables are renameable/ssa variables
- Code variables simply expand to arbitrary code
Bases: ast.NodeTransformer
Interpolate template substitutions.
substitutions: { var_name : substitution_node }
This is for {{var_name}} template syntax. This allows substituting arbitrary asts is specific places.
template_variables: [TemplateVariable(...)]
This is for $var syntax. This allows the introductions of typed or untyped variables, as well as code variables.
Bases: object
The context in which a template is evaluated. Allows defining template variables and a mechanism to merge those variables back into the function being compiled.
Add an external template $variable to this context
Create a template $variable that expands to generated code statements
Create a number of code $variables
Create and add a new template $variable
Create a number of template $variables
Run a template and perform the given {{substitutions}}
Update an external jit/autojit locals dict with our template $variables
Bases: numba.symtab.Variable
A fake variable used in a template. The ‘code’ is substituted using string interpolation before the source is parsed. If the type is set, the symbol table is updated. The default ‘code’ is a temporary variable name.
Minimal traits implementation:
@traits class MyClass(object):
attr = Instance(SomeClass) my_delegation = Delegate(‘attr’)
Delegate to some other object.
Bases: object
Base class for traits
@traits class decorator
This module provides a variety of transforms that transform the AST into a final form ready for code generation.
Below follows an explanation and justification of the design of the main compilation stages in numba.
We start with a Python AST, compiled from source code or decompiled from bytecode using meta. We run the following transformations:
Type inference
Infer types of all expressions, and fix the types of all local variables. Local variable types are promoted (for instance float to double), but cannot change (e.g. string cannot be assigned to float).
When the type inferencer cannot determine a type, such as when it calls a Python function or method that is not a Numba function, it assumes type object. Object variables may be coerced to and from most native types.
The type inferencer inserts CoercionNode nodes that perform such coercions, as well as coercions between promotable native types. It also resolves the return type of many math functions called in the numpy, math and cmath modules.
Each AST expression node has a Variable that holds the type of the expression, as well as any meta-data such as constant values that have been determined.
Transform for loops
Provides some transformations of for loops over arrays to loops over a range. Iteration over range/xrange is resolved at compilation time.
What I would like to see is the generation of a RangeNode holding a ast.Compare and an iteration variable incrementing ast.BinOp.
Low level specializations (LateSpecializer)
This stage performs low-level specializations. For instance it resolves coercions to and from object into calls such as PyFloat_FromDouble, with a fallback to Py_BuildValue/PyArg_ParseTuple.
This specializer also has the responsibility to ensure that new references are accounted for by refcounting ObjectTempNode nodes. This node absorbs the references and lets parent nodes borrow the reference. At function cleanup, it decrefs its value. In loops, it also decrefs any previous value, if set. Hence, these temporaries must be initialized to NULL.
An object temporary is specific to one specific sub-expression, and they are not reused (like in Cython).
It also rewrites object attribute access and method calls into PyObject_GetAttrString etc.
Code generation
Generate LLVM code from the transformed AST.
This should be as minimal as possible, and should not contain blobs of code performing complex operations. Instead, complex operations should be broken down by AST transformers into fundamental operations that are already supported by the AST.
This way we maximize code reuse, and make potential future additions of different code generation backends easier. This can be taken only so far, since low-level transformations must also tailor to limitations of the code generation backend, such as intrinsic LLVM calls or calls into libc. However, code reuse is especially convenient in the face of type coercions, which LLVM does not provide any leniency for.
Bases: object
Perform final low-level transformations such as abs(value) -> fabs(value)
Resolve an ast.Call() of a built-in function.
Returns None if no specific transformation is applied.
Resolve an ast.Call() of a built-in function, or call the built-in through the object layer otherwise.
Bases: numba.transforms.ResolveCoercions, numba.visitors.NoPythonContextMixin
Set FunctionDef.error_return to the AST statement that returns a “bad value” that can be used as error indicator.
Rewrite slice objects. Do this late in the pipeline so that other code can still recognize the code structure.
Bases: numba.visitors.NumbaTransformer
Return node that converts the given node to the dst_type. This also performs overflow/underflow checking, and conversion to a Python int or long if necessary.
PyLong_AsLong and friends do not do this (overflow/underflow checking is only for longs, and conversion to int|long depends on the Python version).
Try to perform fast coercion using e.g. PyLong_AsLong(), with a fallback to PyArg_ParseTuple().
Bases: object
Create a Python ufunc AST function. Demote the types of arrays to scalars in the ufunc and generate a return.
Compile the ufunc ast to a function
Register a sub-expression as something that will be evaluated outside the kernel, and the result of which will be passed into the kernel. This can be a variable name:
a + b
->
- f(arg1, arg2):
- return arg1 + arg2
For which ‘a’ and ‘b’ are the operands.
Restore saved state
Save the state of the builder to allow processing other parts of the tree.
Bases: ast.NodeTransformer
Convert a Python array expression AST to a scalar ufunc kernel by demoting array types to scalar types.
Register Name etc as operands to the ufunc
Bases: numba.minivect.miniast.LLVMContext
alias of DynamicArgumentASTBuilder
Bases: object
Defines a class property that does a type check in the setter.
Bases: numba.utils.TypedProperty
Transform a Python AST object into nested tuples and lists.
This is a magic function. If you use it in compiled functions, Numba should generate code for displaying the received value.
Transform a Python AST object into nested tuples and lists, and pretty-print the result.
Return a generator of byte-offset, opcode, and argument from a byte-code-string
Transform a Python AST object into nested tuples and lists, and return as a string formatted using pprint.pformat().
Given a signature string consisting of a return type, argument types, and possibly a function name, return a signature object.
Given an AST represented as tuples and lists, attempt to reconstruct the AST object, given a namespace that defines the node constructors.
Bases: object
Bases: object
Bases: numba.visitors.NumbaVisitorMixin, ast.NodeTransformer
Mutating visitor
Bases: ast.NodeVisitor, numba.visitors.NumbaVisitorMixin
Non-mutating visitor
Bases: numba.visitors.CooperativeBase
Callback for when a new cfg block is encountered.
Issue a deferred-terminating error
Issue a terminating error
Return whether the two variables have the indicated properties:
>>> have(int_, float_, "is_float", "is_int")
float_
If true, returns the type indicated by the first property.
Keep an object alive for the lifetime of the translated unit.
This is a HACK. Make live objects part of the function-cache
Issue a warning
Bases: numba.visitors.NumbaVisitor
Find referenced and assigned ast.Name nodes
Determine what category referenced and assignment variables fall in: