make_statements function¶
(Shortest import: from brian2.codegen.translation 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
VariableandFunctionobjects for every identifier used in thecode.dtype :
dtypeThe 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 ofStatement)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
optimiseisTrue, then thescalar_statementsmay 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 asw = w + 1will be replaced byw += 1. Also, statements involving booleans will have additional information added to them (seeStatementfor details) describing how the statement can be reformulated as a sequence of if/then statements. Callsoptimise_statements.