| 115 | } |
| 116 | |
| 117 | void FlexModelTest::AddTfOp(TfOpType op, const std::vector<int>& inputs, |
| 118 | const std::vector<int>& outputs) { |
| 119 | tf_ops_.push_back(next_op_index_); |
| 120 | ++next_op_index_; |
| 121 | |
| 122 | auto attr = [](const string& key, const string& value) { |
| 123 | return " attr{ key: '" + key + "' value {" + value + "}}"; |
| 124 | }; |
| 125 | |
| 126 | string type_attribute; |
| 127 | switch (interpreter_->tensor(inputs[0])->type) { |
| 128 | case kTfLiteInt32: |
| 129 | type_attribute = attr("T", "type: DT_INT32"); |
| 130 | break; |
| 131 | case kTfLiteFloat32: |
| 132 | type_attribute = attr("T", "type: DT_FLOAT"); |
| 133 | break; |
| 134 | case kTfLiteString: |
| 135 | type_attribute = attr("T", "type: DT_STRING"); |
| 136 | break; |
| 137 | default: |
| 138 | // TODO(b/113613439): Use nodedef string utilities to properly handle all |
| 139 | // types. |
| 140 | LOG(FATAL) << "Type not supported"; |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | if (op == kUnpack) { |
| 145 | string attributes = |
| 146 | type_attribute + attr("num", "i: 2") + attr("axis", "i: 0"); |
| 147 | AddTfOp("FlexUnpack", "Unpack", attributes, inputs, outputs); |
| 148 | } else if (op == kIdentity) { |
| 149 | string attributes = type_attribute; |
| 150 | AddTfOp("FlexIdentity", "Identity", attributes, inputs, outputs); |
| 151 | } else if (op == kAdd) { |
| 152 | string attributes = type_attribute; |
| 153 | AddTfOp("FlexAdd", "Add", attributes, inputs, outputs); |
| 154 | } else if (op == kMul) { |
| 155 | string attributes = type_attribute; |
| 156 | AddTfOp("FlexMul", "Mul", attributes, inputs, outputs); |
| 157 | } else if (op == kNonExistent) { |
| 158 | AddTfOp("NonExistentOp", "NonExistentOp", "", inputs, outputs); |
| 159 | } else if (op == kIncompatibleNodeDef) { |
| 160 | // "Cast" op is created without attributes - making it incompatible. |
| 161 | AddTfOp("FlexCast", "Cast", "", inputs, outputs); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void FlexModelTest::AddTfOp(const char* tflite_name, const string& tf_name, |
| 166 | const string& nodedef_str, |
nothing calls this directly
no test coverage detected