make_statements function

(Shortest import: from brian2 import make_statements)

brian2.codegen.translation.make_statements(code, variables, dtype, optimise=True, blockname='')[source]

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.

Parameters:

code : str

A (multi-line) string of statements.

variables : dict-like

A dictionary of with Variable and Function objects for every identifier used in the code.

dtype : dtype

The data type to use for temporary variables

optimise : bool, optional

Whether to optimise expressions, including pulling out loop invariant expressions and putting them in new scalar constants. Defaults to False, since this function is also used just to in contexts where we are not interested by this kind of optimisation. For the main code generation stage, its value is set by the codegen.loop_invariant_optimisations preference.

blockname : str, optional

A name for the block (used to name intermediate variables to avoid name clashes when multiple blocks are used together)

Returns :

——- :

scalar_statements, vector_statements : (list of Statement, list of Statement)

Lists with statements that are to be executed once and statements that are to be executed once for every neuron/synapse/… (or in a vectorised way)

Notes

If optimise is True, then the scalar_statements may include newly introduced scalar constants that have been identified as loop-invariant and have therefore been pulled out of the vector statements. The resulting statements will also use augmented assignments where possible, i.e. a statement such as w = w + 1 will be replaced by w += 1. Also, statements involving booleans will have additional information added to them (see Statement for details) describing how the statement can be reformulated as a sequence of if/then statements. Calls optimise_statements.