Compute the tensors at the boundary of a set of ops. This function looks at all the tensors connected to the given ops (in/out) and classify them into three categories: 1) input tensors: tensors whose generating operation is not in ops. 2) output tensors: tensors whose consumer operations a
(ops)
| 278 | |
| 279 | |
| 280 | def compute_boundary_ts(ops): |
| 281 | """Compute the tensors at the boundary of a set of ops. |
| 282 | |
| 283 | This function looks at all the tensors connected to the given ops (in/out) |
| 284 | and classify them into three categories: |
| 285 | 1) input tensors: tensors whose generating operation is not in ops. |
| 286 | 2) output tensors: tensors whose consumer operations are not in ops |
| 287 | 3) inside tensors: tensors which are neither input nor output tensors. |
| 288 | |
| 289 | Note that a tensor can be both an inside tensor and an output tensor if it is |
| 290 | consumed by operations both outside and inside of `ops`. |
| 291 | |
| 292 | Args: |
| 293 | ops: an object convertible to a list of tf.Operation. |
| 294 | Returns: |
| 295 | A tuple `(outside_input_ts, outside_output_ts, inside_ts)` where: |
| 296 | `outside_input_ts` is a Python list of input tensors; |
| 297 | `outside_output_ts` is a python list of output tensors; |
| 298 | `inside_ts` is a python list of inside tensors. |
| 299 | Since a tensor can be both an inside tensor and an output tensor, |
| 300 | `outside_output_ts` and `inside_ts` might intersect. |
| 301 | Raises: |
| 302 | TypeError: if ops cannot be converted to a list of tf.Operation. |
| 303 | """ |
| 304 | ops = util.make_list_of_op(ops) |
| 305 | input_ts = _get_input_ts(ops) |
| 306 | output_ts = _get_output_ts(ops) |
| 307 | output_ts_set = frozenset(output_ts) |
| 308 | ops_set = frozenset(ops) |
| 309 | |
| 310 | # Compute inside tensors. |
| 311 | inside_ts = [] |
| 312 | only_inside_ts = [] |
| 313 | for t in input_ts: |
| 314 | # Skip if the input tensor is not also an output tensor. |
| 315 | if t not in output_ts_set: |
| 316 | continue |
| 317 | # Mark as "inside". |
| 318 | inside_ts.append(t) |
| 319 | # Mark as "only inside" if the tensor is not both inside and output. |
| 320 | consumers = frozenset(t.consumers()) |
| 321 | if consumers - ops_set: |
| 322 | continue |
| 323 | only_inside_ts.append(t) |
| 324 | |
| 325 | inside_ts_set = frozenset(inside_ts) |
| 326 | only_inside_ts_set = frozenset(only_inside_ts) |
| 327 | outside_output_ts = [t for t in output_ts if t not in only_inside_ts_set] |
| 328 | outside_input_ts = [t for t in input_ts if t not in inside_ts_set] |
| 329 | return outside_input_ts, outside_output_ts, inside_ts |
| 330 | |
| 331 | |
| 332 | def get_within_boundary_ops(ops, |
nothing calls this directly
no test coverage detected