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

Function get_unique_graph

tensorflow/contrib/graph_editor/util.py:186–221  ·  view source on GitHub ↗

Return the unique graph used by the all the elements in tops. Args: tops: list of elements to check (usually a list of tf.Operation and/or tf.Tensor). Or a tf.Graph. check_types: check that the element in tops are of given type(s). If None, the types (tf.Operation, tf.Tensor)

(tops, check_types=None, none_if_empty=False)

Source from the content-addressed store, hash-verified

184
185
186def get_unique_graph(tops, check_types=None, none_if_empty=False):
187 """Return the unique graph used by the all the elements in tops.
188
189 Args:
190 tops: list of elements to check (usually a list of tf.Operation and/or
191 tf.Tensor). Or a tf.Graph.
192 check_types: check that the element in tops are of given type(s). If None,
193 the types (tf.Operation, tf.Tensor) are used.
194 none_if_empty: don't raise an error if tops is an empty list, just return
195 None.
196 Returns:
197 The unique graph used by all the tops.
198 Raises:
199 TypeError: if tops is not a iterable of tf.Operation.
200 ValueError: if the graph is not unique.
201 """
202 if isinstance(tops, tf_ops.Graph):
203 return tops
204 if not is_iterable(tops):
205 raise TypeError("{} is not iterable".format(type(tops)))
206 if check_types is None:
207 check_types = (tf_ops.Operation, tf_ops.Tensor)
208 elif not is_iterable(check_types):
209 check_types = (check_types,)
210 g = None
211 for op in tops:
212 if not isinstance(op, check_types):
213 raise TypeError("Expected a type in ({}), got: {}".format(", ".join([str(
214 t) for t in check_types]), type(op)))
215 if g is None:
216 g = op.graph
217 elif g is not op.graph:
218 raise ValueError("Operation {} does not belong to given graph".format(op))
219 if g is None and not none_if_empty:
220 raise ValueError("Can't find the unique graph of an empty list")
221 return g
222
223
224def make_list_of_op(ops, check_graph=True, allow_graph=True, ignore_ts=False):

Callers 2

make_list_of_opFunction · 0.70
make_list_of_tFunction · 0.70

Calls 4

typeFunction · 0.85
is_iterableFunction · 0.70
formatMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected