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