Returns the index of the OpCode. If a OpCode doesn't exist, adds it and returns its index.
| 32 | // Returns the index of the OpCode. |
| 33 | // If a OpCode doesn't exist, adds it and returns its index. |
| 34 | int32_t GetOrInsertOpCodeIndex(ModelT* model, const BuiltinOperator& op_code, |
| 35 | int32_t version) { |
| 36 | for (size_t i = 0; i < model->operator_codes.size(); ++i) { |
| 37 | if (model->operator_codes[i]->builtin_code == op_code) { |
| 38 | return i; |
| 39 | } |
| 40 | } |
| 41 | model->operator_codes.push_back(absl::make_unique<OperatorCodeT>()); |
| 42 | int op_code_idx = model->operator_codes.size() - 1; |
| 43 | model->operator_codes[op_code_idx]->builtin_code = op_code; |
| 44 | // Version 2 and onwards supports INT8 inputs. |
| 45 | model->operator_codes[op_code_idx]->version = version; |
| 46 | |
| 47 | // Return the index of the newly placed OperatorCodeT. |
| 48 | return op_code_idx; |
| 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 |
no test coverage detected