| 28 | constexpr int kOutputTensor = 0; |
| 29 | |
| 30 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { |
| 31 | TfLitePackParams* data = |
| 32 | reinterpret_cast<TfLitePackParams*>(node->builtin_data); |
| 33 | |
| 34 | TF_LITE_ENSURE_EQ(context, NumInputs(node), data->values_count); |
| 35 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
| 36 | |
| 37 | const TfLiteTensor* input0 = GetInput(context, node, 0); |
| 38 | const int dimension_size = NumDimensions(input0) + 1; |
| 39 | if (data->axis < 0) { |
| 40 | data->axis += dimension_size; |
| 41 | } |
| 42 | TF_LITE_ENSURE(context, NumDimensions(input0) >= data->axis); |
| 43 | TF_LITE_ENSURE(context, data->axis >= 0); |
| 44 | |
| 45 | if (input0->type != kTfLiteInt32 && input0->type != kTfLiteFloat32 && |
| 46 | input0->type != kTfLiteUInt8 && input0->type != kTfLiteInt8 && |
| 47 | input0->type != kTfLiteInt16 && input0->type != kTfLiteInt64) { |
| 48 | context->ReportError(context, "Type '%s' is not supported by pack.", |
| 49 | TfLiteTypeGetName(input0->type)); |
| 50 | return kTfLiteError; |
| 51 | } |
| 52 | // Make sure all inputs have the same shape and type. |
| 53 | for (int i = 1; i < data->values_count; ++i) { |
| 54 | const TfLiteTensor* input = GetInput(context, node, i); |
| 55 | TF_LITE_ENSURE(context, HaveSameShapes(input0, input)); |
| 56 | TF_LITE_ENSURE_EQ(context, input0->type, input->type); |
| 57 | } |
| 58 | |
| 59 | // Resize output. rank R will become rank R + 1 |
| 60 | const TfLiteIntArray* input_shape = input0->dims; |
| 61 | TfLiteIntArray* output_shape = TfLiteIntArrayCreate(dimension_size); |
| 62 | int i = 0; |
| 63 | for (int index = 0; index < dimension_size; ++index) { |
| 64 | if (index == data->axis) { |
| 65 | output_shape->data[index] = data->values_count; |
| 66 | } else { |
| 67 | output_shape->data[index] = input_shape->data[i++]; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 72 | TF_LITE_ENSURE_EQ(context, output->type, input0->type); |
| 73 | |
| 74 | // Guarantee input/output quantization params match as we do not support |
| 75 | // packing quantized tensors. |
| 76 | for (int i = 0; i < data->values_count; i++) { |
| 77 | const TfLiteTensor* input = GetInput(context, node, i); |
| 78 | TF_LITE_ENSURE_EQ(context, input->params.zero_point, |
| 79 | output->params.zero_point); |
| 80 | TF_LITE_ENSURE_EQ(context, input->params.scale, output->params.scale); |
| 81 | } |
| 82 | |
| 83 | return context->ResizeTensor(context, output, output_shape); |
| 84 | } |
| 85 | |
| 86 | template <typename T> |
| 87 | TfLiteStatus PackImpl(TfLiteContext* context, TfLiteNode* node, |
nothing calls this directly
no test coverage detected