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 //*****************************************************************************
25 #include "gtest/gtest.h"
26 #include "ngraph/ngraph.hpp"
27 #include "ngraph/runtime/tensor.hpp"
28 #include "runtime/backend.hpp"
29 #include "util/all_close.hpp"
30 #include "util/all_close_f.hpp"
31 #include "util/engine/test_engines.hpp"
32 #include "util/ndarray.hpp"
33 #include "util/test_case.hpp"
34 #include "util/test_control.hpp"
35 #include "util/test_tools.hpp"
37 NGRAPH_SUPPRESS_DEPRECATED_START
40 using namespace ngraph;
42 static string s_manifest = "${MANIFEST}";
44 using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
46 NGRAPH_TEST(${BACKEND_NAME}, reshape_t2v_012)
48 Shape shape_a{2, 2, 3};
49 auto A = make_shared<op::Parameter>(element::f32, shape_a);
51 auto r = make_shared<op::Reshape>(A, AxisVector{0, 1, 2}, shape_r);
52 auto f = make_shared<Function>(r, ParameterVector{A});
54 auto backend = runtime::Backend::create("${BACKEND_NAME}");
56 // Create some tensors for input/output
57 auto a = backend->create_tensor(element::f32, shape_a);
58 copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
59 auto result = backend->create_tensor(element::f32, shape_r);
61 auto handle = backend->compile(f);
62 handle->call_with_validate({result}, {a});
63 EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
64 read_vector<float>(result),
65 MIN_FLOAT_TOLERANCE_BITS));
68 NGRAPH_TEST(${BACKEND_NAME}, reshape_t2s_012)
70 Shape shape_a{1, 1, 1};
71 auto A = make_shared<op::Parameter>(element::f32, shape_a);
73 auto r = make_shared<op::Reshape>(A, AxisVector{0, 1, 2}, shape_r);
74 auto f = make_shared<Function>(r, ParameterVector{A});
76 auto backend = runtime::Backend::create("${BACKEND_NAME}");
78 // Create some tensors for input/output
79 auto a = backend->create_tensor(element::f32, shape_a);
80 copy_data(a, vector<float>{6});
81 auto result = backend->create_tensor(element::f32, shape_r);
83 auto handle = backend->compile(f);
84 handle->call_with_validate({result}, {a});
85 EXPECT_TRUE(test::all_close_f(
86 (vector<float>{6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
89 NGRAPH_TEST(${BACKEND_NAME}, reshape_t2s_120)
91 Shape shape_a{1, 1, 1};
92 auto A = make_shared<op::Parameter>(element::f32, shape_a);
94 auto r = make_shared<op::Reshape>(A, AxisVector{1, 2, 0}, shape_r);
95 auto f = make_shared<Function>(r, ParameterVector{A});
97 auto backend = runtime::Backend::create("${BACKEND_NAME}");
99 // Create some tensors for input/output
100 auto a = backend->create_tensor(element::f32, shape_a);
101 copy_data(a, vector<float>{6});
102 auto result = backend->create_tensor(element::f32, shape_r);
104 auto handle = backend->compile(f);
105 handle->call_with_validate({result}, {a});
106 EXPECT_TRUE(test::all_close_f(
107 (vector<float>{6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
110 NGRAPH_TEST(${BACKEND_NAME}, reshape_s2t)
113 auto A = make_shared<op::Parameter>(element::f32, shape_a);
114 Shape shape_r{1, 1, 1, 1, 1, 1};
115 auto r = make_shared<op::Reshape>(A, AxisVector{}, shape_r);
116 auto f = make_shared<Function>(r, ParameterVector{A});
118 auto backend = runtime::Backend::create("${BACKEND_NAME}");
120 // Create some tensors for input/output
121 auto a = backend->create_tensor(element::f32, shape_a);
122 copy_data(a, vector<float>{42});
123 auto result = backend->create_tensor(element::f32, shape_r);
125 auto handle = backend->compile(f);
126 handle->call_with_validate({result}, {a});
127 EXPECT_TRUE(test::all_close_f(
128 (vector<float>{42}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
131 NGRAPH_TEST(${BACKEND_NAME}, reshape_s2t1)
134 auto A = make_shared<op::Parameter>(element::boolean, shape_a);
136 auto r = make_shared<op::Reshape>(A, AxisVector{}, shape_r);
137 auto f = make_shared<Function>(r, ParameterVector{A});
139 auto backend = runtime::Backend::create("${BACKEND_NAME}");
141 // Create some tensors for input/output
142 auto a = backend->create_tensor(element::boolean, shape_a);
143 copy_data(a, vector<char>{42});
144 auto result = backend->create_tensor(element::boolean, shape_r);
146 auto handle = backend->compile(f);
147 handle->call_with_validate({result}, {a});
148 EXPECT_EQ((vector<char>{42}), read_vector<char>(result));
151 NGRAPH_TEST(${BACKEND_NAME}, reshape_v2m_col)
154 auto A = make_shared<op::Parameter>(element::f32, shape_a);
156 auto r = make_shared<op::Reshape>(A, AxisVector{0}, shape_r);
157 auto f = make_shared<Function>(r, ParameterVector{A});
159 auto backend = runtime::Backend::create("${BACKEND_NAME}");
161 // Create some tensors for input/output
162 auto a = backend->create_tensor(element::f32, shape_a);
163 copy_data(a, vector<float>{1, 2, 3});
164 auto result = backend->create_tensor(element::f32, shape_r);
166 auto handle = backend->compile(f);
167 handle->call_with_validate({result}, {a});
168 EXPECT_TRUE(test::all_close_f(
169 (vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
172 NGRAPH_TEST(${BACKEND_NAME}, reshape_v2m_row)
175 auto A = make_shared<op::Parameter>(element::f32, shape_a);
177 auto r = make_shared<op::Reshape>(A, AxisVector{0}, shape_r);
178 auto f = make_shared<Function>(r, ParameterVector{A});
180 auto backend = runtime::Backend::create("${BACKEND_NAME}");
182 // Create some tensors for input/output
183 auto a = backend->create_tensor(element::f32, shape_a);
184 copy_data(a, vector<float>{1, 2, 3});
185 auto result = backend->create_tensor(element::f32, shape_r);
187 auto handle = backend->compile(f);
188 handle->call_with_validate({result}, {a});
189 EXPECT_TRUE(test::all_close_f(
190 (vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
193 NGRAPH_TEST(${BACKEND_NAME}, reshape_v2t_middle)
196 auto A = make_shared<op::Parameter>(element::f32, shape_a);
197 Shape shape_r{1, 3, 1};
198 auto r = make_shared<op::Reshape>(A, AxisVector{0}, shape_r);
199 auto f = make_shared<Function>(r, ParameterVector{A});
201 auto backend = runtime::Backend::create("${BACKEND_NAME}");
203 // Create some tensors for input/output
204 auto a = backend->create_tensor(element::f32, shape_a);
205 copy_data(a, vector<float>{1, 2, 3});
206 auto result = backend->create_tensor(element::f32, shape_r);
208 auto handle = backend->compile(f);
209 handle->call_with_validate({result}, {a});
210 EXPECT_TRUE(test::all_close_f(
211 (vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
214 NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_same)
217 auto A = make_shared<op::Parameter>(element::f32, shape_a);
219 auto r = make_shared<op::Reshape>(A, AxisVector{0, 1}, shape_r);
220 auto f = make_shared<Function>(r, ParameterVector{A});
222 auto backend = runtime::Backend::create("${BACKEND_NAME}");
224 // Create some tensors for input/output
225 auto a = backend->create_tensor(element::f32, shape_a);
226 copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
227 auto result = backend->create_tensor(element::f32, shape_r);
229 auto handle = backend->compile(f);
230 handle->call_with_validate({result}, {a});
231 EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9}),
232 read_vector<float>(result),
233 MIN_FLOAT_TOLERANCE_BITS));
236 NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_transpose)
239 auto A = make_shared<op::Parameter>(element::f32, shape_a);
241 auto r = make_shared<op::Reshape>(A, AxisVector{1, 0}, shape_r);
242 auto f = make_shared<Function>(r, ParameterVector{A});
244 auto backend = runtime::Backend::create("${BACKEND_NAME}");
246 // Create some tensors for input/output
247 auto a = backend->create_tensor(element::f32, shape_a);
248 copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
249 auto result = backend->create_tensor(element::f32, shape_r);
251 auto handle = backend->compile(f);
252 handle->call_with_validate({result}, {a});
253 EXPECT_TRUE(test::all_close_f((vector<float>{1, 4, 7, 2, 5, 8, 3, 6, 9}),
254 read_vector<float>(result),
255 MIN_FLOAT_TOLERANCE_BITS));
258 NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_dim_change_transpose)
261 auto A = make_shared<op::Parameter>(element::f32, shape_a);
263 auto r = make_shared<op::Reshape>(A, AxisVector{1, 0}, shape_r);
264 auto f = make_shared<Function>(r, ParameterVector{A});
266 auto backend = runtime::Backend::create("${BACKEND_NAME}");
268 // Create some tensors for input/output
269 auto a = backend->create_tensor(element::f32, shape_a);
270 copy_data(a, vector<float>{1, 2, 3, 4, 5, 6});
271 auto result = backend->create_tensor(element::f32, shape_r);
273 auto handle = backend->compile(f);
274 handle->call_with_validate({result}, {a});
275 EXPECT_TRUE(test::all_close_f(
276 (vector<float>{1, 3, 5, 2, 4, 6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
279 NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_021)
281 Shape shape_a{2, 3, 4};
282 Shape shape_r{2, 4, 3};
283 auto A = make_shared<op::Parameter>(element::f32, shape_a);
284 auto r = make_shared<op::Reshape>(A, AxisVector{0, 2, 1}, shape_r);
285 auto f = make_shared<Function>(r, ParameterVector{A});
287 vector<float> a_data(shape_size(shape_a));
288 iota(a_data.begin(), a_data.end(), 1.f);
290 auto backend = runtime::Backend::create("${BACKEND_NAME}");
292 // Create some tensors for input/output
293 auto a = backend->create_tensor(element::f32, shape_a);
294 copy_data(a, a_data);
295 auto result = backend->create_tensor(element::f32, shape_r);
297 auto handle = backend->compile(f);
298 handle->call_with_validate({result}, {a});
299 EXPECT_TRUE(test::all_close_f((vector<float>{1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12,
300 13, 17, 21, 14, 18, 22, 15, 19, 23, 16, 20, 24}),
301 read_vector<float>(result),
302 MIN_FLOAT_TOLERANCE_BITS));
305 NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_210)
307 Shape shape_a{2, 3, 4};
308 Shape shape_r{4, 3, 2};
309 auto A = make_shared<op::Parameter>(element::f32, shape_a);
310 auto r = make_shared<op::Reshape>(A, AxisVector{2, 1, 0}, shape_r);
311 auto f = make_shared<Function>(r, ParameterVector{A});
313 vector<float> a_data(shape_size(shape_a));
314 iota(a_data.begin(), a_data.end(), 1.f);
316 auto backend = runtime::Backend::create("${BACKEND_NAME}");
318 // Create some tensors for input/output
319 auto a = backend->create_tensor(element::f32, shape_a);
320 copy_data(a, a_data);
321 auto result = backend->create_tensor(element::f32, shape_r);
323 auto handle = backend->compile(f);
324 handle->call_with_validate({result}, {a});
325 EXPECT_TRUE(test::all_close_f((vector<float>{1, 13, 5, 17, 9, 21, 2, 14, 6, 18, 10, 22,
326 3, 15, 7, 19, 11, 23, 4, 16, 8, 20, 12, 24}),
327 read_vector<float>(result),
328 MIN_FLOAT_TOLERANCE_BITS));
331 NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_201)
333 Shape shape_a{2, 3, 4};
334 Shape shape_r{4, 2, 3};
335 auto A = make_shared<op::Parameter>(element::f32, shape_a);
336 auto r = make_shared<op::Reshape>(A, AxisVector{2, 0, 1}, shape_r);
337 auto f = make_shared<Function>(r, ParameterVector{A});
339 vector<float> a_data(shape_size(shape_a));
340 iota(a_data.begin(), a_data.end(), 1.f);
342 auto backend = runtime::Backend::create("${BACKEND_NAME}");
344 // Create some tensors for input/output
345 auto a = backend->create_tensor(element::f32, shape_a);
346 copy_data(a, a_data);
347 auto result = backend->create_tensor(element::f32, shape_r);
349 auto handle = backend->compile(f);
350 handle->call_with_validate({result}, {a});
351 EXPECT_TRUE(test::all_close_f((vector<float>{1, 5, 9, 13, 17, 21, 2, 6, 10, 14, 18, 22,
352 3, 7, 11, 15, 19, 23, 4, 8, 12, 16, 20, 24}),
353 read_vector<float>(result),
354 MIN_FLOAT_TOLERANCE_BITS));
357 NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_102)
359 Shape shape_a{2, 3, 4};
360 Shape shape_r{3, 2, 4};
361 auto A = make_shared<op::Parameter>(element::f32, shape_a);
362 auto r = make_shared<op::Reshape>(A, AxisVector{1, 0, 2}, shape_r);
363 auto f = make_shared<Function>(r, ParameterVector{A});
365 vector<float> a_data(shape_size(shape_a));
366 iota(a_data.begin(), a_data.end(), 1.f);
368 auto backend = runtime::Backend::create("${BACKEND_NAME}");
370 // Create some tensors for input/output
371 auto a = backend->create_tensor(element::f32, shape_a);
372 copy_data(a, a_data);
373 auto result = backend->create_tensor(element::f32, shape_r);
375 auto handle = backend->compile(f);
376 handle->call_with_validate({result}, {a});
377 EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 13, 14, 15, 16, 5, 6, 7, 8,
378 17, 18, 19, 20, 9, 10, 11, 12, 21, 22, 23, 24}),
379 read_vector<float>(result),
380 MIN_FLOAT_TOLERANCE_BITS));
383 NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_120)
385 Shape shape_a{2, 3, 4};
386 Shape shape_r{3, 4, 2};
387 auto A = make_shared<op::Parameter>(element::f32, shape_a);
388 auto r = make_shared<op::Reshape>(A, AxisVector{1, 2, 0}, shape_r);
389 auto f = make_shared<Function>(r, ParameterVector{A});
391 vector<float> a_data(shape_size(shape_a));
392 iota(a_data.begin(), a_data.end(), 1.f);
394 auto backend = runtime::Backend::create("${BACKEND_NAME}");
396 // Create some tensors for input/output
397 auto a = backend->create_tensor(element::f32, shape_a);
398 copy_data(a, a_data);
399 auto result = backend->create_tensor(element::f32, shape_r);
401 auto handle = backend->compile(f);
402 handle->call_with_validate({result}, {a});
403 EXPECT_TRUE(test::all_close_f((vector<float>{1, 13, 2, 14, 3, 15, 4, 16, 5, 17, 6, 18,
404 7, 19, 8, 20, 9, 21, 10, 22, 11, 23, 12, 24}),
405 read_vector<float>(result),
406 MIN_FLOAT_TOLERANCE_BITS));
409 NGRAPH_TEST(${BACKEND_NAME}, reshape_4d_transpose)
411 Shape shape_a{2, 2, 5, 5};
412 Shape shape_r{2, 5, 5, 2};
413 auto A = make_shared<op::Parameter>(element::f32, shape_a);
414 auto r = make_shared<op::Reshape>(A, AxisVector{0, 2, 3, 1}, shape_r);
415 auto f = make_shared<Function>(r, ParameterVector{A});
417 vector<float> a_data(shape_size(shape_a));
418 iota(a_data.begin(), a_data.end(), 1.f);
420 auto backend = runtime::Backend::create("${BACKEND_NAME}");
422 // Create some tensors for input/output
423 auto a = backend->create_tensor(element::f32, shape_a);
424 copy_data(a, a_data);
425 auto result = backend->create_tensor(element::f32, shape_r);
427 auto handle = backend->compile(f);
428 handle->call_with_validate({result}, {a});
429 EXPECT_TRUE(test::all_close_f(
430 (vector<float>{1., 26., 2., 27., 3., 28., 4., 29., 5., 30., 6., 31., 7., 32., 8.,
431 33., 9., 34., 10., 35., 11., 36., 12., 37., 13., 38., 14., 39., 15., 40.,
432 16., 41., 17., 42., 18., 43., 19., 44., 20., 45., 21., 46., 22., 47., 23.,
433 48., 24., 49., 25., 50., 51., 76., 52., 77., 53., 78., 54., 79., 55., 80.,
434 56., 81., 57., 82., 58., 83., 59., 84., 60., 85., 61., 86., 62., 87., 63.,
435 88., 64., 89., 65., 90., 66., 91., 67., 92., 68., 93., 69., 94., 70., 95.,
436 71., 96., 72., 97., 73., 98., 74., 99., 75., 100.}),
437 read_vector<float>(result),
438 MIN_FLOAT_TOLERANCE_BITS));
441 NGRAPH_TEST(${BACKEND_NAME}, reshape_4d_no_transpose)
443 Shape shape_a{2, 2, 5, 5};
444 Shape shape_r{2, 5, 5, 2};
445 auto A = make_shared<op::Parameter>(element::f32, shape_a);
446 auto r = make_shared<op::Reshape>(A, AxisVector{0, 1, 2, 3}, shape_r);
447 auto f = make_shared<Function>(r, ParameterVector{A});
449 vector<float> a_data(shape_size(shape_a));
450 iota(a_data.begin(), a_data.end(), 1.f);
452 auto backend = runtime::Backend::create("${BACKEND_NAME}");
454 // Create some tensors for input/output
455 auto a = backend->create_tensor(element::f32, shape_a);
456 copy_data(a, a_data);
457 auto result = backend->create_tensor(element::f32, shape_r);
459 auto handle = backend->compile(f);
460 handle->call_with_validate({result}, {a});
461 EXPECT_TRUE(test::all_close_f(a_data, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
464 NGRAPH_TEST(${BACKEND_NAME}, reshape_transposed_shape_change)
467 auto A = make_shared<op::Parameter>(element::f32, shape_a);
469 auto r = make_shared<op::Reshape>(A, AxisVector{1, 0}, shape_r);
470 auto f = make_shared<Function>(r, ParameterVector{A});
472 auto backend = runtime::Backend::create("${BACKEND_NAME}");
474 // Create some tensors for input/output
475 auto a = backend->create_tensor(element::f32, shape_a);
476 copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
477 auto result = backend->create_tensor(element::f32, shape_r);
479 auto handle = backend->compile(f);
480 handle->call_with_validate({result}, {a});
481 EXPECT_TRUE(test::all_close_f((vector<float>{1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12}),
482 read_vector<float>(result),
483 MIN_FLOAT_TOLERANCE_BITS));
489 // >>> x = linspace(1,2*2*3*3*2*4,2*2*3*3*2*4)
490 // >>> x.shape=(2,2,3,3,2,4)
491 // >>> y = ascontiguousarray(transpose(x,(2,4,0,5,3,1)))
492 // >>> y.shape=2*2*3*3*2*4
494 // array([ 1., 73., 9., 81., 17., 89., 2., 74., 10.,
495 // 82., 18., 90., 3., 75., 11., 83., 19., 91.,
496 // 4., 76., 12., 84., 20., 92., 145., 217., 153.,
497 // 225., 161., 233., 146., 218., 154., 226., 162., 234.,
498 // 147., 219., 155., 227., 163., 235., 148., 220., 156.,
499 // 228., 164., 236., 5., 77., 13., 85., 21., 93.,
500 // 6., 78., 14., 86., 22., 94., 7., 79., 15.,
501 // 87., 23., 95., 8., 80., 16., 88., 24., 96.,
502 // 149., 221., 157., 229., 165., 237., 150., 222., 158.,
503 // 230., 166., 238., 151., 223., 159., 231., 167., 239.,
504 // 152., 224., 160., 232., 168., 240., 25., 97., 33.,
505 // 105., 41., 113., 26., 98., 34., 106., 42., 114.,
506 // 27., 99., 35., 107., 43., 115., 28., 100., 36.,
507 // 108., 44., 116., 169., 241., 177., 249., 185., 257.,
508 // 170., 242., 178., 250., 186., 258., 171., 243., 179.,
509 // 251., 187., 259., 172., 244., 180., 252., 188., 260.,
510 // 29., 101., 37., 109., 45., 117., 30., 102., 38.,
511 // 110., 46., 118., 31., 103., 39., 111., 47., 119.,
512 // 32., 104., 40., 112., 48., 120., 173., 245., 181.,
513 // 253., 189., 261., 174., 246., 182., 254., 190., 262.,
514 // 175., 247., 183., 255., 191., 263., 176., 248., 184.,
515 // 256., 192., 264., 49., 121., 57., 129., 65., 137.,
516 // 50., 122., 58., 130., 66., 138., 51., 123., 59.,
517 // 131., 67., 139., 52., 124., 60., 132., 68., 140.,
518 // 193., 265., 201., 273., 209., 281., 194., 266., 202.,
519 // 274., 210., 282., 195., 267., 203., 275., 211., 283.,
520 // 196., 268., 204., 276., 212., 284., 53., 125., 61.,
521 // 133., 69., 141., 54., 126., 62., 134., 70., 142.,
522 // 55., 127., 63., 135., 71., 143., 56., 128., 64.,
523 // 136., 72., 144., 197., 269., 205., 277., 213., 285.,
524 // 198., 270., 206., 278., 214., 286., 199., 271., 207.,
525 // 279., 215., 287., 200., 272., 208., 280., 216., 288.])
527 NGRAPH_TEST(${BACKEND_NAME}, reshape_6d)
529 Shape shape_a{2, 2, 3, 3, 2, 4};
530 auto A = make_shared<op::Parameter>(element::f32, shape_a);
531 Shape shape_r{3, 2, 2, 4, 3, 2};
533 vector<float> a_data(shape_size(shape_a));
534 iota(a_data.begin(), a_data.end(), 1.f);
536 auto r = make_shared<op::Reshape>(A, AxisVector{2, 4, 0, 5, 3, 1}, shape_r);
537 auto f = make_shared<Function>(r, ParameterVector{A});
539 auto backend = runtime::Backend::create("${BACKEND_NAME}");
541 // Create some tensors for input/output
542 auto a = backend->create_tensor(element::f32, shape_a);
543 copy_data(a, a_data);
545 auto result = backend->create_tensor(element::f32, shape_r);
547 auto handle = backend->compile(f);
548 handle->call_with_validate({result}, {a});
549 EXPECT_TRUE(test::all_close_f(
551 1., 73., 9., 81., 17., 89., 2., 74., 10., 82., 18., 90., 3., 75.,
552 11., 83., 19., 91., 4., 76., 12., 84., 20., 92., 145., 217., 153., 225.,
553 161., 233., 146., 218., 154., 226., 162., 234., 147., 219., 155., 227., 163., 235.,
554 148., 220., 156., 228., 164., 236., 5., 77., 13., 85., 21., 93., 6., 78.,
555 14., 86., 22., 94., 7., 79., 15., 87., 23., 95., 8., 80., 16., 88.,
556 24., 96., 149., 221., 157., 229., 165., 237., 150., 222., 158., 230., 166., 238.,
557 151., 223., 159., 231., 167., 239., 152., 224., 160., 232., 168., 240., 25., 97.,
558 33., 105., 41., 113., 26., 98., 34., 106., 42., 114., 27., 99., 35., 107.,
559 43., 115., 28., 100., 36., 108., 44., 116., 169., 241., 177., 249., 185., 257.,
560 170., 242., 178., 250., 186., 258., 171., 243., 179., 251., 187., 259., 172., 244.,
561 180., 252., 188., 260., 29., 101., 37., 109., 45., 117., 30., 102., 38., 110.,
562 46., 118., 31., 103., 39., 111., 47., 119., 32., 104., 40., 112., 48., 120.,
563 173., 245., 181., 253., 189., 261., 174., 246., 182., 254., 190., 262., 175., 247.,
564 183., 255., 191., 263., 176., 248., 184., 256., 192., 264., 49., 121., 57., 129.,
565 65., 137., 50., 122., 58., 130., 66., 138., 51., 123., 59., 131., 67., 139.,
566 52., 124., 60., 132., 68., 140., 193., 265., 201., 273., 209., 281., 194., 266.,
567 202., 274., 210., 282., 195., 267., 203., 275., 211., 283., 196., 268., 204., 276.,
568 212., 284., 53., 125., 61., 133., 69., 141., 54., 126., 62., 134., 70., 142.,
569 55., 127., 63., 135., 71., 143., 56., 128., 64., 136., 72., 144., 197., 269.,
570 205., 277., 213., 285., 198., 270., 206., 278., 214., 286., 199., 271., 207., 279.,
571 215., 287., 200., 272., 208., 280., 216., 288.}),
572 read_vector<float>(result),
573 MIN_FLOAT_TOLERANCE_BITS));
576 NGRAPH_TEST(${BACKEND_NAME}, builder_reshape_1D_to_scalar)
578 const Shape input_shape{1};
579 const auto input = make_shared<op::Parameter>(element::f32, input_shape);
580 const auto reshape_builder = builder::opset1::reshape(input, Shape{});
581 auto function = make_shared<Function>(reshape_builder, ParameterVector{input});
583 auto test_case = test::TestCase<TestEngine>(function);
584 vector<float> input_values(shape_size(input_shape), 1.f);
585 test_case.add_input<float>(input_shape, input_values);
586 test_case.add_expected_output<float>(Shape{}, vector<float>{1.f});
591 NGRAPH_TEST(${BACKEND_NAME}, builder_reshape_3D_to_scalar)
593 const Shape input_shape{1, 1, 1};
594 const auto input = make_shared<op::Parameter>(element::f32, input_shape);
595 const auto reshape_builder = builder::opset1::reshape(input, Shape{});
596 auto function = make_shared<Function>(reshape_builder, ParameterVector{input});
598 auto test_case = test::TestCase<TestEngine>(function);
599 vector<float> input_values(shape_size(input_shape), 1.f);
600 test_case.add_input<float>(input_shape, input_values);
601 test_case.add_expected_output<float>(Shape{}, vector<float>{1.f});
606 #if NGRAPH_INTERPRETER_ENABLE
608 NGRAPH_TEST(${BACKEND_NAME}, reshape_shufflenet_5d)
610 Shape shape_a{1, 112, 56, 56};
611 auto A = make_shared<op::Parameter>(element::f32, shape_a);
612 Shape shape_b{1, 4, 28, 56, 56};
613 auto B = make_shared<op::Parameter>(element::f32, shape_b);
614 Shape shape_c{1, 28, 4, 56, 56};
615 auto C = make_shared<op::Parameter>(element::f32, shape_c);
616 Shape shape_r{1, 112, 56, 56};
618 vector<float> a_data(shape_size(shape_a));
619 iota(a_data.begin(), a_data.end(), 1.f);
621 auto r0 = make_shared<op::Reshape>(A, AxisVector{0, 1, 2, 3}, shape_b);
622 auto r1 = make_shared<op::Reshape>(r0, AxisVector{0, 2, 1, 3, 4}, shape_c);
623 auto r2 = make_shared<op::Reshape>(r1, AxisVector{0, 1, 2, 3, 4}, shape_r);
624 auto f = make_shared<Function>(r2, ParameterVector{A});
626 auto ref_func = clone_function(*f);
627 auto bk_func = clone_function(*f);
629 vector<vector<float>> args;
630 args.push_back(a_data);
632 auto ref_results = execute(ref_func, args, "INTERPRETER");
633 auto bk_results = execute(bk_func, args, "${BACKEND_NAME}");
635 EXPECT_TRUE(test::all_close_f(ref_results.at(0), bk_results.at(0), MIN_FLOAT_TOLERANCE_BITS));
638 #endif // NGRAPH_INTERPRETER_ENABLE