1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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 //*****************************************************************************
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"
23 NGRAPH_SUPPRESS_DEPRECATED_START
26 using namespace ngraph;
28 static string s_manifest = "${MANIFEST}";
29 using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
31 // Trivial case with no reduced axes.
32 NGRAPH_TEST(${BACKEND_NAME}, min_trivial)
35 auto A = make_shared<op::Parameter>(element::f32, shape);
36 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{}), ParameterVector{A});
38 std::vector<float> a{1, 2, 3, 4};
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);
46 // Failure has been reported at 5D for some reason
47 NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d)
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};
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);
62 NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d_int32)
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});
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};
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});
78 NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar)
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});
84 std::vector<float> a{1, 2, 3, 4};
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);
92 NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar_int8)
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});
98 std::vector<int8_t> a{1, 2, 3, 4};
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});
106 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_columns)
109 auto A = make_shared<op::Parameter>(element::f32, shape_a);
111 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
113 std::vector<float> a{1, 2, 3, 4, 5, 6};
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);
121 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows)
124 auto A = make_shared<op::Parameter>(element::f32, shape_a);
126 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
128 std::vector<float> a{1, 2, 3, 4, 5, 6};
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);
136 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_int32)
139 auto A = make_shared<op::Parameter>(element::i32, shape_a);
141 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
143 std::vector<int32_t> a{1, 2, 3, 4, 5, 6};
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});
151 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_zero)
154 auto A = make_shared<op::Parameter>(element::f32, shape_a);
156 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
158 std::vector<float> a{};
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()});
169 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_cols_zero)
171 // Now the reduction (g(x:float32[2,2],y:float32[]) = reduce(x,y,f,axes={})).
173 auto A = make_shared<op::Parameter>(element::f32, shape_a);
175 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
177 std::vector<float> a{};
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()});
186 NGRAPH_TEST(${BACKEND_NAME}, min_vector_zero)
189 auto A = make_shared<op::Parameter>(element::f32, shape_a);
191 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
193 std::vector<float> a{};
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()});
201 NGRAPH_TEST(${BACKEND_NAME}, min_matrix_to_scalar_zero_by_zero)
204 auto A = make_shared<op::Parameter>(element::f32, shape_a);
206 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
208 std::vector<float> a{};
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()});
216 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_most_sig)
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});
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};
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);
232 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_least_sig)
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});
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};
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);
248 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_vector)
250 Shape shape_a{3, 3, 3};
251 auto A = make_shared<op::Parameter>(element::f32, shape_a);
253 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
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};
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);
264 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar)
266 Shape shape_a{3, 3, 3};
267 auto A = make_shared<op::Parameter>(element::f32, shape_a);
269 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1, 2}), ParameterVector{A});
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};
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);
280 NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar_int32)
282 Shape shape_a{3, 3, 3};
283 auto A = make_shared<op::Parameter>(element::i32, shape_a);
285 auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1, 2}), ParameterVector{A});
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};
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});
296 NGRAPH_TEST(${BACKEND_NAME}, min_3d_eliminate_zero_dim)
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});
303 std::vector<float> a{};
305 float inf = std::numeric_limits<float>::infinity();
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});