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

Function Prepare

tensorflow/lite/kernels/gather_nd.cc:30–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28constexpr int kOutputTensor = 0;
29
30TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
31 TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
32 TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
33
34 const TfLiteTensor* params = GetInput(context, node, kParams);
35 const TfLiteTensor* indices = GetInput(context, node, kIndices);
36 TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
37
38 switch (params->type) {
39 case kTfLiteFloat32:
40 case kTfLiteUInt8:
41 case kTfLiteInt8:
42 case kTfLiteInt64:
43 case kTfLiteInt32:
44 break;
45 default:
46 context->ReportError(
47 context, "Params of type '%s' are not supported by gather_nd.",
48 TfLiteTypeGetName(params->type));
49 return kTfLiteError;
50 }
51 switch (indices->type) {
52 case kTfLiteInt64:
53 case kTfLiteInt32:
54 break;
55 default:
56 context->ReportError(
57 context, "Indices of type '%s' are not supported by gather_nd.",
58 TfLiteTypeGetName(indices->type));
59 return kTfLiteError;
60 }
61
62 const int params_rank = NumDimensions(params);
63 const int indices_rank = NumDimensions(indices);
64 const int indices_nd = SizeOfDimension(indices, indices_rank - 1);
65 if (params_rank < 1) {
66 context->ReportError(context, "Params must be at least a vector.");
67 return kTfLiteError;
68 }
69 if (indices_rank < 1) {
70 context->ReportError(context, "Indices must be at least a vector.");
71 return kTfLiteError;
72 }
73 if (indices_nd > params_rank) {
74 context->ReportError(
75 context, "Index innermost dimension length must be <= params rank.");
76 return kTfLiteError;
77 }
78
79 // Assign to output the input type.
80 output->type = params->type;
81
82 // The result shape is
83 // indices.shape[:-1] + params.shape[indices.shape[-1]:]
84 const int output_rank = indices_rank + params_rank - indices_nd - 1;
85 TfLiteIntArray* output_shape = TfLiteIntArrayCreate(output_rank);
86 int output_index = 0;
87 for (int i = 0; i < indices_rank - 1; ++i) {

Callers

nothing calls this directly

Calls 10

NumInputsFunction · 0.85
GetInputFunction · 0.85
GetOutputFunction · 0.85
TfLiteTypeGetNameFunction · 0.85
NumDimensionsFunction · 0.85
SizeOfDimensionFunction · 0.85
TfLiteIntArrayCreateFunction · 0.85
ResizeTensorMethod · 0.80
NumOutputsFunction · 0.70
ReportErrorMethod · 0.45

Tested by

no test coverage detected