| 290 | } |
| 291 | |
| 292 | Offset<Vector<Offset<OperatorCode>>> ExportOperatorCodes( |
| 293 | const Model& model, |
| 294 | const std::map<OperatorType, std::unique_ptr<BaseOperator>>& ops_by_type, |
| 295 | const details::OperatorsMap& operators_map, FlatBufferBuilder* builder, |
| 296 | const ExportParams& params) { |
| 297 | // Map from operator name to TF Lite enum value, for all builtins. |
| 298 | std::map<string, BuiltinOperator> builtin_ops; |
| 299 | for (int i = BuiltinOperator_MIN; i <= BuiltinOperator_MAX; ++i) { |
| 300 | BuiltinOperator op = static_cast<BuiltinOperator>(i); |
| 301 | string name = EnumNameBuiltinOperator(op); |
| 302 | if (op != BuiltinOperator_CUSTOM && !name.empty()) { |
| 303 | builtin_ops[name] = op; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // We will need to produce a vector of codes in the same order as they |
| 308 | // appear in the operators_map. |
| 309 | std::map<int, Offset<OperatorCode>> ordered_opcodes; |
| 310 | |
| 311 | for (const auto& op : model.operators) { |
| 312 | const toco::OperatorSignature op_signature = {op.get(), &model}; |
| 313 | const details::OperatorKey operator_key = details::OperatorKey( |
| 314 | op_signature, ops_by_type, params.enable_select_tf_ops); |
| 315 | int op_index = operators_map.at(operator_key); |
| 316 | |
| 317 | flatbuffers::Offset<flatbuffers::String> custom_code = 0; |
| 318 | if (!operator_key.custom_code().empty()) { |
| 319 | custom_code = builder->CreateString(operator_key.custom_code()); |
| 320 | } |
| 321 | |
| 322 | ordered_opcodes[op_index] = CreateOperatorCode( |
| 323 | *builder, operator_key.type(), custom_code, operator_key.version()); |
| 324 | } |
| 325 | |
| 326 | std::vector<Offset<OperatorCode>> opcode_vector; |
| 327 | opcode_vector.reserve(ordered_opcodes.size()); |
| 328 | for (const auto& opcode : ordered_opcodes) { |
| 329 | opcode_vector.push_back(opcode.second); |
| 330 | } |
| 331 | |
| 332 | return builder->CreateVector(opcode_vector); |
| 333 | } |
| 334 | |
| 335 | Offset<Vector<Offset<Operator>>> ExportOperators( |
| 336 | const Model& model, |
no test coverage detected