| 61 | } |
| 62 | |
| 63 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { |
| 64 | auto* params = reinterpret_cast<TfLiteDivParams*>(node->builtin_data); |
| 65 | OpData* data = reinterpret_cast<OpData*>(node->user_data); |
| 66 | |
| 67 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); |
| 68 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
| 69 | |
| 70 | const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1); |
| 71 | const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2); |
| 72 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 73 | |
| 74 | TF_LITE_ENSURE_EQ(context, input1->type, input2->type); |
| 75 | output->type = input2->type; |
| 76 | |
| 77 | data->requires_broadcast = !HaveSameShapes(input1, input2); |
| 78 | |
| 79 | TfLiteIntArray* output_size = nullptr; |
| 80 | if (data->requires_broadcast) { |
| 81 | TF_LITE_ENSURE_OK(context, CalculateShapeForBroadcast( |
| 82 | context, input1, input2, &output_size)); |
| 83 | } else { |
| 84 | output_size = TfLiteIntArrayCopy(input1->dims); |
| 85 | } |
| 86 | |
| 87 | if (output->type == kTfLiteUInt8) { |
| 88 | CalculateActivationRangeUint8(params->activation, output, |
| 89 | &data->output_activation_min, |
| 90 | &data->output_activation_max); |
| 91 | const double real_multiplier = |
| 92 | input1->params.scale / (input2->params.scale * output->params.scale); |
| 93 | QuantizeMultiplier(real_multiplier, &data->output_multiplier, |
| 94 | &data->output_shift); |
| 95 | } |
| 96 | |
| 97 | return context->ResizeTensor(context, output, output_size); |
| 98 | } |
| 99 | |
| 100 | template <KernelType kernel_type> |
| 101 | void EvalDiv(TfLiteContext* context, TfLiteNode* node, TfLiteDivParams* params, |
nothing calls this directly
no test coverage detected