Add the subgraph defined by fn() to the graph.
(self, fn)
| 1056 | return self._ProcessOutputTensor(ops.convert_to_tensor(v)) |
| 1057 | |
| 1058 | def BuildCondBranch(self, fn): |
| 1059 | """Add the subgraph defined by fn() to the graph.""" |
| 1060 | pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access |
| 1061 | original_result = fn() |
| 1062 | post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access |
| 1063 | if len(post_summaries) > len(pre_summaries): |
| 1064 | new_summaries = post_summaries[len(pre_summaries):] |
| 1065 | summary_ref = ops.get_collection_ref(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access |
| 1066 | summary_ref[:] = pre_summaries |
| 1067 | with ops.control_dependencies(new_summaries): |
| 1068 | if original_result is None: |
| 1069 | return no_op(), None |
| 1070 | else: |
| 1071 | original_result = nest.map_structure( |
| 1072 | array_ops.identity, original_result, expand_composites=True) |
| 1073 | if original_result is None: |
| 1074 | return None, None |
| 1075 | |
| 1076 | result = nest.map_structure( |
| 1077 | self._BuildCondTensor, original_result, expand_composites=True) |
| 1078 | if not isinstance(result, (list, _basetuple)): |
| 1079 | result = [result] |
| 1080 | return original_result, result |
| 1081 | |
| 1082 | def IsCondContext(self): |
| 1083 | return True |
no test coverage detected