| 71 | |
| 72 | template <KernelType kernel_type> |
| 73 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
| 74 | const TfLiteTensor* input = GetInput(context, node, kInputTensor); |
| 75 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 76 | |
| 77 | if (output->type == kTfLiteFloat32) { |
| 78 | #define TF_LITE_L2NORM(type) \ |
| 79 | tflite::L2NormalizationParams op_params; \ |
| 80 | op_params.input_zero_point = 0; \ |
| 81 | type::L2Normalization(op_params, GetTensorShape(input), \ |
| 82 | GetTensorData<float>(input), GetTensorShape(output), \ |
| 83 | GetTensorData<float>(output)) |
| 84 | |
| 85 | if (kernel_type == kReference) { |
| 86 | TF_LITE_L2NORM(reference_ops); |
| 87 | } |
| 88 | if (kernel_type == kGenericOptimized) { |
| 89 | TF_LITE_L2NORM(optimized_ops); |
| 90 | } |
| 91 | #undef TF_LITE_L2NORM |
| 92 | } else if (output->type == kTfLiteUInt8) { |
| 93 | #define TF_LITE_L2NORM(type) \ |
| 94 | tflite::L2NormalizationParams op_params; \ |
| 95 | op_params.input_zero_point = input->params.zero_point; \ |
| 96 | type::L2Normalization(op_params, GetTensorShape(input), \ |
| 97 | GetTensorData<uint8>(input), GetTensorShape(output), \ |
| 98 | GetTensorData<uint8>(output)) |
| 99 | |
| 100 | if (kernel_type == kReference) { |
| 101 | TF_LITE_L2NORM(reference_ops); |
| 102 | } |
| 103 | if (kernel_type == kGenericOptimized) { |
| 104 | TF_LITE_L2NORM(optimized_ops); |
| 105 | } |
| 106 | #undef TF_LITE_L2NORM |
| 107 | } else if (output->type == kTfLiteInt8) { |
| 108 | const auto input_shape = GetTensorShape(input); |
| 109 | const auto output_shape = GetTensorShape(output); |
| 110 | const int trailing_dim = input_shape.DimensionsCount() - 1; |
| 111 | const int depth = |
| 112 | MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); |
| 113 | const int outer_size = |
| 114 | MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); |
| 115 | reference_integer_ops::L2Normalization(input->params.zero_point, outer_size, |
| 116 | depth, GetTensorData<int8>(input), |
| 117 | GetTensorData<int8>(output)); |
| 118 | } else { |
| 119 | context->ReportError(context, "Output type is %d, requires float.", |
| 120 | output->type); |
| 121 | return kTfLiteError; |
| 122 | } |
| 123 | |
| 124 | return kTfLiteOk; |
| 125 | } |
| 126 | |
| 127 | } // namespace l2norm |
| 128 |
nothing calls this directly
no test coverage detected