Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / luci-interpreter / src / kernels / Concatenation.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/Concatenation.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 TEST(ConcatenationTest, Float)
30 {
31   std::vector<float> input1_data{1, 2, 3, 4, 5, 6};
32   std::vector<float> input2_data{7, 8, 9, 10, 11, 12};
33   Tensor input1_tensor = makeInputTensor<DataType::FLOAT32>({2, 3}, input1_data);
34   Tensor input2_tensor = makeInputTensor<DataType::FLOAT32>({2, 3}, input2_data);
35   Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
36   ConcatenationParams params{};
37
38   // Try different 'axis' and expect different results.
39   {
40     params.axis = 0;
41
42     Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
43     kernel.configure();
44     kernel.execute();
45
46     EXPECT_THAT(extractTensorData<float>(output_tensor),
47                 ElementsAreArray(ArrayFloatNear({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12})));
48   }
49   {
50     params.axis = -2; // Same as '0'.
51
52     Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
53     kernel.configure();
54     kernel.execute();
55
56     EXPECT_THAT(extractTensorData<float>(output_tensor),
57                 ElementsAreArray(ArrayFloatNear({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12})));
58   }
59   {
60     params.axis = 1;
61
62     Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
63     kernel.configure();
64     kernel.execute();
65
66     EXPECT_THAT(extractTensorData<float>(output_tensor),
67                 ElementsAreArray(ArrayFloatNear({1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12})));
68   }
69   {
70     params.axis = -1; // Same as '1'.
71
72     Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
73     kernel.configure();
74     kernel.execute();
75
76     EXPECT_THAT(extractTensorData<float>(output_tensor),
77                 ElementsAreArray(ArrayFloatNear({1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12})));
78   }
79 }
80
81 } // namespace
82 } // namespace kernels
83 } // namespace luci_interpreter