Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / luci-interpreter / src / kernels / Elu.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/Elu.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 void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape,
30            std::initializer_list<float> input_data, std::initializer_list<float> output_data)
31 {
32   Tensor input_tensor{DataType::FLOAT32, input_shape, {}, ""};
33   input_tensor.writeData(input_data.begin(), input_data.size() * sizeof(float));
34
35   Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
36
37   Elu kernel(&input_tensor, &output_tensor);
38   kernel.configure();
39   kernel.execute();
40
41   (void)output_shape;
42   EXPECT_THAT(extractTensorData<float>(output_tensor),
43               ::testing::ElementsAreArray(ArrayFloatNear(output_data)));
44 }
45
46 TEST(EluTest, SimpleElu)
47 {
48   Check(
49       /*input_shape=*/{1, 2, 4, 1}, /*output_shape=*/{1, 2, 4, 1},
50       /*input_data=*/
51       {
52           0, -6, 2, -4,    //
53           3, -2, 10, -0.1, //
54       },
55       /*output_data=*/
56       {
57           0.0, -0.997521, 2.0, -0.981684,   //
58           3.0, -0.864665, 10.0, -0.0951626, //
59       });
60 }
61
62 } // namespace
63 } // namespace kernels
64 } // namespace luci_interpreter