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 //*****************************************************************************
23 #include "gtest/gtest.h"
24 #include "ngraph/ngraph.hpp"
25 #include "ngraph/runtime/tensor.hpp"
26 #include "runtime/backend.hpp"
27 #include "util/all_close.hpp"
28 #include "util/all_close_f.hpp"
29 #include "util/ndarray.hpp"
30 #include "util/random.hpp"
31 #include "util/test_control.hpp"
32 #include "util/test_tools.hpp"
34 NGRAPH_SUPPRESS_DEPRECATED_START
37 using namespace ngraph;
39 static string s_manifest = "${MANIFEST}";
41 // Trivial case with no reduced axes.
42 NGRAPH_TEST(${BACKEND_NAME}, any_trivial)
45 auto A = make_shared<op::Parameter>(element::boolean, shape);
46 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{}), ParameterVector{A});
48 auto backend = runtime::Backend::create("${BACKEND_NAME}");
50 // Create some tensors for input/output
51 auto a = backend->create_tensor(element::boolean, shape);
52 copy_data(a, vector<char>{0, 1, 1, 0});
53 auto result = backend->create_tensor(element::boolean, shape);
55 auto handle = backend->compile(f);
56 handle->call_with_validate({result}, {a});
57 EXPECT_EQ((vector<char>{0, 1, 1, 0}), read_vector<char>(result));
60 NGRAPH_TEST(${BACKEND_NAME}, any_2x2_to_scalar_true)
63 auto A = make_shared<op::Parameter>(element::boolean, shape);
64 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0, 1}), ParameterVector{A});
66 auto backend = runtime::Backend::create("${BACKEND_NAME}");
68 // Create some tensors for input/output
69 auto a = backend->create_tensor(element::boolean, shape);
70 copy_data(a, vector<char>{0, 1, 1, 0});
71 auto result = backend->create_tensor(element::boolean, Shape{});
73 auto handle = backend->compile(f);
74 handle->call_with_validate({result}, {a});
75 EXPECT_EQ((vector<char>{1}), read_vector<char>(result));
78 NGRAPH_TEST(${BACKEND_NAME}, any_2x2_to_scalar_false)
81 auto A = make_shared<op::Parameter>(element::boolean, shape);
82 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0, 1}), ParameterVector{A});
84 auto backend = runtime::Backend::create("${BACKEND_NAME}");
86 // Create some tensors for input/output
87 auto a = backend->create_tensor(element::boolean, shape);
88 copy_data(a, vector<char>{0, 0, 0, 0});
89 auto result = backend->create_tensor(element::boolean, Shape{});
91 auto handle = backend->compile(f);
92 handle->call_with_validate({result}, {a});
93 EXPECT_EQ((vector<char>{0}), read_vector<char>(result));
96 NGRAPH_TEST(${BACKEND_NAME}, any_2x0_to_scalar)
99 auto A = make_shared<op::Parameter>(element::boolean, shape);
100 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0, 1}), ParameterVector{A});
102 auto backend = runtime::Backend::create("${BACKEND_NAME}");
104 // Create some tensors for input/output
105 auto a = backend->create_tensor(element::boolean, shape);
106 auto result = backend->create_tensor(element::boolean, Shape{});
108 auto handle = backend->compile(f);
109 handle->call_with_validate({result}, {a});
110 EXPECT_EQ((vector<char>{0}), read_vector<char>(result));
113 NGRAPH_TEST(${BACKEND_NAME}, any_2x3_eliminate_col_dim)
116 auto A = make_shared<op::Parameter>(element::boolean, shape);
117 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{1}), ParameterVector{A});
119 auto backend = runtime::Backend::create("${BACKEND_NAME}");
121 // Create some tensors for input/output
122 auto a = backend->create_tensor(element::boolean, shape);
123 copy_data(a, test::NDArray<char, 2>({{0, 1, 0}, {0, 0, 0}}).get_vector());
124 auto result = backend->create_tensor(element::boolean, Shape{2});
126 auto handle = backend->compile(f);
127 handle->call_with_validate({result}, {a});
128 EXPECT_EQ((vector<char>{1, 0}), read_vector<char>(result));
131 NGRAPH_TEST(${BACKEND_NAME}, any_2x3_eliminate_row_dim)
134 auto A = make_shared<op::Parameter>(element::boolean, shape);
135 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0}), ParameterVector{A});
137 auto backend = runtime::Backend::create("${BACKEND_NAME}");
139 // Create some tensors for input/output
140 auto a = backend->create_tensor(element::boolean, shape);
141 copy_data(a, test::NDArray<char, 2>({{0, 1, 0}, {0, 0, 1}}).get_vector());
142 auto result = backend->create_tensor(element::boolean, Shape{3});
144 auto handle = backend->compile(f);
145 handle->call_with_validate({result}, {a});
146 EXPECT_EQ((vector<char>{0, 1, 1}), read_vector<char>(result));
149 NGRAPH_TEST(${BACKEND_NAME}, any_2x2x3_eliminate_dim_0)
151 Shape shape{2, 2, 3};
152 auto A = make_shared<op::Parameter>(element::boolean, shape);
153 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0}), ParameterVector{A});
155 auto backend = runtime::Backend::create("${BACKEND_NAME}");
157 // Create some tensors for input/output
158 auto a = backend->create_tensor(element::boolean, shape);
160 a, test::NDArray<char, 3>({{{0, 1, 0}, {0, 0, 1}}, {{1, 0, 1}, {0, 0, 0}}}).get_vector());
161 auto result = backend->create_tensor(element::boolean, Shape{2, 3});
163 auto handle = backend->compile(f);
164 handle->call_with_validate({result}, {a});
165 EXPECT_EQ((vector<char>{1, 1, 1, 0, 0, 1}), read_vector<char>(result));
168 NGRAPH_TEST(${BACKEND_NAME}, any_2x2x3_eliminate_dim_1)
170 Shape shape{2, 2, 3};
171 auto A = make_shared<op::Parameter>(element::boolean, shape);
172 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{1}), ParameterVector{A});
174 auto backend = runtime::Backend::create("${BACKEND_NAME}");
176 // Create some tensors for input/output
177 auto a = backend->create_tensor(element::boolean, shape);
179 a, test::NDArray<char, 3>({{{0, 1, 0}, {0, 0, 1}}, {{1, 0, 1}, {0, 0, 0}}}).get_vector());
180 auto result = backend->create_tensor(element::boolean, Shape{2, 3});
182 auto handle = backend->compile(f);
183 handle->call_with_validate({result}, {a});
184 EXPECT_EQ((vector<char>{0, 1, 1, 1, 0, 1}), read_vector<char>(result));
187 NGRAPH_TEST(${BACKEND_NAME}, any_2x2x3_eliminate_dim_2)
189 Shape shape{2, 2, 3};
190 auto A = make_shared<op::Parameter>(element::boolean, shape);
191 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{2}), ParameterVector{A});
193 auto backend = runtime::Backend::create("${BACKEND_NAME}");
195 // Create some tensors for input/output
196 auto a = backend->create_tensor(element::boolean, shape);
198 a, test::NDArray<char, 3>({{{0, 1, 0}, {0, 0, 1}}, {{1, 0, 1}, {0, 0, 0}}}).get_vector());
199 auto result = backend->create_tensor(element::boolean, Shape{2, 2});
201 auto handle = backend->compile(f);
202 handle->call_with_validate({result}, {a});
203 EXPECT_EQ((vector<char>{1, 1, 1, 0}), read_vector<char>(result));
206 NGRAPH_TEST(${BACKEND_NAME}, any_2x2x3_eliminate_dims_0_1)
208 Shape shape{2, 2, 3};
209 auto A = make_shared<op::Parameter>(element::boolean, shape);
210 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0, 1}), ParameterVector{A});
212 auto backend = runtime::Backend::create("${BACKEND_NAME}");
214 // Create some tensors for input/output
215 auto a = backend->create_tensor(element::boolean, shape);
217 a, test::NDArray<char, 3>({{{0, 1, 0}, {0, 0, 1}}, {{1, 0, 1}, {0, 0, 0}}}).get_vector());
218 auto result = backend->create_tensor(element::boolean, Shape{3});
220 auto handle = backend->compile(f);
221 handle->call_with_validate({result}, {a});
222 EXPECT_EQ((vector<char>{1, 1, 1}), read_vector<char>(result));
225 NGRAPH_TEST(${BACKEND_NAME}, any_2x2x3_eliminate_dims_0_2)
227 Shape shape{2, 2, 3};
228 auto A = make_shared<op::Parameter>(element::boolean, shape);
229 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0, 2}), ParameterVector{A});
231 auto backend = runtime::Backend::create("${BACKEND_NAME}");
233 // Create some tensors for input/output
234 auto a = backend->create_tensor(element::boolean, shape);
236 a, test::NDArray<char, 3>({{{0, 1, 0}, {0, 0, 1}}, {{1, 0, 1}, {0, 0, 0}}}).get_vector());
237 auto result = backend->create_tensor(element::boolean, Shape{2});
239 auto handle = backend->compile(f);
240 handle->call_with_validate({result}, {a});
241 EXPECT_EQ((vector<char>{1, 1}), read_vector<char>(result));
244 NGRAPH_TEST(${BACKEND_NAME}, any_2x2x3_eliminate_dims_1_2)
246 Shape shape{2, 2, 3};
247 auto A = make_shared<op::Parameter>(element::boolean, shape);
248 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{1, 2}), ParameterVector{A});
250 auto backend = runtime::Backend::create("${BACKEND_NAME}");
252 // Create some tensors for input/output
253 auto a = backend->create_tensor(element::boolean, shape);
255 a, test::NDArray<char, 3>({{{0, 1, 0}, {0, 0, 1}}, {{1, 0, 1}, {0, 0, 0}}}).get_vector());
256 auto result = backend->create_tensor(element::boolean, Shape{2});
258 auto handle = backend->compile(f);
259 handle->call_with_validate({result}, {a});
260 EXPECT_EQ((vector<char>{1, 1}), read_vector<char>(result));
263 NGRAPH_TEST(${BACKEND_NAME}, any_2x2x3_eliminate_dims_0_1_2)
265 Shape shape{2, 2, 3};
266 auto A = make_shared<op::Parameter>(element::boolean, shape);
267 auto f = make_shared<Function>(make_shared<op::Any>(A, AxisSet{0, 1, 2}), ParameterVector{A});
269 auto backend = runtime::Backend::create("${BACKEND_NAME}");
271 // Create some tensors for input/output
272 auto a = backend->create_tensor(element::boolean, shape);
274 a, test::NDArray<char, 3>({{{0, 1, 0}, {0, 0, 1}}, {{1, 0, 1}, {0, 0, 0}}}).get_vector());
275 auto result = backend->create_tensor(element::boolean, Shape{});
277 auto handle = backend->compile(f);
278 handle->call_with_validate({result}, {a});
279 EXPECT_EQ((vector<char>{1}), read_vector<char>(result));