Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/frontends/pytorch/src/op/deg2rad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) 2018-2026 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::frontend::pytorch::op {

OutputVector translate_deg2rad(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{}, {static_cast<float>(pi_val) / 180.0f}));

// 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 degrees to radians
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 ov::frontend::pytorch::op
2 changes: 2 additions & 0 deletions src/frontends/pytorch/src/op_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ OP_CONVERTER(translate_copy_);
OP_CONVERTER(translate_cross);
OP_CONVERTER(translate_cumsum);
OP_CONVERTER(translate_deform_conv);
OP_CONVERTER(translate_deg2rad);
OP_CONVERTER(translate_derive_index);
OP_CONVERTER(translate_dim);
OP_CONVERTER(translate_div);
Expand Down Expand Up @@ -501,6 +502,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {
{"aten::cosh_", op::inplace_op<op::translate_1to1_match_1_inputs<opset10::Cosh>>},
{"aten::cross", op::translate_cross},
{"aten::cumsum", op::translate_cumsum},
{"aten::deg2rad", op::translate_deg2rad},
{"aten::det", op::translate_linalg_det},
{"aten::detach", op::skip_node},
{"aten::dequantize", op::skip_node}, // we convert model to fp32 using FQ, so dequantization is not needed
Expand Down
27 changes: 27 additions & 0 deletions tests/layer_tests/pytorch_tests/test_deg2rad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import pytest
import torch
import numpy as np
from pytorch_layer_test_class import PytorchLayerTest


class TestDeg2Rad(PytorchLayerTest):
def _prepare_input(self, input_shape=(2, 2), dtype=np.float32):
return (self.random.uniform(-360.0, 360.0, size=input_shape, dtype=dtype),)

def create_model(self):
class aten_deg2rad(torch.nn.Module):
def forward(self, x):
return torch.deg2rad(x)
return aten_deg2rad(), "aten::deg2rad"

@pytest.mark.parametrize("input_shape", [(3, 3)])
@pytest.mark.parametrize("dtype", [np.float32, np.float64, np.int32])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_deg2rad(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})
Loading