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
Rad2deg (#29352)
Leonardo Heim475517af52a0
diff --git a/src/frontends/pytorch/src/op/rad2deg.cpp b/src/frontends/pytorch/src/op/rad2deg.cppnew file mode 100644index 00000000000..7f4c6980280--- /dev/null+++ b/src/frontends/pytorch/src/op/rad2deg.cpp@@ -0,0 +1,44 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <cmath>++#include "openvino/frontend/pytorch/node_context.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/multiply.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace pytorch {+namespace op {++OutputVector translate_rad2deg(const NodeContext& context) {+ // Ensure that the operation has exactly one input (the input tensor)+ num_inputs_check(context, 1, 1);++ // Retrieve the input tensor+ auto input = context.get_input(0);++ // Define the value of π+ const double pi_val = std::atan(1.0) * 4;++ // Create a constant node with the conversion factor (180 / π) using fp32 type+ Output<Node> conversion_factor_output = context.mark_node(+ ov::op::v0::Constant::create(ov::element::f32, Shape{}, {180.0f / static_cast<float>(pi_val)}));++ // Align elementwise input types to handle integer cases correctly+ align_eltwise_input_types(context, input, conversion_factor_output, is_python_scalar_input(context, 0), true);++ // Apply the multiplication operation to convert radians to degrees+ auto result = context.mark_node(std::make_shared<ov::op::v1::Multiply>(input, conversion_factor_output));++ // Return the computed result as an OutputVector+ return {result};+}++} // namespace op+} // namespace pytorch+} // namespace frontend+} // namespace ov\ No newline at end of filediff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cppindex 37e7383fcbb..040e58bc7a7 100644--- a/src/frontends/pytorch/src/op_table.cpp+++ b/src/frontends/pytorch/src/op_table.cpp@@ -208,6 +208,7 @@ OP_CONVERTER(translate_quantized_add_relu);OP_CONVERTER(translate_quantized_hardswish);OP_CONVERTER(translate_quantized_mul);OP_CONVERTER(translate_range_length);+OP_CONVERTER(translate_rad2deg);OP_CONVERTER(translate_rand);OP_CONVERTER(translate_randperm);OP_CONVERTER(translate_randn);@@ -643,6 +644,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {{"aten::prod", op::translate_prod},{"aten::quantize_per_channel", op::translate_quantize_per_channel},{"aten::quantize_per_tensor", op::translate_quantize_per_tensor},+ {"aten::rad2deg", op::translate_rad2deg},{"aten::rand", op::translate_rand},{"aten::randperm", op::translate_randperm},{"aten::rand_like", op::translate_rand_like},diff --git a/tests/layer_tests/pytorch_tests/test_rad2deg.py b/tests/layer_tests/pytorch_tests/test_rad2deg.pynew file mode 100644index 00000000000..055d062493b--- /dev/null+++ b/tests/layer_tests/pytorch_tests/test_rad2deg.py@@ -0,0 +1,27 @@+# Copyright (C) 2018-2025 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++import pytest+import torch+import numpy as np+from pytorch_layer_test_class import PytorchLayerTest+++class TestRad2Deg(PytorchLayerTest):+ def _prepare_input(self, input_shape=(2, 2), dtype=np.float32):+ return (np.random.uniform(-np.pi, np.pi, size=input_shape).astype(dtype),)++ def create_model(self):+ class aten_rad2deg(torch.nn.Module):+ def forward(self, x):+ return torch.rad2deg(x)+ ref_net = None+ return aten_rad2deg(), ref_net, "aten::rad2deg"++ @pytest.mark.parametrize("input_shape", [(3, 3)])+ @pytest.mark.parametrize("dtype", [np.float32, np.float64, np.int32])+ @pytest.mark.nightly+ @pytest.mark.precommit+ def test_rad2deg(self, input_shape, dtype, ie_device, precision, ir_version):+ self._test(*self.create_model(), ie_device, precision, ir_version,+ kwargs_to_prepare_input={"input_shape": input_shape, "dtype": dtype})\ No newline at end of file