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

Function InitializeTemporaries

tensorflow/lite/kernels/reduce.cc:163–208  ·  view source on GitHub ↗

Initializes temp tensors to store index and resolved axis.

Source from the content-addressed store, hash-verified

161
162// Initializes temp tensors to store index and resolved axis.
163TfLiteStatus InitializeTemporaries(TfLiteContext* context, TfLiteNode* node,
164 OpContext* op_context) {
165 // Creates a temp index to iterate through input data.
166 OpData* op_data = reinterpret_cast<OpData*>(node->user_data);
167 TfLiteIntArrayFree(node->temporaries);
168 node->temporaries = TfLiteIntArrayCreate(3);
169 node->temporaries->data[0] = op_data->scratch_tensor_index;
170 TfLiteTensor* scratch_tensor = GetTemporary(context, node, /*index=*/0);
171 scratch_tensor->type = kTfLiteInt32;
172 scratch_tensor->allocation_type = kTfLiteArenaRw;
173 TfLiteIntArray* index_size = TfLiteIntArrayCreate(1);
174 index_size->data[0] = NumDimensions(op_context->input);
175 TF_LITE_ENSURE_OK(context,
176 context->ResizeTensor(context, scratch_tensor, index_size));
177
178 // Creates a temp tensor to store resolved axis given input data.
179 node->temporaries->data[1] = op_data->scratch_tensor_index + 1;
180 TfLiteTensor* resolved_axis = GetTemporary(context, node, /*index=*/1);
181 resolved_axis->type = kTfLiteInt32;
182 // Creates a temp tensor to store temp sums when calculating mean.
183 node->temporaries->data[2] = op_data->scratch_tensor_index + 2;
184 TfLiteTensor* temp_sum = GetTemporary(context, node, /*index=*/2);
185 switch (op_context->input->type) {
186 case kTfLiteFloat32:
187 temp_sum->type = kTfLiteFloat32;
188 break;
189 case kTfLiteInt32:
190 temp_sum->type = kTfLiteInt64;
191 break;
192 case kTfLiteInt64:
193 temp_sum->type = kTfLiteInt64;
194 break;
195 case kTfLiteUInt8:
196 temp_sum->type = kTfLiteInt32;
197 break;
198 case kTfLiteInt8:
199 temp_sum->type = kTfLiteInt32;
200 break;
201 case kTfLiteBool:
202 temp_sum->type = kTfLiteBool;
203 break;
204 default:
205 return kTfLiteError;
206 }
207 return kTfLiteOk;
208}
209
210TfLiteStatus PrepareSimple(TfLiteContext* context, TfLiteNode* node) {
211 TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);

Callers 1

PrepareSimpleFunction · 0.85

Calls 5

TfLiteIntArrayFreeFunction · 0.85
TfLiteIntArrayCreateFunction · 0.85
GetTemporaryFunction · 0.85
NumDimensionsFunction · 0.85
ResizeTensorMethod · 0.80

Tested by

no test coverage detected