Statement class
(Shortest import: from brian2.codegen.statements import Statement)
- class brian2.codegen.statements.Statement(var, op, expr, comment, dtype, constant=False, subexpression=False, scalar=False)[source]
Bases:
object
A single line mathematical statement.
The structure is
var op expr
.- Parameters:
var : str
The left hand side of the statement, the value being written to.
op : str
The operation, can be any of the standard Python operators (including
+=
etc.) or a special operator:=
which means you are defining a new symbol (whereas=
means you are setting the value of an existing symbol).expr : str,
Expression
The right hand side of the statement.
dtype :
dtype
The numpy dtype of the value or array
var
.constant : bool, optional
Set this flag to
True
if the value will not change (only applies forop==':='
.subexpression : bool, optional
Set this flag to
True
if the variable is a subexpression. In some languages (e.g. Python) you can use this to save a memory copy, because you don’t need to dolhs[:] = rhs
but a redefinitionlhs = rhs
.scalar : bool, optional
Set this flag to
True
ifvar
andexpr
are scalar.
Notes
Will compute the following attribute:
inplace
True or False depending if the operation is in-place or not.
Boolean simplification notes:
Will initially set the attribute
used_boolean_variables
toNone
. This is set byoptimise_statements
when it is called on a sequence of statements to the list of boolean variables that are used in this expression. In addition, the attributeboolean_simplified_expressions
is set to a dictionary with keys consisting of a tuple of pairs(var, value)
wherevar
is the name of the boolean variable (will be inused_boolean_variables
) andvar
isTrue
orFalse
. The values of the dictionary are strings representing the simplified version of the expression if eachvar=value
substitution is made for that key. The keys will range over all possible values of the set of boolean variables. The complexity of the original statement is set as the attributecomplexity_std
, and the complexity of the simplified versions are in the dictionarycomplexities
(with the same keys).This information can be used to generate code that replaces a complex expression that varies depending on the value of one or more boolean variables with an
if/then
sequence where each subexpression is simplified. It is optional to use this (e.g. the numpy codegen does not, but the cython one does).