numba.ast_constant_folding

This module implements constant folding on the AST. It handles simple cases such as

  • 1 + 2 -> 3

  • 2 ** 10 -> 1024

  • N=1; N + 1 -> 2 (for N is assigned as global variable or a variable

    that’s only assigned once)

class numba.ast_constant_folding.ConstantFolder(*args, **kws)

Perform constant folding on AST.

NOTE: Forbids assignment to True, False, None.

eval_binary_operation(op, left, right)

Evaluate the constant expression and return a ast.Num instance containing the result.

valueof(node)

Get constant value from AST node.

visit_Assign(node)

Store the rhs value so we can inline them in future reference.

TODO: Remove assignment of constant

class numba.ast_constant_folding.ConstantMarker(*args, **kws)

A conservative constant marker. Conservative because we handle the simplest cases only.

get_constants()

Return a set of constant variable names

Previous topic

numba

Next topic

numba.ast_translate

This Page