| 886 | } |
| 887 | |
| 888 | Status Conditional::BuildAndReplace( |
| 889 | Graph* graph, FunctionLibraryDefinition* library, |
| 890 | std::unordered_map<Node*, OutputTensor>* merge_to_replacement) { |
| 891 | VLOG(1) << "Build If and replace merge nodes " |
| 892 | << NodesToString(this->merges_); |
| 893 | if (replaced_) return Status::OK(); |
| 894 | |
| 895 | TF_RETURN_IF_ERROR(ExtractBodies(graph)); |
| 896 | TF_RETURN_IF_ERROR(BuildArgumentNodes()); |
| 897 | |
| 898 | if (VLOG_IS_ON(3)) { |
| 899 | LOG(INFO) << "Extracted bodies:"; |
| 900 | for (auto branch : {BranchType::kElseBranch, BranchType::kThenBranch}) { |
| 901 | int branch_index = static_cast<int>(branch); |
| 902 | auto output = bodies_[branch_index].get(); |
| 903 | LOG(INFO) << Branch_Name(branch) << ": " |
| 904 | << DebugString(output->ToGraphDefDebug()); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | TF_RETURN_IF_ERROR(BuildIfNode(graph, library)); |
| 909 | TF_RETURN_IF_ERROR(AddInputEdges(graph, *merge_to_replacement)); |
| 910 | TF_RETURN_IF_ERROR(AddOutputEdges(graph, merge_to_replacement)); |
| 911 | TF_RETURN_IF_ERROR(parent_->PropagateUpdatedState(if_node_)); |
| 912 | |
| 913 | // Check that the if_node doesn't feed into itself. |
| 914 | TF_RETURN_WITH_CONTEXT_IF_ERROR( |
| 915 | CheckNodeNotInCycle(if_node_, graph->num_node_ids()), |
| 916 | "Converting to If failed."); |
| 917 | |
| 918 | replaced_ = true; |
| 919 | return Status::OK(); |
| 920 | } |
| 921 | |
| 922 | string Conditional::name() const { |
| 923 | CHECK(!merges_.empty()); |
no test coverage detected