| 519 | } |
| 520 | |
| 521 | Status GraphConstructor::EnsureNoNameCollisions() { |
| 522 | existing_nodes_.reserve(g_->num_nodes()); |
| 523 | // Populate existing_nodes_ and existing_prefixes_. |
| 524 | for (Node* n : g_->nodes()) { |
| 525 | bool already_exists = !existing_nodes_.insert({n->name(), n}).second; |
| 526 | if (already_exists) { |
| 527 | if (NodeNameInValues(opts_.input_map, n->name())) { |
| 528 | return errors::InvalidArgument( |
| 529 | "cannot resolve input_map because multiple nodes exist with name '", |
| 530 | n->name(), "'"); |
| 531 | } |
| 532 | if (NodeNameInValues(opts_.control_dependencies, n->name())) { |
| 533 | return errors::InvalidArgument( |
| 534 | "cannot resolve control_dependencies because multiple nodes exist " |
| 535 | "with name '", |
| 536 | n->name(), "'"); |
| 537 | } |
| 538 | } |
| 539 | AddPrefixes(n->name(), &existing_prefixes_); |
| 540 | } |
| 541 | if (prefix_.empty() && opts_.importing && !opts_.uniquify_names) { |
| 542 | for (size_t i = 0; i < node_def_count(); ++i) { |
| 543 | const string& name = get_node_def(i).name(); |
| 544 | if (NameExistsInGraph(name)) { |
| 545 | return errors::InvalidArgument("Node name '", name, |
| 546 | "' already exists in the Graph"); |
| 547 | } |
| 548 | } |
| 549 | } else if (!prefix_.empty()) { |
| 550 | StringPiece prefix_no_slash(prefix_); |
| 551 | prefix_no_slash.remove_suffix(1); |
| 552 | if (!IsValidNodeName(prefix_no_slash, false)) { |
| 553 | return errors::InvalidArgument("Imported node name prefix '", prefix_, |
| 554 | "' would lead to invalid node names"); |
| 555 | } |
| 556 | if (NameExistsInGraph(prefix_no_slash) && opts_.uniquify_prefix) { |
| 557 | prefix_ = strings::StrCat(FindUniqueName(prefix_no_slash), "/"); |
| 558 | } |
| 559 | } |
| 560 | return Status::OK(); |
| 561 | } |
| 562 | |
| 563 | Status GraphConstructor::ValidateInputMapAndControlDependencies() { |
| 564 | for (const auto& mapping : opts_.input_map) { |
nothing calls this directly
no test coverage detected