| 49 | } |
| 50 | |
| 51 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { |
| 52 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); |
| 53 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
| 54 | |
| 55 | const TfLiteTensor* input = GetInput(context, node, kInputTensor); |
| 56 | const TfLiteTensor* axis = GetInput(context, node, kAxis); |
| 57 | // Make sure the axis is only 1 dimension. |
| 58 | TF_LITE_ENSURE_EQ(context, NumElements(axis), 1); |
| 59 | // Make sure the axis is only either int32 or int64. |
| 60 | TF_LITE_ENSURE(context, |
| 61 | axis->type == kTfLiteInt32 || axis->type == kTfLiteInt64); |
| 62 | |
| 63 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 64 | |
| 65 | auto* params = reinterpret_cast<TfLiteArgMaxParams*>(node->builtin_data); |
| 66 | switch (params->output_type) { |
| 67 | case kTfLiteInt32: |
| 68 | output->type = kTfLiteInt32; |
| 69 | break; |
| 70 | case kTfLiteInt64: |
| 71 | output->type = kTfLiteInt64; |
| 72 | break; |
| 73 | default: |
| 74 | context->ReportError(context, "Unknown index output data type: %d", |
| 75 | params->output_type); |
| 76 | return kTfLiteError; |
| 77 | } |
| 78 | |
| 79 | // Check conditions for different types. |
| 80 | switch (input->type) { |
| 81 | case kTfLiteFloat32: |
| 82 | case kTfLiteUInt8: |
| 83 | case kTfLiteInt8: |
| 84 | case kTfLiteInt32: |
| 85 | break; |
| 86 | |
| 87 | default: |
| 88 | context->ReportError( |
| 89 | context, |
| 90 | "Unknown input type: %d, only float32 and int types are supported", |
| 91 | input->type); |
| 92 | return kTfLiteError; |
| 93 | } |
| 94 | |
| 95 | TF_LITE_ENSURE(context, NumDimensions(input) >= 1); |
| 96 | |
| 97 | if (IsConstantTensor(axis)) { |
| 98 | TF_LITE_ENSURE_STATUS(ResizeOutput(context, input, axis, output)); |
| 99 | } else { |
| 100 | SetTensorToDynamic(output); |
| 101 | } |
| 102 | |
| 103 | return kTfLiteOk; |
| 104 | } |
| 105 | |
| 106 | template <typename T> |
| 107 | std::function<bool(T, T)> GetComparefunction(bool is_arg_max) { |
nothing calls this directly
no test coverage detected