def collect_nodes(collected_nodes, *args):
    """Collect all nodes belonging to the same graph

    Walks dependent Nodes and inputs recursively.

    """
    if not args:
        return
    node = args[0]
    rest = args[1:]
    collect_nodes(collected_nodes, *rest)
    if node in collected_nodes:
        return
    collected_nodes.add(node)
    collect_nodes(collected_nodes, *node._dependents)
    if isinstance(node, Node):
        collect_nodes(collected_nodes, *node._iterate_inputs())
dataset/ETHPy150Open akaihola/lusmu/lusmu/visualization.py/collect_nodes/original