From 815980f290dfc42074031ae12447203014d28644 Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Mon, 27 Nov 2023 11:51:01 +0400 Subject: [PATCH] [PyOV] Replace legacy assert (#21268) * [PyOV] Replace legacy assert * codestyle * apply comments * Update src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp --- .../graph/dict_attribute_visitor.cpp | 4 +-- .../graph/dict_attribute_visitor.hpp | 8 ++--- .../python/src/pyopenvino/graph/model.cpp | 6 ++-- .../src/pyopenvino/graph/node_factory.cpp | 36 +++++++++---------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp b/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp index 3a170543f2e..2d8e36e64fa 100644 --- a/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp +++ b/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp @@ -262,7 +262,7 @@ void util::DictAttributeDeserializer::on_adapter(const std::string& name, auto body = std::make_shared(body_outputs, body_parameters); adapter.set(body); } else { - NGRAPH_CHECK(false, "No AttributeVisitor support for accessing attribute named: ", name); + OPENVINO_THROW("No AttributeVisitor support for accessing attribute named: ", name); } } } @@ -272,7 +272,7 @@ util::DictAttributeSerializer::DictAttributeSerializer(const std::shared_ptr& adapter) { if (m_attributes.contains(name)) { - NGRAPH_CHECK(false, "No AttributeVisitor support for accessing attribute named: ", name); + OPENVINO_THROW("No AttributeVisitor support for accessing attribute named: ", name); } } void util::DictAttributeSerializer::on_adapter(const std::string& name, ov::ValueAccessor& adapter) { diff --git a/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.hpp b/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.hpp index 84308b9c487..59462e5df54 100644 --- a/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.hpp +++ b/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.hpp @@ -86,10 +86,10 @@ public: template T get_attribute(const std::string& name) { - NGRAPH_CHECK(m_attributes.contains(name), - "Couldn't find attribute \"", - name, - "\" in serialized node attribute dictionary."); + OPENVINO_ASSERT(m_attributes.contains(name), + "Couldn't find attribute \"", + name, + "\" in serialized node attribute dictionary."); return m_attributes[name.c_str()].cast(); } diff --git a/src/bindings/python/src/pyopenvino/graph/model.cpp b/src/bindings/python/src/pyopenvino/graph/model.cpp index e83c403d3d5..08c30afd7d2 100644 --- a/src/bindings/python/src/pyopenvino/graph/model.cpp +++ b/src/bindings/python/src/pyopenvino/graph/model.cpp @@ -44,7 +44,7 @@ static ov::SinkVector cast_to_sink_vector(const std::vector(node); - NGRAPH_CHECK(sink != nullptr, "Node {} is not instance of Sink"); + OPENVINO_ASSERT(sink != nullptr, "Node {} is not instance of Sink"); sinks.push_back(sink); } return sinks; @@ -54,7 +54,7 @@ static std::vector> cast_to_node_vector(const ov::Sink std::vector> nodes; for (const auto& sink : sinks) { auto node = std::dynamic_pointer_cast(sink); - NGRAPH_CHECK(node != nullptr, "Sink {} is not instance of Node"); + OPENVINO_ASSERT(node != nullptr, "Sink {} is not instance of Node"); nodes.push_back(node); } return nodes; @@ -823,7 +823,7 @@ void regclass_graph_Model(py::module m) { for (py::handle sink : sinks) { auto sink_cpp = std::dynamic_pointer_cast(sink.cast>()); - NGRAPH_CHECK(sink_cpp != nullptr, "Assign {} is not instance of Sink"); + OPENVINO_ASSERT(sink_cpp != nullptr, "Assign {} is not instance of Sink"); sinks_cpp.push_back(sink_cpp); } self.add_sinks(sinks_cpp); diff --git a/src/bindings/python/src/pyopenvino/graph/node_factory.cpp b/src/bindings/python/src/pyopenvino/graph/node_factory.cpp index 7dde2d53b7b..6bcbb28b590 100644 --- a/src/bindings/python/src/pyopenvino/graph/node_factory.cpp +++ b/src/bindings/python/src/pyopenvino/graph/node_factory.cpp @@ -43,24 +43,24 @@ public: auto ext_it = m_opset_so_extensions.find(op_type_name); if (ext_it != m_opset_so_extensions.end()) { auto op_extension = std::dynamic_pointer_cast(ext_it->second->extension()); - NGRAPH_CHECK(op_extension); // guaranteed by add_extension method + OPENVINO_ASSERT(op_extension); // guaranteed by add_extension method util::DictAttributeDeserializer visitor(attributes, m_variables); auto outputs = op_extension->create(arguments, visitor); - NGRAPH_CHECK(outputs.size() > 0, - "Failed to create extension operation with type: ", - op_type_name, - " because it doesn't contain output ports. Operation should has at least one output port."); + OPENVINO_ASSERT(outputs.size() > 0, + "Failed to create extension operation with type: ", + op_type_name, + " because it doesn't contain output ports. Operation should has at least one output port."); auto node = outputs[0].get_node_shared_ptr(); return node; } else { std::shared_ptr op_node = std::shared_ptr(m_opset.create(op_type_name)); - NGRAPH_CHECK(op_node != nullptr, "Couldn't create operation: ", op_type_name); - NGRAPH_CHECK(!ov::op::util::is_constant(op_node), - "Currently NodeFactory doesn't support Constant operation: ", - op_type_name); + OPENVINO_ASSERT(op_node != nullptr, "Couldn't create operation: ", op_type_name); + OPENVINO_ASSERT(!ov::op::util::is_constant(op_node), + "Currently NodeFactory doesn't support Constant operation: ", + op_type_name); util::DictAttributeDeserializer visitor(attributes, m_variables); @@ -76,18 +76,18 @@ public: // Check for available extensions first, because they may override ops from main opset auto ext_it = m_opset_so_extensions.find(op_type_name); // No way to instantiate operation without inputs, so if extension operation is found report an error. - NGRAPH_CHECK(ext_it == m_opset_so_extensions.end(), - "Couldn't create operation of type ", - op_type_name, - " from an extension library as no inputs were provided. Currently NodeFactory doesn't support ", - "operations without inputs. Provide at least one input."); + OPENVINO_ASSERT(ext_it == m_opset_so_extensions.end(), + "Couldn't create operation of type ", + op_type_name, + " from an extension library as no inputs were provided. Currently NodeFactory doesn't support ", + "operations without inputs. Provide at least one input."); std::shared_ptr op_node = std::shared_ptr(m_opset.create(op_type_name)); - NGRAPH_CHECK(op_node != nullptr, "Couldn't create operation: ", op_type_name); - NGRAPH_CHECK(!ov::op::util::is_constant(op_node), - "Currently NodeFactory doesn't support Constant node: ", - op_type_name); + OPENVINO_ASSERT(op_node != nullptr, "Couldn't create operation: ", op_type_name); + OPENVINO_ASSERT(!ov::op::util::is_constant(op_node), + "Currently NodeFactory doesn't support Constant node: ", + op_type_name); OPENVINO_WARN << "Empty op created! Please assign inputs and attributes and run validate() before op is used.";