| 449 | } |
| 450 | |
| 451 | Status MakeFunctionDefHelper::AsFunctionDefInput(const string& graph_def_input, |
| 452 | string* func_def_input) const { |
| 453 | if (IsControlInput(graph_def_input)) { |
| 454 | *func_def_input = graph_def_input; |
| 455 | return Status::OK(); |
| 456 | } |
| 457 | |
| 458 | const SafeTensorId tensor = ParseTensorName(graph_def_input); |
| 459 | DCHECK_GE(tensor.index(), 0); |
| 460 | |
| 461 | // Graph def input corresponds to one of the function inputs. |
| 462 | const auto is_input = input_nodes_.find(tensor.node()); |
| 463 | if (is_input != input_nodes_.end()) { |
| 464 | DCHECK_EQ(tensor.index(), 0); |
| 465 | *func_def_input = tensor.node(); |
| 466 | return Status::OK(); |
| 467 | } |
| 468 | |
| 469 | // Or it must be output from one of the function body nodes |
| 470 | const auto is_body_output = function_body_outputs_.find(tensor.node()); |
| 471 | if (is_body_output != function_body_outputs_.end()) { |
| 472 | const tensorflow::NameRangeMap& outputs_range_map = is_body_output->second; |
| 473 | |
| 474 | for (const auto& el : outputs_range_map) { |
| 475 | const auto& output_name = el.first; |
| 476 | const auto& output_range = el.second; |
| 477 | if (tensor.index() >= output_range.first && |
| 478 | tensor.index() < output_range.second) { |
| 479 | *func_def_input = absl::StrCat(tensor.node(), ":", output_name, ":", |
| 480 | tensor.index() - output_range.first); |
| 481 | return Status::OK(); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return errors::InvalidArgument("Unknown graph def input: ", graph_def_input); |
| 487 | } |
| 488 | |
| 489 | Status MakeFunctionDefHelper::AsFunctionDefNode( |
| 490 | NodeDef* function_body_node) const { |
no test coverage detected