Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / LogicalNot.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "kernels/LogicalNot.h"
18
19 #include "kernels/Utils.h"
20
21 #include "kernels/BinaryOpCommon.h"
22
23 namespace luci_interpreter
24 {
25 namespace kernels
26 {
27
28 LogicalNot::LogicalNot(const Tensor *input, Tensor *output) : Kernel({input}, {output}) {}
29
30 void LogicalNot::configure()
31 {
32   LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
33   // TODO: enable it only if kernel with dynamic shapes
34   output()->resize(input()->shape());
35 }
36
37 void LogicalNot::execute() const
38 {
39   switch (input()->element_type())
40   {
41     case DataType::BOOL:
42       evalLogicalNot();
43       break;
44     default:
45       assert(false && "Unsupported type.");
46   }
47 }
48
49 inline void LogicalNot::evalLogicalNot() const
50 {
51   const int size = tflite::MatchingFlatSize(getTensorShape(input()), getTensorShape(output()));
52   bool *output_data = getTensorData<bool>(output());
53   const bool *input_data = getTensorData<bool>(input());
54   for (int i = 0; i < size; ++i)
55   {
56     output_data[i] = !input_data[i];
57   }
58 }
59
60 } // namespace kernels
61 } // namespace luci_interpreter