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

Function Eval

tensorflow/lite/kernels/topk_v2.cc:212–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210}
211
212TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
213 TfLiteTensor* output_values = GetOutput(context, node, kOutputValues);
214 TfLiteTensor* output_indexes = GetOutput(context, node, kOutputIndexes);
215 if (IsDynamicTensor(output_values)) {
216 TF_LITE_ENSURE_OK(context, ResizeOutput(context, node));
217 }
218 const TfLiteTensor* top_k = GetInput(context, node, kInputTopK);
219 const int32 k = top_k->data.i32[0];
220 // The tensor can have more than 2 dimensions or even be a vector, the code
221 // anyway calls the internal dimension as row;
222 const TfLiteTensor* input = GetInput(context, node, kInputTensor);
223 const int32 row_size = input->dims->data[input->dims->size - 1];
224 int32 num_rows = 1;
225 for (int i = 0; i < input->dims->size - 1; ++i) {
226 num_rows *= input->dims->data[i];
227 }
228 switch (output_values->type) {
229 case kTfLiteFloat32:
230 TopK(row_size, num_rows, input->data.f, k, output_indexes->data.i32,
231 output_values->data.f);
232 break;
233 case kTfLiteUInt8:
234 TopK(row_size, num_rows, input->data.uint8, k, output_indexes->data.i32,
235 output_values->data.uint8);
236 break;
237 case kTfLiteInt8:
238 TopK(row_size, num_rows, input->data.int8, k, output_indexes->data.i32,
239 output_values->data.int8);
240 break;
241 case kTfLiteInt32:
242 TopK(row_size, num_rows, input->data.i32, k, output_indexes->data.i32,
243 output_values->data.i32);
244 break;
245 case kTfLiteInt64:
246 TopK(row_size, num_rows, input->data.i64, k, output_indexes->data.i32,
247 output_values->data.i64);
248 break;
249 default:
250 context->ReportError(context,
251 "Type %d is currently not supported by TopK.",
252 output_values->type);
253 return kTfLiteError;
254 }
255
256 return kTfLiteOk;
257}
258} // namespace topk_v2
259TfLiteRegistration* Register_TOPK_V2() {
260 static TfLiteRegistration r = {nullptr, nullptr, topk_v2::Prepare,

Callers

nothing calls this directly

Calls 6

GetOutputFunction · 0.85
IsDynamicTensorFunction · 0.85
GetInputFunction · 0.85
ResizeOutputFunction · 0.70
TopKFunction · 0.70
ReportErrorMethod · 0.45

Tested by

no test coverage detected