OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[Common, PT, TF FE] Introduce common translators to support complex tensors in PyTorch (#29150)
Roman Kazantsev1a6536a6efac
diff --git a/cmake/developer_package/frontends/frontends.cmake b/cmake/developer_package/frontends/frontends.cmakeindex 955c7ca1e2c..0f3f0630421 100644--- a/cmake/developer_package/frontends/frontends.cmake+++ b/cmake/developer_package/frontends/frontends.cmake@@ -228,7 +228,8 @@ macro(ov_add_frontend)ov_add_vs_version_file(NAME ${TARGET_NAME}FILEDESCRIPTION ${OV_FRONTEND_FILEDESCRIPTION})- target_link_libraries(${TARGET_NAME} PRIVATE ${OV_FRONTEND_LINK_LIBRARIES} PUBLIC openvino::runtime)+ target_link_libraries(${TARGET_NAME} PRIVATE ${OV_FRONTEND_LINK_LIBRARIES} openvino::frontend::common_translators+ PUBLIC openvino::runtime)ov_add_library_version(${TARGET_NAME})if(OV_FRONTEND_PROTOBUF_REQUIRED)diff --git a/src/frontends/CMakeLists.txt b/src/frontends/CMakeLists.txtindex 7f66ddbb571..4535fa9f0e7 100644--- a/src/frontends/CMakeLists.txt+++ b/src/frontends/CMakeLists.txt@@ -4,6 +4,8 @@add_subdirectory(common)+add_subdirectory(common_translators)+if(ENABLE_TESTS)add_subdirectory(tests)endif()diff --git a/src/frontends/common/include/openvino/frontend/complex_type_mark.hpp b/src/frontends/common/include/openvino/frontend/complex_type_mark.hppindex b2300423762..c8f7d9f97fe 100644--- a/src/frontends/common/include/openvino/frontend/complex_type_mark.hpp+++ b/src/frontends/common/include/openvino/frontend/complex_type_mark.hpp@@ -5,6 +5,8 @@#pragma once#include "openvino/core/type/element_type.hpp"+#include "openvino/frontend/exception.hpp"+#include "openvino/frontend/node_context.hpp"#include "openvino/frontend/visibility.hpp"#include "openvino/op/util/framework_node.hpp"@@ -22,11 +24,12 @@ class FRONTEND_API ComplexTypeMark : public ov::op::util::FrameworkNode {public:OPENVINO_OP("ComplexTypeMark", "util", ov::op::util::FrameworkNode);- ComplexTypeMark(const ov::Output<ov::Node>& input, const ov::element::Type& complex_part_type)- : ov::op::util::FrameworkNode(ov::OutputVector{input}, 1),- m_complex_part_type(complex_part_type) {- validate_and_infer_types();- }+ ComplexTypeMark(const ov::Output<ov::Node>& input,+ const ov::element::Type& complex_part_type = ov::element::dynamic);++ ComplexTypeMark(const ov::Output<ov::Node>& real,+ const ov::Output<ov::Node>& imag,+ const ov::element::Type& complex_part_type = ov::element::dynamic);~ComplexTypeMark() override;@@ -44,8 +47,68 @@ public:return m_complex_part_type;}+ // Get a real part of the complex tensor+ ov::Output<ov::Node> get_real(bool squeezed = true);++ // Get an imaginary part of the complex tensor+ ov::Output<ov::Node> get_imag(bool squeezed = true);++ // Get floating-point representation of the complex tensor+ ov::Output<ov::Node> get_data();++ // Compute summation of two operands that can be of complex type+ // if operand is of complex type, complex type will be indicated by bool flag+ // complex tensor is represented as a real tensor with auxiliary dimension 2 in the tail+ // types of both operands must be aligned prior to the call+ static ov::Output<ov::Node> add(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs);++ // Compute subtraction of two operands that can be of complex type+ // if operand is of complex type, complex type will be indicated by bool flag+ // complex tensor is represented as a real tensor with auxiliary dimension 2 in the tail+ // types of both operands must be aligned prior to the call+ static ov::Output<ov::Node> sub(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs);++ // Compute multiplication of two operands that can be of complex type+ // if operand is of complex type, complex type will be indicated by bool flag+ // complex tensor is represented as a real tensor with auxiliary dimension 2 in the tail+ // types of both operands must be aligned prior to the call+ static ov::Output<ov::Node> mul(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs);++ // Compute inverse of operand that can be of complex type+ // if operand is of complex type, complex type will be indicated by bool flag+ // complex tensor is represented as a real tensor with auxiliary dimension 2 in the tail+ static ov::Output<ov::Node> inv(const NodeContext& context, const ov::Output<ov::Node>& data);++ // Compute division of two operands that can be of complex type+ // if operand is of complex type, complex type will be indicated by bool flag+ // complex tensor is represented as a real tensor with auxiliary dimension 2 in the tail+ // types of both operands must be aligned prior to the call+ static ov::Output<ov::Node> div(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs);++ // Convert type of real and imaginary parts of input to like type+ static ov::Output<ov::Node> convert_like(const NodeContext& context,+ const ov::Output<ov::Node>& input,+ const ov::Output<ov::Node>& like);+private:ov::element::Type m_complex_part_type;++ // floating-point tensor that represents complex tensor+ ov::Output<ov::Node> m_data;++ // real part of the complex tensor in squeezed form (no auxiliary dimension)+ ov::Output<ov::Node> m_real;++ // imaginary part of the complex tensor in squeezed form (no auxiliary dimension)+ ov::Output<ov::Node> m_imag;};} // namespace frontenddiff --git a/src/frontends/common/include/openvino/frontend/node_context.hpp b/src/frontends/common/include/openvino/frontend/node_context.hppindex 9d6bb787892..3ae60115226 100644--- a/src/frontends/common/include/openvino/frontend/node_context.hpp+++ b/src/frontends/common/include/openvino/frontend/node_context.hpp@@ -120,6 +120,21 @@ public:FRONT_END_NOT_IMPLEMENTED(get_subgraph);}+ /// \brief Returns Node object that can be with updated attributes+ /// such node name, runtime info, etc.+ /// By default, it returns the same node without update+ virtual std::shared_ptr<Node> mark_node(std::shared_ptr<Node> ov_node) const {+ return ov_node;+ }++ /// \brief PyTorch may have None inputs coming to operations+ /// Other frontends do not have it per our observation+ virtual bool input_is_none(size_t index) const {+ auto num_inputs = get_input_size();+ FRONT_END_GENERAL_CHECK(index < num_inputs, "Input index is out of allowed indices range");+ return false;+ }+private:virtual ov::Any apply_additional_conversion_rules(const ov::Any& data, const std::type_info& type_info) const {return data;diff --git a/src/frontends/common/src/complex_type_mark.cpp b/src/frontends/common/src/complex_type_mark.cppindex 25ccb1fe4a2..5f411c21653 100644--- a/src/frontends/common/src/complex_type_mark.cpp+++ b/src/frontends/common/src/complex_type_mark.cpp@@ -4,6 +4,314 @@#include "openvino/frontend/complex_type_mark.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/broadcast.hpp"+#include "openvino/op/concat.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/convert_like.hpp"+#include "openvino/op/divide.hpp"+#include "openvino/op/gather.hpp"+#include "openvino/op/maximum.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/op/negative.hpp"+#include "openvino/op/power.hpp"+#include "openvino/op/shape_of.hpp"+#include "openvino/op/subtract.hpp"+#include "openvino/op/unsqueeze.hpp"+using namespace ov::frontend;+using namespace ov::op;+using namespace std;++ComplexTypeMark::ComplexTypeMark(const ov::Output<ov::Node>& input, const ov::element::Type& complex_part_type)+ : ov::op::util::FrameworkNode(ov::OutputVector{input}, 1),+ m_complex_part_type(complex_part_type),+ m_data(input),+ m_real{},+ m_imag{} {+ validate_and_infer_types();+ if (input.get_element_type() != m_complex_part_type && m_complex_part_type.is_static()) {+ m_data = make_shared<v0::Convert>(m_data, m_complex_part_type);+ }++ if (m_complex_part_type.is_dynamic()) {+ m_complex_part_type = m_data.get_element_type();+ }+}++ComplexTypeMark::ComplexTypeMark(const ov::Output<ov::Node>& real,+ const ov::Output<ov::Node>& imag,+ const ov::element::Type& complex_part_type)+ : ov::op::util::FrameworkNode(ov::OutputVector{real, imag}, 1),+ m_complex_part_type(complex_part_type),+ m_data{},+ m_real{real},+ m_imag{imag} {+ validate_and_infer_types();+ if (m_real.get_element_type() != m_complex_part_type && m_complex_part_type.is_static()) {+ m_real = make_shared<v0::Convert>(m_real, m_complex_part_type);+ }+ if (m_imag.get_element_type() != m_complex_part_type && m_complex_part_type.is_static()) {+ m_imag = make_shared<v0::Convert>(m_imag, m_complex_part_type);+ }++ // need broadcast real and imaginary parts if they are of different shapes+ if (m_real.get_partial_shape().is_dynamic() || m_real.get_partial_shape() != m_imag.get_partial_shape()) {+ auto real_shape = make_shared<v3::ShapeOf>(m_real, element::i32);+ auto imag_shape = make_shared<v3::ShapeOf>(m_imag, element::i32);+ m_real = make_shared<v3::Broadcast>(m_real, imag_shape, BroadcastType::BIDIRECTIONAL);+ m_imag = make_shared<v3::Broadcast>(m_imag, real_shape, BroadcastType::BIDIRECTIONAL);+ }++ if (m_complex_part_type.is_dynamic()) {+ m_complex_part_type = m_real.get_element_type();+ }+}++ov::Output<ov::Node> ComplexTypeMark::get_real(bool squeezed) {+ if (m_real.get_node_shared_ptr() && squeezed) {+ return m_real;+ } else if (m_real.get_node_shared_ptr()) {+ auto minus_one = make_shared<v0::Constant>(element::i32, Shape{1}, -1);+ auto unsqueeze_real = make_shared<v0::Unsqueeze>(m_real, minus_one);+ return unsqueeze_real;+ }++ auto gather_index = make_shared<v0::Constant>(element::i32, Shape{}, 0);+ auto gather_axis = make_shared<v0::Constant>(element::i32, Shape{1}, -1);+ m_real = make_shared<v8::Gather>(m_data, gather_index, gather_axis);+ return m_real;+}++ov::Output<ov::Node> ComplexTypeMark::get_imag(bool squeezed) {+ if (m_imag.get_node_shared_ptr() && squeezed) {+ return m_imag;+ } else if (m_imag.get_node_shared_ptr()) {+ auto minus_one = make_shared<v0::Constant>(element::i32, Shape{1}, -1);+ auto unsqueeze_imag = make_shared<v0::Unsqueeze>(m_imag, minus_one);+ return unsqueeze_imag;+ }++ auto gather_index = make_shared<v0::Constant>(element::i32, Shape{}, 1);+ auto gather_axis = make_shared<v0::Constant>(element::i32, Shape{1}, -1);+ m_imag = make_shared<v8::Gather>(m_data, gather_index, gather_axis);+ return m_imag;+}++ov::Output<ov::Node> ComplexTypeMark::get_data() {+ if (m_data.get_node_shared_ptr()) {+ return m_data;+ }++ // create auxiliary dimensions to concatenate both real and imaginary parts to common shape+ auto const_neg_1 = v0::Constant::create(element::i32, Shape{}, {-1});+ auto unsqueeze_real = make_shared<v0::Unsqueeze>(m_real, const_neg_1);+ auto unsqueeze_imag = make_shared<v0::Unsqueeze>(m_imag, const_neg_1);++ m_data = make_shared<v0::Concat>(OutputVector{unsqueeze_real, unsqueeze_imag}, -1);+ return m_data;+}ComplexTypeMark::~ComplexTypeMark() = default;++ov::Output<ov::Node> ComplexTypeMark::add(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs) {+ auto lhs_complex = as_type_ptr<ComplexTypeMark>(lhs.get_node_shared_ptr());+ auto rhs_complex = as_type_ptr<ComplexTypeMark>(rhs.get_node_shared_ptr());++ if (lhs_complex && rhs_complex) {+ auto lhs_data = lhs_complex->get_data();+ auto rhs_data = rhs_complex->get_data();++ // both operands are of complex type+ auto result = context.mark_node(make_shared<v1::Add>(lhs_data, rhs_data))->output(0);+ auto complex_result = context.mark_node(make_shared<ComplexTypeMark>(result, result.get_element_type()));+ return {complex_result};+ } else if (lhs_complex) {+ // rhs is of a real type+ auto lhs_real = lhs_complex->get_real();+ auto lhs_imag = lhs_complex->get_imag();+ auto result_real = context.mark_node(make_shared<v1::Add>(lhs_real, rhs))->output(0);+ auto complex_result =+ context.mark_node(make_shared<ComplexTypeMark>(result_real, lhs_imag, result_real.get_element_type()));+ return {complex_result};+ } else if (rhs_complex) {+ // lhs is of a real type+ auto rhs_real = rhs_complex->get_real();+ auto rhs_imag = rhs_complex->get_imag();+ auto result_real = context.mark_node(make_shared<v1::Add>(rhs_real, lhs))->output(0);+ auto complex_result =+ context.mark_node(make_shared<ComplexTypeMark>(result_real, rhs_imag, result_real.get_element_type()));+ return {complex_result};+ }++ // both operands are real+ auto result = context.mark_node(make_shared<v1::Add>(lhs, rhs));++ return {result};+}++ov::Output<ov::Node> ComplexTypeMark::sub(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs) {+ auto lhs_complex = as_type_ptr<ComplexTypeMark>(lhs.get_node_shared_ptr());+ auto rhs_complex = as_type_ptr<ComplexTypeMark>(rhs.get_node_shared_ptr());++ if (lhs_complex && rhs_complex) {+ auto lhs_data = lhs_complex->get_data();+ auto rhs_data = rhs_complex->get_data();++ // both operands are of complex type+ auto result = context.mark_node(make_shared<v1::Subtract>(lhs_data, rhs_data))->output(0);+ auto complex_result = context.mark_node(make_shared<ComplexTypeMark>(result, result.get_element_type()));+ return {complex_result};+ } else if (lhs_complex) {+ // rhs is of a real type+ auto lhs_real = lhs_complex->get_real();+ auto lhs_imag = lhs_complex->get_imag();+ auto result_real = context.mark_node(make_shared<v1::Subtract>(lhs_real, rhs))->output(0);+ auto complex_result =+ context.mark_node(make_shared<ComplexTypeMark>(result_real, lhs_imag, result_real.get_element_type()));+ return {complex_result};+ } else if (rhs_complex) {+ // lhs is of a real type+ auto rhs_real = rhs_complex->get_real();+ auto rhs_imag = rhs_complex->get_imag();+ auto result_real = context.mark_node(make_shared<v1::Subtract>(lhs, rhs_real))->output(0);+ rhs_imag = context.mark_node(make_shared<v0::Negative>(rhs_imag));++ auto complex_result =+ context.mark_node(make_shared<ComplexTypeMark>(result_real, rhs_imag, result_real.get_element_type()));+ return {complex_result};+ }++ // both operands are real+ auto result = context.mark_node(make_shared<v1::Subtract>(lhs, rhs));++ return {result};+}++ov::Output<ov::Node> ComplexTypeMark::mul(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs) {+ auto lhs_complex = as_type_ptr<ComplexTypeMark>(lhs.get_node_shared_ptr());+ auto rhs_complex = as_type_ptr<ComplexTypeMark>(rhs.get_node_shared_ptr());++ if (lhs_complex && rhs_complex) {+ // both operands are of complex type+ // formula for guidance: (a + b*i) * (c + d*i) = (ac-bd) + (ad+bc)*i+ auto lr = lhs_complex->get_real();+ auto li = lhs_complex->get_imag();++ auto rr = rhs_complex->get_real();+ auto ri = rhs_complex->get_imag();++ auto mul_lr_rr = context.mark_node(make_shared<v1::Multiply>(lr, rr));+ auto mul_li_ri = context.mark_node(make_shared<v1::Multiply>(li, ri));+ auto res_real = context.mark_node(make_shared<v1::Subtract>(mul_lr_rr, mul_li_ri))->output(0);++ auto mul_lr_ri = context.mark_node(make_shared<v1::Multiply>(lr, ri));+ auto mul_li_rr = context.mark_node(make_shared<v1::Multiply>(li, rr));+ auto res_imag = context.mark_node(make_shared<v1::Add>(mul_lr_ri, mul_li_rr));++ auto complex_result =+ context.mark_node(make_shared<ComplexTypeMark>(res_real, res_imag, res_real.get_element_type()));+ return {complex_result};+ } else if (lhs_complex) {+ auto lhs_data = lhs_complex->get_data();++ // rhs is of a real type+ auto unsqueeze_axis = context.mark_node(make_shared<v0::Constant>(element::i32, Shape{1}, -1));+ auto unsqueezed_rhs = context.mark_node(make_shared<v0::Unsqueeze>(rhs, unsqueeze_axis));+ auto result = context.mark_node(make_shared<v1::Multiply>(lhs_data, unsqueezed_rhs))->output(0);++ auto complex_result = context.mark_node(make_shared<ComplexTypeMark>(result, result.get_element_type()));+ return {complex_result};+ } else if (rhs_complex) {+ auto rhs_data = rhs_complex->get_data();++ // rhs is of a real type+ auto unsqueeze_axis = context.mark_node(make_shared<v0::Constant>(element::i32, Shape{1}, -1));+ auto unsqueezed_lhs = context.mark_node(make_shared<v0::Unsqueeze>(lhs, unsqueeze_axis));+ auto result = context.mark_node(make_shared<v1::Multiply>(unsqueezed_lhs, rhs_data))->output(0);++ auto complex_result = context.mark_node(make_shared<ComplexTypeMark>(result, result.get_element_type()));+ return {complex_result};+ }++ // both operands are real+ auto result = context.mark_node(make_shared<v1::Multiply>(lhs, rhs));++ return {result};+}++ov::Output<ov::Node> ComplexTypeMark::inv(const NodeContext& context, const ov::Output<ov::Node>& data) {+ auto data_complex = as_type_ptr<ComplexTypeMark>(data.get_node_shared_ptr());++ if (data_complex) {+ auto real_imag = data_complex->get_data();+ auto real = data_complex->get_real();+ auto imag = data_complex->get_imag();++ // inverse of complex number:+ // 1 / (a + b*i) = (a/(a^2 + b^2)) + (-b/(a^2 + b^2))*i+ auto two = context.mark_node(make_shared<v0::Constant>(element::i32, Shape{}, 2));+ two = context.mark_node(make_shared<v1::ConvertLike>(two, real));+ auto real_squared = context.mark_node(make_shared<v1::Power>(real, two));+ auto imag_squared = context.mark_node(make_shared<v1::Power>(imag, two));+ auto denom = context.mark_node(make_shared<v1::Add>(real_squared, imag_squared));++ auto minus_imag = context.mark_node(make_shared<v0::Negative>(imag));++ auto res_real = context.mark_node(make_shared<v1::Divide>(real, denom))->output(0);+ auto res_imag = context.mark_node(make_shared<v1::Divide>(minus_imag, denom));++ auto complex_result =+ context.mark_node(make_shared<ComplexTypeMark>(res_real, res_imag, res_real.get_element_type()));+ return {complex_result};+ }++ auto one = context.mark_node(make_shared<v0::Constant>(element::i32, Shape{}, 1));+ one = context.mark_node(make_shared<v1::ConvertLike>(one, data));+ auto result = context.mark_node(make_shared<v1::Divide>(one, data));+ return {result};+}++ov::Output<ov::Node> ComplexTypeMark::div(const NodeContext& context,+ const ov::Output<ov::Node>& lhs,+ const ov::Output<ov::Node>& rhs) {+ // compute inverse of rhs+ auto inv_rhs = inv(context, rhs);+ // multiply lhs by inversed rhs+ auto result = mul(context, lhs, inv_rhs);+ return {result};+}++ov::Output<ov::Node> ComplexTypeMark::convert_like(const NodeContext& context,+ const ov::Output<ov::Node>& input,+ const ov::Output<ov::Node>& like) {+ auto like_complex = as_type_ptr<ComplexTypeMark>(like.get_node_shared_ptr());++ ov::Output<ov::Node> like_data = like;+ if (like_complex) {+ like_data =+ (like_complex->get_data().get_node_shared_ptr() ? like_complex->get_data() : like_complex->get_real());+ }++ auto input_complex = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());+ if (input_complex && input_complex->get_data().get_node_shared_ptr()) {+ auto new_input_data = input_complex->get_data();+ new_input_data = context.mark_node(make_shared<v1::ConvertLike>(new_input_data, like_data));+ return context.mark_node(make_shared<ComplexTypeMark>(new_input_data));+ } else if (input_complex) {+ auto new_real = input_complex->get_real();+ auto new_imag = input_complex->get_imag();+ new_real = context.mark_node(make_shared<v1::ConvertLike>(new_real, like_data));+ new_imag = context.mark_node(make_shared<v1::ConvertLike>(new_imag, like_data));+ return context.mark_node(make_shared<ComplexTypeMark>(new_real, new_imag));+ }++ return context.mark_node(make_shared<v1::ConvertLike>(input, like_data));+}diff --git a/src/frontends/common_translators/CMakeLists.txt b/src/frontends/common_translators/CMakeLists.txtnew file mode 100644index 00000000000..a2a72848153--- /dev/null+++ b/src/frontends/common_translators/CMakeLists.txt@@ -0,0 +1,5 @@+# Copyright (C) 2018-2025 Intel Corporation+# SPDX-License-Identifier: Apache-2.0+#++add_subdirectory(src)diff --git a/src/frontends/common_translators/include/common_translators.hpp b/src/frontends/common_translators/include/common_translators.hppnew file mode 100644index 00000000000..636c73c7f2e--- /dev/null+++ b/src/frontends/common_translators/include/common_translators.hpp@@ -0,0 +1,26 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/core/node_vector.hpp"+#include "openvino/frontend/node_context.hpp"++namespace ov {+namespace frontend {+namespace common_translators {+#define COMMON_OP_CONVERTER(op) OutputVector op(const ov::frontend::NodeContext& node)++COMMON_OP_CONVERTER(translate_complex);+COMMON_OP_CONVERTER(translate_real);+COMMON_OP_CONVERTER(translate_imag);++COMMON_OP_CONVERTER(translate_atan2);+COMMON_OP_CONVERTER(translate_angle);++OutputVector translate_atan2_util(const NodeContext& context, const Output<Node>& lhs, const Output<Node>& rhs);++} // namespace common_translators+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/common_translators/src/CMakeLists.txt b/src/frontends/common_translators/src/CMakeLists.txtnew file mode 100644index 00000000000..3d5556e040d--- /dev/null+++ b/src/frontends/common_translators/src/CMakeLists.txt@@ -0,0 +1,40 @@+# Copyright (C) 2018-2025 Intel Corporation+# SPDX-License-Identifier: Apache-2.0+#++set(TARGET_NAME "openvino_common_translators")+get_filename_component(root_dir "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)++file(GLOB_RECURSE LIBRARY_SRC ${root_dir}/src/*.cpp)+file(GLOB_RECURSE LIBRARY_HEADERS ${root_dir}/include/*.hpp)++add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${LIBRARY_HEADERS})+add_library(openvino::frontend::common_translators ALIAS ${TARGET_NAME})++if(NOT BUILD_SHARED_LIBS)+ target_compile_definitions(${TARGET_NAME} PRIVATE OPENVINO_STATIC_LIBRARY)+endif()++# remove -Wmissing-declarations warning, because of frontends implementation specific+if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG)+ target_compile_options(${TARGET_NAME} PRIVATE -Wno-missing-declarations)+endif()++set_target_properties(${TARGET_NAME} PROPERTIES+ INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})++target_link_libraries(${TARGET_NAME} PUBLIC openvino::core::dev)++target_include_directories(${TARGET_NAME}+ PUBLIC $<BUILD_INTERFACE:${root_dir}/include>+ PRIVATE ${root_dir}/src)++ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})+ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE})++ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}+ SOURCE_DIRECTORIES "${root_dir}/include"+ "${root_dir}/src"+ ADDITIONAL_INCLUDE_DIRECTORIES+ $<TARGET_PROPERTY:${TARGET_NAME},INTERFACE_INCLUDE_DIRECTORIES>+ $<TARGET_PROPERTY:${TARGET_NAME},INCLUDE_DIRECTORIES>)diff --git a/src/frontends/common_translators/src/op/angle.cpp b/src/frontends/common_translators/src/op/angle.cppnew file mode 100644index 00000000000..ed1dd3c6097--- /dev/null+++ b/src/frontends/common_translators/src/op/angle.cpp@@ -0,0 +1,55 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_translators.hpp"+#include "openvino/frontend/complex_type_mark.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/less.hpp"+#include "openvino/op/select.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace common_translators {++using namespace ov::op;+using namespace std;++OutputVector translate_angle(const NodeContext& context) {+ num_inputs_check(context, 1, 1, true);+ auto complex = context.get_input(0);++ auto op_type = context.get_op_type();+ auto complex_type_mark = as_type_ptr<ComplexTypeMark>(complex.get_node_shared_ptr());+ if (complex_type_mark) {+ // input is a complex tensor+ auto real_part = complex_type_mark->get_real();+ auto imag_part = complex_type_mark->get_imag();++ auto angle = translate_atan2_util(context, imag_part, real_part);+ return {angle};+ }++ // input real tensors is handled in such a way:+ // angle returns pi for negative real numbers,+ // zero for non-negative real numbers.+ const double pi_val = atan(1.0) * 4;+ auto real = complex;++ auto real_type = real.get_element_type();+ if (real_type.is_static() && real_type.is_integral()) {+ real = context.mark_node(std::make_shared<v0::Convert>(real, element::f32));+ }++ ov::Output<ov::Node> pi = create_same_type_const_scalar<double>(real, pi_val);+ ov::Output<ov::Node> zero = create_same_type_const_scalar<int32_t>(real, 0);+ auto is_negative = context.mark_node(make_shared<v1::Less>(real, zero));++ auto angle = context.mark_node(make_shared<v1::Select>(is_negative, pi, zero));+ return {angle};+}++} // namespace common_translators+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/common_translators/src/op/atan2.cpp b/src/frontends/common_translators/src/op/atan2.cppnew file mode 100644index 00000000000..8572f322c73--- /dev/null+++ b/src/frontends/common_translators/src/op/atan2.cpp@@ -0,0 +1,90 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/add.hpp"+#include "openvino/op/atan.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert_like.hpp"+#include "openvino/op/divide.hpp"+#include "openvino/op/equal.hpp"+#include "openvino/op/greater.hpp"+#include "openvino/op/greater_eq.hpp"+#include "openvino/op/less.hpp"+#include "openvino/op/logical_and.hpp"+#include "openvino/op/logical_or.hpp"+#include "openvino/op/select.hpp"+#include "openvino/op/subtract.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace common_translators {++using namespace ov::op;+using namespace std;++OutputVector translate_atan2_util(const NodeContext& context, const Output<Node>& lhs, const Output<Node>& rhs) {+ const double pi_val = atan(1.0) * 4;++ auto div = context.mark_node(make_shared<v1::Divide>(lhs, rhs));+ auto atan = context.mark_node(make_shared<v0::Atan>(div));++ // create some constants to adjust result according to quadrant.+ auto zero = context.mark_node(v0::Constant::create(ov::element::i32, Shape{}, {0}));+ auto pi = context.mark_node(v0::Constant::create(ov::element::f64, Shape{}, {pi_val}));+ auto half_pi = context.mark_node(v0::Constant::create(ov::element::f64, Shape{}, {pi_val / 2}));+ auto neg_half_pi = context.mark_node(v0::Constant::create(ov::element::f64, Shape{}, {-pi_val / 2}));++ zero = context.mark_node(make_shared<v1::ConvertLike>(zero, rhs));+ pi = context.mark_node(make_shared<v1::ConvertLike>(pi, rhs));+ half_pi = context.mark_node(make_shared<v1::ConvertLike>(half_pi, rhs));+ neg_half_pi = context.mark_node(make_shared<v1::ConvertLike>(neg_half_pi, rhs));++ // x > 0, no adjustment needed+ auto x_greater_than_zero = context.mark_node(make_shared<v1::Greater>(rhs, zero));++ // x < 0 and y >= 0, need to plus pi+ auto y_greater_equal_zero = context.mark_node(make_shared<v1::GreaterEqual>(lhs, zero));+ auto x_less_than_zero = context.mark_node(make_shared<v1::Less>(rhs, zero));+ auto add_pi_condition = context.mark_node(make_shared<v1::LogicalAnd>(x_less_than_zero, y_greater_equal_zero));++ // x < 0 and y < 0, need to minus pi+ auto y_less_than_zero = make_shared<v1::Less>(lhs, zero);+ auto subtract_pi_condition = context.mark_node(make_shared<v1::LogicalAnd>(x_less_than_zero, y_less_than_zero));++ // x = 0 and y > 0, pi/2+ auto x_equal_zero = make_shared<v1::Equal>(rhs, zero);+ auto y_greater_than_zero = make_shared<v1::Greater>(lhs, zero);+ auto half_pi_condition = context.mark_node(make_shared<v1::LogicalAnd>(x_equal_zero, y_greater_than_zero));++ // x = 0 and y < 0, -pi/2+ auto neg_half_pi_condition = context.mark_node(make_shared<v1::LogicalAnd>(x_equal_zero, y_less_than_zero));++ auto special_case_condition =+ context.mark_node(make_shared<v1::LogicalOr>(half_pi_condition, neg_half_pi_condition));++ // do adjustment+ auto atan_plus_pi = context.mark_node(make_shared<v1::Add>(atan, pi));+ auto atan_minus_pi = context.mark_node(make_shared<v1::Subtract>(atan, pi));++ // select result+ auto ajusted_case = context.mark_node(make_shared<v1::Select>(add_pi_condition, atan_plus_pi, atan_minus_pi));+ auto special_case = context.mark_node(make_shared<v1::Select>(half_pi_condition, half_pi, neg_half_pi));+ auto adjusted_atan = context.mark_node(make_shared<v1::Select>(x_greater_than_zero, atan, ajusted_case));+ auto result = context.mark_node(make_shared<v1::Select>(special_case_condition, special_case, adjusted_atan));++ return {result};+}++OutputVector translate_atan2(const NodeContext& context) {+ num_inputs_check(context, 2, 2);+ auto lhs = context.get_input(0);+ auto rhs = context.get_input(1);++ return translate_atan2_util(context, lhs, rhs);+}++} // namespace common_translators+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/common_translators/src/op/complex.cpp b/src/frontends/common_translators/src/op/complex.cppnew file mode 100644index 00000000000..e6d0afb3626--- /dev/null+++ b/src/frontends/common_translators/src/op/complex.cpp@@ -0,0 +1,59 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_translators.hpp"+#include "openvino/frontend/complex_type_mark.hpp"+#include "openvino/frontend/exception.hpp"+#include "openvino/frontend/node_context.hpp"+#include "openvino/op/broadcast.hpp"+#include "openvino/op/concat.hpp"+#include "openvino/op/maximum.hpp"+#include "openvino/op/shape_of.hpp"+#include "openvino/op/split.hpp"+#include "openvino/op/squeeze.hpp"+#include "openvino/op/unsqueeze.hpp"+#include "utils.hpp"++using namespace std;+using namespace ov::op;++namespace ov {+namespace frontend {+namespace common_translators {++OutputVector translate_complex(const NodeContext& context) {+ num_inputs_check(context, 2, 2);+ auto real = context.get_input(0);+ auto imag = context.get_input(1);++ auto complex_mark = context.mark_node(make_shared<ComplexTypeMark>(real, imag));++ return {complex_mark};+};++OutputVector translate_real(const NodeContext& context) {+ num_inputs_check(context, 1, 1, true);+ auto complex = context.get_input(0);++ auto complex_type_mark = as_type_ptr<ComplexTypeMark>(complex.get_node_shared_ptr());+ auto op_type = context.get_op_type();+ FRONT_END_OP_CONVERSION_CHECK(complex_type_mark, op_type + " operation expects complex type tensor on input.");++ return {complex_type_mark->get_real()};+};++OutputVector translate_imag(const NodeContext& context) {+ num_inputs_check(context, 1, 1, true);+ auto complex = context.get_input(0);++ auto complex_type_mark = as_type_ptr<ComplexTypeMark>(complex.get_node_shared_ptr());+ auto op_type = context.get_op_type();+ FRONT_END_OP_CONVERSION_CHECK(complex_type_mark, op_type + " operation expects complex type tensor on input.");++ return {complex_type_mark->get_imag()};+};++} // namespace common_translators+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/common_translators/src/utils.cpp b/src/frontends/common_translators/src/utils.cppnew file mode 100644index 00000000000..3af5d320cbd--- /dev/null+++ b/src/frontends/common_translators/src/utils.cpp@@ -0,0 +1,37 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "utils.hpp"++#include "openvino/frontend/complex_type_mark.hpp"+#include "openvino/frontend/exception.hpp"++namespace ov {+namespace frontend {+namespace common_translators {++void num_inputs_check(const NodeContext& context, size_t min_inputs, size_t max_inputs, bool allow_complex) {+ auto num_inputs = context.get_input_size();+ FRONT_END_OP_CONVERSION_CHECK(num_inputs >= min_inputs,+ "Got less inputs ",+ num_inputs,+ " than expected ",+ min_inputs);+ if (!allow_complex) {+ // verify that no input is complex+ for (int i = 0; i < static_cast<int>(std::min(num_inputs, max_inputs)); ++i) {+ auto input = context.get_input(i);+ auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());+ FRONT_END_OP_CONVERSION_CHECK(!complex_type_mark, "The operation doesn't allow complex type.");+ }+ }+ // Check that additional inputs are all None, otherwise raise exception+ for (auto i = max_inputs; i < num_inputs; i++) {+ FRONT_END_OP_CONVERSION_CHECK(context.input_is_none(i), "Got more inputs than expected: ", i + 1);+ }+}++} // namespace common_translators+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/common_translators/src/utils.hpp b/src/frontends/common_translators/src/utils.hppnew file mode 100644index 00000000000..115ad660481--- /dev/null+++ b/src/frontends/common_translators/src/utils.hpp@@ -0,0 +1,44 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/frontend/node_context.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert_like.hpp"++namespace ov {+namespace frontend {+namespace common_translators {++void num_inputs_check(const NodeContext& context, size_t min_inputs, size_t max_inputs, bool allow_complex = false);++template <typename T>+ov::Output<ov::Node> create_same_type_const_scalar(const ov::Output<ov::Node>& same_type_output, const T& value) {+ if (same_type_output.get_element_type().is_static()) {+ return std::make_shared<ov::op::v0::Constant>(same_type_output.get_element_type(), ov::Shape{}, value);+ } else {+ ov::Output<ov::Node> const_res =+ std::make_shared<ov::op::v0::Constant>(ov::element::from<T>(), ov::Shape{}, value);+ const_res = std::make_shared<ov::op::v1::ConvertLike>(const_res, same_type_output);+ return const_res;+ }+}++template <typename T>+ov::Output<ov::Node> create_same_type_const(const ov::Output<ov::Node>& same_type_output,+ const std::vector<T>& value,+ const ov::Shape& shape) {+ if (same_type_output.get_element_type().is_static()) {+ return std::make_shared<ov::op::v0::Constant>(same_type_output.get_element_type(), shape, value);+ } else {+ ov::Output<ov::Node> const_res = std::make_shared<ov::op::v0::Constant>(ov::element::from<T>(), shape, value);+ const_res = std::make_shared<ov::op::v1::ConvertLike>(const_res, same_type_output);+ return const_res;+ }+}++} // namespace common_translators+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hpp b/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hppindex 3dabfd2cdc0..ac99ce2ec5f 100644--- a/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hpp+++ b/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hpp@@ -63,7 +63,7 @@ public:return m_decoder->get_input_type(index);}- bool input_is_none(size_t index) const;+ bool input_is_none(size_t index) const override;Any get_output_type(size_t index) const {return m_decoder->get_output_type(index);@@ -85,7 +85,7 @@ public:return m_decoder->get_schema();}- std::shared_ptr<Node> mark_node(std::shared_ptr<Node> ov_node) const;+ std::shared_ptr<Node> mark_node(std::shared_ptr<Node> ov_node) const override;// Call mark_node for each node from the vectorvoid mark_nodes(std::vector<std::shared_ptr<Node>> ov_nodes) const {diff --git a/src/frontends/pytorch/src/op/add.cpp b/src/frontends/pytorch/src/op/add.cppindex d61fb263e56..0035fe56ab1 100644--- a/src/frontends/pytorch/src/op/add.cpp+++ b/src/frontends/pytorch/src/op/add.cpp@@ -4,6 +4,7 @@#include "openvino/op/add.hpp"+#include "openvino/frontend/complex_type_mark.hpp"#include "openvino/frontend/pytorch/node_context.hpp"#include "openvino/op/concat.hpp"#include "openvino/op/convert_like.hpp"@@ -17,26 +18,30 @@ namespace pytorch {namespace op {using namespace ov::op;+using namespace std;namespace {OutputVector translate_add_common(const NodeContext& context, bool inplace) {- num_inputs_check(context, 2, 3);- Output<Node> lhs;- Output<Node> rhs;+ num_inputs_check(context, 2, 3, true);+ Output<Node> lhs = context.get_input(0);+ Output<Node> rhs = context.get_input(1);auto dtype0 = context.get_input_type(0);auto dtype1 = context.get_input_type(1);+if (dtype0.is<type::List>() && dtype1.is<type::List>()) {// aten::add.t(t[] a, t[] b) -> t[]// Case when two lists gets concatenatedPYTORCH_OP_CONVERSION_CHECK(false, "aten::add is used for concatenation of lists, not possible to convert");}if (inplace) {- lhs = context.get_input(0);- rhs = context.get_input(1);if (lhs.get_element_type().is_dynamic() || lhs.get_element_type() != rhs.get_element_type())- rhs = context.mark_node(std::make_shared<v1::ConvertLike>(rhs, lhs));+ rhs = ComplexTypeMark::convert_like(context, rhs, lhs);} else {- std::tie(lhs, rhs) = get_inputs_with_promoted_types(context, 0, 1);+ align_eltwise_input_types(context,+ lhs,+ rhs,+ is_python_scalar_input(context, 0),+ is_python_scalar_input(context, 1));}auto left_is_bool = lhs.get_element_type() == ov::element::boolean ||@@ -59,13 +64,17 @@ OutputVector translate_add_common(const NodeContext& context, bool inplace) {} else if (context.has_attribute("alpha")) {alpha = context.get_attribute<Output<Node>>("alpha");}+if (alpha.get_node_shared_ptr()) {- auto converted_alpha = context.mark_node(std::make_shared<v1::ConvertLike>(alpha, rhs));- rhs = context.mark_node(std::make_shared<v1::Multiply>(converted_alpha, rhs));+ auto converted_alpha = ComplexTypeMark::convert_like(context, alpha, rhs);+ rhs = ComplexTypeMark::mul(context, rhs, converted_alpha);}- auto add = context.mark_node(std::make_shared<v1::Add>(lhs, rhs));++ auto add = ComplexTypeMark::add(context, lhs, rhs);+if (inplace)context.mutate_input(0, add);+return {add};};} // namespacediff --git a/src/frontends/pytorch/src/op/atan2.cpp b/src/frontends/pytorch/src/op/atan2.cppindex 501718bb844..b64776d0c12 100644--- a/src/frontends/pytorch/src/op/atan2.cpp+++ b/src/frontends/pytorch/src/op/atan2.cpp@@ -2,28 +2,8 @@// SPDX-License-Identifier: Apache-2.0//-#define _USE_MATH_DEFINES--#include <math.h>--#include <memory>--#include "openvino/core/type/element_type.hpp"+#include "common_translators.hpp"#include "openvino/frontend/pytorch/node_context.hpp"-#include "openvino/op/add.hpp"-#include "openvino/op/atan.hpp"-#include "openvino/op/constant.hpp"-#include "openvino/op/convert_like.hpp"-#include "openvino/op/divide.hpp"-#include "openvino/op/equal.hpp"-#include "openvino/op/greater.hpp"-#include "openvino/op/greater_eq.hpp"-#include "openvino/op/less.hpp"-#include "openvino/op/logical_and.hpp"-#include "openvino/op/logical_or.hpp"-#include "openvino/op/multiply.hpp"-#include "openvino/op/select.hpp"-#include "openvino/op/subtract.hpp"#include "utils.hpp"namespace ov {@@ -41,56 +21,7 @@ OutputVector translate_atan2(const NodeContext& context) {std::tie(lhs, rhs) = get_inputs_with_promoted_types(context, 0, 1);- auto div = context.mark_node(std::make_shared<v1::Divide>(lhs, rhs));-- auto atan = context.mark_node(std::make_shared<v0::Atan>(div));-- // create some constants to adjust result according to quadrant.- auto zero = context.mark_node(v0::Constant::create(ov::element::i32, Shape{}, {0}));- auto pi = context.mark_node(v0::Constant::create(ov::element::f64, Shape{}, {M_PI}));- auto half_pi = context.mark_node(v0::Constant::create(ov::element::f64, Shape{}, {M_PI_2}));- auto neg_half_pi = context.mark_node(v0::Constant::create(ov::element::f64, Shape{}, {-M_PI_2}));-- zero = context.mark_node(std::make_shared<v1::ConvertLike>(zero, rhs));- pi = context.mark_node(std::make_shared<v1::ConvertLike>(pi, rhs));- half_pi = context.mark_node(std::make_shared<v1::ConvertLike>(half_pi, rhs));- neg_half_pi = context.mark_node(std::make_shared<v1::ConvertLike>(neg_half_pi, rhs));-- // x > 0, no adjustment needed- auto x_greater_than_zero = context.mark_node(std::make_shared<v1::Greater>(rhs, zero));-- // x < 0 and y >= 0, need to plus pi- auto y_greater_equal_zero = context.mark_node(std::make_shared<v1::GreaterEqual>(lhs, zero));- auto x_less_than_zero = context.mark_node(std::make_shared<v1::Less>(rhs, zero));- auto add_pi_condition = context.mark_node(std::make_shared<v1::LogicalAnd>(x_less_than_zero, y_greater_equal_zero));-- // x < 0 and y < 0, need to minus pi- auto y_less_than_zero = std::make_shared<v1::Less>(lhs, zero);- auto subtract_pi_condition =- context.mark_node(std::make_shared<v1::LogicalAnd>(x_less_than_zero, y_less_than_zero));-- // x = 0 and y > 0, pi/2- auto x_equal_zero = std::make_shared<v1::Equal>(rhs, zero);- auto y_greater_than_zero = std::make_shared<v1::Greater>(lhs, zero);- auto half_pi_condition = context.mark_node(std::make_shared<v1::LogicalAnd>(x_equal_zero, y_greater_than_zero));-- // x = 0 and y < 0, -pi/2- auto neg_half_pi_condition = context.mark_node(std::make_shared<v1::LogicalAnd>(x_equal_zero, y_less_than_zero));-- auto special_case_condition =- context.mark_node(std::make_shared<v1::LogicalOr>(half_pi_condition, neg_half_pi_condition));-- // do adjustment- auto atan_plus_pi = context.mark_node(std::make_shared<v1::Add>(atan, pi));- auto atan_minus_pi = context.mark_node(std::make_shared<v1::Subtract>(atan, pi));-- // select result- auto ajusted_case = context.mark_node(std::make_shared<v1::Select>(add_pi_condition, atan_plus_pi, atan_minus_pi));- auto special_case = context.mark_node(std::make_shared<v1::Select>(half_pi_condition, half_pi, neg_half_pi));- auto adjusted_atan = context.mark_node(std::make_shared<v1::Select>(x_greater_than_zero, atan, ajusted_case));- auto result = context.mark_node(std::make_shared<v1::Select>(special_case_condition, special_case, adjusted_atan));-- return {result};+ return common_translators::translate_atan2_util(context, lhs, rhs);}} // namespace opdiff --git a/src/frontends/pytorch/src/op/complex.cpp b/src/frontends/pytorch/src/op/complex.cppindex 8ec0f5435e3..83f8a0fe3c4 100644--- a/src/frontends/pytorch/src/op/complex.cpp+++ b/src/frontends/pytorch/src/op/complex.cpp@@ -17,50 +17,6 @@ namespace op {using namespace ov::op;-OutputVector translate_complex(const NodeContext& context) {- num_inputs_check(context, 2, 2);- auto real = context.get_input(0);- auto imag = context.get_input(1);-- auto const_neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {-1}));- real = context.mark_node(std::make_shared<v0::Unsqueeze>(real, const_neg_1));- imag = context.mark_node(std::make_shared<v0::Unsqueeze>(imag, const_neg_1));-- auto complex = context.mark_node(std::make_shared<v0::Concat>(OutputVector{real, imag}, -1));-- return {context.mark_node(std::make_shared<ComplexTypeMark>(complex, complex->get_element_type()))};-};--OutputVector translate_imag(const NodeContext& context) {- num_inputs_check(context, 1, 1, true);- auto complex = context.get_input(0);-- auto complex_type_mark = as_type_ptr<ComplexTypeMark>(complex.get_node_shared_ptr());- PYTORCH_OP_CONVERSION_CHECK(complex_type_mark, "aten::imag operation expects complex type tensor on input.");-- complex = complex_type_mark->input_value(0);- auto axis = context.mark_node(v0::Constant::create(element::i32, Shape{}, {-1}));- auto imag = context.mark_node(std::make_shared<v1::Split>(complex, axis, 2))->output(1);-- auto const_neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {-1}));- return {context.mark_node(std::make_shared<v0::Squeeze>(imag, const_neg_1))};-};--OutputVector translate_real(const NodeContext& context) {- num_inputs_check(context, 1, 1, true);- auto complex = context.get_input(0);-- auto complex_type_mark = as_type_ptr<ComplexTypeMark>(complex.get_node_shared_ptr());- PYTORCH_OP_CONVERSION_CHECK(complex_type_mark, "aten::real operation expects complex type tensor on input.");-- complex = complex_type_mark->input_value(0);- auto axis = context.mark_node(v0::Constant::create(element::i32, Shape{}, {-1}));- auto real = context.mark_node(std::make_shared<v1::Split>(complex, axis, 2))->output(0);-- auto const_neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {-1}));- return {context.mark_node(std::make_shared<v0::Squeeze>(real, const_neg_1))};-};-OutputVector translate_view_as_real(const NodeContext& context) {num_inputs_check(context, 1, 1, true);auto complex = context.get_input(0);@@ -68,14 +24,14 @@ OutputVector translate_view_as_real(const NodeContext& context) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(complex.get_node_shared_ptr());PYTORCH_OP_CONVERSION_CHECK(complex_type_mark, "aten::real operation expects complex type tensor on input.");- return {complex_type_mark->input_value(0)};+ return {complex_type_mark->get_data()};};OutputVector translate_view_as_complex(const NodeContext& context) {num_inputs_check(context, 1, 1);auto complex = context.get_input(0);- return {context.mark_node(std::make_shared<ComplexTypeMark>(complex, complex.get_element_type()))};+ return {context.mark_node(std::make_shared<ComplexTypeMark>(complex))};};} // namespace opdiff --git a/src/frontends/pytorch/src/op/fft.cpp b/src/frontends/pytorch/src/op/fft.cppindex 0c2eb17c49d..b86b01efb21 100644--- a/src/frontends/pytorch/src/op/fft.cpp+++ b/src/frontends/pytorch/src/op/fft.cpp@@ -114,7 +114,7 @@ OutputVector translate_fft_irfftn(const NodeContext& context) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());PYTORCH_OP_CONVERSION_CHECK(complex_type_mark, "aten::fft_irfftn operation expects complex type tensor on input.");- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();auto const_neg_1 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {-1}));auto const_0 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0}));diff --git a/src/frontends/pytorch/src/op/mul.cpp b/src/frontends/pytorch/src/op/mul.cppindex e49b08637d1..50065bed674 100644--- a/src/frontends/pytorch/src/op/mul.cpp+++ b/src/frontends/pytorch/src/op/mul.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: Apache-2.0//+#include "openvino/frontend/complex_type_mark.hpp"#include "openvino/frontend/pytorch/node_context.hpp"#include "openvino/op/logical_and.hpp"#include "openvino/op/multiply.hpp"@@ -13,8 +14,10 @@ namespace pytorch {namespace op {using namespace ov::op;+using namespace std;OutputVector translate_mul_common(const NodeContext& context, bool inplace) {+ num_inputs_check(context, 2, 2, true);auto lhs = context.get_input(0);auto rhs = context.get_input(1);auto lhs_dtype = simplified_type_interpret(context.get_input_type(0));@@ -26,17 +29,38 @@ OutputVector translate_mul_common(const NodeContext& context, bool inplace) {(rhs_dtype.is<element::Type>() && rhs_dtype.as<element::Type>() == element::boolean);if (left_is_bool && right_is_bool) {- // if input types are boolean then aten::mul meand logical Add operation+ // if input types are boolean then aten::mul means logical Add operationif (inplace)return op::inplace_translate_1to1_match_2_inputs_align_types<v1::LogicalAnd>(context);elsereturn op::translate_1to1_match_2_inputs_align_types<v1::LogicalAnd>(context);}- if (inplace)- return op::inplace_translate_1to1_match_2_inputs_align_types<v1::Multiply>(context);- else- return op::translate_1to1_match_2_inputs_align_types<v1::Multiply>(context);+ if (inplace) {+ // For inplace op we know direction of type alignment+ if (lhs.get_element_type().is_dynamic() || lhs.get_element_type() != rhs.get_element_type())+ rhs = ComplexTypeMark::convert_like(context, rhs, lhs);++ auto res = ComplexTypeMark::mul(context, lhs, rhs);++ context.mutate_input(0, res);+ return {res};+ } else {+ auto lhs_type = context.get_input_type(0);+ auto rhs_type = context.get_input_type(1);+ // If type is string or None, we shouldn't align+ if (!lhs_type.is<type::Str>() && !rhs_type.is<type::Str>() && !lhs_type.is<type::PyNone>() &&+ !rhs_type.is<type::PyNone>()) {+ align_eltwise_input_types(context,+ lhs,+ rhs,+ is_python_scalar_input(context, 0),+ is_python_scalar_input(context, 1));+ }+ auto mul_res = OutputVector{ComplexTypeMark::mul(context, lhs, rhs)};+ align_output_types(context, mul_res);+ return mul_res;+ }}OutputVector translate_mul(const NodeContext& context) {@@ -50,4 +74,4 @@ OutputVector translate_mul_(const NodeContext& context) {} // namespace op} // namespace pytorch} // namespace frontend-} // namespace ov\ No newline at end of file+} // namespace ovdiff --git a/src/frontends/pytorch/src/op/permute.cpp b/src/frontends/pytorch/src/op/permute.cppindex c724e38b807..7621f77a4a5 100644--- a/src/frontends/pytorch/src/op/permute.cpp+++ b/src/frontends/pytorch/src/op/permute.cpp@@ -25,7 +25,7 @@ OutputVector translate_permute(const NodeContext& context) {Output<Node> rank;auto complex_type_mark = as_type_ptr<ComplexTypeMark>(data.get_node_shared_ptr());if (complex_type_mark) {- data = complex_type_mark->input_value(0);+ data = complex_type_mark->get_data();rank = std::get<1>(get_shape_rank(context, data));auto const_1 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1}));rank = context.mark_node(std::make_shared<v1::Subtract>(rank, const_1));diff --git a/src/frontends/pytorch/src/op/reshape.cpp b/src/frontends/pytorch/src/op/reshape.cppindex b9dcfc8d9af..8653f3216cf 100644--- a/src/frontends/pytorch/src/op/reshape.cpp+++ b/src/frontends/pytorch/src/op/reshape.cpp@@ -29,7 +29,7 @@ OutputVector translate_reshape(const NodeContext& context) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(tensor.get_node_shared_ptr());if (complex_type_mark) {- tensor = complex_type_mark->input_value(0);+ tensor = complex_type_mark->get_data();auto const_2 = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {2}));const_2 = context.mark_node(std::make_shared<v1::ConvertLike>(const_2, shape));diff --git a/src/frontends/pytorch/src/op/size.cpp b/src/frontends/pytorch/src/op/size.cppindex 2eca5f2707e..1beeba60b1f 100644--- a/src/frontends/pytorch/src/op/size.cpp+++ b/src/frontends/pytorch/src/op/size.cpp@@ -24,7 +24,7 @@ OutputVector translate_size(const NodeContext& context) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(data.get_node_shared_ptr());if (complex_type_mark) {- data = complex_type_mark->input_value(0);+ data = complex_type_mark->get_data();shape = context.mark_node(std::make_shared<v3::ShapeOf>(data, element::i64));auto zero = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0}));diff --git a/src/frontends/pytorch/src/op/sub.cpp b/src/frontends/pytorch/src/op/sub.cppindex 0697bc0cd01..54078aa0c8e 100644--- a/src/frontends/pytorch/src/op/sub.cpp+++ b/src/frontends/pytorch/src/op/sub.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: Apache-2.0//+#include "openvino/frontend/complex_type_mark.hpp"#include "openvino/frontend/pytorch/node_context.hpp"#include "openvino/op/convert_like.hpp"#include "openvino/op/multiply.hpp"@@ -14,26 +15,34 @@ namespace pytorch {namespace op {using namespace ov::op;+using namespace std;OutputVector translate_sub_common(const NodeContext& context, bool inplace) {- num_inputs_check(context, 2, 3);- Output<Node> x;- Output<Node> y;+ num_inputs_check(context, 2, 3, true);+ Output<Node> x = context.get_input(0);+ Output<Node> y = context.get_input(1);+if (inplace) {- x = context.get_input(0);- y = context.get_input(1);if (x.get_element_type().is_dynamic() || x.get_element_type() != y.get_element_type())- y = context.mark_node(std::make_shared<v1::ConvertLike>(y, x));+ y = ComplexTypeMark::convert_like(context, y, x);} else {- std::tie(x, y) = get_inputs_with_promoted_types(context, 0, 1);+ align_eltwise_input_types(context,+ x,+ y,+ is_python_scalar_input(context, 0),+ is_python_scalar_input(context, 1));}+// default alpha is 1 so no need to multiply if alpha is not providedif (!context.input_is_none(2)) {auto alpha = context.get_input(2);- auto casted_alpha = context.mark_node(std::make_shared<v1::ConvertLike>(alpha, y));- y = context.mark_node(std::make_shared<v1::Multiply>(casted_alpha, y));+ auto casted_alpha = ComplexTypeMark::convert_like(context, alpha, y);++ y = ComplexTypeMark::mul(context, y, casted_alpha);}- auto sub = context.mark_node(std::make_shared<v1::Subtract>(x, y));++ auto sub = ComplexTypeMark::sub(context, x, y);+if (inplace)context.mutate_input(0, sub);return {sub};diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cppindex 2d33b32472b..aeffe0c2a3d 100644--- a/src/frontends/pytorch/src/op_table.cpp+++ b/src/frontends/pytorch/src/op_table.cpp@@ -4,6 +4,7 @@#include "op_table.hpp"+#include "common_translators.hpp"#include "openvino/opsets/opset10.hpp"#include "utils.hpp"#include "utils_quantize.hpp"@@ -15,6 +16,8 @@ namespace op {#define OP_CONVERTER(op) OutputVector op(const NodeContext& node)+using namespace ov::frontend;+// TorchScript translationsOP_CONVERTER(translate_adaptive_avg_pool3d);OP_CONVERTER(translate_adaptive_avg_pool2d);@@ -385,6 +388,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {{"aten::amax", op::translate_amax},{"aten::amin", op::translate_amin},{"aten::aminmax", op::translate_aminmax},+ {"aten::angle", common_translators::translate_angle},{"aten::any", op::translate_any},// aten::append - Supported in limited set of patterns{"aten::arange", op::translate_arange},@@ -432,7 +436,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {{"aten::clip", op::translate_clamp},{"aten::clone", op::skip_node}, // ignore clone operators that are inserted by PyTorch autograd{"aten::col2im", op::translate_col2im},- {"aten::complex", op::translate_complex},+ {"aten::complex", common_translators::translate_complex},{"aten::concat", op::translate_cat},{"aten::concatenate", op::translate_cat},{"aten::contiguous", op::skip_node}, // In openvino how tensors are stored in memory is internal plugin detail,@@ -507,7 +511,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {{"aten::hardswish", op::quantizable_op<op::translate_1to1_match_1_inputs<opset10::HSwish>>},{"aten::hardtanh", op::quantizable_op<op::translate_hardtanh>},{"aten::im2col", op::translate_im2col},- {"aten::imag", op::translate_imag},+ {"aten::imag", common_translators::translate_imag},// aten::index - Supported in limited set of patterns{"aten::index_copy_", op::inplace_op<op::translate_index_copy_>},{"aten::index_fill_", op::inplace_op<op::translate_index_fill_>},@@ -616,7 +620,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {{"aten::randint", op::translate_randint},{"aten::randn", op::translate_randn},{"aten::randn_like", op::translate_randn_like},- {"aten::real", op::translate_real},+ {"aten::real", common_translators::translate_real},{"aten::reciprocal", op::optional_out<op::translate_reciprocal, 1>},{"aten::reciprocal_", op::inplace_op<op::translate_reciprocal>},// aten::reflection_pad2d - Supported in limited set of patterns@@ -794,6 +798,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_fx() {{"aten.all.default", op::translate_all},{"aten.amax.default", op::translate_amax},{"aten.amin.default", op::translate_amin},+ {"aten.angle.default", common_translators::translate_angle},{"aten.any.default", op::translate_any_fx},{"aten.any.dim", op::translate_any_fx},{"aten.any.dims", op::translate_any_fx},diff --git a/src/frontends/pytorch/src/utils.cpp b/src/frontends/pytorch/src/utils.cppindex bada5a97b82..69753fbc358 100644--- a/src/frontends/pytorch/src/utils.cpp+++ b/src/frontends/pytorch/src/utils.cpp@@ -472,6 +472,15 @@ void align_eltwise_input_types(const NodeContext& context,Output<Node>& rhs,const bool& is_lhs_python_scalar,const bool& is_rhs_python_scalar) {+ auto lhs_complex = as_type_ptr<ComplexTypeMark>(lhs.get_node_shared_ptr());+ auto rhs_complex = as_type_ptr<ComplexTypeMark>(rhs.get_node_shared_ptr());+ if (lhs_complex) {+ lhs = lhs_complex->input_value(0);+ }+ if (rhs_complex) {+ rhs = rhs_complex->input_value(0);+ }+const auto& lhs_type = lhs.get_element_type();const auto& rhs_type = rhs.get_element_type();auto const_0 = v0::Constant::create(element::i32, Shape{}, {1});@@ -506,6 +515,14 @@ void align_eltwise_input_types(const NodeContext& context,rhs = context.mark_node(std::make_shared<v0::Convert>(rhs, dst_type));}}++ if (lhs_complex) {+ lhs = ComplexTypeMark::convert_like(context, lhs_complex, lhs);+ }+ if (rhs_complex) {+ rhs = ComplexTypeMark::convert_like(context, rhs_complex, rhs);+ }+return;}diff --git a/src/frontends/tensorflow_common/include/utils.hpp b/src/frontends/tensorflow_common/include/utils.hppindex 30a3f31dc85..bb4deaa4b1e 100644--- a/src/frontends/tensorflow_common/include/utils.hpp+++ b/src/frontends/tensorflow_common/include/utils.hpp@@ -166,9 +166,8 @@ ov::Output<ov::Node> create_dense_tensor(const ov::Output<ov::Node>& indices,const ov::Output<ov::Node>& shape,const ov::Output<ov::Node>& values);-ov::Output<ov::Node> atan2_op(const ov::Output<ov::Node>& y, const ov::Output<ov::Node>& x);-std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> complex_rectangular_to_polar(+ const ov::frontend::NodeContext& node_context,const ov::Output<ov::Node>& real_part,const ov::Output<ov::Node>& imag_part);diff --git a/src/frontends/tensorflow_common/src/CMakeLists.txt b/src/frontends/tensorflow_common/src/CMakeLists.txtindex 5151468feba..77719bf73fb 100644--- a/src/frontends/tensorflow_common/src/CMakeLists.txt+++ b/src/frontends/tensorflow_common/src/CMakeLists.txt@@ -23,7 +23,7 @@ endif()set_target_properties(${TARGET_NAME} PROPERTIESINTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})-target_link_libraries(${TARGET_NAME} PRIVATE openvino::util+target_link_libraries(${TARGET_NAME} PRIVATE openvino::util openvino::frontend::common_translatorsPUBLIC openvino::core::dev)target_include_directories(${TARGET_NAME}diff --git a/src/frontends/tensorflow_common/src/op/addN.cpp b/src/frontends/tensorflow_common/src/op/addN.cppindex 9d16d12f7e5..678663d793f 100644--- a/src/frontends/tensorflow_common/src/op/addN.cpp+++ b/src/frontends/tensorflow_common/src/op/addN.cpp@@ -22,12 +22,12 @@ OutputVector translate_add_n_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(result.get_node_shared_ptr());if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- result = complex_type_mark->input_value(0);+ result = complex_type_mark->get_data();// converting all the inputs to complex type (simulating complex type) and adding themfor (int ind = 1; ind < num_size; ++ind) {auto complex_type_mark_ind = as_type_ptr<ComplexTypeMark>(node.get_input(ind).get_node_shared_ptr());- result = make_shared<v1::Add>(result, complex_type_mark_ind->input_value(0));+ result = make_shared<v1::Add>(result, complex_type_mark_ind->get_data());}auto complex_add_n = make_shared<ComplexTypeMark>(result, complex_part_type);set_node_name(node.get_name(), result.get_node_shared_ptr());diff --git a/src/frontends/tensorflow_common/src/op/angle.cpp b/src/frontends/tensorflow_common/src/op/angle.cppindex 28bc0bc42dd..ed9d8a2382d 100644--- a/src/frontends/tensorflow_common/src/op/angle.cpp+++ b/src/frontends/tensorflow_common/src/op/angle.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: Apache-2.0#include "common_op_table.hpp"+#include "common_translators.hpp"#include "helper_ops/complex_type_mark.hpp"#include "openvino/op/add.hpp"#include "openvino/op/atan.hpp"@@ -28,61 +29,14 @@ namespace op {OutputVector translate_angle_op(const NodeContext& node) {default_op_checks(node, 1, {"Angle"}, true);- auto complex = node.get_input(0);- auto result_type = node.get_attribute<ov::element::Type>("Tout");+ auto result_type = node.get_attribute<ov::element::Type>("Tout", element::f32);- auto complex_type_mark = as_type_ptr<ComplexTypeMark>(complex.get_node_shared_ptr());+ auto angle = common_translators::translate_angle(node)[0];- TENSORFLOW_OP_VALIDATION(- node,- complex_type_mark,- "[TensorFlow Frontend] inconsistent model: Angle operation expects complex type tensor on input");+ angle = make_shared<v0::Convert>(angle, result_type)->output(0);- complex = complex_type_mark->input_value(0);- auto real_index = make_shared<v0::Constant>(element::i32, Shape{}, 0);- auto imag_index = make_shared<v0::Constant>(element::i32, Shape{}, 1);- auto gather_axis = make_shared<v0::Constant>(element::i32, Shape{1}, -1);-- auto x = make_shared<v8::Gather>(complex, real_index, gather_axis)->output(0);- auto y = make_shared<v8::Gather>(complex, imag_index, gather_axis)->output(0);-- // handle the first condition : x>0- auto div_y_x = make_shared<v1::Divide>(y, x);- auto atan = make_shared<v0::Atan>(div_y_x);- auto const_zero = create_same_type_const_scalar<int32_t>(x, 0);- auto result = atan->output(0);-- // handle the second condition : x<0 && y>=0- auto const_pi = create_same_type_const_scalar<double>(x, std::atan(1.0) * 4);- auto is_x_negative = make_shared<v1::Less>(x, const_zero);- auto y_non_negative = make_shared<v1::GreaterEqual>(y, const_zero);- auto cond1 = make_shared<v1::LogicalAnd>(is_x_negative, y_non_negative);- auto atan_y_x_plus_pi = make_shared<v1::Add>(atan, const_pi);- result = make_shared<v1::Select>(cond1, atan_y_x_plus_pi, result);-- // handle the third condition : x<0 && y<0- auto is_y_negative = make_shared<v1::Less>(y, const_zero);- auto cond2 = make_shared<v1::LogicalAnd>(is_x_negative, is_y_negative);- auto atan_y_x_minus_pi = make_shared<v1::Subtract>(atan, const_pi);- result = make_shared<v1::Select>(cond2, atan_y_x_minus_pi, result);-- // handle the fourth condition : x=0 && y>0- auto is_x_zero = make_shared<v1::Equal>(x, const_zero);- auto is_y_positive = make_shared<v1::Greater>(y, const_zero);- auto cond3 = make_shared<v1::LogicalAnd>(is_x_zero, is_y_positive);- auto const_two = create_same_type_const_scalar<int32_t>(x, 2);- auto pi_div_two = make_shared<v1::Divide>(const_pi, const_two);- result = make_shared<v1::Select>(cond3, pi_div_two, result);-- // handle the fifth condition : x=0 && y<0- auto cond4 = make_shared<v1::LogicalAnd>(is_x_zero, is_y_negative);- auto const_minus_two = create_same_type_const_scalar<int32_t>(x, -2);- auto pi_div_minus_two = make_shared<v1::Divide>(const_pi, const_minus_two);- result = make_shared<v1::Select>(cond4, pi_div_two, result);- auto result_changed_type = make_shared<v0::Convert>(result, result_type)->output(0);-- set_node_name(node.get_name(), result_changed_type.get_node_shared_ptr());- return {result_changed_type};+ set_node_name(node.get_name(), angle.get_node_shared_ptr());+ return {angle};}} // namespace op} // namespace tensorflowdiff --git a/src/frontends/tensorflow_common/src/op/atan2.cpp b/src/frontends/tensorflow_common/src/op/atan2.cppindex 5cd48444bf3..97564ad4261 100644--- a/src/frontends/tensorflow_common/src/op/atan2.cpp+++ b/src/frontends/tensorflow_common/src/op/atan2.cpp@@ -2,19 +2,7 @@// SPDX-License-Identifier: Apache-2.0#include "common_op_table.hpp"-#include "openvino/op/add.hpp"-#include "openvino/op/atan.hpp"-#include "openvino/op/constant.hpp"-#include "openvino/op/convert_like.hpp"-#include "openvino/op/divide.hpp"-#include "openvino/op/equal.hpp"-#include "openvino/op/greater.hpp"-#include "openvino/op/greater_eq.hpp"-#include "openvino/op/less.hpp"-#include "openvino/op/logical_and.hpp"-#include "openvino/op/multiply.hpp"-#include "openvino/op/select.hpp"-#include "openvino/op/subtract.hpp"+#include "common_translators.hpp"using namespace std;using namespace ov::op;@@ -29,10 +17,10 @@ OutputVector translate_atan2_op(const NodeContext& node) {auto y = node.get_input(0);auto x = node.get_input(1);- auto result = atan2_op(y, x);+ auto result = common_translators::translate_atan2(node);- set_node_name(node.get_name(), result.get_node_shared_ptr());- return {result};+ set_node_name(node.get_name(), result[0].get_node_shared_ptr());+ return result;}} // namespace op} // namespace tensorflowdiff --git a/src/frontends/tensorflow_common/src/op/bias_add.cpp b/src/frontends/tensorflow_common/src/op/bias_add.cppindex 5e69a0f1c64..f9168cb4f2b 100644--- a/src/frontends/tensorflow_common/src/op/bias_add.cpp+++ b/src/frontends/tensorflow_common/src/op/bias_add.cpp@@ -27,8 +27,8 @@ OutputVector translate_bias_add_op(const NodeContext& node) {// validations prior to processingif (complex_type_inputs) {// extractions for complex processing- bias = complex_type_mark_bias->input_value(0);- value = complex_type_mark_value->input_value(0);+ bias = complex_type_mark_bias->get_data();+ value = complex_type_mark_value->get_data();}// retrieve optional attributesdiff --git a/src/frontends/tensorflow_common/src/op/binary_op.cpp b/src/frontends/tensorflow_common/src/op/binary_op.cppindex e2d89af6126..1e8beb56e12 100644--- a/src/frontends/tensorflow_common/src/op/binary_op.cpp+++ b/src/frontends/tensorflow_common/src/op/binary_op.cpp@@ -98,50 +98,10 @@ OutputVector translate_mul_op(const NodeContext& node) {default_op_checks(node, 2, {}, true);auto lhs = node.get_input(0);auto rhs = node.get_input(1);- auto result = make_shared<v1::Multiply>(lhs, rhs);- auto complex_type_mark_lhs = as_type_ptr<ComplexTypeMark>(lhs.get_node_shared_ptr());- auto complex_type_mark_rhs = as_type_ptr<ComplexTypeMark>(rhs.get_node_shared_ptr());- if (complex_type_mark_lhs || complex_type_mark_rhs) {- FRONT_END_GENERAL_CHECK(complex_type_mark_lhs != nullptr && complex_type_mark_rhs != nullptr,- "Mul gox complex and non-complex inputs. Inputs should be of same type.");- lhs = complex_type_mark_lhs->input_value(0);- rhs = complex_type_mark_rhs->input_value(0);+ auto result = ComplexTypeMark::mul(node, lhs, rhs);- element::Type complex_part_type_lhs = complex_type_mark_lhs->get_complex_part_type();- element::Type complex_part_type_rhs = complex_type_mark_rhs->get_complex_part_type();- FRONT_END_GENERAL_CHECK(complex_part_type_lhs == complex_part_type_rhs,- "Mul got complex inputs of different types. Inputs should be of same type.");-- auto gather_index_real = make_shared<v0::Constant>(element::i32, Shape{}, 0);- auto gather_index_imag = make_shared<v0::Constant>(element::i32, Shape{}, 1);-- auto minus_one = make_shared<v0::Constant>(element::i32, Shape{1}, -1);-- auto lhs_real = make_shared<v8::Gather>(lhs, gather_index_real, minus_one)->output(0);- auto lhs_imag = make_shared<v8::Gather>(lhs, gather_index_imag, minus_one)->output(0);- auto rhs_real = make_shared<v8::Gather>(rhs, gather_index_real, minus_one)->output(0);- auto rhs_imag = make_shared<v8::Gather>(rhs, gather_index_imag, minus_one)->output(0);-- // result_real = lhs_real * rhs_real - lhs_imag * rhs_imag- auto result_real = make_shared<v1::Subtract>(make_shared<v1::Multiply>(lhs_real, rhs_real),- make_shared<v1::Multiply>(lhs_imag, rhs_imag));-- // result_imag = lhs_real * rhs_imag + lhs_imag * rhs_real- auto result_imag = make_shared<v1::Add>(make_shared<v1::Multiply>(lhs_real, rhs_imag),- make_shared<v1::Multiply>(lhs_imag, rhs_real));-- auto real_unsqueeze = make_shared<v0::Unsqueeze>(result_real, minus_one);- auto imag_unsqueeze = make_shared<v0::Unsqueeze>(result_imag, minus_one);-- auto concat_result = make_shared<v0::Concat>(OutputVector{real_unsqueeze, imag_unsqueeze}, -1);- set_node_name(node.get_name(), concat_result);-- auto complex_result = make_shared<ComplexTypeMark>(concat_result->output(0), complex_part_type_lhs);- return {complex_result};- }-- set_node_name(node.get_name(), result);+ set_node_name(node.get_name(), result.get_node_shared_ptr());return {result};}@@ -150,24 +110,9 @@ OutputVector translate_addv2_op(const NodeContext& node) {auto lhs = node.get_input(0);auto rhs = node.get_input(1);- auto complex_type_mark_lhs = as_type_ptr<ComplexTypeMark>(lhs.get_node_shared_ptr());- auto complex_type_mark_rhs = as_type_ptr<ComplexTypeMark>(rhs.get_node_shared_ptr());- auto complex_type_inputs = (complex_type_mark_lhs || complex_type_mark_rhs) ? true : false;-- if (complex_type_inputs) {- lhs = complex_type_mark_lhs->input_value(0);- rhs = complex_type_mark_rhs->input_value(0);- }-- auto result = make_shared<v1::Add>(lhs, rhs);- if (complex_type_inputs) {- auto complex_result = make_shared<ComplexTypeMark>(result, complex_type_mark_lhs->get_complex_part_type());- set_node_name(node.get_name(), result);+ auto result = ComplexTypeMark::add(node, lhs, rhs);- return {complex_result};- }-- set_node_name(node.get_name(), result);+ set_node_name(node.get_name(), result.get_node_shared_ptr());return {result};}@@ -176,25 +121,9 @@ OutputVector translate_sub_op(const NodeContext& node) {auto lhs = node.get_input(0);auto rhs = node.get_input(1);- auto complex_type_mark_lhs = as_type_ptr<ComplexTypeMark>(lhs.get_node_shared_ptr());- auto complex_type_mark_rhs = as_type_ptr<ComplexTypeMark>(rhs.get_node_shared_ptr());- auto complex_type_inputs = (complex_type_mark_lhs && complex_type_mark_rhs);+ auto result = ComplexTypeMark::sub(node, lhs, rhs);- if (complex_type_inputs) {- lhs = complex_type_mark_lhs->input_value(0);- rhs = complex_type_mark_rhs->input_value(0);- }-- // performing an actual operation- auto result = make_shared<v1::Subtract>(lhs, rhs);-- if (complex_type_inputs) {- auto complex_result = make_shared<ComplexTypeMark>(result, complex_type_mark_lhs->get_complex_part_type());- set_node_name(node.get_name(), result);-- return {complex_result};- }- set_node_name(node.get_name(), result);+ set_node_name(node.get_name(), result.get_node_shared_ptr());return {result};}diff --git a/src/frontends/tensorflow_common/src/op/complex.cpp b/src/frontends/tensorflow_common/src/op/complex.cppindex 2dad0f323b4..2f46ec3fb32 100644--- a/src/frontends/tensorflow_common/src/op/complex.cpp+++ b/src/frontends/tensorflow_common/src/op/complex.cpp@@ -3,6 +3,7 @@//#include "common_op_table.hpp"+#include "common_translators.hpp"#include "helper_ops/complex_type_mark.hpp"#include "openvino/op/broadcast.hpp"#include "openvino/op/concat.hpp"@@ -22,37 +23,18 @@ namespace op {OutputVector translate_complex_op(const NodeContext& node) {default_op_checks(node, 2, {"Complex"}, true);- auto real = node.get_input(0);- auto imag = node.get_input(1);auto tout = node.get_attribute<string>("Tout", "DT_COMPLEX64");element::Type complex_part_type = (tout == "DT_COMPLEX64" ? element::f32 : element::f64);- // compute target shape to which real and imag parts must be broadcasted- // and broadcast them- auto real_shape = make_shared<v3::ShapeOf>(real, element::i32);- auto imag_shape = make_shared<v3::ShapeOf>(imag, element::i32);- auto target_shape = compute_broadcast_args(real_shape, imag_shape);- real = make_shared<v3::Broadcast>(real, target_shape);- imag = make_shared<v3::Broadcast>(imag, target_shape);+ auto complex_type_mark = common_translators::translate_complex(node);- // expand real and imaginary parts with one dimension in the end for further concatenation- // this way, complex tensor with real and imag of shapes [N1, N2, ..., Nk] will be represented as floating-point- // tensor of shape [N1, N2, ..., Nk, 2]- auto real_rank = compute_subgraph_scalar_rank(real, element::i32, false);- real = make_shared<v0::Unsqueeze>(real, real_rank);- imag = make_shared<v0::Unsqueeze>(imag, real_rank);-- // concatenate real and imaginary parts to have a complex tensor represented as a floating-point tensor of shape- // [N1, N2, ..., Nk, 2]- auto complex_tensor = make_shared<v0::Concat>(OutputVector{real, imag}, -1)->output(0);- complex_tensor = make_shared<v0::Convert>(complex_tensor, complex_part_type);-- // set node name and tensor- set_node_name(node.get_name(), complex_tensor.get_node_shared_ptr());-- // create complex type mark operation for upcoming operations in a graph- auto complex_type_mark = make_shared<ComplexTypeMark>(complex_tensor, complex_part_type);- return complex_type_mark->outputs();+ auto complex_type_mark_node = as_type_ptr<ComplexTypeMark>(complex_type_mark[0].get_node_shared_ptr());+ auto complex_tensor = complex_type_mark_node->get_data();+ if (complex_tensor.get_element_type() != complex_part_type) {+ complex_tensor = make_shared<v0::Convert>(complex_tensor, complex_part_type)->output(0);+ return make_shared<ComplexTypeMark>(complex_tensor, complex_part_type)->outputs();+ }+ return complex_type_mark;}} // namespace opdiff --git a/src/frontends/tensorflow_common/src/op/complex_abs.cpp b/src/frontends/tensorflow_common/src/op/complex_abs.cppindex af7ffd14404..c7088ea6424 100644--- a/src/frontends/tensorflow_common/src/op/complex_abs.cpp+++ b/src/frontends/tensorflow_common/src/op/complex_abs.cpp@@ -30,14 +30,13 @@ OutputVector translate_complex_abs_op(const NodeContext& node) {TENSORFLOW_OP_VALIDATION(node,complex_type_mark,"[TensorFlow Frontend] internal error: ComplexTypeMark is not set to input of " + op_type);- auto complex_part_type = complex_type_mark->get_complex_part_type();// data is complex tensor representation in a form [N1, N2, ..., Nk, 2]// where slice [N1, N2, ..., Nk, 0] contains real part of the complex tensor and// slice [N1, N2, ..., Nk, 1] contains imaginary part of the complex tensor- auto data = complex_type_mark->input_value(0);+ auto data = complex_type_mark->get_data();// compute element-wise square for complex representation- auto const_two = make_shared<v0::Constant>(complex_part_type, Shape{}, 2);+ auto const_two = create_same_type_const_scalar<int32_t>(data, 2);auto squared_data = make_shared<v1::Power>(data, const_two);// compute sum of squared real and imaginary parts@@ -45,7 +44,7 @@ OutputVector translate_complex_abs_op(const NodeContext& node) {auto complex_abs = make_shared<v1::ReduceSum>(squared_data, const_minus_one, false)->output(0);// compute ComplexAbs by root-squared operation- auto const_half = make_shared<v0::Constant>(complex_part_type, Shape{}, 0.5f);+ auto const_half = create_same_type_const_scalar<float>(data, 0.5f);complex_abs = make_shared<v1::Power>(complex_abs, const_half);// aling output type required by tout attributediff --git a/src/frontends/tensorflow_common/src/op/conj_transpose.cpp b/src/frontends/tensorflow_common/src/op/conj_transpose.cppindex ddfafd9b038..f22bd698543 100644--- a/src/frontends/tensorflow_common/src/op/conj_transpose.cpp+++ b/src/frontends/tensorflow_common/src/op/conj_transpose.cpp@@ -44,7 +44,7 @@ OutputVector translate_conj_op(const NodeContext& node) {std::shared_ptr<Node> conj{x.get_node_shared_ptr()};if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- auto x = complex_type_mark->input_value(0);+ auto x = complex_type_mark->get_data();auto conj = get_conj_ptr(x);set_node_name(node.get_name(), conj);@@ -65,7 +65,7 @@ OutputVector translate_conj_transpose_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(x.get_node_shared_ptr());if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- auto x = complex_type_mark->input_value(0);+ auto x = complex_type_mark->get_data();auto conj_tensor = get_conj_ptr(x);OutputVector concat_inputs;diff --git a/src/frontends/tensorflow_common/src/op/cumsum.cpp b/src/frontends/tensorflow_common/src/op/cumsum.cppindex ec9a1fb2ed8..dffaf465b96 100644--- a/src/frontends/tensorflow_common/src/op/cumsum.cpp+++ b/src/frontends/tensorflow_common/src/op/cumsum.cpp@@ -27,7 +27,7 @@ OutputVector translate_cumsum_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(x.get_node_shared_ptr());if (complex_type_mark) {- x = complex_type_mark->input_value(0);+ x = complex_type_mark->get_data();auto zero = create_same_type_const_scalar<int32_t>(axis, 0);auto less_than_zero = make_shared<v1::Less>(axis, zero);auto const_one = create_same_type_const_scalar<int32_t>(axis, 1);diff --git a/src/frontends/tensorflow_common/src/op/expand_dims.cpp b/src/frontends/tensorflow_common/src/op/expand_dims.cppindex be947fa07d1..478b6f935e3 100644--- a/src/frontends/tensorflow_common/src/op/expand_dims.cpp+++ b/src/frontends/tensorflow_common/src/op/expand_dims.cpp@@ -27,7 +27,7 @@ OutputVector translate_expand_dims_op(const NodeContext& node) {if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();auto const_zero = create_same_type_const_scalar<int32_t>(axis, 0);diff --git a/src/frontends/tensorflow_common/src/op/fft.cpp b/src/frontends/tensorflow_common/src/op/fft.cppindex f9715d046dd..17121ff44b9 100644--- a/src/frontends/tensorflow_common/src/op/fft.cpp+++ b/src/frontends/tensorflow_common/src/op/fft.cpp@@ -29,7 +29,7 @@ OutputVector translate_fft_op(const NodeContext& node) {node,complex_type_mark,"[TensorFlow Frontend] internal error: ComplexTypeMark is not set to input for " + op_type);- auto data = complex_type_mark->input_value(0);+ auto data = complex_type_mark->get_data();auto complex_part_type = complex_type_mark->get_complex_part_type();// compute a number of inner-most dimensionsdiff --git a/src/frontends/tensorflow_common/src/op/ifft.cpp b/src/frontends/tensorflow_common/src/op/ifft.cppindex 911c2ab1efa..8d7fb66e56c 100644--- a/src/frontends/tensorflow_common/src/op/ifft.cpp+++ b/src/frontends/tensorflow_common/src/op/ifft.cpp@@ -29,7 +29,7 @@ OutputVector translate_ifft_op(const NodeContext& node) {node,complex_type_mark,"[TensorFlow Frontend] internal error: ComplexTypeMark is not set to input for " + op_type);- auto data = complex_type_mark->input_value(0);+ auto data = complex_type_mark->get_data();auto complex_part_type = complex_type_mark->get_complex_part_type();// compute a number of inner-most dimensionsdiff --git a/src/frontends/tensorflow_common/src/op/inv.cpp b/src/frontends/tensorflow_common/src/op/inv.cppindex 6c351da2ed5..641b056ffec 100644--- a/src/frontends/tensorflow_common/src/op/inv.cpp+++ b/src/frontends/tensorflow_common/src/op/inv.cpp@@ -23,44 +23,11 @@ namespace op {OutputVector translate_inv_op(const NodeContext& node) {default_op_checks(node, 1, {"Inv"}, true);auto x = node.get_input(0);-- auto complex_type_mark = as_type_ptr<ComplexTypeMark>(x.get_node_shared_ptr());- if (complex_type_mark) {- x = complex_type_mark->input_value(0);- element::Type complex_part_type = complex_type_mark->get_complex_part_type();-- auto gather_index_real = make_shared<v0::Constant>(element::i32, Shape{}, 0);- auto gather_index_imag = make_shared<v0::Constant>(element::i32, Shape{}, 1);-- auto minus_one = make_shared<v0::Constant>(element::i32, Shape{1}, -1);-- auto x_real = make_shared<v8::Gather>(x, gather_index_real, minus_one)->output(0);- auto x_imag = make_shared<v8::Gather>(x, gather_index_imag, minus_one)->output(0);-- auto scale =- make_shared<v1::Add>(make_shared<v1::Multiply>(x_real, x_real), make_shared<v1::Multiply>(x_imag, x_imag));-- auto y_real = make_shared<v1::Divide>(x_real, scale);- auto y_imag = make_shared<v1::Divide>(make_shared<v0::Negative>(x_imag), scale);-- auto real_unsqueeze = make_shared<v0::Unsqueeze>(y_real, minus_one);- auto imag_unsqueeze = make_shared<v0::Unsqueeze>(y_imag, minus_one);-- auto concat_result = make_shared<v0::Concat>(OutputVector{real_unsqueeze, imag_unsqueeze}, -1);- set_node_name(node.get_name(), concat_result);-- auto complex_result = make_shared<ComplexTypeMark>(concat_result->output(0), complex_part_type);- return {complex_result};- }-- // prepare auxiliary one constants of the same type as the inputs- auto one = create_same_type_const_scalar<int32_t>(x, 1);-- auto inv = make_shared<v1::Divide>(one, x);- set_node_name(node.get_name(), inv);- return inv->outputs();+ auto inv = ComplexTypeMark::inv(node, x);+ set_node_name(node.get_name(), inv.get_node_shared_ptr());+ return {inv};}} // namespace op} // namespace tensorflow} // namespace frontend-} // namespace ov\ No newline at end of file+} // namespace ovdiff --git a/src/frontends/tensorflow_common/src/op/irfft.cpp b/src/frontends/tensorflow_common/src/op/irfft.cppindex 074762255bb..1616b146f2e 100644--- a/src/frontends/tensorflow_common/src/op/irfft.cpp+++ b/src/frontends/tensorflow_common/src/op/irfft.cpp@@ -43,13 +43,13 @@ OutputVector translate_irfft_op(const NodeContext& node) {// compute axes along which to compute inverse RFFTauto const_num_axes = make_shared<v0::Constant>(element::i32, Shape{}, num_axes);- auto data = complex_type_mark->input_value(0);+ auto data = complex_type_mark->get_data();auto data_rank = compute_subgraph_scalar_rank(data, element::i32, true);auto const_one = make_shared<v0::Constant>(element::i32, Shape{}, 1);auto data_rank_minus_one = make_shared<v1::Subtract>(data_rank, const_one);auto start = make_shared<v1::Subtract>(data_rank_minus_one, const_num_axes);auto axes = make_shared<v4::Range>(start, data_rank_minus_one, const_one, element::i32);- auto irdft = make_shared<v9::IRDFT>(complex_type_mark->input_value(0), axes, fft_length)->output(0);+ auto irdft = make_shared<v9::IRDFT>(data, axes, fft_length)->output(0);// no need to insert ComplexTypeMark because operation generates a floating-point tensorirdft = make_shared<v0::Convert>(irdft, treal);diff --git a/src/frontends/tensorflow_common/src/op/ones_like.cpp b/src/frontends/tensorflow_common/src/op/ones_like.cppindex 26221d9974e..2ca54a38427 100644--- a/src/frontends/tensorflow_common/src/op/ones_like.cpp+++ b/src/frontends/tensorflow_common/src/op/ones_like.cpp@@ -25,7 +25,7 @@ OutputVector translate_ones_like_op(const NodeContext& node) {auto x = node.get_input(0);auto complex_type_mark_x = as_type_ptr<ComplexTypeMark>(x.get_node_shared_ptr());if (complex_type_mark_x) {- x = complex_type_mark_x->input_value(0);+ x = complex_type_mark_x->get_data();auto gather_index_real = make_shared<v0::Constant>(element::i32, Shape{1}, 0);auto minus_one = make_shared<v0::Constant>(element::i32, Shape{1}, -1);auto x_real = make_shared<v8::Gather>(x, gather_index_real, minus_one)->output(0);diff --git a/src/frontends/tensorflow_common/src/op/pack.cpp b/src/frontends/tensorflow_common/src/op/pack.cppindex 7d0c281ea6b..481f06b0686 100644--- a/src/frontends/tensorflow_common/src/op/pack.cpp+++ b/src/frontends/tensorflow_common/src/op/pack.cpp@@ -39,7 +39,7 @@ OutputVector translate_pack_op(const NodeContext& node) {if (complex_type_mark) {has_complex_input = true;complex_part_type = complex_type_mark->get_complex_part_type();- in = complex_type_mark->input_value(0);+ in = complex_type_mark->get_data();}concat_inputs.push_back(make_shared<v0::Unsqueeze>(in, axis_const));}diff --git a/src/frontends/tensorflow_common/src/op/pad.cpp b/src/frontends/tensorflow_common/src/op/pad.cppindex dee3779fb0e..77b19a7cef9 100644--- a/src/frontends/tensorflow_common/src/op/pad.cpp+++ b/src/frontends/tensorflow_common/src/op/pad.cpp@@ -50,7 +50,7 @@ static OutputVector translate_pad_base_op(const NodeContext& node,if (auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr())) {is_complex = true;complex_part_type = complex_type_mark->get_complex_part_type();- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();}auto pad_mode = ov::op::PadMode::CONSTANT;@@ -76,7 +76,7 @@ OutputVector translate_pad_op(const NodeContext& node) {auto constant_value = create_same_type_const_scalar<int32_t>(input, 0);if (auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr())) {- constant_value = create_same_type_const_scalar<int32_t>(complex_type_mark->input_value(0), 0);+ constant_value = create_same_type_const_scalar<int32_t>(complex_type_mark->get_data(), 0);}return translate_pad_base_op(node, input, paddings, constant_value);@@ -88,7 +88,7 @@ OutputVector translate_padv2_op(const NodeContext& node) {auto paddings = node.get_input(1);auto constant_value = node.get_input(2);if (auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr())) {- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();element::Type complex_part_type = complex_type_mark->get_complex_part_type();auto gather_index_real = make_shared<v0::Constant>(element::i32, Shape{}, 0);@@ -98,7 +98,7 @@ OutputVector translate_padv2_op(const NodeContext& node) {auto x_imag = make_shared<v8::Gather>(input, gather_index_imag, minus_one)->output(0);auto constant_complex_type_mark = as_type_ptr<ComplexTypeMark>(constant_value.get_node_shared_ptr());- auto constant_input = constant_complex_type_mark->input_value(0);+ auto constant_input = constant_complex_type_mark->get_data();auto constant_value_real = make_shared<v8::Gather>(constant_input, gather_index_real, minus_one)->output(0);auto constant_value_imag = make_shared<v8::Gather>(constant_input, gather_index_imag, minus_one)->output(0);diff --git a/src/frontends/tensorflow_common/src/op/rank.cpp b/src/frontends/tensorflow_common/src/op/rank.cppindex 0f0038e4f9e..31a10e7e0cb 100644--- a/src/frontends/tensorflow_common/src/op/rank.cpp+++ b/src/frontends/tensorflow_common/src/op/rank.cpp@@ -22,7 +22,7 @@ ov::OutputVector translate_rank_op(const NodeContext& node) {auto input = node.get_input(0);auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());if (complex_type_mark) {- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();auto input_shape = make_shared<v3::ShapeOf>(input, ov::element::i32);auto unsqueeze_input_rank = make_shared<v3::ShapeOf>(input_shape, ov::element::i32);diff --git a/src/frontends/tensorflow_common/src/op/real_imag.cpp b/src/frontends/tensorflow_common/src/op/real_imag.cppindex a4a68b0bc6c..874152150b8 100644--- a/src/frontends/tensorflow_common/src/op/real_imag.cpp+++ b/src/frontends/tensorflow_common/src/op/real_imag.cpp@@ -3,6 +3,7 @@//#include "common_op_table.hpp"+#include "common_translators.hpp"#include "helper_ops/complex_type_mark.hpp"#include "openvino/op/constant.hpp"#include "openvino/op/convert.hpp"@@ -23,26 +24,18 @@ OutputVector translate_real_imag_op(const NodeContext& node) {auto op_type = node.get_op_type();auto input = node.get_input(0);auto tout = node.get_attribute<element::Type>("Tout", element::f32);- // Complex tensor is represented as a floating-point tensor of shape [N1, N2, ..., Nk, 2]- // where real part is placed in the slice by last dimension [..., 0] and- // imaginary part is placed by index [..., 1]- int32_t axis_value = (op_type == "Real") ? 0 : 1;-- // check that complex type mark is set at the input- auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());- TENSORFLOW_OP_VALIDATION(- node,- complex_type_mark,- "[TensorFlow Frontend] internal error: ComplexTypeMark is not set at the input of " + op_type);- auto data = complex_type_mark->input_value(0);-- // gather the required slice corresponding to Real or Imaginary part- auto gather_index = make_shared<v0::Constant>(element::i32, Shape{}, axis_value);- auto gather_axis = make_shared<v0::Constant>(element::i32, Shape{1}, -1);- auto complex_part = make_shared<v8::Gather>(data, gather_index, gather_axis)->output(0);++ ov::Output<ov::Node> complex_part;+ if (node.get_op_type() == "Real") {+ complex_part = common_translators::translate_real(node)[0];+ } else {+ complex_part = common_translators::translate_imag(node)[0];+ }// align output type required by tout attribute- complex_part = make_shared<v0::Convert>(complex_part, tout);+ if (tout != complex_part.get_element_type()) {+ complex_part = make_shared<v0::Convert>(complex_part, tout);+ }set_node_name(node.get_name(), complex_part.get_node_shared_ptr());diff --git a/src/frontends/tensorflow_common/src/op/reciprocal.cpp b/src/frontends/tensorflow_common/src/op/reciprocal.cppindex a18bed8fb37..9444cca3f22 100644--- a/src/frontends/tensorflow_common/src/op/reciprocal.cpp+++ b/src/frontends/tensorflow_common/src/op/reciprocal.cpp@@ -26,7 +26,7 @@ OutputVector translate_reciprocal_op(const NodeContext& node) {auto x = node.get_input(0);auto complex_type_mark_x = as_type_ptr<ComplexTypeMark>(x.get_node_shared_ptr());if (complex_type_mark_x) {- x = complex_type_mark_x->input_value(0);+ x = complex_type_mark_x->get_data();auto minus_one = make_shared<v0::Constant>(element::i32, Shape{1}, -1);auto two = create_same_type_const_scalar<int32_t>(x, 2);auto gather_index_real = make_shared<v0::Constant>(element::i32, Shape{1}, 0);diff --git a/src/frontends/tensorflow_common/src/op/reduce.cpp b/src/frontends/tensorflow_common/src/op/reduce.cppindex 94c9b506cd0..87459ae7904 100644--- a/src/frontends/tensorflow_common/src/op/reduce.cpp+++ b/src/frontends/tensorflow_common/src/op/reduce.cpp@@ -64,7 +64,7 @@ OutputVector translate_prod_op(const NodeContext& node) {if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();auto gather_index_real = make_shared<v0::Constant>(element::i64, Shape{}, 0);auto gather_index_imag = make_shared<v0::Constant>(element::i64, Shape{}, 1);@@ -80,7 +80,7 @@ OutputVector translate_prod_op(const NodeContext& node) {auto is_complex_number_zero = make_shared<v1::LogicalAnd>(is_real_part_zero, is_imag_part_zero);Output<Node> r, theta;- std::tie(r, theta) = complex_rectangular_to_polar(real_part, imag_part);+ std::tie(r, theta) = complex_rectangular_to_polar(node, real_part, imag_part);// theta for 0+0j will be nan but to make formula work properly it should be 0theta = make_shared<v1::Select>(is_complex_number_zero, const_zero, theta);diff --git a/src/frontends/tensorflow_common/src/op/reshape.cpp b/src/frontends/tensorflow_common/src/op/reshape.cppindex 678a815f9b3..44bbbdab8c0 100644--- a/src/frontends/tensorflow_common/src/op/reshape.cpp+++ b/src/frontends/tensorflow_common/src/op/reshape.cpp@@ -24,7 +24,7 @@ OutputVector translate_reshape_op(const NodeContext& node) {auto shape = node.get_input(1);if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- tensor = complex_type_mark->input_value(0);+ tensor = complex_type_mark->get_data();OutputVector concat_inputs;concat_inputs.push_back(shape);diff --git a/src/frontends/tensorflow_common/src/op/roll.cpp b/src/frontends/tensorflow_common/src/op/roll.cppindex 3beb967d7a4..3121d24c3c4 100644--- a/src/frontends/tensorflow_common/src/op/roll.cpp+++ b/src/frontends/tensorflow_common/src/op/roll.cpp@@ -32,7 +32,7 @@ ov::OutputVector translate_roll_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());element::Type complex_part_type = element::dynamic;if (complex_type_mark) {- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();complex_part_type = complex_type_mark->get_complex_part_type();// axes can be negative so we need to adjust themdiff --git a/src/frontends/tensorflow_common/src/op/rsqrt.cpp b/src/frontends/tensorflow_common/src/op/rsqrt.cppindex 92b3416d3d7..fa41f502273 100644--- a/src/frontends/tensorflow_common/src/op/rsqrt.cpp+++ b/src/frontends/tensorflow_common/src/op/rsqrt.cpp@@ -36,7 +36,7 @@ OutputVector translate_rsqrt_op(const NodeContext& node) {if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();// input is complex tensor representation in a form [N1, N2, ..., Nk, 2]// where slice [N1, N2, ..., Nk, 0] contains real part of the complex tensor// and slice [N1, N2, ..., Nk, 1] contains imaginary part of the complex tensordiff --git a/src/frontends/tensorflow_common/src/op/scatter_nd.cpp b/src/frontends/tensorflow_common/src/op/scatter_nd.cppindex 16b3bfd92bc..5ac4231ed48 100644--- a/src/frontends/tensorflow_common/src/op/scatter_nd.cpp+++ b/src/frontends/tensorflow_common/src/op/scatter_nd.cpp@@ -25,7 +25,7 @@ OutputVector translate_scatter_nd_op(const NodeContext& node) {if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- updates = complex_type_mark->input_value(0);+ updates = complex_type_mark->get_data();auto new_dim = create_same_type_const<int32_t>(shape, vector<int32_t>{2}, Shape{1});auto new_shape = make_shared<v0::Concat>(OutputVector{shape, new_dim}, -1);diff --git a/src/frontends/tensorflow_common/src/op/segment_sum.cpp b/src/frontends/tensorflow_common/src/op/segment_sum.cppindex df0ca8455b5..cedd60c3ea9 100644--- a/src/frontends/tensorflow_common/src/op/segment_sum.cpp+++ b/src/frontends/tensorflow_common/src/op/segment_sum.cpp@@ -49,7 +49,7 @@ OutputVector translate_segment_sum_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(data.get_node_shared_ptr());if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- data = complex_type_mark->input_value(0);+ data = complex_type_mark->get_data();auto emb_segment_sum_complex = make_shared<v3::EmbeddingSegmentsSum>(data, indices, segment_ids, num_segments);auto emb_segment_sum_complex_output =make_shared<ComplexTypeMark>(emb_segment_sum_complex->output(0), complex_part_type);diff --git a/src/frontends/tensorflow_common/src/op/select.cpp b/src/frontends/tensorflow_common/src/op/select.cppindex 35c7e893e54..dea7781b643 100644--- a/src/frontends/tensorflow_common/src/op/select.cpp+++ b/src/frontends/tensorflow_common/src/op/select.cpp@@ -36,11 +36,11 @@ bool has_complex_inputs(Output<Node>& x, Output<Node>& y, element::Type& complexauto complex_type_mark_x = as_type_ptr<ComplexTypeMark>(x.get_node_shared_ptr());auto complex_type_mark_y = as_type_ptr<ComplexTypeMark>(y.get_node_shared_ptr());if (complex_type_mark_x) {- x = complex_type_mark_x->input_value(0);+ x = complex_type_mark_x->get_data();complex_part_type = complex_type_mark_x->get_complex_part_type();}if (complex_type_mark_y) {- y = complex_type_mark_y->input_value(0);+ y = complex_type_mark_y->get_data();complex_part_type = complex_type_mark_y->get_complex_part_type();}return (complex_type_mark_x || complex_type_mark_y);diff --git a/src/frontends/tensorflow_common/src/op/shape.cpp b/src/frontends/tensorflow_common/src/op/shape.cppindex 0cf19832e10..8733f83ae18 100644--- a/src/frontends/tensorflow_common/src/op/shape.cpp+++ b/src/frontends/tensorflow_common/src/op/shape.cpp@@ -42,7 +42,7 @@ OutputVector translate_shape_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());if (complex_type_mark) {- auto slice = compute_complex_shape(complex_type_mark->input_value(0), out_type);+ auto slice = compute_complex_shape(complex_type_mark->get_data(), out_type);set_node_name(node_name, slice);return {slice};} else {@@ -58,7 +58,7 @@ OutputVector translate_shape_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(input.get_node_shared_ptr());if (complex_type_mark) {- auto slice = compute_complex_shape(complex_type_mark->input_value(input_ind), out_type);+ auto slice = compute_complex_shape(complex_type_mark->get_data(), out_type);slice->set_friendly_name(node_name + "_" + to_string(input_ind));auto shapeof_output = slice->output(0);set_out_name({node_name + ":" + to_string(input_ind)}, shapeof_output);diff --git a/src/frontends/tensorflow_common/src/op/size.cpp b/src/frontends/tensorflow_common/src/op/size.cppindex 3edd3942d24..e58287d06b9 100644--- a/src/frontends/tensorflow_common/src/op/size.cpp+++ b/src/frontends/tensorflow_common/src/op/size.cpp@@ -30,7 +30,7 @@ ov::OutputVector translate_size_op(const NodeContext& node) {auto out_type = node.get_attribute<element::Type>("out_type", element::i32);if (complex_type_mark) {- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();// compute the input tensor sizeauto shape_of = make_shared<v3::ShapeOf>(input, out_type);diff --git a/src/frontends/tensorflow_common/src/op/squeeze.cpp b/src/frontends/tensorflow_common/src/op/squeeze.cppindex 93bff25f03a..92cb4bf0db7 100644--- a/src/frontends/tensorflow_common/src/op/squeeze.cpp+++ b/src/frontends/tensorflow_common/src/op/squeeze.cpp@@ -37,7 +37,7 @@ OutputVector translate_squeeze_op(const NodeContext& node) {if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();auto input_rank = compute_subgraph_scalar_rank(input, element::i32, true);auto const_one = make_shared<v0::Constant>(element::i32, Shape{}, 1);diff --git a/src/frontends/tensorflow_common/src/op/strided_slice.cpp b/src/frontends/tensorflow_common/src/op/strided_slice.cppindex 674996335a7..b07b4b426ff 100644--- a/src/frontends/tensorflow_common/src/op/strided_slice.cpp+++ b/src/frontends/tensorflow_common/src/op/strided_slice.cpp@@ -59,7 +59,7 @@ OutputVector translate_strided_slice_op(const NodeContext& node) {std::vector<int64_t> begin_axes;if (complex_type_mark) {complex_part_type = complex_type_mark->get_complex_part_type();- input = complex_type_mark->input_value(0);+ input = complex_type_mark->get_data();TENSORFLOW_OP_VALIDATION(node,as_type_ptr<v0::Constant>(node.get_input(1).get_node_shared_ptr()),diff --git a/src/frontends/tensorflow_common/src/op/transpose.cpp b/src/frontends/tensorflow_common/src/op/transpose.cppindex 802cc6d5ac1..09f5fee1342 100644--- a/src/frontends/tensorflow_common/src/op/transpose.cpp+++ b/src/frontends/tensorflow_common/src/op/transpose.cpp@@ -27,7 +27,7 @@ OutputVector translate_transpose_op(const NodeContext& node) {auto complex_type_mark = as_type_ptr<ComplexTypeMark>(x.get_node_shared_ptr());if (complex_type_mark) {element::Type complex_part_type = complex_type_mark->get_complex_part_type();- x = complex_type_mark->input_value(0);+ x = complex_type_mark->get_data();auto input_rank = compute_subgraph_scalar_rank(x, element::i32, false);auto const_one = make_shared<v0::Constant>(element::i32, Shape{1}, 1);diff --git a/src/frontends/tensorflow_common/src/utils.cpp b/src/frontends/tensorflow_common/src/utils.cppindex 79bca9a0ae5..8646e32b1d5 100644--- a/src/frontends/tensorflow_common/src/utils.cpp+++ b/src/frontends/tensorflow_common/src/utils.cpp@@ -7,6 +7,7 @@#include <limits>#include "common_op_table.hpp"+#include "common_translators.hpp"#include "helper_ops/complex_type_mark.hpp"#include "openvino/op/abs.hpp"#include "openvino/op/add.hpp"@@ -618,6 +619,7 @@ ov::Output<ov::Node> atan2_op(const ov::Output<ov::Node>& y, const ov::Output<ov}std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> complex_rectangular_to_polar(+ const ov::frontend::NodeContext& node_context,const ov::Output<ov::Node>& real_part,const ov::Output<ov::Node>& imag_part) {// r = sqrt(a^2 + b^2)@@ -627,9 +629,9 @@ std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> complex_rectangular_to_polauto r = std::make_shared<v0::Sqrt>(sum_sq);// theta = atan2(b, a)- auto theta = atan2_op(imag_part, real_part);+ auto theta = common_translators::translate_atan2_util(node_context, imag_part, real_part);- return std::make_pair(r, theta);+ return std::make_pair(r, theta[0]);};std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> complex_polar_to_rectangular(const ov::Output<ov::Node>& r,diff --git a/tests/layer_tests/py_frontend_tests/test_torch_frontend.py b/tests/layer_tests/py_frontend_tests/test_torch_frontend.pyindex 60e97dfd003..2d618ecb682 100644--- a/tests/layer_tests/py_frontend_tests/test_torch_frontend.py+++ b/tests/layer_tests/py_frontend_tests/test_torch_frontend.py@@ -432,7 +432,7 @@ def test_multiple_module_extension():converted_model = fe.convert(input_model)assert converted_modelassert [n.get_type_name() for n in converted_model.get_ordered_ops()] == [- "Parameter", "Convert", "Convert", "Cos", "Constant", "Convert", "Relu", "Multiply", "Add", "Result"]+ "Parameter", "Convert", "Convert", "Cos", "Relu", "Constant", "Convert", "Multiply", "Add", "Result"]converted_model = convert_model(model, example_input=(torch.randn(100),), extension=[ModuleExtension(CosModel, "aten::sin"), ModuleExtension(model.relu_module, "aten::tan")])diff --git a/tests/layer_tests/pytorch_tests/test_add.py b/tests/layer_tests/pytorch_tests/test_add.pyindex a985baa67fe..4212cda9d8d 100644--- a/tests/layer_tests/pytorch_tests/test_add.py+++ b/tests/layer_tests/pytorch_tests/test_add.py@@ -120,6 +120,7 @@ class TestAddTypes(PytorchLayerTest):self._test(*self.create_model(lhs_type, lhs_shape, rhs_type, rhs_shape),ie_device, precision, ir_version, freeze_model=False, trace_model=True)+class TestAddLists(PytorchLayerTest):def _prepare_input(self):@@ -145,10 +146,9 @@ class TestAddBool(PytorchLayerTest):def _prepare_input(self):input2 = np.random.randint(0, 2, (1, 3, 20, 24)).astype(bool)input1 = np.random.randint(0, 2, (1, 3, 20, 24)).astype(bool)- return (input1, input2)+ return (input1, input2)def create_model(self, lhs_type=torch.bool, rhs_type=torch.bool):-class aten_add(torch.nn.Module):def __init__(self):super(aten_add, self).__init__()@@ -157,6 +157,7 @@ class TestAddBool(PytorchLayerTest):def forward(self, x1, x2):return torch.add(x1.to(self.rhs_type), x2.to(self.lhs_type))+ref_net = Nonereturn aten_add(), ref_net, "aten::add"@@ -172,3 +173,144 @@ class TestAddBool(PytorchLayerTest):@pytest.mark.precommit_torch_exportdef test_add(self, lhs_type, rhs_type, ie_device, precision, ir_version):self._test(*self.create_model(lhs_type, rhs_type), ie_device, precision, ir_version)+++class TestAddWithLhsComplex(PytorchLayerTest):+ def _prepare_input(self):+ rhs_input_shape = [3, 4, 5]+ lhs_input_shape = rhs_input_shape + [2]+ return [torch.randint(0, 10, lhs_input_shape).to(self.lhs_type).numpy(),+ torch.randint(0, 10, rhs_input_shape).to(self.rhs_type).numpy()]++ def create_model(self, alpha, op_type):+ class aten_add(torch.nn.Module):++ def __init__(self, alpha, op) -> None:+ super().__init__()+ self.alpha = alpha+ self.forward = self.forward1 if op == "add" else self.forward2++ def forward1(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ res = torch.add(lhs, rhs, alpha=self.alpha)+ return torch.view_as_real(res)++ def forward2(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ res = lhs.add_(rhs, alpha=self.alpha)+ return torch.view_as_real(res + lhs)++ ref_net = None++ return aten_add(alpha, op_type), ref_net, f"aten::{op_type}"++ @pytest.mark.parametrize('alpha', (0, 0.5))+ @pytest.mark.parametrize("lhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("rhs_type",+ [torch.uint8,+ torch.int8,+ torch.int32,+ torch.int64,+ torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.parametrize("op_type", ["add", "add_"])+ def test_add(self, ie_device, precision, ir_version, alpha, lhs_type, rhs_type, op_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version,+ use_convert_model=True)+++class TestAddWithRhsComplex(PytorchLayerTest):+ def _prepare_input(self):+ lhs_input_shape = [3, 4, 5]+ rhs_input_shape = lhs_input_shape + [2]+ return [torch.randint(0, 10, lhs_input_shape).to(self.lhs_type).numpy(),+ torch.randint(0, 10, rhs_input_shape).to(self.rhs_type).numpy()]++ def create_model(self, alpha):+ class aten_add(torch.nn.Module):++ def __init__(self, alpha) -> None:+ super().__init__()+ self.alpha = alpha++ def forward(self, lhs, rhs):+ rhs = torch.view_as_complex(rhs)+ res = torch.add(lhs, rhs, alpha=self.alpha)+ return torch.view_as_real(res)++ ref_net = None++ return aten_add(alpha), ref_net, f"aten::add"++ @pytest.mark.parametrize('alpha', (0, 0.5))+ @pytest.mark.parametrize("rhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("lhs_type",+ [torch.uint8,+ torch.int8,+ torch.int32,+ torch.int64,+ torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ def test_add(self, ie_device, precision, ir_version, alpha, lhs_type, rhs_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(alpha), ie_device, precision, ir_version,+ use_convert_model=True)+++class TestAddWithBothComplex(PytorchLayerTest):+ def _prepare_input(self):+ input_shape = [3, 4, 5]+ input_shape = input_shape + [2]+ return [torch.randint(0, 10, input_shape).to(self.lhs_type).numpy(),+ torch.randint(0, 10, input_shape).to(self.rhs_type).numpy()]++ def create_model(self, alpha, op_type):+ class aten_add(torch.nn.Module):++ def __init__(self, alpha, op) -> None:+ super().__init__()+ self.alpha = alpha+ self.forward = self.forward1 if op == "add" else self.forward2++ def forward1(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ rhs = torch.view_as_complex(rhs)+ res = torch.add(lhs, rhs, alpha=self.alpha)+ return torch.view_as_real(res)++ def forward2(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ rhs = torch.view_as_complex(rhs)+ res = lhs.add_(rhs, alpha=self.alpha)+ return torch.view_as_real(res + lhs)++ ref_net = None++ return aten_add(alpha, op_type), ref_net, f"aten::{op_type}"++ @pytest.mark.parametrize('alpha', (0, 0.5))+ @pytest.mark.parametrize("lhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("rhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.parametrize("op_type", ["add", "add_"])+ def test_add(self, ie_device, precision, ir_version, alpha, lhs_type, rhs_type, op_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version,+ use_convert_model=True)diff --git a/tests/layer_tests/pytorch_tests/test_angle.py b/tests/layer_tests/pytorch_tests/test_angle.pynew file mode 100644index 00000000000..b20dcf0fbbd--- /dev/null+++ b/tests/layer_tests/pytorch_tests/test_angle.py@@ -0,0 +1,41 @@+# Copyright (C) 2018-2025 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++import numpy as np+import pytest++from pytorch_layer_test_class import PytorchLayerTest+++class TestAngle(PytorchLayerTest):+ def _prepare_input(self, complex_type):+ shape = (5, 6, 7)+ if complex_type:+ shape += (2,)+ return [np.random.uniform(-10, 10, shape).astype(np.float32)]++ def create_model(self, complex_type):+ import torch++ class aten_angle(torch.nn.Module):+ def __init__(self, complex_type):+ super().__init__()+ self.complex_type = complex_type++ def forward(self, x):+ if self.complex_type:+ x = torch.view_as_complex(x)+ res = torch.angle(x)+ return res++ return aten_angle(complex_type), None, "aten::angle"++ @pytest.mark.parametrize("complex_type", [True, False])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.precommit_torch_export+ @pytest.mark.precommit_fx_backend+ def test_angle(self, complex_type, ie_device, precision, ir_version):+ self._test(*self.create_model(complex_type),+ ie_device, precision, ir_version,+ kwargs_to_prepare_input={"complex_type": complex_type})diff --git a/tests/layer_tests/pytorch_tests/test_mul.py b/tests/layer_tests/pytorch_tests/test_mul.pyindex adb7679a8a2..c07f24f0d77 100644--- a/tests/layer_tests/pytorch_tests/test_mul.py+++ b/tests/layer_tests/pytorch_tests/test_mul.py@@ -13,7 +13,6 @@ class TestMul(PytorchLayerTest):return (self.input_array.astype(self.input_type), self.other_array.astype(self.other_type))def create_model(self):-class aten_mul(torch.nn.Module):def __init__(self):super(aten_mul, self).__init__()@@ -26,7 +25,7 @@ class TestMul(PytorchLayerTest):return aten_mul(), ref_net, "aten::mul"@pytest.mark.parametrize(("input_array", "other_array"), [- [np.array([0.2015, -0.4255, 2.6087]), np.array(100)],+ [np.array([0.2015, -0.4255, 2.6087]), np.array(100)],[np.array([[1.1207], [-0.3137], [0.0700], [0.8378]]),np.array([[0.5146, 0.1216, -0.5244, 2.2382]])],])@@ -117,7 +116,6 @@ class TestMulBool(PytorchLayerTest):other_tensor = torch.randint(0, 2, size=(1, 100)).numpy()return (input_tensor, other_tensor)-def create_model(self, lhs_type, rhs_type):class aten_mul(torch.nn.Module):def __init__(self):@@ -143,3 +141,184 @@ class TestMulBool(PytorchLayerTest):@pytest.mark.precommit_torch_exportdef test_mul_bool(self, lhs_type, rhs_type, ie_device, precision, ir_version):self._test(*self.create_model(lhs_type, rhs_type), ie_device, precision, ir_version, use_convert_model=True)+++class TestMulWithLhsComplex(PytorchLayerTest):+ def _prepare_input(self):+ rhs_input_shape = [3, 4, 5]+ lhs_input_shape = rhs_input_shape + [2]+ return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),+ torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]++ def create_model(self, op_type):+ class aten_mul(torch.nn.Module):++ def __init__(self, op) -> None:+ super().__init__()+ self.forward = self.forward1 if op == "mul" else self.forward2++ def forward1(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ res = torch.mul(lhs, rhs)+ return torch.view_as_real(res)++ def forward2(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ lhs.mul_(rhs)+ return torch.view_as_real(lhs)++ ref_net = None++ return aten_mul(op_type), ref_net, f"aten::{op_type}"++ @pytest.mark.parametrize("lhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("rhs_type",+ [torch.int8,+ torch.int32,+ torch.int64,+ torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.parametrize("op_type", ["mul", "mul_"])+ def test_mul(self, ie_device, precision, ir_version, lhs_type, rhs_type, op_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(op_type), ie_device, precision, ir_version,+ use_convert_model=True)+++class TestMulWithLhsComplex(PytorchLayerTest):+ def _prepare_input(self):+ rhs_input_shape = [3, 4, 5]+ lhs_input_shape = rhs_input_shape + [2]+ return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),+ torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]++ def create_model(self, op_type):+ class aten_mul(torch.nn.Module):++ def __init__(self, op) -> None:+ super().__init__()+ self.forward = self.forward1 if op == "mul" else self.forward2++ def forward1(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ res = torch.mul(lhs, rhs)+ return torch.view_as_real(res)++ def forward2(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ lhs.mul_(rhs)+ return torch.view_as_real(lhs)++ ref_net = None++ return aten_mul(op_type), ref_net, f"aten::{op_type}"++ @pytest.mark.parametrize("lhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("rhs_type",+ [torch.int8,+ torch.int32,+ torch.int64,+ torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.parametrize("op_type", ["mul", "mul_"])+ def test_mul(self, ie_device, precision, ir_version, lhs_type, rhs_type, op_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(op_type), ie_device, precision, ir_version,+ use_convert_model=True)+++class TestMulWithRhsComplex(PytorchLayerTest):+ def _prepare_input(self):+ lhs_input_shape = [3, 4, 5]+ rhs_input_shape = lhs_input_shape + [2]+ return [torch.randint(0, 10, lhs_input_shape).to(self.lhs_type).numpy(),+ torch.randint(0, 10, rhs_input_shape).to(self.rhs_type).numpy()]++ def create_model(self):+ class aten_mul(torch.nn.Module):++ def __init__(self) -> None:+ super().__init__()++ def forward(self, lhs, rhs):+ rhs = torch.view_as_complex(rhs)+ res = torch.mul(lhs, rhs)+ return torch.view_as_real(res)++ ref_net = None++ return aten_mul(), ref_net, f"aten::mul"++ @pytest.mark.parametrize("rhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("lhs_type",+ [torch.uint8,+ torch.int8,+ torch.int32,+ torch.int64,+ torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ def test_mul(self, ie_device, precision, ir_version, lhs_type, rhs_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(), ie_device, precision, ir_version,+ use_convert_model=True)+++class TestMulWithBothComplex(PytorchLayerTest):+ def _prepare_input(self):+ input_shape = [3, 4, 5]+ input_shape = input_shape + [2]+ return [torch.randint(0, 10, input_shape).to(self.lhs_type).numpy(),+ torch.randint(0, 10, input_shape).to(self.rhs_type).numpy()]++ def create_model(self, op_type):+ class aten_mul(torch.nn.Module):++ def __init__(self, op) -> None:+ super().__init__()+ self.forward = self.forward1 if op == "mul" else self.forward2++ def forward1(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ rhs = torch.view_as_complex(rhs)+ res = torch.mul(lhs, rhs)+ return torch.view_as_real(res)++ def forward2(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ rhs = torch.view_as_complex(rhs)+ res = lhs.mul_(rhs)+ return torch.view_as_real(res + lhs)++ ref_net = None++ return aten_mul(op_type), ref_net, f"aten::{op_type}"++ @pytest.mark.parametrize("lhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("rhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.parametrize("op_type", ["mul", "mul_"])+ def test_mul(self, ie_device, precision, ir_version, lhs_type, rhs_type, op_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(op_type), ie_device, precision, ir_version,+ use_convert_model=True)diff --git a/tests/layer_tests/pytorch_tests/test_sub.py b/tests/layer_tests/pytorch_tests/test_sub.pyindex 88779c6343b..d5f63b712d4 100644--- a/tests/layer_tests/pytorch_tests/test_sub.py+++ b/tests/layer_tests/pytorch_tests/test_sub.py@@ -38,14 +38,14 @@ class TestSub(PytorchLayerTest):return aten_sub(inplace), ref_net, op_name@pytest.mark.parametrize('input_shapes',- [- [- [2, 3, 4], [2, 3, 4], [1]- ],- [- [4, 2, 3], [1, 2, 3], [1]- ]- ])+ [+ [+ [2, 3, 4], [2, 3, 4], [1]+ ],+ [+ [4, 2, 3], [1, 2, 3], [1]+ ]+ ])@pytest.mark.parametrize("inplace", [True, False])@pytest.mark.nightly@pytest.mark.precommit@@ -118,3 +118,142 @@ class TestSubTypes(PytorchLayerTest):self.rhs_shape = rhs_shapeself._test(*self.create_model(lhs_type, lhs_shape, rhs_type, rhs_shape),ie_device, precision, ir_version)+++class TestSubWithLhsComplex(PytorchLayerTest):+ def _prepare_input(self):+ rhs_input_shape = [3, 4, 5]+ lhs_input_shape = rhs_input_shape + [2]+ return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),+ torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]++ def create_model(self, alpha, op_type):+ class aten_sub(torch.nn.Module):++ def __init__(self, alpha, op) -> None:+ super().__init__()+ self.alpha = alpha+ self.forward = self.forward1 if op == "sub" else self.forward2++ def forward1(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ res = torch.sub(lhs, rhs, alpha=self.alpha)+ return torch.view_as_real(res)++ def forward2(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ res = lhs.sub_(rhs, alpha=self.alpha)+ return torch.view_as_real(res + lhs)++ ref_net = None++ return aten_sub(alpha, op_type), ref_net, f"aten::{op_type}"++ @pytest.mark.parametrize('alpha', (0, 0.5))+ @pytest.mark.parametrize("lhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("rhs_type",+ [torch.int8,+ torch.int32,+ torch.int64,+ torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.parametrize("op_type", ["sub", "sub_"])+ def test_sub(self, ie_device, precision, ir_version, alpha, lhs_type, rhs_type, op_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version,+ use_convert_model=True)+++class TestSubWithRhsComplex(PytorchLayerTest):+ def _prepare_input(self):+ lhs_input_shape = [3, 4, 5]+ rhs_input_shape = lhs_input_shape + [2]+ return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),+ torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]++ def create_model(self, alpha):+ class aten_sub(torch.nn.Module):++ def __init__(self, alpha) -> None:+ super().__init__()+ self.alpha = alpha++ def forward(self, lhs, rhs):+ rhs = torch.view_as_complex(rhs)+ res = torch.sub(lhs, rhs, alpha=self.alpha)+ return torch.view_as_real(res)++ ref_net = None++ return aten_sub(alpha), ref_net, f"aten::sub"++ @pytest.mark.parametrize('alpha', (0, 0.5))+ @pytest.mark.parametrize("rhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("lhs_type",+ [torch.int8,+ torch.int32,+ torch.int64,+ torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ def test_sub(self, ie_device, precision, ir_version, alpha, lhs_type, rhs_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(alpha), ie_device, precision, ir_version,+ use_convert_model=True)+++class TestSubWithBothComplex(PytorchLayerTest):+ def _prepare_input(self):+ input_shape = [3, 4, 5]+ input_shape = input_shape + [2]+ return [torch.randint(0, 10, input_shape).to(self.lhs_type).numpy(),+ torch.randint(0, 10, input_shape).to(self.rhs_type).numpy()]++ def create_model(self, alpha, op_type):+ class aten_sub(torch.nn.Module):++ def __init__(self, alpha, op) -> None:+ super().__init__()+ self.alpha = alpha+ self.forward = self.forward1 if op == "sub" else self.forward2++ def forward1(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ rhs = torch.view_as_complex(rhs)+ res = torch.sub(lhs, rhs, alpha=self.alpha)+ return torch.view_as_real(res)++ def forward2(self, lhs, rhs):+ lhs = torch.view_as_complex(lhs)+ rhs = torch.view_as_complex(rhs)+ res = lhs.sub_(rhs, alpha=self.alpha)+ return torch.view_as_real(res + lhs)++ ref_net = None++ return aten_sub(alpha, op_type), ref_net, f"aten::{op_type}"++ @pytest.mark.parametrize('alpha', (0, 0.5))+ @pytest.mark.parametrize("lhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.parametrize("rhs_type",+ [torch.float32,+ torch.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.parametrize("op_type", ["sub", "sub_"])+ def test_sub(self, ie_device, precision, ir_version, alpha, lhs_type, rhs_type, op_type):+ self.lhs_type = lhs_type+ self.rhs_type = rhs_type+ self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version,+ use_convert_model=True)