Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / 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
20 namespace luci_interpreter
21 {
22 namespace kernels
23 {
24 namespace
25 {
26
27 using namespace testing;
28
29 template <typename T>
30 void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape,
31            std::initializer_list<T> input_data, std::initializer_list<T> output_data,
32            DataType element_type, std::vector<int32_t> squeeze_dims)
33 {
34   Tensor input_tensor{element_type, input_shape, {}, ""};
35   input_tensor.writeData(input_data.begin(), input_data.size() * sizeof(T));
36   Tensor output_tensor = makeOutputTensor(element_type);
37
38   SqueezeParams params{};
39   for (size_t i = 0; i < squeeze_dims.size(); i++)
40   {
41     params.squeeze_dims.push_back(squeeze_dims.at(i));
42   }
43
44   Squeeze kernel(&input_tensor, &output_tensor, params);
45   kernel.configure();
46   kernel.execute();
47
48   EXPECT_THAT(extractTensorData<T>(output_tensor), ::testing::ElementsAreArray(output_data));
49   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
50 }
51
52 template <typename T> class SqueezeTest : public ::testing::Test
53 {
54 };
55
56 using DataTypes = ::testing::Types<float, uint8_t>;
57 TYPED_TEST_CASE(SqueezeTest, DataTypes);
58
59 TYPED_TEST(SqueezeTest, TotalTest)
60 {
61   Check<TypeParam>(
62       /*input_shape=*/{1, 24, 1}, /*output_shape=*/{24},
63       /*input_data=*/{1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12,
64                       13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24},
65       /*output_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       getElementType<TypeParam>(), {-1, 0});
68 }
69
70 } // namespace
71 } // namespace kernels
72 } // namespace luci_interpreter