MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Prepare

Function Prepare

tensorflow/lite/kernels/arg_min_max.cc:51–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51TfLiteStatus 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
106template <typename T>
107std::function<bool(T, T)> GetComparefunction(bool is_arg_max) {

Callers

nothing calls this directly

Calls 10

NumInputsFunction · 0.85
GetInputFunction · 0.85
GetOutputFunction · 0.85
NumDimensionsFunction · 0.85
SetTensorToDynamicFunction · 0.85
NumOutputsFunction · 0.70
NumElementsFunction · 0.70
IsConstantTensorFunction · 0.70
ResizeOutputFunction · 0.70
ReportErrorMethod · 0.45

Tested by

no test coverage detected