diff --git a/src/bindings/python/src/compatibility/pyngraph/types/element_type.cpp b/src/bindings/python/src/compatibility/pyngraph/types/element_type.cpp index 7165b28b758..070a89acd78 100644 --- a/src/bindings/python/src/compatibility/pyngraph/types/element_type.cpp +++ b/src/bindings/python/src/compatibility/pyngraph/types/element_type.cpp @@ -48,4 +48,5 @@ void regclass_pyngraph_Type(py::module m) { type.def_property_readonly("bitwidth", &ngraph::element::Type::bitwidth); type.def_property_readonly("is_real", &ngraph::element::Type::is_real); type.def("get_type_name", &ngraph::element::Type::get_type_name); + type.def("to_string", &ngraph::element::Type::to_string); } diff --git a/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp b/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp index f676b8822d7..9153287c5b2 100644 --- a/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp +++ b/src/bindings/python/src/pyopenvino/graph/types/element_type.cpp @@ -78,6 +78,7 @@ void regclass_graph_Type(py::module m) { type.def_property_readonly("signed", &ov::element::Type::is_signed); type.def("is_quantized", &ov::element::Type::is_quantized); type.def_property_readonly("quantized", &ov::element::Type::is_quantized); + type.def("to_string", &ov::element::Type::to_string); type.def("get_type_name", &ov::element::Type::get_type_name); type.def_property_readonly("type_name", &ov::element::Type::get_type_name); type.def("compatible", diff --git a/src/bindings/python/tests/test_transformations/test_offline_api.py b/src/bindings/python/tests/test_transformations/test_offline_api.py index b200006de5f..a1ba34d0e06 100644 --- a/src/bindings/python/tests/test_transformations/test_offline_api.py +++ b/src/bindings/python/tests/test_transformations/test_offline_api.py @@ -243,12 +243,12 @@ def test_compress_model_transformation(): node_constant = ov.opset8.constant(np.array([[0.0, 0.1, -0.1], [-2.5, 2.5, 3.0]], dtype=np.float32)) node_ceil = ov.opset8.ceiling(node_constant) model = Model(node_ceil, [], "TestModel") - elem_type = model.get_ordered_ops()[0].get_element_type().get_type_name() + elem_type = model.get_ordered_ops()[0].get_element_type().to_string() assert elem_type == "f32" compress_model_transformation(model) assert model is not None - elem_type = model.get_ordered_ops()[0].get_element_type().get_type_name() + elem_type = model.get_ordered_ops()[0].get_element_type().to_string() assert elem_type == "f16" diff --git a/src/bindings/python/tests_compatibility/runtime.py b/src/bindings/python/tests_compatibility/runtime.py index b2a51c3f744..4a295448532 100644 --- a/src/bindings/python/tests_compatibility/runtime.py +++ b/src/bindings/python/tests_compatibility/runtime.py @@ -50,14 +50,14 @@ def _convert_inputs(cnn_network: IENetwork) -> None: def apply_ng_type(output: DataPtr, ng_type: Type): ng_ie_supported_type_map = { - Type.boolean.get_type_name(): "BOOL", - Type.f32.get_type_name(): "FP32", - Type.i8.get_type_name(): "I8", - Type.i32.get_type_name(): "I32", - Type.u8.get_type_name(): "U8", + Type.boolean.to_string(): "BOOL", + Type.f32.to_string(): "FP32", + Type.i8.to_string(): "I8", + Type.i32.to_string(): "I32", + Type.u8.to_string(): "U8", } - if ng_type.get_type_name() in ng_ie_supported_type_map: - output.precision = ng_ie_supported_type_map[ng_type.get_type_name()] + if ng_type.to_string() in ng_ie_supported_type_map: + output.precision = ng_ie_supported_type_map[ng_type.to_string()] class Runtime(object): diff --git a/src/core/include/openvino/core/type/element_type.hpp b/src/core/include/openvino/core/type/element_type.hpp index b4fe6f80dcd..5bc60c0a397 100644 --- a/src/core/include/openvino/core/type/element_type.hpp +++ b/src/core/include/openvino/core/type/element_type.hpp @@ -114,6 +114,8 @@ public: constexpr operator Type_t() const { return m_type; } + // Return element type in string representation + std::string to_string() const; private: Type_t m_type{Type_t::undefined}; diff --git a/src/core/reference/src/runtime/reference/gather_tree.cpp b/src/core/reference/src/runtime/reference/gather_tree.cpp index ea50ba09c68..00c53995ea7 100644 --- a/src/core/reference/src/runtime/reference/gather_tree.cpp +++ b/src/core/reference/src/runtime/reference/gather_tree.cpp @@ -34,7 +34,7 @@ static size_t _asIndex(const char* source, const element::Type& element_type) { return static_cast(tmpBuff); } default: { - OPENVINO_THROW("Unsupported input data type: ", element_type.get_type_name()); + OPENVINO_THROW("Unsupported input data type: ", element_type.to_string()); } } } diff --git a/src/core/reference/src/runtime/reference/random_uniform.cpp b/src/core/reference/src/runtime/reference/random_uniform.cpp index 3b4b70c1b71..f22aa3e473d 100644 --- a/src/core/reference/src/runtime/reference/random_uniform.cpp +++ b/src/core/reference/src/runtime/reference/random_uniform.cpp @@ -305,7 +305,7 @@ std::pair random_uniform(const uint64_t* out_shape, break; } default: - OPENVINO_THROW("Unsupported type of RandomUniform: ", elem_type.get_type_name()); + OPENVINO_THROW("Unsupported type of RandomUniform: ", elem_type.to_string()); } if (++n == 0) ++counter; diff --git a/src/core/src/op/eye.cpp b/src/core/src/op/eye.cpp index 661cc4b1e12..a2ca854e5e8 100644 --- a/src/core/src/op/eye.cpp +++ b/src/core/src/op/eye.cpp @@ -133,7 +133,7 @@ bool ov::op::v9::Eye::evaluate(const ov::HostTensorVector& outputs, const ov::Ho break; default: OPENVINO_THROW("Unsupported type of input `diagonal_index` in Eye operation: ", - diagonal_index_data->get_element_type().get_type_name()); + diagonal_index_data->get_element_type().to_string()); } } else { diagonal_index = 0; diff --git a/src/core/src/op/psroi_pooling.cpp b/src/core/src/op/psroi_pooling.cpp index 7b4e2748960..d45999b87c5 100644 --- a/src/core/src/op/psroi_pooling.cpp +++ b/src/core/src/op/psroi_pooling.cpp @@ -50,10 +50,10 @@ void PSROIPooling::validate_and_infer_types() { const auto& coords_et = get_input_element_type(1); NODE_VALIDATION_CHECK(this, feat_maps_et.is_real(), - "Feature maps' data type must be floating point. Got " + feat_maps_et.get_type_name()); + "Feature maps' data type must be floating point. Got " + feat_maps_et.to_string()); NODE_VALIDATION_CHECK(this, coords_et.is_real(), - "Coords' data type must be floating point. Got " + coords_et.get_type_name()); + "Coords' data type must be floating point. Got " + coords_et.to_string()); OPENVINO_SUPPRESS_DEPRECATED_START const auto output_shapes = shape_infer(this, get_node_input_partial_shapes(*this)); diff --git a/src/core/src/op/random_uniform.cpp b/src/core/src/op/random_uniform.cpp index 1418ed4d948..5794df433f8 100644 --- a/src/core/src/op/random_uniform.cpp +++ b/src/core/src/op/random_uniform.cpp @@ -103,7 +103,7 @@ void op::v8::RandomUniform::validate_and_infer_types() { ", max value: ", max_val); } else { - OPENVINO_THROW("Unsupported output type of RandomUniform: " + get_out_type().get_type_name()); + OPENVINO_THROW("Unsupported output type of RandomUniform: " + get_out_type().to_string()); } } } @@ -155,7 +155,7 @@ bool op::v8::RandomUniform::evaluate(const HostTensorVector& outputs, const Host out_shape = out_shape_uint64.data(); } else { OPENVINO_THROW("Unsupported type of out shape in RandomUniform operation: " + - inputs[0]->get_element_type().get_type_name()); + inputs[0]->get_element_type().to_string()); } element::Type_t t_out = get_out_type(); @@ -180,7 +180,7 @@ bool op::v8::RandomUniform::evaluate(const HostTensorVector& outputs, const Host out = (char*)outputs[0]->get_data_ptr(); break; default: - OPENVINO_THROW("Unsupported type of RandomUniform: " + get_out_type().get_type_name()); + OPENVINO_THROW("Unsupported type of RandomUniform: " + get_out_type().to_string()); } auto state = ngraph::runtime::reference::random_uniform(out_shape, diff --git a/src/core/src/op/util/detection_output_base.cpp b/src/core/src/op/util/detection_output_base.cpp index 68c4b72f7b0..f8f1e3a22c9 100644 --- a/src/core/src/op/util/detection_output_base.cpp +++ b/src/core/src/op/util/detection_output_base.cpp @@ -28,16 +28,16 @@ void DetectionOutputBase::validate_base(const DetectionOutputBase::AttributesBas auto box_logits_et = get_input_element_type(0); NODE_VALIDATION_CHECK(this, box_logits_et.is_real(), - "Box logits' data type must be floating point. Got " + box_logits_et.get_type_name()); + "Box logits' data type must be floating point. Got " + box_logits_et.to_string()); auto class_preds_et = get_input_element_type(1); NODE_VALIDATION_CHECK(this, class_preds_et == box_logits_et, "Class predictions' data type must be the same as box logits type (" + - box_logits_et.get_type_name() + "). Got " + class_preds_et.get_type_name()); + box_logits_et.to_string() + "). Got " + class_preds_et.to_string()); auto proposals_et = get_input_element_type(2); NODE_VALIDATION_CHECK(this, proposals_et.is_real(), - "Proposals' data type must be floating point. Got " + proposals_et.get_type_name()); + "Proposals' data type must be floating point. Got " + proposals_et.to_string()); if (get_input_size() == 5) { auto aux_class_preds_et = get_input_element_type(3); @@ -45,12 +45,12 @@ void DetectionOutputBase::validate_base(const DetectionOutputBase::AttributesBas aux_class_preds_et == class_preds_et, "Additional class predictions' data type must be the same as class " "predictions data type (" + - class_preds_et.get_type_name() + "). Got " + aux_class_preds_et.get_type_name()); + class_preds_et.to_string() + "). Got " + aux_class_preds_et.to_string()); auto aux_box_preds_et = get_input_element_type(4); NODE_VALIDATION_CHECK(this, aux_box_preds_et == box_logits_et, "Additional box predictions' data type must be the same as box logits data type (" + - box_logits_et.get_type_name() + "). Got " + aux_box_preds_et.get_type_name()); + box_logits_et.to_string() + "). Got " + aux_box_preds_et.to_string()); } } diff --git a/src/core/src/pass/visualize_tree.cpp b/src/core/src/pass/visualize_tree.cpp index 813ac7de970..d694d6b1494 100644 --- a/src/core/src/pass/visualize_tree.cpp +++ b/src/core/src/pass/visualize_tree.cpp @@ -443,7 +443,7 @@ static std::string get_bounds_and_label_info(const ov::Output output) std::string pass::VisualizeTree::get_constant_value(std::shared_ptr node, size_t max_elements) { std::stringstream ss; - ss << "{" << node->get_element_type().get_type_name() << "}"; + ss << "{" << node->get_element_type().to_string() << "}"; ss << pretty_partial_shape(node->get_output_partial_shape(0)); if (const auto& constant = ov::as_type_ptr(node)) @@ -482,7 +482,7 @@ string pass::VisualizeTree::get_attributes(shared_ptr node) { for (const auto& input : node->inputs()) { label << "\\nin" << to_string(input.get_index()) << ": "; if (nvtot) - label << "{" << input.get_element_type().get_type_name() << "}"; + label << "{" << input.get_element_type().to_string() << "}"; if (nvtos) label << pretty_partial_shape(input.get_partial_shape()); label << ": " << node->get_input_node_ptr(input.get_index())->get_name() << ": out" @@ -497,7 +497,7 @@ string pass::VisualizeTree::get_attributes(shared_ptr node) { if (nvtio) label << "\\nout" << to_string(output.get_index()) << ": "; if (nvtot) - label << "{" << output.get_element_type().get_type_name() << "}"; + label << "{" << output.get_element_type().to_string() << "}"; if (nvtos) label << pretty_partial_shape(output.get_partial_shape()); diff --git a/src/core/src/preprocess/preprocess_steps_impl.cpp b/src/core/src/preprocess/preprocess_steps_impl.cpp index e1ab465863b..e155f89f5ac 100644 --- a/src/core/src/preprocess/preprocess_steps_impl.cpp +++ b/src/core/src/preprocess/preprocess_steps_impl.cpp @@ -155,7 +155,7 @@ void PreStepsList::add_convert_impl(const element::Type& type) { // doesn't require shape or type propagation. return std::make_tuple(res, false); }, - "convert type (" + type.get_type_name() + ")"); + "convert type (" + type.to_string() + ")"); } void PreStepsList::add_resize_impl(ResizeAlgorithm alg, int dst_height, int dst_width) { @@ -656,7 +656,7 @@ void PostStepsList::add_convert_impl(const element::Type& type) { auto convert = std::make_shared(node, t); return std::make_tuple(Output(convert), true); }, - "convert type (" + type.get_type_name() + ")"); + "convert type (" + type.to_string() + ")"); } void PostStepsList::add_convert_layout_impl(const Layout& layout) { diff --git a/src/core/src/type/element_type.cpp b/src/core/src/type/element_type.cpp index 3a04c9cc177..4dfafc38772 100644 --- a/src/core/src/type/element_type.cpp +++ b/src/core/src/type/element_type.cpp @@ -190,6 +190,10 @@ size_t ov::element::Type::hash() const { } std::string ov::element::Type::get_type_name() const { + return to_string(); +} + +std::string ov::element::Type::to_string() const { return get_type_info(m_type).m_type_name; } @@ -295,7 +299,7 @@ Type fundamental_type_for(const Type& type) { } // namespace ov std::ostream& ov::element::operator<<(std::ostream& out, const ov::element::Type& obj) { - return out << obj.get_type_name(); + return out << obj.to_string(); } std::istream& ov::element::operator>>(std::istream& in, ov::element::Type& obj) { @@ -325,7 +329,7 @@ std::istream& ov::element::operator>>(std::istream& in, ov::element::Type& obj) return in; } for (auto&& type : Type::get_known_types()) { - if (type->get_type_name() == str) { + if (type->to_string() == str) { obj = *type; break; } diff --git a/src/inference/dev_api/ie_ngraph_utils.hpp b/src/inference/dev_api/ie_ngraph_utils.hpp index 9d42867eba6..57ea7a00036 100644 --- a/src/inference/dev_api/ie_ngraph_utils.hpp +++ b/src/inference/dev_api/ie_ngraph_utils.hpp @@ -104,7 +104,7 @@ INFERENCE_ENGINE_1_0_DEPRECATED inline Precision convertPrecision(const ::ngraph case ::ngraph::element::Type_t::dynamic: return Precision(Precision::UNSPECIFIED); default: - IE_THROW() << "Incorrect precision " << precision.get_type_name() << "!"; + IE_THROW() << "Incorrect precision " << precision.to_string() << "!"; return {}; } }