| 106 | } // namespace |
| 107 | |
| 108 | bool EqualNodeDef(const NodeDef& actual, const NodeDef& expected, string* diff, |
| 109 | const EqualGraphDefOptions& options) { |
| 110 | if (actual.name() != expected.name()) { |
| 111 | if (diff != nullptr) { |
| 112 | *diff = strings::StrCat("Actual node name '", actual.name(), |
| 113 | "' is not expected '", expected.name(), "'"); |
| 114 | } |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | if (actual.op() != expected.op()) { |
| 119 | if (diff != nullptr) { |
| 120 | *diff = strings::StrCat("Node named '", actual.name(), "' has op '", |
| 121 | actual.op(), "' that is not expected '", |
| 122 | expected.op(), "'"); |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | if (actual.device() != expected.device()) { |
| 128 | if (diff != nullptr) { |
| 129 | *diff = strings::StrCat("Node named '", actual.name(), "' has device '", |
| 130 | actual.device(), "' that is not expected '", |
| 131 | expected.device(), "'"); |
| 132 | } |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | if (actual.input_size() != expected.input_size()) { |
| 137 | if (diff != nullptr) { |
| 138 | *diff = strings::StrCat("Node named '", actual.name(), "' has inputs '", |
| 139 | JoinStringField(actual.input()), |
| 140 | "' that don't match expected '", |
| 141 | JoinStringField(expected.input()), "'"); |
| 142 | } |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | int first_control_input = actual.input_size(); |
| 147 | for (int i = 0; i < actual.input_size(); ++i) { |
| 148 | if (absl::StartsWith(actual.input(i), "^")) { |
| 149 | first_control_input = i; |
| 150 | break; |
| 151 | } |
| 152 | // Special case for inputs: "tensor" is equivalent to "tensor:0" |
| 153 | if (actual.input(i) != expected.input(i) && |
| 154 | actual.input(i) != strings::StrCat(expected.input(i), ":0") && |
| 155 | strings::StrCat(actual.input(i), ":0") != expected.input(i)) { |
| 156 | if (diff != nullptr) { |
| 157 | *diff = strings::StrCat("Node named '", actual.name(), "' has input ", |
| 158 | i, " '", actual.input(i), |
| 159 | "' that doesn't match expected '", |
| 160 | expected.input(i), "'"); |
| 161 | } |
| 162 | return false; |
| 163 | } |
| 164 | } |
| 165 | |