Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
Change-Id: I92c88291217bef18a73809511a60f2a4af4a982d
  • Loading branch information
AdrianLundell committed Nov 18, 2024
1 parent 836e51a commit 31467fa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 59 deletions.
26 changes: 0 additions & 26 deletions tensorflow/lite/micro/kernels/cmsis_nn/transpose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,6 @@ limitations under the License.
namespace tflite {
namespace {

TfLiteStatus TransposePrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);

TransposeContext op_context(context, node);

// Ensure validity of input tensor.
TF_LITE_ENSURE_MSG(context, NumDimensions(op_context.input) <= 5,
"Transpose op only supports 1D-5D input arrays.");
TF_LITE_ENSURE_TYPES_EQ(context, op_context.input->type,
op_context.output->type);

int dims = NumDimensions(op_context.input);
const int32_t* perm_data = GetTensorData<int32_t>(op_context.perm);

// Ensure validity of the permutations tensor as a 1D tensor.
TF_LITE_ENSURE_EQ(context, NumDimensions(op_context.perm), 1);
TF_LITE_ENSURE_EQ(context, op_context.perm->dims->data[0], dims);
for (int idx = 0; idx < dims; ++idx) {
TF_LITE_ENSURE_MSG(context, (perm_data[idx] >= 0 && perm_data[idx] < dims),
"Transpose op permutations array is out of bounds.");
}

return kTfLiteOk;
}

TfLiteStatus TransposeEvalInt8(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* perm_tensor =
tflite::micro::GetEvalInput(context, node, kTransposePermTensor);
Expand Down
29 changes: 2 additions & 27 deletions tensorflow/lite/micro/kernels/transpose.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
/* Copyright 2024 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ limitations under the License.
#include "tensorflow/lite/kernels/internal/types.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/micro/kernels/kernel_util.h"
#include "tensorflow/lite/micro/kernels/transpose.h"
#include "tensorflow/lite/micro/micro_log.h"

namespace tflite {
Expand Down Expand Up @@ -46,32 +47,6 @@ struct TransposeContext {
TfLiteTensor* output;
};

TfLiteStatus TransposePrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);

TransposeContext op_context(context, node);

// Ensure validity of input tensor.
TF_LITE_ENSURE_MSG(context, NumDimensions(op_context.input) <= 5,
"Transpose op only supports 1D-5D input arrays.");
TF_LITE_ENSURE_TYPES_EQ(context, op_context.input->type,
op_context.output->type);

int dims = NumDimensions(op_context.input);
const int32_t* perm_data = GetTensorData<int32_t>(op_context.perm);

// Ensure validity of the permutations tensor as a 1D tensor.
TF_LITE_ENSURE_EQ(context, NumDimensions(op_context.perm), 1);
TF_LITE_ENSURE_EQ(context, op_context.perm->dims->data[0], dims);
for (int idx = 0; idx < dims; ++idx) {
TF_LITE_ENSURE_MSG(context, (perm_data[idx] >= 0 && perm_data[idx] < dims),
"Transpose op permutations array is out of bounds.");
}

return kTfLiteOk;
}

TfLiteStatus TransposeEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* perm_tensor =
tflite::micro::GetEvalInput(context, node, kPermTensor);
Expand Down
7 changes: 1 addition & 6 deletions tensorflow/lite/micro/kernels/transpose.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ limitations under the License.
#define TENSORFLOW_LITE_MICRO_KERNELS_TRANSPOSE_H_

#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/kernels/internal/reference/transpose.h"
#include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
#include "tensorflow/lite/kernels/internal/types.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/micro/kernels/kernel_util.h"
#include "tensorflow/lite/micro/micro_log.h"

namespace tflite {

Expand All @@ -49,6 +43,7 @@ struct TransposeContext {
TfLiteTensor* output;
};

TfLiteStatus TransposePrepare(TfLiteContext* context, TfLiteNode* node);
TFLMRegistration Register_TRANSPOSE();

#if defined(CMSIS_NN)
Expand Down

0 comments on commit 31467fa

Please sign in to comment.