Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compiler / luci-interpreter / src / kernels / DepthToSpace.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/DepthToSpace.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> class DepthToSpaceTest : public ::testing::Test
30 {
31 };
32
33 using DataTypes = ::testing::Types<float, uint8_t>;
34 TYPED_TEST_CASE(DepthToSpaceTest, DataTypes);
35
36 TYPED_TEST(DepthToSpaceTest, SimpleCase)
37 {
38   std::vector<TypeParam> input_data{1, 2, 3, 4, 5, 6, 7, 8};
39   Shape input_shape{1, 1, 2, 4};
40   std::vector<TypeParam> output_data{1, 2, 5, 6, 3, 4, 7, 8};
41   std::vector<int32_t> output_shape{1, 2, 4, 1};
42
43   Tensor input_tensor = makeInputTensor<getElementType<TypeParam>()>(input_shape, input_data);
44   Tensor output_tensor = makeOutputTensor(getElementType<TypeParam>());
45
46   DepthToSpaceParams params{};
47   params.block_size = 2;
48
49   DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
50   kernel.configure();
51   kernel.execute();
52
53   EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
54               ::testing::ElementsAreArray(output_data));
55   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
56 }
57
58 } // namespace
59 } // namespace kernels
60 } // namespace luci_interpreter