Imported Upstream version 1.18.0
[platform/core/ml/nnfw.git] / compiler / luci-interpreter / src / kernels / ReverseV2.test.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2017 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/ReverseV2.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 ReverseV2Test : public ::testing::Test
32 {
33 };
34
35 using DataTypes = ::testing::Types<float, uint8_t>;
36 TYPED_TEST_CASE(ReverseV2Test, DataTypes);
37
38 TYPED_TEST(ReverseV2Test, MultiDimensions)
39 {
40   std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
41
42   // TypeParam
43   std::vector<TypeParam> input_data{1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12,
44                                     13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
45   Shape input_shape{4, 3, 2};
46   std::vector<int32_t> axis_data{1};
47   Shape axis_shape{1};
48
49   std::vector<TypeParam> output_data{5,  6,  3,  4,  1,  2,  11, 12, 9,  10, 7,  8,
50                                      17, 18, 15, 16, 13, 14, 23, 24, 21, 22, 19, 20};
51   std::vector<int32_t> output_shape{4, 3, 2};
52
53   Tensor input_tensor =
54     makeInputTensor<getElementType<TypeParam>()>(input_shape, input_data, memory_manager.get());
55   Tensor axis_tensor = makeInputTensor<DataType::S32>(axis_shape, axis_data, memory_manager.get());
56
57   Tensor output_tensor = makeOutputTensor(getElementType<TypeParam>());
58
59   ReverseV2 kernel = ReverseV2(&input_tensor, &axis_tensor, &output_tensor);
60   kernel.configure();
61   memory_manager->allocate_memory(output_tensor);
62   kernel.execute();
63
64   EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
65               ::testing::ElementsAreArray(output_data));
66   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
67 }
68
69 } // namespace
70 } // namespace kernels
71 } // namespace luci_interpreter