MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / flatten_tree

Function flatten_tree

tensorflow/contrib/graph_editor/util.py:110–130  ·  view source on GitHub ↗

Flatten a tree into a list. Args: tree: iterable or not. If iterable, its elements (child) can also be iterable or not. leaves: list to which the tree leaves are appended (None by default). Returns: A list of all the leaves in the tree.

(tree, leaves=None)

Source from the content-addressed store, hash-verified

108
109
110def flatten_tree(tree, leaves=None):
111 """Flatten a tree into a list.
112
113 Args:
114 tree: iterable or not. If iterable, its elements (child) can also be
115 iterable or not.
116 leaves: list to which the tree leaves are appended (None by default).
117 Returns:
118 A list of all the leaves in the tree.
119 """
120 if leaves is None:
121 leaves = []
122 if isinstance(tree, dict):
123 for _, child in iteritems(tree):
124 flatten_tree(child, leaves)
125 elif is_iterable(tree):
126 for child in tree:
127 flatten_tree(child, leaves)
128 else:
129 leaves.append(tree)
130 return leaves
131
132
133def transform_tree(tree, fn, iterable_type=tuple):

Callers

nothing calls this directly

Calls 2

is_iterableFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected