Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / Squeeze.test.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/Squeeze.h"
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/TestMemoryManager.h"
20
21 namespace luci_interpreter
22 {
23 namespace kernels
24 {
25 namespace
26 {
27
28 using namespace testing;
29
30 template <typename T>
31 void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape,
32            std::initializer_list<T> input_data, std::initializer_list<T> output_data,
33            std::initializer_list<int32_t> squeeze_dims)
34 {
35   std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
36
37   constexpr DataType element_type = getElementType<T>();
38   Tensor input_tensor =
39     makeInputTensor<element_type>(input_shape, input_data, memory_manager.get());
40   Tensor output_tensor = makeOutputTensor(element_type);
41
42   SqueezeParams params{};
43   params.squeeze_dims = squeeze_dims;
44
45   Squeeze kernel(&input_tensor, &output_tensor, params);
46   kernel.configure();
47   memory_manager->allocate_memory(output_tensor);
48   kernel.execute();
49
50   EXPECT_THAT(extractTensorData<T>(output_tensor), ::testing::ElementsAreArray(output_data));
51   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
52 }
53
54 template <typename T> class SqueezeTest : public ::testing::Test
55 {
56 };
57
58 using DataTypes = ::testing::Types<float, uint8_t>;
59 TYPED_TEST_SUITE(SqueezeTest, DataTypes);
60
61 TYPED_TEST(SqueezeTest, TotalTest)
62 {
63   Check<TypeParam>(
64     /*input_shape=*/{1, 24, 1}, /*output_shape=*/{24},
65     /*input_data=*/{1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12,
66                     13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24},
67     /*output_data=*/{1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12,
68                      13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24},
69     {-1, 0});
70 }
71
72 } // namespace
73 } // namespace kernels
74 } // namespace luci_interpreter