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)
| 184 | |
| 185 | |
| 186 | def 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 | |
| 224 | def make_list_of_op(ops, check_graph=True, allow_graph=True, ignore_ts=False): |
no test coverage detected