1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/lite/kernels/internal/reference/neg.h"
17
18 #include "tensorflow/lite/c/common.h"
19 #include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
20 #include "tensorflow/lite/micro/kernels/kernel_util.h"
21
22 namespace tflite {
23 namespace ops {
24 namespace micro {
25 namespace neg {
26
27 constexpr int kInputTensor = 0;
28 constexpr int kOutputTensor = 0;
29
Eval(TfLiteContext * context,TfLiteNode * node)30 TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
31 const TfLiteEvalTensor* input =
32 tflite::micro::GetEvalInput(context, node, kInputTensor);
33 TfLiteEvalTensor* output =
34 tflite::micro::GetEvalOutput(context, node, kOutputTensor);
35 switch (input->type) {
36 // TODO(wangtz): handle for kTfLiteInt8
37 case kTfLiteFloat32:
38 reference_ops::Negate(tflite::micro::GetTensorShape(input),
39 tflite::micro::GetTensorData<float>(input),
40 tflite::micro::GetTensorShape(output),
41 tflite::micro::GetTensorData<float>(output));
42 break;
43 default:
44 TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.",
45 TfLiteTypeGetName(input->type), input->type);
46 return kTfLiteError;
47 }
48 return kTfLiteOk;
49 }
50
51 } // namespace neg
52
Register_NEG()53 TfLiteRegistration Register_NEG() {
54 return {/*init=*/nullptr,
55 /*free=*/nullptr,
56 /*prepare=*/nullptr,
57 /*invoke=*/neg::Eval,
58 /*profiling_string=*/nullptr,
59 /*builtin_code=*/0,
60 /*custom_name=*/nullptr,
61 /*version=*/0};
62 }
63
64 } // namespace micro
65 } // namespace ops
66 } // namespace tflite
67