| 250 | } |
| 251 | |
| 252 | TfLiteStatus 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 |
| 289 | TfLiteRegistration* Register_MIRROR_PAD() { |
nothing calls this directly
no test coverage detected