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/Reshape.h"
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/TestMemoryManager.h"
21 namespace luci_interpreter
28 using namespace testing;
30 class ReshapeTest : public ::testing::Test
33 void SetUp() override { _memory_manager = std::make_unique<TestMemoryManager>(); }
35 std::unique_ptr<IMemoryManager> _memory_manager;
38 // TODO Test types other than FLOAT32.
40 TEST_F(ReshapeTest, Regular)
42 Shape input_shape{1, 2, 2, 3};
43 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
45 std::vector<int32_t> shape_data{3, 4};
47 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, _memory_manager.get());
49 makeInputTensor<DataType::S32>(shape_shape, shape_data, _memory_manager.get());
50 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
52 Reshape kernel(&input_tensor, &shape_tensor, &output_tensor);
54 _memory_manager->allocate_memory(output_tensor);
57 EXPECT_THAT(extractTensorData<float>(output_tensor), FloatArrayNear(input_data));
60 TEST_F(ReshapeTest, UnknownDimension)
62 Shape input_shape{2, 1, 2, 3};
63 std::vector<float> input_data{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
65 std::vector<int32_t> shape_data{2, -1, 2};
67 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, _memory_manager.get());
69 makeInputTensor<DataType::S32>(shape_shape, shape_data, _memory_manager.get());
70 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
72 Reshape kernel(&input_tensor, &shape_tensor, &output_tensor);
74 _memory_manager->allocate_memory(output_tensor);
77 EXPECT_THAT(extractTensorData<float>(output_tensor), FloatArrayNear(input_data));
81 } // namespace kernels
82 } // namespace luci_interpreter