724abd053cb321b71fe1d6ceeebe26314c0a420f
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / SpaceToDepth.test.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *    http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "kernels/SpaceToDepth.h"
19 #include "kernels/TestUtils.h"
20 #include "luci_interpreter/TestMemoryManager.h"
21
22 namespace luci_interpreter
23 {
24 namespace kernels
25 {
26 namespace
27 {
28
29 using namespace testing;
30
31 template <typename T> class SpaceToDepthTest : public ::testing::Test
32 {
33 };
34
35 using DataTypes = ::testing::Types<float, uint8_t>;
36 TYPED_TEST_SUITE(SpaceToDepthTest, DataTypes);
37
38 TYPED_TEST(SpaceToDepthTest, SimpleCase)
39 {
40   std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
41
42   constexpr DataType element_type = getElementType<TypeParam>();
43   std::vector<TypeParam> input_data{1, 5, 6, 7, 2, 3, 4, 8};
44   Shape input_shape{1, 2, 2, 2};
45   Tensor input_tensor =
46     makeInputTensor<element_type>(input_shape, input_data, memory_manager.get());
47   std::vector<TypeParam> output_data{1, 5, 6, 7, 2, 3, 4, 8};
48   std::vector<int32_t> output_shape{1, 1, 1, 8};
49   Tensor output_tensor = makeOutputTensor(element_type);
50
51   SpaceToDepthParams params{};
52   params.block_size = 2;
53
54   SpaceToDepth kernel(&input_tensor, &output_tensor, params);
55   kernel.configure();
56   memory_manager->allocate_memory(output_tensor);
57   kernel.execute();
58
59   EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
60               ::testing::ElementsAreArray(output_data));
61   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
62 }
63
64 } // namespace
65 } // namespace kernels
66 } // namespace luci_interpreter