Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / exo / src / TFLite / TFLExporterUtils.test.cpp
1 /*
2  * Copyright (c) 2019 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 "TFLExporterUtils.h"
18
19 #include <gtest/gtest.h>
20
21 using namespace exo::tflite_detail;
22
23 TEST(ExporterUtilsTests, getOpPadding)
24 {
25   loco::Padding2D pad;
26   loco::Stride<2> stride;
27   exo::ShapeDescription ifm;
28   exo::ShapeDescription ofm;
29
30   ifm._dims.resize(4);
31   ofm._dims.resize(4);
32
33   // VALID padding
34   {
35     pad.top(0);
36     pad.bottom(0);
37     pad.left(0);
38     pad.right(0);
39
40     stride.vertical(2);
41     stride.horizontal(2);
42
43     ifm._dims[1] = 5;
44     ifm._dims[2] = 5;
45
46     ofm._dims[1] = 2;
47     ofm._dims[2] = 2;
48
49     ASSERT_EQ(tflite::Padding_VALID, getOpPadding(&pad, &stride, ifm, ofm));
50   }
51
52   // SAME padding
53   {
54     pad.top(1);
55     pad.bottom(1);
56     pad.left(1);
57     pad.right(1);
58
59     stride.vertical(2);
60     stride.horizontal(2);
61
62     ifm._dims[1] = 5;
63     ifm._dims[2] = 5;
64
65     ofm._dims[1] = 3;
66     ofm._dims[2] = 3;
67
68     ASSERT_EQ(tflite::Padding_SAME, getOpPadding(&pad, &stride, ifm, ofm));
69   }
70
71   // Custom padding 1 - Not supported by tflite
72   {
73     pad.top(2);
74     pad.bottom(0);
75     pad.left(1);
76     pad.right(1);
77
78     stride.vertical(2);
79     stride.horizontal(2);
80
81     ifm._dims[1] = 5;
82     ifm._dims[2] = 5;
83
84     ofm._dims[1] = 3;
85     ofm._dims[2] = 3;
86
87     ASSERT_ANY_THROW(getOpPadding(&pad, &stride, ifm, ofm));
88   }
89
90   // Custom padding 2 - Not supported by tflite
91   {
92     pad.top(2);
93     pad.bottom(2);
94     pad.left(2);
95     pad.right(2);
96
97     stride.vertical(2);
98     stride.horizontal(2);
99
100     ifm._dims[1] = 5;
101     ifm._dims[2] = 5;
102
103     ofm._dims[1] = 4;
104     ofm._dims[2] = 4;
105
106     ASSERT_ANY_THROW(getOpPadding(&pad, &stride, ifm, ofm));
107   }
108 }