backend_reshape.in.cpp 24.7 KB
Newer Older
1
//*****************************************************************************
2
// Copyright 2017-2019 Intel Corporation
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>

#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"

using namespace std;
using namespace ngraph;

static string s_manifest = "${MANIFEST}";

NGRAPH_TEST(${BACKEND_NAME}, reshape_t2v_012)
{
    Shape shape_a{2, 2, 3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{12};
    auto r = make_shared<op::Reshape>(A, AxisVector{0, 1, 2}, shape_r);
43
    auto f = make_shared<Function>(r, ParameterVector{A});
44 45 46 47 48 49 50 51

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
    auto result = backend->create_tensor(element::f32, shape_r);

52
    auto handle = backend->compile(f);
53
    handle->call_with_validate({result}, {a});
54 55 56
    EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
57 58 59 60 61 62 63 64
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_t2s_012)
{
    Shape shape_a{1, 1, 1};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{};
    auto r = make_shared<op::Reshape>(A, AxisVector{0, 1, 2}, shape_r);
65
    auto f = make_shared<Function>(r, ParameterVector{A});
66 67 68 69 70 71 72 73

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{6});
    auto result = backend->create_tensor(element::f32, shape_r);

74
    auto handle = backend->compile(f);
75
    handle->call_with_validate({result}, {a});
76 77
    EXPECT_TRUE(test::all_close_f(
        (vector<float>{6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
78 79 80 81 82 83 84 85
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_t2s_120)
{
    Shape shape_a{1, 1, 1};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{};
    auto r = make_shared<op::Reshape>(A, AxisVector{1, 2, 0}, shape_r);
86
    auto f = make_shared<Function>(r, ParameterVector{A});
87 88 89 90 91 92 93 94

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{6});
    auto result = backend->create_tensor(element::f32, shape_r);

95
    auto handle = backend->compile(f);
96
    handle->call_with_validate({result}, {a});
97 98
    EXPECT_TRUE(test::all_close_f(
        (vector<float>{6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
99 100 101 102 103 104 105 106
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_s2t)
{
    Shape shape_a{};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{1, 1, 1, 1, 1, 1};
    auto r = make_shared<op::Reshape>(A, AxisVector{}, shape_r);
107
    auto f = make_shared<Function>(r, ParameterVector{A});
108 109 110 111 112 113 114 115

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{42});
    auto result = backend->create_tensor(element::f32, shape_r);

116
    auto handle = backend->compile(f);
117
    handle->call_with_validate({result}, {a});
118 119
    EXPECT_TRUE(test::all_close_f(
        (vector<float>{42}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
120 121 122 123 124 125 126 127
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_s2t1)
{
    Shape shape_a{};
    auto A = make_shared<op::Parameter>(element::boolean, shape_a);
    Shape shape_r{1};
    auto r = make_shared<op::Reshape>(A, AxisVector{}, shape_r);
128
    auto f = make_shared<Function>(r, ParameterVector{A});
129 130 131 132 133 134 135 136

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::boolean, shape_a);
    copy_data(a, vector<char>{42});
    auto result = backend->create_tensor(element::boolean, shape_r);

137
    auto handle = backend->compile(f);
138
    handle->call_with_validate({result}, {a});
139 140 141 142 143 144 145 146 147
    EXPECT_EQ((vector<char>{42}), read_vector<char>(result));
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_v2m_col)
{
    Shape shape_a{3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{3, 1};
    auto r = make_shared<op::Reshape>(A, AxisVector{0}, shape_r);
148
    auto f = make_shared<Function>(r, ParameterVector{A});
149 150 151 152 153 154 155 156

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3});
    auto result = backend->create_tensor(element::f32, shape_r);

157
    auto handle = backend->compile(f);
158
    handle->call_with_validate({result}, {a});
159 160
    EXPECT_TRUE(test::all_close_f(
        (vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
161 162 163 164 165 166 167 168
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_v2m_row)
{
    Shape shape_a{3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{1, 3};
    auto r = make_shared<op::Reshape>(A, AxisVector{0}, shape_r);
169
    auto f = make_shared<Function>(r, ParameterVector{A});
170 171 172 173 174 175 176 177

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3});
    auto result = backend->create_tensor(element::f32, shape_r);

178
    auto handle = backend->compile(f);
179
    handle->call_with_validate({result}, {a});
180 181
    EXPECT_TRUE(test::all_close_f(
        (vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
182 183 184 185 186 187 188 189
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_v2t_middle)
{
    Shape shape_a{3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{1, 3, 1};
    auto r = make_shared<op::Reshape>(A, AxisVector{0}, shape_r);
190
    auto f = make_shared<Function>(r, ParameterVector{A});
191 192 193 194 195 196 197 198

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3});
    auto result = backend->create_tensor(element::f32, shape_r);

199
    auto handle = backend->compile(f);
200
    handle->call_with_validate({result}, {a});
201 202
    EXPECT_TRUE(test::all_close_f(
        (vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
203 204 205 206 207 208 209 210
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_same)
{
    Shape shape_a{3, 3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{3, 3};
    auto r = make_shared<op::Reshape>(A, AxisVector{0, 1}, shape_r);
211
    auto f = make_shared<Function>(r, ParameterVector{A});
212 213 214 215 216 217 218 219

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
    auto result = backend->create_tensor(element::f32, shape_r);

220
    auto handle = backend->compile(f);
221
    handle->call_with_validate({result}, {a});
222 223 224
    EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
225 226 227 228 229 230 231 232
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_transpose)
{
    Shape shape_a{3, 3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{3, 3};
    auto r = make_shared<op::Reshape>(A, AxisVector{1, 0}, shape_r);
233
    auto f = make_shared<Function>(r, ParameterVector{A});
234 235 236 237 238 239 240 241

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
    auto result = backend->create_tensor(element::f32, shape_r);

242
    auto handle = backend->compile(f);
243
    handle->call_with_validate({result}, {a});
244 245 246
    EXPECT_TRUE(test::all_close_f((vector<float>{1, 4, 7, 2, 5, 8, 3, 6, 9}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
247 248 249 250 251 252 253 254
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_dim_change_transpose)
{
    Shape shape_a{3, 2};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{2, 3};
    auto r = make_shared<op::Reshape>(A, AxisVector{1, 0}, shape_r);
255
    auto f = make_shared<Function>(r, ParameterVector{A});
256 257 258 259 260 261 262 263

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3, 4, 5, 6});
    auto result = backend->create_tensor(element::f32, shape_r);

264
    auto handle = backend->compile(f);
265
    handle->call_with_validate({result}, {a});
266 267
    EXPECT_TRUE(test::all_close_f(
        (vector<float>{1, 3, 5, 2, 4, 6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
268 269 270 271 272 273 274 275
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_021)
{
    Shape shape_a{2, 3, 4};
    Shape shape_r{2, 4, 3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    auto r = make_shared<op::Reshape>(A, AxisVector{0, 2, 1}, shape_r);
276
    auto f = make_shared<Function>(r, ParameterVector{A});
277

278
    vector<float> a_data(shape_size(shape_a));
279
    iota(a_data.begin(), a_data.end(), 1.f);
280

281 282 283 284 285 286 287
    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);
    auto result = backend->create_tensor(element::f32, shape_r);

288
    auto handle = backend->compile(f);
289
    handle->call_with_validate({result}, {a});
290 291 292 293
    EXPECT_TRUE(test::all_close_f((vector<float>{1,  5,  9,  2,  6,  10, 3,  7,  11, 4,  8,  12,
                                                 13, 17, 21, 14, 18, 22, 15, 19, 23, 16, 20, 24}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
294 295 296 297 298 299 300 301
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_210)
{
    Shape shape_a{2, 3, 4};
    Shape shape_r{4, 3, 2};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    auto r = make_shared<op::Reshape>(A, AxisVector{2, 1, 0}, shape_r);
302
    auto f = make_shared<Function>(r, ParameterVector{A});
303

304
    vector<float> a_data(shape_size(shape_a));
305
    iota(a_data.begin(), a_data.end(), 1.f);
306

307 308 309 310 311 312 313
    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);
    auto result = backend->create_tensor(element::f32, shape_r);

314
    auto handle = backend->compile(f);
315
    handle->call_with_validate({result}, {a});
316 317 318 319
    EXPECT_TRUE(test::all_close_f((vector<float>{1, 13, 5, 17, 9,  21, 2, 14, 6, 18, 10, 22,
                                                 3, 15, 7, 19, 11, 23, 4, 16, 8, 20, 12, 24}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
320 321 322 323 324 325 326 327
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_201)
{
    Shape shape_a{2, 3, 4};
    Shape shape_r{4, 2, 3};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    auto r = make_shared<op::Reshape>(A, AxisVector{2, 0, 1}, shape_r);
328
    auto f = make_shared<Function>(r, ParameterVector{A});
329

330
    vector<float> a_data(shape_size(shape_a));
331
    iota(a_data.begin(), a_data.end(), 1.f);
332

333 334 335 336 337 338 339
    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);
    auto result = backend->create_tensor(element::f32, shape_r);

340
    auto handle = backend->compile(f);
341
    handle->call_with_validate({result}, {a});
342 343 344 345
    EXPECT_TRUE(test::all_close_f((vector<float>{1, 5, 9,  13, 17, 21, 2, 6, 10, 14, 18, 22,
                                                 3, 7, 11, 15, 19, 23, 4, 8, 12, 16, 20, 24}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
346 347 348 349 350 351 352 353
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_102)
{
    Shape shape_a{2, 3, 4};
    Shape shape_r{3, 2, 4};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    auto r = make_shared<op::Reshape>(A, AxisVector{1, 0, 2}, shape_r);
354
    auto f = make_shared<Function>(r, ParameterVector{A});
355

356
    vector<float> a_data(shape_size(shape_a));
357
    iota(a_data.begin(), a_data.end(), 1.f);
358

359 360 361 362 363 364 365
    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);
    auto result = backend->create_tensor(element::f32, shape_r);

366
    auto handle = backend->compile(f);
367
    handle->call_with_validate({result}, {a});
368 369 370 371
    EXPECT_TRUE(test::all_close_f((vector<float>{1,  2,  3,  4,  13, 14, 15, 16, 5,  6,  7,  8,
                                                 17, 18, 19, 20, 9,  10, 11, 12, 21, 22, 23, 24}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
372 373 374 375 376 377 378 379
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_3d_transpose_120)
{
    Shape shape_a{2, 3, 4};
    Shape shape_r{3, 4, 2};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    auto r = make_shared<op::Reshape>(A, AxisVector{1, 2, 0}, shape_r);
380
    auto f = make_shared<Function>(r, ParameterVector{A});
381

382
    vector<float> a_data(shape_size(shape_a));
383
    iota(a_data.begin(), a_data.end(), 1.f);
384

385 386 387 388 389 390 391
    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);
    auto result = backend->create_tensor(element::f32, shape_r);

392
    auto handle = backend->compile(f);
393
    handle->call_with_validate({result}, {a});
394 395 396 397
    EXPECT_TRUE(test::all_close_f((vector<float>{1, 13, 2, 14, 3, 15, 4,  16, 5,  17, 6,  18,
                                                 7, 19, 8, 20, 9, 21, 10, 22, 11, 23, 12, 24}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
398 399 400 401 402 403 404 405
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_4d_transpose)
{
    Shape shape_a{2, 2, 5, 5};
    Shape shape_r{2, 5, 5, 2};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    auto r = make_shared<op::Reshape>(A, AxisVector{0, 2, 3, 1}, shape_r);
406
    auto f = make_shared<Function>(r, ParameterVector{A});
407

408
    vector<float> a_data(shape_size(shape_a));
409
    iota(a_data.begin(), a_data.end(), 1.f);
410

411 412 413 414 415 416 417
    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);
    auto result = backend->create_tensor(element::f32, shape_r);

418
    auto handle = backend->compile(f);
419
    handle->call_with_validate({result}, {a});
420
    EXPECT_TRUE(test::all_close_f(
421 422 423 424 425 426 427
        (vector<float>{1.,  26., 2.,  27., 3.,  28., 4.,  29., 5.,  30., 6.,  31., 7.,  32., 8.,
                       33., 9.,  34., 10., 35., 11., 36., 12., 37., 13., 38., 14., 39., 15., 40.,
                       16., 41., 17., 42., 18., 43., 19., 44., 20., 45., 21., 46., 22., 47., 23.,
                       48., 24., 49., 25., 50., 51., 76., 52., 77., 53., 78., 54., 79., 55., 80.,
                       56., 81., 57., 82., 58., 83., 59., 84., 60., 85., 61., 86., 62., 87., 63.,
                       88., 64., 89., 65., 90., 66., 91., 67., 92., 68., 93., 69., 94., 70., 95.,
                       71., 96., 72., 97., 73., 98., 74., 99., 75., 100.}),
428 429
        read_vector<float>(result),
        MIN_FLOAT_TOLERANCE_BITS));
430 431 432 433 434 435 436 437
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_4d_no_transpose)
{
    Shape shape_a{2, 2, 5, 5};
    Shape shape_r{2, 5, 5, 2};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    auto r = make_shared<op::Reshape>(A, AxisVector{0, 1, 2, 3}, shape_r);
438
    auto f = make_shared<Function>(r, ParameterVector{A});
439

440
    vector<float> a_data(shape_size(shape_a));
441
    iota(a_data.begin(), a_data.end(), 1.f);
442

443 444 445 446 447 448 449
    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);
    auto result = backend->create_tensor(element::f32, shape_r);

450
    auto handle = backend->compile(f);
451
    handle->call_with_validate({result}, {a});
452
    EXPECT_TRUE(test::all_close_f(a_data, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
453 454 455 456 457 458 459 460
}

NGRAPH_TEST(${BACKEND_NAME}, reshape_transposed_shape_change)
{
    Shape shape_a{2, 6};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{12};
    auto r = make_shared<op::Reshape>(A, AxisVector{1, 0}, shape_r);
461
    auto f = make_shared<Function>(r, ParameterVector{A});
462 463 464 465 466 467 468 469

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
    auto result = backend->create_tensor(element::f32, shape_r);

470
    auto handle = backend->compile(f);
471
    handle->call_with_validate({result}, {a});
472 473 474
    EXPECT_TRUE(test::all_close_f((vector<float>{1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12}),
                                  read_vector<float>(result),
                                  MIN_FLOAT_TOLERANCE_BITS));
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
}

//
// Numpy:
//
// >>> x = linspace(1,2*2*3*3*2*4,2*2*3*3*2*4)
// >>> x.shape=(2,2,3,3,2,4)
// >>> y = ascontiguousarray(transpose(x,(2,4,0,5,3,1)))
// >>> y.shape=2*2*3*3*2*4
// >>> y
// array([   1.,   73.,    9.,   81.,   17.,   89.,    2.,   74.,   10.,
//          82.,   18.,   90.,    3.,   75.,   11.,   83.,   19.,   91.,
//           4.,   76.,   12.,   84.,   20.,   92.,  145.,  217.,  153.,
//         225.,  161.,  233.,  146.,  218.,  154.,  226.,  162.,  234.,
//         147.,  219.,  155.,  227.,  163.,  235.,  148.,  220.,  156.,
//         228.,  164.,  236.,    5.,   77.,   13.,   85.,   21.,   93.,
//           6.,   78.,   14.,   86.,   22.,   94.,    7.,   79.,   15.,
//          87.,   23.,   95.,    8.,   80.,   16.,   88.,   24.,   96.,
//         149.,  221.,  157.,  229.,  165.,  237.,  150.,  222.,  158.,
//         230.,  166.,  238.,  151.,  223.,  159.,  231.,  167.,  239.,
//         152.,  224.,  160.,  232.,  168.,  240.,   25.,   97.,   33.,
//         105.,   41.,  113.,   26.,   98.,   34.,  106.,   42.,  114.,
//          27.,   99.,   35.,  107.,   43.,  115.,   28.,  100.,   36.,
//         108.,   44.,  116.,  169.,  241.,  177.,  249.,  185.,  257.,
//         170.,  242.,  178.,  250.,  186.,  258.,  171.,  243.,  179.,
//         251.,  187.,  259.,  172.,  244.,  180.,  252.,  188.,  260.,
//          29.,  101.,   37.,  109.,   45.,  117.,   30.,  102.,   38.,
//         110.,   46.,  118.,   31.,  103.,   39.,  111.,   47.,  119.,
//          32.,  104.,   40.,  112.,   48.,  120.,  173.,  245.,  181.,
//         253.,  189.,  261.,  174.,  246.,  182.,  254.,  190.,  262.,
//         175.,  247.,  183.,  255.,  191.,  263.,  176.,  248.,  184.,
//         256.,  192.,  264.,   49.,  121.,   57.,  129.,   65.,  137.,
//          50.,  122.,   58.,  130.,   66.,  138.,   51.,  123.,   59.,
//         131.,   67.,  139.,   52.,  124.,   60.,  132.,   68.,  140.,
//         193.,  265.,  201.,  273.,  209.,  281.,  194.,  266.,  202.,
//         274.,  210.,  282.,  195.,  267.,  203.,  275.,  211.,  283.,
//         196.,  268.,  204.,  276.,  212.,  284.,   53.,  125.,   61.,
//         133.,   69.,  141.,   54.,  126.,   62.,  134.,   70.,  142.,
//          55.,  127.,   63.,  135.,   71.,  143.,   56.,  128.,   64.,
//         136.,   72.,  144.,  197.,  269.,  205.,  277.,  213.,  285.,
//         198.,  270.,  206.,  278.,  214.,  286.,  199.,  271.,  207.,
//         279.,  215.,  287.,  200.,  272.,  208.,  280.,  216.,  288.])
//
NGRAPH_TEST(${BACKEND_NAME}, reshape_6d)
{
    Shape shape_a{2, 2, 3, 3, 2, 4};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_r{3, 2, 2, 4, 3, 2};

524
    vector<float> a_data(shape_size(shape_a));
525
    iota(a_data.begin(), a_data.end(), 1.f);
526

527
    auto r = make_shared<op::Reshape>(A, AxisVector{2, 4, 0, 5, 3, 1}, shape_r);
528
    auto f = make_shared<Function>(r, ParameterVector{A});
529 530 531 532 533 534 535 536 537

    auto backend = runtime::Backend::create("${BACKEND_NAME}");

    // Create some tensors for input/output
    auto a = backend->create_tensor(element::f32, shape_a);
    copy_data(a, a_data);

    auto result = backend->create_tensor(element::f32, shape_r);

538
    auto handle = backend->compile(f);
539
    handle->call_with_validate({result}, {a});
540
    EXPECT_TRUE(test::all_close_f(
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
        (vector<float>{
            1.,   73.,  9.,   81.,  17.,  89.,  2.,   74.,  10.,  82.,  18.,  90.,  3.,   75.,
            11.,  83.,  19.,  91.,  4.,   76.,  12.,  84.,  20.,  92.,  145., 217., 153., 225.,
            161., 233., 146., 218., 154., 226., 162., 234., 147., 219., 155., 227., 163., 235.,
            148., 220., 156., 228., 164., 236., 5.,   77.,  13.,  85.,  21.,  93.,  6.,   78.,
            14.,  86.,  22.,  94.,  7.,   79.,  15.,  87.,  23.,  95.,  8.,   80.,  16.,  88.,
            24.,  96.,  149., 221., 157., 229., 165., 237., 150., 222., 158., 230., 166., 238.,
            151., 223., 159., 231., 167., 239., 152., 224., 160., 232., 168., 240., 25.,  97.,
            33.,  105., 41.,  113., 26.,  98.,  34.,  106., 42.,  114., 27.,  99.,  35.,  107.,
            43.,  115., 28.,  100., 36.,  108., 44.,  116., 169., 241., 177., 249., 185., 257.,
            170., 242., 178., 250., 186., 258., 171., 243., 179., 251., 187., 259., 172., 244.,
            180., 252., 188., 260., 29.,  101., 37.,  109., 45.,  117., 30.,  102., 38.,  110.,
            46.,  118., 31.,  103., 39.,  111., 47.,  119., 32.,  104., 40.,  112., 48.,  120.,
            173., 245., 181., 253., 189., 261., 174., 246., 182., 254., 190., 262., 175., 247.,
            183., 255., 191., 263., 176., 248., 184., 256., 192., 264., 49.,  121., 57.,  129.,
            65.,  137., 50.,  122., 58.,  130., 66.,  138., 51.,  123., 59.,  131., 67.,  139.,
            52.,  124., 60.,  132., 68.,  140., 193., 265., 201., 273., 209., 281., 194., 266.,
            202., 274., 210., 282., 195., 267., 203., 275., 211., 283., 196., 268., 204., 276.,
            212., 284., 53.,  125., 61.,  133., 69.,  141., 54.,  126., 62.,  134., 70.,  142.,
            55.,  127., 63.,  135., 71.,  143., 56.,  128., 64.,  136., 72.,  144., 197., 269.,
            205., 277., 213., 285., 198., 270., 206., 278., 214., 286., 199., 271., 207., 279.,
            215., 287., 200., 272., 208., 280., 216., 288.}),
563 564
        read_vector<float>(result),
        MIN_FLOAT_TOLERANCE_BITS));
565
}
566 567 568 569 570 571 572 573 574 575 576 577 578 579

#if NGRAPH_INTERPRETER_ENABLE

NGRAPH_TEST(${BACKEND_NAME}, reshape_shufflenet_5d)
{
    Shape shape_a{1, 112, 56, 56};
    auto A = make_shared<op::Parameter>(element::f32, shape_a);
    Shape shape_b{1, 4, 28, 56, 56};
    auto B = make_shared<op::Parameter>(element::f32, shape_b);
    Shape shape_c{1, 28, 4, 56, 56};
    auto C = make_shared<op::Parameter>(element::f32, shape_c);
    Shape shape_r{1, 112, 56, 56};

    vector<float> a_data(shape_size(shape_a));
580
    iota(a_data.begin(), a_data.end(), 1.f);
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595

    auto r0 = make_shared<op::Reshape>(A, AxisVector{0, 1, 2, 3}, shape_b);
    auto r1 = make_shared<op::Reshape>(r0, AxisVector{0, 2, 1, 3, 4}, shape_c);
    auto r2 = make_shared<op::Reshape>(r1, AxisVector{0, 1, 2, 3, 4}, shape_r);
    auto f = make_shared<Function>(r2, ParameterVector{A});

    auto ref_func = clone_function(*f);
    auto bk_func = clone_function(*f);

    vector<vector<float>> args;
    args.push_back(a_data);

    auto ref_results = execute(ref_func, args, "INTERPRETER");
    auto bk_results = execute(bk_func, args, "${BACKEND_NAME}");

596
    EXPECT_TRUE(test::all_close_f(ref_results.at(0), bk_results.at(0), MIN_FLOAT_TOLERANCE_BITS));
597 598 599
}

#endif //NGRAPH_INTERPRETER_ENABLE