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

Function Prepare

tensorflow/lite/kernels/mirror_pad.cc:252–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250}
251
252TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
253 const TfLiteTensor* input_tensor = GetInput(context, node, 0);
254 const TfLiteTensor* padding_matrix = GetInput(context, node, 1);
255 TfLiteTensor* output_tensor = GetOutput(context, node, 0);
256 OpData* op_data = reinterpret_cast<OpData*>(node->user_data);
257
258 TF_LITE_ENSURE_EQ(context, NumDimensions(padding_matrix), 2);
259 TF_LITE_ENSURE_EQ(context, SizeOfDimension(padding_matrix, 0),
260 NumDimensions(input_tensor));
261
262 TfLiteIntArrayFree(node->temporaries);
263 node->temporaries = TfLiteIntArrayCreate(1);
264 node->temporaries->data[0] = op_data->cache_tensor_index;
265
266 int num_elements = NumElements(input_tensor) * NumDimensions(input_tensor);
267 TfLiteIntArray* cache_dims = TfLiteIntArrayCreate(1);
268 cache_dims->data[0] = (num_elements + 1);
269
270 TfLiteTensor* cache = &context->tensors[op_data->cache_tensor_index];
271 cache->type = kTfLiteInt64;
272 cache->allocation_type = kTfLiteArenaRw;
273 TF_LITE_ENSURE_OK(context, context->ResizeTensor(context, cache, cache_dims));
274
275 if (!IsConstantTensor(padding_matrix)) {
276 SetTensorToDynamic(output_tensor);
277 return kTfLiteOk;
278 }
279 // We have constant padding, so we can infer output size.
280
281 auto output_size = GetPaddedOutputShape(input_tensor, padding_matrix);
282 if (output_size == nullptr) {
283 return kTfLiteError;
284 }
285 return context->ResizeTensor(context, output_tensor, output_size.release());
286}
287
288} // namespace mirror_pad
289TfLiteRegistration* Register_MIRROR_PAD() {

Callers

nothing calls this directly

Calls 12

GetInputFunction · 0.85
GetOutputFunction · 0.85
NumDimensionsFunction · 0.85
SizeOfDimensionFunction · 0.85
TfLiteIntArrayFreeFunction · 0.85
TfLiteIntArrayCreateFunction · 0.85
SetTensorToDynamicFunction · 0.85
GetPaddedOutputShapeFunction · 0.85
ResizeTensorMethod · 0.80
NumElementsFunction · 0.70
IsConstantTensorFunction · 0.70
releaseMethod · 0.45

Tested by

no test coverage detected