1 | /* Copyright 2018 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/c/common.h" |
17 | #include "tensorflow/lite/kernels/internal/optimized/optimized_ops.h" |
18 | #include "tensorflow/lite/kernels/internal/tensor.h" |
19 | #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" |
20 | #include "tensorflow/lite/kernels/kernel_util.h" |
21 | #include "tensorflow/lite/kernels/op_macros.h" |
22 | |
23 | namespace tflite { |
24 | namespace ops { |
25 | namespace builtin { |
26 | namespace ceil { |
27 | |
28 | constexpr int kInputTensor = 0; |
29 | constexpr int kOutputTensor = 0; |
30 | |
31 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { |
32 | const TfLiteTensor* input; |
33 | TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); |
34 | TfLiteTensor* output; |
35 | TF_LITE_ENSURE_OK(context, |
36 | GetOutputSafe(context, node, kOutputTensor, &output)); |
37 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); |
38 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
39 | TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); |
40 | output->type = input->type; |
41 | TfLiteIntArray* output_size = TfLiteIntArrayCopy(input->dims); |
42 | return context->ResizeTensor(context, output, output_size); |
43 | } |
44 | |
45 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
46 | const TfLiteTensor* input; |
47 | TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); |
48 | TfLiteTensor* output; |
49 | TF_LITE_ENSURE_OK(context, |
50 | GetOutputSafe(context, node, kOutputTensor, &output)); |
51 | if (input->type != kTfLiteFloat32) { |
52 | TF_LITE_UNSUPPORTED_TYPE(context, input->type, "Ceil" ); |
53 | } |
54 | |
55 | optimized_ops::Ceil(GetTensorShape(input), GetTensorData<float>(input), |
56 | GetTensorShape(output), GetTensorData<float>(output)); |
57 | |
58 | return kTfLiteOk; |
59 | } |
60 | } // namespace ceil |
61 | |
62 | TfLiteRegistration* Register_CEIL() { |
63 | static TfLiteRegistration r = {/*init=*/nullptr, |
64 | /*free=*/nullptr, ceil::Prepare, ceil::Eval}; |
65 | return &r; |
66 | } |
67 | |
68 | } // namespace builtin |
69 | } // namespace ops |
70 | } // namespace tflite |
71 | |