2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "kernels/DepthToSpace.h"
19 #include "kernels/TestUtils.h"
20 #include "luci_interpreter/TestMemoryManager.h"
22 namespace luci_interpreter
29 using namespace testing;
31 template <typename T> class DepthToSpaceTest : public ::testing::Test
35 using DataTypes = ::testing::Types<float, uint8_t>;
36 TYPED_TEST_SUITE(DepthToSpaceTest, DataTypes);
38 TYPED_TEST(DepthToSpaceTest, SimpleCase)
40 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
41 std::vector<TypeParam> input_data{1, 2, 3, 4, 5, 6, 7, 8};
42 Shape input_shape{1, 1, 2, 4};
43 std::vector<TypeParam> output_data{1, 2, 5, 6, 3, 4, 7, 8};
44 std::vector<int32_t> output_shape{1, 2, 4, 1};
47 makeInputTensor<getElementType<TypeParam>()>(input_shape, input_data, memory_manager.get());
48 Tensor output_tensor = makeOutputTensor(getElementType<TypeParam>());
50 DepthToSpaceParams params{};
51 params.block_size = 2;
53 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
55 memory_manager->allocate_memory(output_tensor);
58 EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
59 ::testing::ElementsAreArray(output_data));
60 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
63 TEST(DepthToSpaceTest, InvalidInputShape_NEG)
65 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
66 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8};
67 Shape input_shape{1, 2, 4};
70 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
71 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
73 DepthToSpaceParams params{};
74 params.block_size = 2;
76 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
77 EXPECT_ANY_THROW(kernel.configure());
80 TEST(DepthToSpaceTest, InOutTypeMismatch_NEG)
82 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
83 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8};
84 Shape input_shape{1, 1, 2, 4};
87 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
88 Tensor output_tensor = makeOutputTensor(DataType::U8);
90 DepthToSpaceParams params{};
91 params.block_size = 2;
93 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
94 EXPECT_ANY_THROW(kernel.configure());
97 TEST(DepthToSpaceTest, InvalidBlockSize_NEG)
99 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
100 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8};
101 Shape input_shape{1, 1, 2, 4};
103 Tensor input_tensor =
104 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
105 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
107 DepthToSpaceParams params{};
108 params.block_size = 3;
110 DepthToSpace kernel = DepthToSpace(&input_tensor, &output_tensor, params);
111 EXPECT_ANY_THROW(kernel.configure());
115 } // namespace kernels
116 } // namespace luci_interpreter