# optimise_statements function¶

(Shortest import: from brian2.codegen.optimisation import optimise_statements)

brian2.codegen.optimisation.optimise_statements(scalar_statements, vector_statements, variables, blockname='')[source]

Optimise a sequence of scalar and vector statements

Performs the following optimisations:

1. Constant evaluations (e.g. exp(0) to 1). See evaluate_expr.

2. Arithmetic simplifications (e.g. 0*x to 0). See ArithmeticSimplifier, collect().

3. Pulling out loop invariants (e.g. v*exp(-dt/tau) to a=exp(-dt/tau) outside the loop and v*a inside). See Simplifier.

4. Boolean simplifications (allowing the replacement of expressions with booleans with a sequence of if/thens). See Simplifier.

Parameters

scalar_statements : sequence of Statement

Statements that only involve scalar values and should be evaluated in the scalar block.

vector_statements : sequence of Statement

Statements that involve vector values and should be evaluated in the vector block.

variables : dict of (str, Variable)

Definition of the types of the variables.

blockname : str, optional

Name of the block (used for LIO constant prefixes to avoid name clashes)

Returns

new_scalar_statements : sequence of Statement

As above but with loop invariants pulled out from vector statements

new_vector_statements : sequence of Statement

Simplified/optimised versions of statements