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/c_api_internal.h" 17 #include "tensorflow/lite/kernels/internal/optimized/optimized_ops.h" 18 #include "tensorflow/lite/kernels/internal/reference/reference_ops.h" 19 #include "tensorflow/lite/kernels/internal/tensor.h" 20 #include "tensorflow/lite/kernels/kernel_util.h" 21 22 namespace tflite { 23 namespace ops { 24 namespace builtin { 25 namespace floor { 26 27 constexpr int kInputTensor = 0; 28 constexpr int kOutputTensor = 0; 29 30 enum KernelType { 31 kReference, 32 kGenericOptimized, 33 }; 34 35 TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { 36 const TfLiteTensor* input = GetInput(context, node, kInputTensor); 37 TfLiteTensor* output = GetOutput(context, node, kOutputTensor); 38 TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); 39 TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); 40 TF_LITE_ENSURE_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 46 template <KernelType type> 47 TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { 48 const TfLiteTensor* input = GetInput(context, node, kInputTensor); 49 TfLiteTensor* output = GetOutput(context, node, kOutputTensor); 50 51 if (type == kGenericOptimized) { 52 optimized_ops::Floor(GetTensorShape(input), GetTensorData<float>(input), 53 GetTensorShape(output), GetTensorData<float>(output)); 54 } else { 55 reference_ops::Floor(GetTensorShape(input), GetTensorData<float>(input), 56 GetTensorShape(output), GetTensorData<float>(output)); 57 } 58 59 return kTfLiteOk; 60 } 61 } // namespace floor 62 63 TfLiteRegistration* Register_FLOOR_REF() { 64 static TfLiteRegistration r = {/*init=*/nullptr, 65 /*free=*/nullptr, floor::Prepare, 66 floor::Eval<floor::kReference>}; 67 return &r; 68 } 69 70 TfLiteRegistration* Register_FLOOR() { 71 static TfLiteRegistration r = {/*init=*/nullptr, 72 /*free=*/nullptr, floor::Prepare, 73 floor::Eval<floor::kGenericOptimized>}; 74 return &r; 75 } 76 77 } // namespace builtin 78 } // namespace ops 79 } // namespace tflite 80