2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "kernels/LogicalOr.h"
19 #include "kernels/TestUtils.h"
20 #include "luci_interpreter/TestMemoryManager.h"
22 namespace luci_interpreter
29 using namespace testing;
31 class LogicalOrTest : public ::testing::Test
34 void SetUp() override { _memory_manager = std::make_unique<TestMemoryManager>(); }
36 std::unique_ptr<IMemoryManager> _memory_manager;
39 TEST_F(LogicalOrTest, Basic)
41 Tensor input1_tensor = makeInputTensor<DataType::BOOL>({1, 1, 1, 4}, {true, false, false, true},
42 _memory_manager.get());
43 Tensor input2_tensor = makeInputTensor<DataType::BOOL>({1, 1, 1, 4}, {true, false, true, false},
44 _memory_manager.get());
46 Tensor output_tensor = makeOutputTensor(DataType::BOOL);
48 LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor);
50 _memory_manager->allocate_memory(output_tensor);
53 EXPECT_THAT(extractTensorData<bool>(output_tensor),
54 ::testing::ElementsAre(true, false, true, true));
55 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4));
58 TEST_F(LogicalOrTest, Broadcast)
60 Tensor input1_tensor = makeInputTensor<DataType::BOOL>({1, 1, 1, 4}, {true, false, false, true},
61 _memory_manager.get());
62 Tensor input2_tensor =
63 makeInputTensor<DataType::BOOL>({1, 1, 1, 1}, {false}, _memory_manager.get());
65 Tensor output_tensor = makeOutputTensor(DataType::BOOL);
67 LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor);
69 _memory_manager->allocate_memory(output_tensor);
72 EXPECT_THAT(extractTensorData<bool>(output_tensor),
73 ::testing::ElementsAre(true, false, false, true));
74 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4));
77 TEST_F(LogicalOrTest, MismatchInputType_NEG)
79 Tensor input1_tensor =
80 makeInputTensor<DataType::S32>({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get());
81 Tensor input2_tensor =
82 makeInputTensor<DataType::BOOL>({1, 1, 1, 1}, {false}, _memory_manager.get());
84 Tensor output_tensor = makeOutputTensor(DataType::S32);
86 LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor);
87 EXPECT_ANY_THROW(kernel.configure());
90 TEST_F(LogicalOrTest, InputTypeInvalid_NEG)
92 Tensor input1_tensor =
93 makeInputTensor<DataType::S32>({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get());
94 Tensor input2_tensor = makeInputTensor<DataType::S32>({1, 1, 1, 1}, {0}, _memory_manager.get());
96 Tensor output_tensor = makeOutputTensor(DataType::BOOL);
98 LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor);
99 EXPECT_ANY_THROW(kernel.configure());
103 } // namespace kernels
104 } // namespace luci_interpreter