diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-04-26 19:35:10 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-04-26 19:38:26 -0700 |
commit | e41e70ed9827b81a07c42f68def80f3f61b70375 (patch) | |
tree | 04fadd1f072d787c13f145ebf9c9f4a17008e9ab /tensorflow/contrib/lite/kernels/floor.cc | |
parent | 84b3322931fd6fd73ce4ab250a1bd3cdd6e138f6 (diff) |
Implement floor operator
PiperOrigin-RevId: 194490433
Diffstat (limited to 'tensorflow/contrib/lite/kernels/floor.cc')
-rw-r--r-- | tensorflow/contrib/lite/kernels/floor.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tensorflow/contrib/lite/kernels/floor.cc b/tensorflow/contrib/lite/kernels/floor.cc new file mode 100644 index 0000000000..4b4395f711 --- /dev/null +++ b/tensorflow/contrib/lite/kernels/floor.cc @@ -0,0 +1,58 @@ +/* Copyright 2018 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/contrib/lite/context.h" +#include "tensorflow/contrib/lite/kernels/internal/optimized/optimized_ops.h" +#include "tensorflow/contrib/lite/kernels/internal/tensor.h" +#include "tensorflow/contrib/lite/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace builtin { +namespace floor { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { + TfLiteTensor* input = GetInput(context, node, kInputTensor); + TfLiteTensor* output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + TF_LITE_ENSURE_EQ(context, input->type, kTfLiteFloat32); + output->type = input->type; + TfLiteIntArray* output_size = TfLiteIntArrayCopy(input->dims); + return context->ResizeTensor(context, output, output_size); +} + +TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { + TfLiteTensor* input = GetInput(context, node, kInputTensor); + TfLiteTensor* output = GetOutput(context, node, kOutputTensor); + + optimized_ops::Floor(GetTensorData<float>(input), GetTensorDims(input), + GetTensorData<float>(output), GetTensorDims(output)); + return kTfLiteOk; +} +} // namespace floor + +TfLiteRegistration* Register_FLOOR() { + static TfLiteRegistration r = {/*init=*/nullptr, + /*free=*/nullptr, floor::Prepare, floor::Eval}; + return &r; +} + +} // namespace builtin +} // namespace ops +} // namespace tflite |