neg.cc 2.2 KB

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