PRECONDITION: Node input orders are assumed to be canonicalized, i.e. control inputs for all nodes as well as regular inputs for commutative nodes must be sorted.
| 3525 | // Node input orders are assumed to be canonicalized, i.e. control inputs for |
| 3526 | // all nodes as well as regular inputs for commutative nodes must be sorted. |
| 3527 | bool UniqueNodes::SameNode(const NodeDef& node1, const NodeDef& node2) const { |
| 3528 | if (node1.op() != node2.op()) { |
| 3529 | return false; |
| 3530 | } |
| 3531 | if (node1.device() != node2.device()) { |
| 3532 | return false; |
| 3533 | } |
| 3534 | if (node1.input_size() != node2.input_size()) { |
| 3535 | return false; |
| 3536 | } |
| 3537 | |
| 3538 | int node1_attr_size = node1.attr_size(); |
| 3539 | int node2_attr_size = node2.attr_size(); |
| 3540 | // exclude 'stream_id' attribute |
| 3541 | for (const auto& attr : node1.attr()) { |
| 3542 | if (IsExcludeAttribute(attr.first)) { |
| 3543 | node1_attr_size -= 1; |
| 3544 | } |
| 3545 | } |
| 3546 | for (const auto& attr : node2.attr()) { |
| 3547 | if (IsExcludeAttribute(attr.first)) { |
| 3548 | node2_attr_size -= 1; |
| 3549 | } |
| 3550 | } |
| 3551 | if (node1_attr_size != node2_attr_size) { |
| 3552 | return false; |
| 3553 | } |
| 3554 | |
| 3555 | // Compare inputs. |
| 3556 | auto it1 = node1.input().begin(); |
| 3557 | auto it2 = node2.input().begin(); |
| 3558 | for (; it1 != node1.input().end(); ++it1, ++it2) { |
| 3559 | if (*it1 != *it2) return false; |
| 3560 | } |
| 3561 | |
| 3562 | // Compare attributes. |
| 3563 | for (const auto& attr1 : node1.attr()) { |
| 3564 | // exclude 'stream_id' attribute |
| 3565 | if (IsExcludeAttribute(attr1.first)) |
| 3566 | continue; |
| 3567 | auto it = node2.attr().find(attr1.first); |
| 3568 | if (it == node2.attr().end()) return false; |
| 3569 | if (!FastAreAttrValuesEqual(attr1.second, it->second)) return false; |
| 3570 | } |
| 3571 | |
| 3572 | return true; |
| 3573 | } |
| 3574 | |
| 3575 | bool UniqueNodes::IsExcludeAttribute(const std::string& attr_name) const { |
| 3576 | if (exclude_attrs_.find(attr_name) != exclude_attrs_.end()) |
nothing calls this directly
no test coverage detected