reduced_node function¶
(Shortest import: from brian2.codegen.optimisation import reduced_node)
-
brian2.codegen.optimisation.
reduced_node
(terms, op)[source]¶ Reduce a sequence of terms with the given operator
For examples, if terms were [a, b, c] and op was multiplication then the reduction would be (a*b)*c.
Parameters: terms : list
AST nodes.
op : AST node
Could be
ast.Mult
orast.Add
.Examples
>>> import ast >>> nodes = [ast.Name(id='x'), ast.Num(n=3), ast.Name(id='y')] >>> ast.dump(reduced_node(nodes, ast.Mult), annotate_fields=False) "BinOp(BinOp(Name('x'), Mult(), Num(3)), Mult(), Name('y'))" >>> nodes = [ast.Num(n=17.0)] >>> ast.dump(reduced_node(nodes, ast.Add), annotate_fields=False) 'Num(17.0)'