1/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#include "tensorflow/lite/kernels/internal/reference/round.h"
17
18#include "tensorflow/lite/c/common.h"
19#include "tensorflow/lite/kernels/internal/optimized/optimized_ops.h"
20#include "tensorflow/lite/kernels/internal/tensor.h"
21#include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
22#include "tensorflow/lite/kernels/kernel_util.h"
23
24namespace tflite {
25namespace ops {
26namespace builtin {
27namespace round {
28
29constexpr int kInputTensor = 0;
30constexpr int kOutputTensor = 0;
31
32TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
33 const TfLiteTensor* input;
34 TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input));
35 TfLiteTensor* output;
36 TF_LITE_ENSURE_OK(context,
37 GetOutputSafe(context, node, kOutputTensor, &output));
38 TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
39 TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
40 TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32);
41 output->type = input->type;
42 TfLiteIntArray* output_size = TfLiteIntArrayCopy(input->dims);
43 return context->ResizeTensor(context, output, output_size);
44}
45
46TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
47 const TfLiteTensor* input;
48 TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input));
49 TfLiteTensor* output;
50 TF_LITE_ENSURE_OK(context,
51 GetOutputSafe(context, node, kOutputTensor, &output));
52
53 optimized_ops::Round(GetTensorShape(input), GetTensorData<float>(input),
54 GetTensorShape(output), GetTensorData<float>(output));
55
56 return kTfLiteOk;
57}
58} // namespace round
59
60TfLiteRegistration* Register_ROUND() {
61 static TfLiteRegistration r = {/*init=*/nullptr,
62 /*free=*/nullptr, round::Prepare, round::Eval};
63 return &r;
64}
65
66} // namespace builtin
67} // namespace ops
68} // namespace tflite
69