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
Examples
>>> import ast >>> nodes = [ast.Name(id='x'), ast.Name(id='y'), ast.Name(id='z')] >>> ast.unparse(reduced_node(nodes, ast.Mult)) 'x * y * z' >>> nodes = [ast.Name(id='x')] >>> ast.unparse(reduced_node(nodes, ast.Add)) 'x'