| 199 | } |
| 200 | |
| 201 | bool Compare(const GraphDef& g1, const GraphDef& g2) { |
| 202 | if (g1.node_size() != g2.node_size()) { |
| 203 | return false; |
| 204 | } |
| 205 | std::vector<int> name_index1 = CreateNameIndex(g1); |
| 206 | std::vector<int> name_index2 = CreateNameIndex(g2); |
| 207 | for (int i = 0; i < g1.node_size(); ++i) { |
| 208 | int idx1 = name_index1[i]; |
| 209 | int idx2 = name_index2[i]; |
| 210 | if (g1.node(idx1).op() != g2.node(idx2).op()) { |
| 211 | return false; |
| 212 | } |
| 213 | if (g1.node(idx1).name() != g2.node(idx2).name()) { |
| 214 | return false; |
| 215 | } |
| 216 | if (g1.node(idx1).input_size() != g2.node(idx2).input_size()) { |
| 217 | return false; |
| 218 | } |
| 219 | std::vector<int> input_index1 = CreateInputIndex(g1.node(idx1)); |
| 220 | std::vector<int> input_index2 = CreateInputIndex(g2.node(idx2)); |
| 221 | for (int j = 0; j < g1.node(idx1).input_size(); ++j) { |
| 222 | if (!IsSameInput(g1.node(idx1).input(input_index1[j]), |
| 223 | g2.node(idx2).input(input_index2[j]))) { |
| 224 | return false; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | bool ContainsGraphFunctionWithName(StringPiece name, |
| 232 | const FunctionDefLibrary& library) { |