Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compiler / luci-interpreter / src / kernels / LeakyRelu.test.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
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
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "kernels/LeakyRelu.h"
18 #include "kernels/TestUtils.h"
19
20 namespace luci_interpreter
21 {
22 namespace kernels
23 {
24 namespace
25 {
26
27 using namespace testing;
28
29 template <typename T>
30 void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape,
31            std::initializer_list<T> input_data, std::initializer_list<T> output_data, float alpha,
32            DataType element_type)
33 {
34   Tensor input_tensor{element_type, input_shape, {}, ""};
35   input_tensor.writeData(input_data.begin(), input_data.size() * sizeof(T));
36
37   Tensor output_tensor = makeOutputTensor(element_type);
38
39   LeakyReluParams params{};
40   params.alpha = alpha;
41
42   LeakyRelu kernel(&input_tensor, &output_tensor, params);
43
44   kernel.configure();
45   kernel.execute();
46
47   (void)output_shape;
48   EXPECT_THAT(extractTensorData<T>(output_tensor), ::testing::ElementsAreArray(output_data));
49 }
50
51 TEST(LeakReluTest, FloatSimple)
52 {
53   Check<float>(/*input_shape=*/{2, 3}, /*output_shape=*/{2, 3}, /*input_data=*/
54                {
55                    0.0f, 1.0f, 3.0f,   // Row 1
56                    1.0f, -1.0f, -2.0f, // Row 2
57                },
58                /*output_data=*/
59                {
60                    0.0f, 1.0f, 3.0f,   // Row 1
61                    1.0f, -0.5f, -1.0f, // Row 2
62                },
63                /*alpha=*/0.5f, getElementType<float>());
64
65   SUCCEED();
66 }
67
68 // TODO Uint8Simple
69 // Implement GetDequantizedOutput Function.
70 // Create Test for Uint8 Case
71
72 } // namespace
73 } // namespace kernels
74 } // namespace luci_interpreter