codegen package

Package providing the code generation framework.

_prefs module

Module declaring general code generation preferences.

codeobject module

Module providing the base CodeObject and related functions.

Exported members: CodeObject, CodeObjectUpdater


CodeObject(owner, code, variables, ...[, name]) Executable code object.


check_code_units(code, group[, user_code, ...]) Check statements for correct units.
create_runner_codeobj(group, code, template_name) Create a CodeObject for the execution of code in the context of a Group.

cpp_prefs module

Preferences related to C++ compilation


C++ compilation preferences

codegen.cpp.compiler = ''

Compiler to use (uses default if empty)

Should be gcc or msvc.

codegen.cpp.extra_compile_args = None

Extra arguments to pass to compiler (if None, use either extra_compile_args_gcc or extra_compile_args_msvs).

codegen.cpp.extra_compile_args_gcc = ['-w', '-O3']

Extra compile arguments to pass to GCC compiler

codegen.cpp.extra_compile_args_msvc = ['/Ox', '/EHsc', '/w']

Extra compile arguments to pass to MSVC compiler

codegen.cpp.include_dirs = []

Include directories to use. Note that $prefix/include will be appended to the end automatically, where $prefix is Python’s site-specific directory prefix as returned by sys.prefix.

codegen.cpp.msvc_architecture = ''

MSVC architecture name (or use system architectue by default).

Could take values such as x86, amd64, etc.

codegen.cpp.msvc_vars_location = ''

Location of the MSVC command line tool (or search for best by default).

Exported members: get_compiler_and_args


get_compiler_and_args() Returns the computed compiler and compilation flags

statements module

Module providing the Statement class.


Statement(var, op, expr, comment, dtype[, ...]) A single line mathematical statement.

targets module

Module that stores all known code generation targets as codegen_targets.

Exported members: codegen_targets

templates module

Handles loading templates from a directory.

Exported members: Templater


CodeObjectTemplate(template, template_source)
Templater(package_name[, env_globals]) Class to load and return all the templates a CodeObject defines.



translation module

This module translates a series of statements into a language-specific syntactically correct code block that can be inserted into a template.

It infers whether or not a variable can be declared as constant, etc. It should handle common subexpressions, and so forth.

The input information needed:

  • The sequence of statements (a multiline string) in standard mathematical form
  • The list of known variables, common subexpressions and functions, and for each variable whether or not it is a value or an array, and if an array what the dtype is.
  • The dtype to use for newly created variables
  • The language to translate to

Exported members: make_statements(), analyse_identifiers(), get_identifiers_recursively()


LIONodeRenderer(variables) Renders expressions, pulling out scalar expressions and remembering them for later use.
LineInfo(**kwds) A helper class, just used to store attributes.


analyse_identifiers(code, variables[, recursive]) Analyses a code string (sequence of statements) to find all identifiers by type.
apply_loop_invariant_optimisations(...) Analyzes statements to pull out expressions that need to be evaluated only once.
get_identifiers_recursively(expressions, ...) Gets all the identifiers in a list of expressions, recursing down into subexpressions.
has_non_float(expr, variables) Whether the given expression has an integer or boolean variable in it.
is_scalar_expression(expr, variables) Whether the given expression is scalar.
make_statements(code, variables, dtype) Turn a series of abstract code statements into Statement objects, inferring whether each line is a set/declare operation, whether the variables are constant or not, and handling the cacheing of subexpressions.