Removed InferenceEngine dependency on Legacy library (#1932)
[platform/upstream/dldt.git] / ngraph / test / backend / min.in.cpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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 "gtest/gtest.h"
18 #include "ngraph/ngraph.hpp"
19 #include "util/engine/test_engines.hpp"
20 #include "util/test_case.hpp"
21 #include "util/test_control.hpp"
22
23 NGRAPH_SUPPRESS_DEPRECATED_START
24
25 using namespace std;
26 using namespace ngraph;
27
28 static string s_manifest = "${MANIFEST}";
29 using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
30
31 // Trivial case with no reduced axes.
32 NGRAPH_TEST(${BACKEND_NAME}, min_trivial)
33 {
34     Shape shape{2, 2};
35     auto A = make_shared<op::Parameter>(element::f32, shape);
36     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{}), ParameterVector{A});
37
38     std::vector<float> a{1, 2, 3, 4};
39
40     auto test_case = test::TestCase<TestEngine>(f);
41     test_case.add_input<float>({a});
42     test_case.add_expected_output<float>(shape, {1, 2, 3, 4});
43     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
44 }
45
46 // Failure has been reported at 5D for some reason
47 NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d)
48 {
49     Shape shape{2, 2, 2, 2, 2};
50     auto A = make_shared<op::Parameter>(element::f32, shape);
51     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{}), ParameterVector{A});
52     std::vector<float> a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
53                          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
54
55     auto test_case = test::TestCase<TestEngine>(f);
56     test_case.add_input<float>({a});
57     test_case.add_expected_output<float>(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
58                                                  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
59     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
60 }
61
62 NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d_int32)
63 {
64     Shape shape{2, 2, 2, 2, 2};
65     auto A = make_shared<op::Parameter>(element::i32, shape);
66     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{}), ParameterVector{A});
67
68     std::vector<int32_t> a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
69                            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
70
71     auto test_case = test::TestCase<TestEngine>(f);
72     test_case.add_input<int32_t>({a});
73     test_case.add_expected_output<int32_t>(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
74                                                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
75     test_case.run();
76 }
77
78 NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar)
79 {
80     Shape shape{2, 2};
81     auto A = make_shared<op::Parameter>(element::f32, shape);
82     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
83
84     std::vector<float> a{1, 2, 3, 4};
85
86     auto test_case = test::TestCase<TestEngine>(f);
87     test_case.add_input<float>({a});
88     test_case.add_expected_output<float>(Shape{}, {1});
89     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
90 }
91
92 NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar_int8)
93 {
94     Shape shape{2, 2};
95     auto A = make_shared<op::Parameter>(element::i8, shape);
96     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
97
98     std::vector<int8_t> a{1, 2, 3, 4};
99
100     auto test_case = test::TestCase<TestEngine>(f);
101     test_case.add_input<int8_t>({a});
102     test_case.add_expected_output<int8_t>(Shape{}, {1});
103     test_case.run();
104 }
105
106 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_columns)
107 {
108     Shape shape_a{3, 2};
109     auto A = make_shared<op::Parameter>(element::f32, shape_a);
110     Shape shape_rt{2};
111     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
112
113     std::vector<float> a{1, 2, 3, 4, 5, 6};
114
115     auto test_case = test::TestCase<TestEngine>(f);
116     test_case.add_input<float>({a});
117     test_case.add_expected_output<float>(shape_rt, {1, 2});
118     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
119 }
120
121 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows)
122 {
123     Shape shape_a{3, 2};
124     auto A = make_shared<op::Parameter>(element::f32, shape_a);
125     Shape shape_rt{3};
126     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
127
128     std::vector<float> a{1, 2, 3, 4, 5, 6};
129
130     auto test_case = test::TestCase<TestEngine>(f);
131     test_case.add_input<float>({a});
132     test_case.add_expected_output<float>(shape_rt, {1, 3, 5});
133     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
134 }
135
136 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_int32)
137 {
138     Shape shape_a{3, 2};
139     auto A = make_shared<op::Parameter>(element::i32, shape_a);
140     Shape shape_rt{3};
141     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
142
143     std::vector<int32_t> a{1, 2, 3, 4, 5, 6};
144
145     auto test_case = test::TestCase<TestEngine>(f);
146     test_case.add_input<int32_t>({a});
147     test_case.add_expected_output<int32_t>(shape_rt, {1, 3, 5});
148     test_case.run();
149 }
150
151 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_zero)
152 {
153     Shape shape_a{3, 0};
154     auto A = make_shared<op::Parameter>(element::f32, shape_a);
155     Shape shape_rt{3};
156     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
157
158     std::vector<float> a{};
159
160     auto test_case = test::TestCase<TestEngine>(f);
161     test_case.add_input<float>({a});
162     test_case.add_expected_output<float>(shape_rt,
163                                          {std::numeric_limits<float>::infinity(),
164                                           std::numeric_limits<float>::infinity(),
165                                           std::numeric_limits<float>::infinity()});
166     test_case.run();
167 }
168
169 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_cols_zero)
170 {
171     // Now the reduction (g(x:float32[2,2],y:float32[]) = reduce(x,y,f,axes={})).
172     Shape shape_a{0, 2};
173     auto A = make_shared<op::Parameter>(element::f32, shape_a);
174     Shape shape_rt{2};
175     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
176
177     std::vector<float> a{};
178
179     auto test_case = test::TestCase<TestEngine>(f);
180     test_case.add_input<float>({a});
181     test_case.add_expected_output<float>(
182         shape_rt, {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()});
183     test_case.run();
184 }
185
186 NGRAPH_TEST(${BACKEND_NAME}, min_vector_zero)
187 {
188     Shape shape_a{0};
189     auto A = make_shared<op::Parameter>(element::f32, shape_a);
190     Shape shape_rt{};
191     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
192
193     std::vector<float> a{};
194
195     auto test_case = test::TestCase<TestEngine>(f);
196     test_case.add_input<float>({a});
197     test_case.add_expected_output<float>(shape_rt, {std::numeric_limits<float>::infinity()});
198     test_case.run();
199 }
200
201 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_to_scalar_zero_by_zero)
202 {
203     Shape shape_a{0, 0};
204     auto A = make_shared<op::Parameter>(element::f32, shape_a);
205     Shape shape_rt{};
206     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
207
208     std::vector<float> a{};
209
210     auto test_case = test::TestCase<TestEngine>(f);
211     test_case.add_input<float>({a});
212     test_case.add_expected_output<float>(shape_rt, {std::numeric_limits<float>::infinity()});
213     test_case.run();
214 }
215
216 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_most_sig)
217 {
218     Shape shape_a{3, 3, 3};
219     auto A = make_shared<op::Parameter>(element::f32, shape_a);
220     Shape shape_rt{3, 3};
221     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
222
223     std::vector<float> a{1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14,
224                          15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
225
226     auto test_case = test::TestCase<TestEngine>(f);
227     test_case.add_input<float>({a});
228     test_case.add_expected_output<float>(shape_rt, {1, 2, 3, 4, 5, 6, 7, 8, 9});
229     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
230 }
231
232 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_least_sig)
233 {
234     Shape shape_a{3, 3, 3};
235     auto A = make_shared<op::Parameter>(element::f32, shape_a);
236     Shape shape_rt{3, 3};
237     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{2}), ParameterVector{A});
238
239     std::vector<float> a{1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14,
240                          15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
241
242     auto test_case = test::TestCase<TestEngine>(f);
243     test_case.add_input<float>({a});
244     test_case.add_expected_output<float>(shape_rt, {1, 4, 7, 10, 13, 16, 19, 22, 25});
245     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
246 }
247
248 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_vector)
249 {
250     Shape shape_a{3, 3, 3};
251     auto A = make_shared<op::Parameter>(element::f32, shape_a);
252     Shape shape_rt{3};
253     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
254
255     std::vector<float> a{1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14,
256                          15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
257
258     auto test_case = test::TestCase<TestEngine>(f);
259     test_case.add_input<float>({a});
260     test_case.add_expected_output<float>(shape_rt, {1, 2, 3});
261     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
262 }
263
264 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar)
265 {
266     Shape shape_a{3, 3, 3};
267     auto A = make_shared<op::Parameter>(element::f32, shape_a);
268     Shape shape_rt{};
269     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1, 2}), ParameterVector{A});
270
271     std::vector<float> a{1,  2,  3,  4,  5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
272                          13, 12, 11, 10, 9, 8, 7, 6, 5, 4,  3,  2,  1};
273
274     auto test_case = test::TestCase<TestEngine>(f);
275     test_case.add_input<float>({a});
276     test_case.add_expected_output<float>(shape_rt, {1});
277     test_case.run(MIN_FLOAT_TOLERANCE_BITS);
278 }
279
280 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar_int32)
281 {
282     Shape shape_a{3, 3, 3};
283     auto A = make_shared<op::Parameter>(element::i32, shape_a);
284     Shape shape_rt{};
285     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1, 2}), ParameterVector{A});
286
287     std::vector<int32_t> a{1,  2,  3,  4,  5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
288                            13, 12, 11, 10, 9, 8, 7, 6, 5, 4,  3,  2,  1};
289
290     auto test_case = test::TestCase<TestEngine>(f);
291     test_case.add_input<int32_t>({a});
292     test_case.add_expected_output<int32_t>(shape_rt, {1});
293     test_case.run();
294 }
295
296 NGRAPH_TEST(${BACKEND_NAME}, min_3d_eliminate_zero_dim)
297 {
298     Shape shape_a{3, 0, 2};
299     auto A = make_shared<op::Parameter>(element::f32, shape_a);
300     Shape shape_rt{3, 2};
301     auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
302
303     std::vector<float> a{};
304
305     float inf = std::numeric_limits<float>::infinity();
306
307     auto test_case = test::TestCase<TestEngine>(f);
308     test_case.add_input<float>({a});
309     test_case.add_expected_output<float>(shape_rt, {inf, inf, inf, inf, inf, inf});
310     test_case.run();
311 }