| 190 | } |
| 191 | |
| 192 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { |
| 193 | OpData* data = reinterpret_cast<OpData*>(node->user_data); |
| 194 | auto* params = reinterpret_cast<TfLiteSubParams*>(node->builtin_data); |
| 195 | |
| 196 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); |
| 197 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
| 198 | |
| 199 | const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1); |
| 200 | const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2); |
| 201 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 202 | |
| 203 | TF_LITE_ENSURE_EQ(context, input1->type, input2->type); |
| 204 | output->type = input2->type; |
| 205 | |
| 206 | data->requires_broadcast = !HaveSameShapes(input1, input2); |
| 207 | |
| 208 | TfLiteIntArray* output_size = nullptr; |
| 209 | if (data->requires_broadcast) { |
| 210 | TF_LITE_ENSURE_OK(context, CalculateShapeForBroadcast( |
| 211 | context, input1, input2, &output_size)); |
| 212 | } else { |
| 213 | output_size = TfLiteIntArrayCopy(input1->dims); |
| 214 | } |
| 215 | |
| 216 | if (output->type == kTfLiteUInt8 || output->type == kTfLiteInt8) { |
| 217 | TF_LITE_ENSURE_OK(context, Prepare8BitSubOp(context, input1, input2, output, |
| 218 | params, data, -1)); |
| 219 | } else if (output->type == kTfLiteInt16) { |
| 220 | TF_LITE_ENSURE_OK(context, PrepareInt16SubOp(context, input1, input2, |
| 221 | output, params, data)); |
| 222 | } |
| 223 | |
| 224 | return context->ResizeTensor(context, output, output_size); |
| 225 | } |
| 226 | |
| 227 | template <KernelType kernel_type> |
| 228 | void EvalSub(TfLiteContext* context, TfLiteNode* node, TfLiteSubParams* params, |
nothing calls this directly
no test coverage detected