diff --git a/src/core/src/layout.cpp b/src/core/src/layout.cpp index 6b22685f6b0..d583f13750f 100644 --- a/src/core/src/layout.cpp +++ b/src/core/src/layout.cpp @@ -277,7 +277,7 @@ Layout apply_permutation(const Layout& src_layout, const std::vector& std::vector find_permutation(const Layout& src_layout, const Rank& rank, const Layout& dst) { auto check_trivial = [](std::vector& res) -> std::vector& { size_t i = 0; - while (res[i] == i && i < res.size()) { + while (i < res.size() && res[i] == i) { i++; } if (i == res.size()) { diff --git a/src/core/tests/preprocess.cpp b/src/core/tests/preprocess.cpp index 097df100ea3..15222dbd013 100644 --- a/src/core/tests/preprocess.cpp +++ b/src/core/tests/preprocess.cpp @@ -675,6 +675,23 @@ TEST(pre_post_process, preprocess_convert_layout_default) { EXPECT_EQ(f->get_parameters()[0]->get_output_tensor(0).get_partial_shape(), (PartialShape{1, 2, 2, 3})); } +TEST(pre_post_process, preprocess_convert_layout_same_various) { + for (size_t i = 1; i < 100; i++) { + auto f = create_simple_function(element::f32, PartialShape::dynamic(static_cast(i))); + auto p = PrePostProcessor(f); + std::stringstream stream; + stream << "[0"; + for (auto j = 1; j < i; j++) { + stream << "," << std::to_string(j); + } + stream << "]"; + auto l = stream.str(); + p.input().tensor().set_layout(ov::Layout(l)); + p.input().network().set_layout(ov::Layout(std::string(i, '?'))); + EXPECT_NO_THROW(p.build()); + } +} + TEST(pre_post_process, preprocess_convert_layout_same) { auto f = create_simple_function(element::f32, Shape{1, 3, 2, 2}); auto size_old = f->get_ordered_ops().size();