2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "kernels/HardSwish.h"
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/TestMemoryManager.h"
21 namespace luci_interpreter
28 using namespace testing;
30 void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape,
31 std::initializer_list<float> input_data, std::initializer_list<float> output_data)
33 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
35 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
36 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
38 HardSwish kernel(&input_tensor, &output_tensor);
40 memory_manager->allocate_memory(output_tensor);
44 EXPECT_THAT(extractTensorData<float>(output_tensor), FloatArrayNear(output_data));
47 TEST(HardSwishTest, SimpleHardSwish)
50 /*input_shape=*/{1, 2, 4, 1}, /*output_shape=*/{1, 2, 4, 1},
58 0, -0, 1.66667, -0, //
59 3, -0.333333, 10, -0.0483333, //
63 TEST(HardSwishTest, InOutTypeMismatch_NEG)
65 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
66 Shape input_shape{1, 2, 4, 1};
67 std::vector<float> input_data{
72 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
73 Tensor output_tensor = makeOutputTensor(DataType::U8);
75 HardSwish kernel(&input_tensor, &output_tensor);
76 EXPECT_ANY_THROW(kernel.configure());
80 } // namespace kernels
81 } // namespace luci_interpreter