2 * Copyright (c) 2020 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/Concatenation.h"
18 #include "kernels/TestUtils.h"
20 namespace luci_interpreter
27 using namespace testing;
29 TEST(ConcatenationTest, Float)
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{};
38 // Try different 'axis' and expect different results.
42 Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
46 EXPECT_THAT(extractTensorData<float>(output_tensor),
47 ElementsAreArray(ArrayFloatNear({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12})));
50 params.axis = -2; // Same as '0'.
52 Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
56 EXPECT_THAT(extractTensorData<float>(output_tensor),
57 ElementsAreArray(ArrayFloatNear({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12})));
62 Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
66 EXPECT_THAT(extractTensorData<float>(output_tensor),
67 ElementsAreArray(ArrayFloatNear({1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12})));
70 params.axis = -1; // Same as '1'.
72 Concatenation kernel({&input1_tensor, &input2_tensor}, &output_tensor, params);
76 EXPECT_THAT(extractTensorData<float>(output_tensor),
77 ElementsAreArray(ArrayFloatNear({1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12})));
82 } // namespace kernels
83 } // namespace luci_interpreter