codegen package

Package providing the code generation framework.

_prefs module

Module declaring general code generation preferences.

Preferences

Code generation preferences

codegen.loop_invariant_optimisations = True

Whether to pull out scalar expressions out of the statements, so that they are only evaluated once instead of once for every neuron/synapse/... Can be switched off, e.g. because it complicates the code (and the same optimisation is already performed by the compiler) or because the code generation target does not deal well with it. Defaults to True.

codegen.string_expression_target = 'numpy'

Default target for the evaluation of string expressions (e.g. when indexing state variables). Should normally not be changed from the default numpy target, because the overhead of compiling code is not worth the speed gain for simple expressions.

Accepts the same arguments as codegen.target, except for 'auto'

codegen.target = 'auto'

Default target for code generation.

Can be a string, in which case it should be one of:

  • 'auto' the default, automatically chose the best code generation target available.
  • 'weave' uses scipy.weave to generate and compile C++ code, should work anywhere where gcc is installed and available at the command line.
  • 'cython', uses the Cython package to generate C++ code. Needs a working installation of Cython and a C++ compiler.
  • 'numpy' works on all platforms and doesn’t need a C compiler but is often less efficient.

Or it can be a CodeObject class.

codeobject module

Module providing the base CodeObject and related functions.

Exported members: CodeObject, CodeObjectUpdater

Classes

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

Functions

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

Preferences

C++ compilation preferences

codegen.cpp.compiler = ''

Compiler to use (uses default if empty)

Should be gcc or msvc.

codegen.cpp.define_macros = []

List of macros to define; each macro is defined using a 2-tuple, where ‘value’ is either the string to define it to or None to define it without a particular value (equivalent of “#define FOO” in source or -DFOO on Unix C compiler command line).

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
Any extra platform- and compiler-specific information to use when linking object files together.

codegen.cpp.headers = []

A list of strings specifying header files to use when compiling the code. The list might look like [“<vector>”,“‘my_header’”]. Note that the header strings need to be in a form than can be pasted at the end of a #include statement in the C++ code.

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.libraries = []

List of library names (not filenames or paths) to link against.

codegen.cpp.library_dirs = []

List of directories to search for C/C++ libraries at link time.

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).

codegen.cpp.runtime_library_dirs = []

List of directories to search for C/C++ libraries at run time.

Exported members: get_compiler_and_args

Functions

get_compiler_and_args() Returns the computed compiler and compilation flags

permutation_analysis module

Module for analysing synaptic pre and post code for synapse order independence.

Exported members: OrderDependenceError, check_for_order_independence

Classes

OrderDependenceError

Functions

check_for_order_independence(statements, ...)

statements module

Module providing the Statement class.

Classes

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

Classes

CodeObjectTemplate(template, template_source)

Attributes

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

Functions

autoindent(code)
autoindent_postfilter(code)

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()

Classes

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

Functions

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.