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 or ast.Add.

Examples

>>> import ast
>>> nodes = [ast.Name(id='x'), ast.Name(id='y'), ast.Name(id='z')]
>>> ast.dump(reduced_node(nodes, ast.Mult), annotate_fields=False)
"BinOp(BinOp(Name('x'), Mult(), Name('y')), Mult(), Name('z'))"
>>> nodes = [ast.Name(id='x')]
>>> ast.dump(reduced_node(nodes, ast.Add), annotate_fields=False)
"Name('x')"