specialize Package

specialize Package

comparisons Module

class numba.specialize.comparisons.SpecializeComparisons(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Bases: numba.visitors.NumbaTransformer

Rewrite cascaded ast.Compare nodes to a sequence of boolean operations ANDed together:

a < b < c

becomes

a < b and b < c
single_compare(node)
single_compare_objects(node)
visit_Compare(node)

Reduce cascaded comparisons into single comparisons

numba.specialize.comparisons.build_boolop(right, left)
numba.specialize.comparisons.compare(lhs, op, rhs)
numba.specialize.comparisons.extract(complex_node)

exceptions Module

class numba.specialize.exceptions.ExceptionSpecializer(*args, **kwargs)

Bases: numba.visitors.NumbaTransformer

Specialize exception handling. Handle error checking and raising.

visit_CheckErrorNode(node)
visit_Name(node)
visit_NativeCallNode(node)
visit_PyErr_OccurredNode(node)
visit_RaiseNode(node)
class numba.specialize.exceptions.LowerRaise(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Bases: numba.visitors.NumbaTransformer

Resolve the ‘raise’ statement.

visit_Raise(node)

exttypes Module

class numba.specialize.exttypes.DebugVirtualLookup

Bases: object

Use a C utility function from numba/utility/utilities/virtuallookup.c to look up virtual methods in a hash table.

Use for debugging.

lookup(env, always_present, node, args)
class numba.specialize.exttypes.DynamicExtensionHandler

Bases: object

Handle attribute lookup and method calls for autojit extensions with dynamic perfect-hash-based virtual method tables and dynamic object layouts.

handle_method_call(env, node, call_node)

Resolve an extension method of a dynamic hash-based vtable:

PyCustomSlots_Table ***vtab_slot = (((char *) obj) + vtab_offset) lookup_virtual_method(*vtab_slot)

We may cache (*vtab_slot), but we may not cache (**vtab_slot), since compilations may regenerate the table.

However, we could preload (**vtab_slot), where function calls invalidate the preload, if we were so inclined.

static_handler = <numba.specialize.exttypes.StaticExtensionHandler object at 0x105b544d0>
class numba.specialize.exttypes.ExtensionTypeLowerer(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Bases: numba.visitors.NumbaTransformer

Lower extension type attribute accesses and method calls.

get_handler(ext_type)
visit_ExtTypeAttribute(node)

Resolve an extension attribute.

visit_ExtensionMethod(node, call_node=None)

Resolve an extension method. We currently only support immediate calls of extension methods.

visit_NativeFunctionCallNode(node)
class numba.specialize.exttypes.NumbaVirtualLookup

Bases: object

Use a numba function from numba.utility.virtuallookup to look up virtual methods in a hash table.

lookup(env, always_present, node, args)
Parameters:
  • node – ExtensionMethodNode
  • args – [vtable_node, prehash_node]
Returns:

The virtual method as a Node

class numba.specialize.exttypes.StaticExtensionHandler

Bases: object

Handle attribute lookup and method calls for static extensions with C++/Cython-like virtual method tables and static object layouts.

handle_attribute_lookup(env, node)

Resolve an extension attribute for a static object layout.

((attributes_struct *)
(((char *) obj) + attributes_offset))->attribute
Node :ExtTypeAttribute AST node
handle_method_call(env, node, call_node)

Resolve an extension method of a static (C++/Cython-like) vtable:

typedef {
double (*method1)(double); ...

} vtab_struct;

vtab_struct vtab = *(vtab_struct *) (((char *) obj) + vtab_offset) void *method = vtab[index]

numba.specialize.exttypes.call_jit(jit_func, args)

funccalls Module

class numba.specialize.funccalls.FunctionCallSpecializer(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Bases: numba.visitors.NumbaTransformer, numba.visitors.NoPythonContextMixin

visit_NativeCallNode(node)
visit_NativeFunctionCallNode(node)

loopimpl Module

Define various loop implementations.

class numba.specialize.loopimpl.IndexingIteratorImpl

Bases: numba.specialize.loopimpl.IteratorImpl

Implement iteration using indexing.

getiter(context, for_node, llvm_module)
length(context, for_node, llvm_module)

Length of the iterable

next(context, for_node, llvm_module)

Index element and update index

class numba.specialize.loopimpl.IteratorImpl

Bases: object

Implementation of an iterator over a value of a certain type

body(context, for_node, llvm_module)

Get the loop body as a list of statements

getiter(context, for_node, llvm_module)

Set up an iterator (statement or None)

next(context, for_node, llvm_module)

Get the next iterator element (ExprNode)

class numba.specialize.loopimpl.NativeIteratorImpl(getiter_func, next_func)

Bases: numba.specialize.loopimpl.IteratorImpl

Implement iteration over an iterator which has externally callable functions for the getiter and next operations.

getiter(context, for_node, llvm_module)
next(context, for_node, llvm_module)
numba.specialize.loopimpl.assign(target, value)
numba.specialize.loopimpl.find_iterator_impl(node)

Find a suitable iterator type for which we have an implementation

numba.specialize.loopimpl.index(value, index)
numba.specialize.loopimpl.register_iterator_implementation(iterator_pattern, iterator_impl)

loops Module

class numba.specialize.loops.SpecializeObjectIteration(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Bases: numba.visitors.NumbaTransformer

This transforms for loops over objects.

visit_For(node)
class numba.specialize.loops.TransformBuiltinLoops(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Bases: numba.visitors.NumbaTransformer

HANDLERS = {4296470880: <function rewrite_enumerate at 0x105b4ca28>, 4297723560: <function rewrite_zip at 0x105b4caa0>}
rewrite_enumerate(node)

Rewrite a loop like

for i, x in enumerate(array[, start]):
...

into

_arr = array [_s = start] for _i in range(len(_arr)):

i = _i [+ _s] x = _arr[_i] ...
rewrite_zip(node)

Rewrite a loop like

for x, y... in zip(xs, ys...):
...

into

_xs = xs; _ys = ys... for _i in range(min(len(_xs), len(_ys)...)):

x = _xs[_i]; y = _ys[_i]... ...
visit_For(node)
class numba.specialize.loops.TransformForIterable(context, func, ast, locals=None, func_signature=None, nopython=0, symtab=None, **kwargs)

Bases: numba.visitors.NumbaTransformer

This transforms loops over 1D arrays and loops over range().

rewrite_array_iteration(node)

Convert 1D array iteration to for-range and indexing:

for value in my_array:
...

becomes

for i in my_array.shape[0]:
value = my_array[i] ...
rewrite_range_iteration(node)

Handle range iteration:

for i in range(start, stop, step):
...

becomes

nsteps = compute_nsteps(start, stop, step) temp = 0

while temp < nsteps:
target = start + temp * step ... temp += 1
visit_For(node)
numba.specialize.loops.copy_basic_blocks(flow_node_src, flow_node_dst)

Copy cfg basic blocks from one flow node to another

numba.specialize.loops.make_while_from_for(for_node)

Create a While from a For. The ‘test’ (loop condition) must still be set.

numba.specialize.loops.make_while_loop(flow_node)

Create a while loop from a flow node (a While or If node)

numba.specialize.loops.unpack_range_args(node)
numba.specialize.loops.untypedTemp()

Temp node with a yet unknown type