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/DepthToSpace.h"
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/TestMemoryManager.h"
21 namespace luci_interpreter
28 using namespace testing;
30 template <typename T> class DepthToSpaceTest : public ::testing::Test
34 using DataTypes = ::testing::Types<float, uint8_t>;
35 TYPED_TEST_CASE(DepthToSpaceTest, DataTypes);
37 TYPED_TEST(DepthToSpaceTest, SimpleCase)
39 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
40 std::vector<TypeParam> input_data{1, 2, 3, 4, 5, 6, 7, 8};
41 Shape input_shape{1, 1, 2, 4};
42 std::vector<TypeParam> output_data{1, 2, 5, 6, 3, 4, 7, 8};
43 std::vector<int32_t> output_shape{1, 2, 4, 1};
46 makeInputTensor<getElementType<TypeParam>()>(input_shape, input_data, memory_manager.get());
47 Tensor output_tensor = makeOutputTensor(getElementType<TypeParam>());
49 DepthToSpaceParams params{};
50 params.block_size = 2;
52 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
54 memory_manager->allocate_memory(output_tensor);
57 EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
58 ::testing::ElementsAreArray(output_data));
59 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
62 TEST(DepthToSpaceTest, InvalidInputShape_NEG)
64 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
65 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8};
66 Shape input_shape{1, 2, 4};
69 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
70 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
72 DepthToSpaceParams params{};
73 params.block_size = 2;
75 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
76 EXPECT_ANY_THROW(kernel.configure());
79 TEST(DepthToSpaceTest, InOutTypeMismatch_NEG)
81 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
82 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8};
83 Shape input_shape{1, 1, 2, 4};
86 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
87 Tensor output_tensor = makeOutputTensor(DataType::U8);
89 DepthToSpaceParams params{};
90 params.block_size = 2;
92 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
93 EXPECT_ANY_THROW(kernel.configure());
96 TEST(DepthToSpaceTest, InvalidBlockSize_NEG)
98 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
99 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8};
100 Shape input_shape{1, 1, 2, 4};
102 Tensor input_tensor =
103 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
104 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
106 DepthToSpaceParams params{};
107 params.block_size = 3;
109 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
110 EXPECT_ANY_THROW(kernel.configure());
114 } // namespace kernels
115 } // namespace luci_interpreter