From ce51b62b7008c75a2871b5b8e3eef00fa9972ee6 Mon Sep 17 00:00:00 2001 From: Gleb Kazantaev Date: Tue, 9 Nov 2021 21:11:54 +0300 Subject: [PATCH] Fix PartialShape Iterators to reset cache (#8453) --- .../include/openvino/core/partial_shape.hpp | 4 ++ ngraph/test/partial_shape.cpp | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/ngraph/core/include/openvino/core/partial_shape.hpp b/ngraph/core/include/openvino/core/partial_shape.hpp index 8ad68c66de7..e2810e6d274 100644 --- a/ngraph/core/include/openvino/core/partial_shape.hpp +++ b/ngraph/core/include/openvino/core/partial_shape.hpp @@ -224,6 +224,7 @@ public: /// element in the shape. Iteration is done in ordinary /// element order. iterator begin() noexcept { + m_shape_type = ShapeType::SHAPE_IS_UPDATED; return m_dimensions.begin(); } /// \brief Returns a read-only (constant) iterator that points to the @@ -236,6 +237,7 @@ public: /// element in the shape. Iteration is done in ordinary /// element order. iterator end() noexcept { + m_shape_type = ShapeType::SHAPE_IS_UPDATED; return m_dimensions.end(); } /// \brief Returns a read-only (constant) iterator that points one past @@ -248,6 +250,7 @@ public: /// last element in the shape. Iteration is done in reverse /// element order. reverse_iterator rbegin() noexcept { + m_shape_type = ShapeType::SHAPE_IS_UPDATED; return m_dimensions.rbegin(); } /// \brief Returns a read-only (constant) reverse iterator that points @@ -260,6 +263,7 @@ public: /// before the first element in the shape. Iteration is done /// in reverse element order. reverse_iterator rend() noexcept { + m_shape_type = ShapeType::SHAPE_IS_UPDATED; return m_dimensions.rend(); } /// \brief Returns a read-only (constant) reverse iterator that points diff --git a/ngraph/test/partial_shape.cpp b/ngraph/test/partial_shape.cpp index 75329b632af..756f793ddcb 100644 --- a/ngraph/test/partial_shape.cpp +++ b/ngraph/test/partial_shape.cpp @@ -9,6 +9,44 @@ using namespace ngraph; +TEST(partial_shape, interators) { + const PartialShape ps({1, 2, 3}); + ASSERT_TRUE(ps.is_static()); + { + auto p = ps; + for (auto& d : p) { + d = Dimension::dynamic(); + } + ASSERT_TRUE(p.is_dynamic()); + } + { + auto p = ps; + auto it = p.begin(); + *it = Dimension::dynamic(); + ASSERT_TRUE(p.is_dynamic()); + } + { + auto p = ps; + auto it = p.rbegin(); + *it = Dimension::dynamic(); + ASSERT_TRUE(p.is_dynamic()); + } + { + auto p = ps; + auto it = p.end(); + --it; + *it = Dimension::dynamic(); + ASSERT_TRUE(p.is_dynamic()); + } + { + auto p = ps; + auto it = p.rend(); + --it; + *it = Dimension::dynamic(); + ASSERT_TRUE(p.is_dynamic()); + } +} + TEST(partial_shape, ps_construction_empty) { auto ps = PartialShape{}; ASSERT_TRUE(ps.rank().is_static());