| 907 | |
| 908 | template <KernelType kernel_type> |
| 909 | TfLiteStatus LogSoftmaxEval(TfLiteContext* context, TfLiteNode* node) { |
| 910 | const LogSoftmaxOpData* data = |
| 911 | reinterpret_cast<LogSoftmaxOpData*>(node->user_data); |
| 912 | const TfLiteTensor* input = GetInput(context, node, 0); |
| 913 | TfLiteTensor* output = GetOutput(context, node, 0); |
| 914 | switch (input->type) { |
| 915 | case kTfLiteFloat32: { |
| 916 | SoftmaxParams op_params; |
| 917 | if (kernel_type == kGenericOptimized) { |
| 918 | optimized_ops::LogSoftmax( |
| 919 | op_params, GetTensorShape(input), GetTensorData<float>(input), |
| 920 | GetTensorShape(output), GetTensorData<float>(output)); |
| 921 | } else { |
| 922 | reference_ops::LogSoftmax( |
| 923 | op_params, GetTensorShape(input), GetTensorData<float>(input), |
| 924 | GetTensorShape(output), GetTensorData<float>(output)); |
| 925 | } |
| 926 | return kTfLiteOk; |
| 927 | } |
| 928 | case kTfLiteUInt8: { |
| 929 | SoftmaxParams op_params; |
| 930 | op_params.input_multiplier = data->input_multiplier; |
| 931 | op_params.input_left_shift = data->input_left_shift; |
| 932 | op_params.reverse_scaling_divisor = data->reverse_scaling_divisor; |
| 933 | op_params.reverse_scaling_right_shift = data->reverse_scaling_right_shift; |
| 934 | op_params.diff_min = data->diff_min; |
| 935 | if (kernel_type == kGenericOptimized) { |
| 936 | optimized_ops::LogSoftmax( |
| 937 | op_params, GetTensorShape(input), GetTensorData<uint8_t>(input), |
| 938 | GetTensorShape(output), GetTensorData<uint8_t>(output)); |
| 939 | } else { |
| 940 | reference_ops::LogSoftmax( |
| 941 | op_params, GetTensorShape(input), GetTensorData<uint8_t>(input), |
| 942 | GetTensorShape(output), GetTensorData<uint8_t>(output)); |
| 943 | } |
| 944 | return kTfLiteOk; |
| 945 | } |
| 946 | case kTfLiteInt8: { |
| 947 | const auto input_shape = GetTensorShape(input); |
| 948 | const auto output_shape = GetTensorShape(output); |
| 949 | const int trailing_dim = input_shape.DimensionsCount() - 1; |
| 950 | const int outer_size = |
| 951 | MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); |
| 952 | const int depth = |
| 953 | MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); |
| 954 | reference_integer_ops::LogSoftmax( |
| 955 | data->input_multiplier, data->input_left_shift, |
| 956 | data->reverse_scaling_divisor, data->reverse_scaling_right_shift, |
| 957 | data->diff_min, outer_size, depth, GetTensorData<int8_t>(input), |
| 958 | GetTensorData<int8_t>(output)); |
| 959 | return kTfLiteOk; |
| 960 | } |
| 961 | default: |
| 962 | context->ReportError( |
| 963 | context, |
| 964 | "Only float32, uint8 and int8 are supported currently, got %s.", |
| 965 | TfLiteTypeGetName(input->type)); |
| 966 | return kTfLiteError; |
nothing calls this directly
no test coverage detected