-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[API Compatibility No.359] param alias for deg2rad -part #77168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zhwesky2010
merged 15 commits into
PaddlePaddle:develop
from
Manfredss:ApiEnhance361_378
Jan 22, 2026
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
76ebb61
cpp sink for tan, param alias for deg2rad
Manfredss 1ba0ead
Remove commented-out tan function and its documentation
Manfredss 50adb4e
Refactor deg2rad function to simplify output handling
Manfredss b92e990
Update Python API information in yaml file
Manfredss 2bae100
Merge branch 'develop' into ApiEnhance361_378
Manfredss 0cc63cb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
Manfredss ec1fd64
fix
Manfredss 4c1c65d
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
Manfredss 264666b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
Manfredss 889443b
increase coverage
Manfredss 15f7bda
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
Manfredss 62ca8d8
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
Manfredss 1e3c12a
fix tests for deg2rad
Manfredss 1d82747
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
Manfredss ad21c42
fix
Manfredss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,11 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| import unittest | ||
|
|
||
| os.environ['FLAGS_enable_pir_api'] = '0' | ||
|
|
||
| import numpy as np | ||
| from op_test import get_device_place | ||
|
|
||
|
|
@@ -61,22 +64,143 @@ def test_dygraph(self): | |
|
|
||
|
|
||
| class TestDeg2radAPI2(TestDeg2radAPI): | ||
| # Test input data type is int | ||
| # Test input data type is int64 | ||
| def setUp(self): | ||
| self.x_np = [180] | ||
| self.x_np = np.array([180]).astype(np.int64) | ||
| self.x_shape = [1] | ||
| self.out_np = np.pi | ||
| self.x_dtype = 'int64' | ||
|
|
||
| def test_dygraph(self): | ||
| paddle.disable_static() | ||
|
|
||
| x2 = paddle.to_tensor([180]) | ||
| # Test int64 input | ||
| x2 = paddle.to_tensor([180], dtype="int64") | ||
| result2 = paddle.deg2rad(x2) | ||
| np.testing.assert_allclose(np.pi, result2.numpy(), rtol=1e-05) | ||
|
|
||
| paddle.enable_static() | ||
|
|
||
|
|
||
| class TestDeg2radAPI3(TestDeg2radAPI): | ||
| # Test input data type is int32 | ||
| def setUp(self): | ||
| self.x_np = np.array([180]).astype(np.int32) | ||
| self.x_shape = [1] | ||
| self.out_np = np.pi | ||
| self.x_dtype = 'int32' | ||
|
|
||
| def test_dygraph(self): | ||
| paddle.disable_static() | ||
|
|
||
| # Test int32 input | ||
| x3 = paddle.to_tensor([180], dtype="int32") | ||
| result3 = paddle.deg2rad(x3) | ||
| np.testing.assert_allclose(np.pi, result3.numpy(), rtol=1e-05) | ||
|
|
||
| paddle.enable_static() | ||
|
|
||
|
|
||
| class TestDeg2radAPI4(TestDeg2radAPI): | ||
| # Test input data type is float32 | ||
| def setUp(self): | ||
| self.x_np = np.array( | ||
| [180.0, -180.0, 360.0, -360.0, 90.0, -90.0] | ||
| ).astype(np.float32) | ||
| self.x_shape = [6] | ||
| self.out_np = np.deg2rad(self.x_np) | ||
| self.x_dtype = 'float32' | ||
|
|
||
|
|
||
| class TestDeg2radAliasAndOut(unittest.TestCase): | ||
| def test_alias(self): | ||
| paddle.disable_static() | ||
| x = paddle.to_tensor([180.0]) | ||
| expected = np.deg2rad(180.0) | ||
|
|
||
| # Test alias | ||
| res = paddle.deg2rad(input=x) | ||
| np.testing.assert_allclose(res.numpy(), expected, rtol=1e-05) | ||
|
|
||
| paddle.enable_static() | ||
|
|
||
| def test_out(self): | ||
| paddle.disable_static() | ||
| x = paddle.to_tensor([180.0]) | ||
| expected = np.deg2rad(180.0) | ||
|
|
||
| # Test without out parameter (default None) | ||
| res_no_out = paddle.deg2rad(x) | ||
| np.testing.assert_allclose(res_no_out.numpy(), expected, rtol=1e-05) | ||
|
|
||
| # Test out parameter with float input | ||
| out = paddle.zeros([1], dtype="float32") | ||
| res = paddle.deg2rad(x, out=out) | ||
|
||
| np.testing.assert_allclose(out.numpy(), expected, rtol=1e-05) | ||
| self.assertTrue(res is out) | ||
|
|
||
| # Test out parameter with int64 input | ||
| x_int = paddle.to_tensor([180], dtype="int64") | ||
| out_float = paddle.zeros([1], dtype="float32") | ||
| res = paddle.deg2rad(x_int, out=out_float) | ||
| np.testing.assert_allclose(out_float.numpy(), expected, rtol=1e-05) | ||
| self.assertTrue(res is out_float) | ||
|
|
||
| # Test out parameter with int32 input | ||
| x_int32 = paddle.to_tensor([180], dtype="int32") | ||
| out_float32 = paddle.zeros([1], dtype="float32") | ||
| res = paddle.deg2rad(x_int32, out=out_float32) | ||
| np.testing.assert_allclose(out_float32.numpy(), expected, rtol=1e-05) | ||
| self.assertTrue(res is out_float32) | ||
|
|
||
| paddle.enable_static() | ||
|
|
||
|
|
||
| class TestDeg2radStaticOut(unittest.TestCase): | ||
| def test_static_out_float(self): | ||
| """Test out parameter in static graph with float input""" | ||
| paddle.enable_static() | ||
| startup_program = paddle.static.Program() | ||
| train_program = paddle.static.Program() | ||
| with paddle.static.program_guard(startup_program, train_program): | ||
| x = paddle.static.data(name='input', dtype='float32', shape=[1]) | ||
| out = paddle.static.data(name='out', dtype='float32', shape=[1]) | ||
| result = paddle.deg2rad(x, out=out) | ||
|
||
|
|
||
| place = get_device_place() | ||
| exe = base.Executor(place) | ||
| x_np = np.array([180.0]).astype(np.float32) | ||
| out_np = np.zeros([1]).astype(np.float32) | ||
| expected = np.deg2rad(180.0) | ||
|
|
||
| res, out_res = exe.run( | ||
| feed={'input': x_np, 'out': out_np}, | ||
| fetch_list=[result, out], | ||
| ) | ||
| np.testing.assert_allclose(out_res, expected, rtol=1e-05) | ||
|
|
||
| def test_static_out_int(self): | ||
| """Test out parameter in static graph with int input""" | ||
| paddle.enable_static() | ||
| startup_program = paddle.static.Program() | ||
| train_program = paddle.static.Program() | ||
| with paddle.static.program_guard(startup_program, train_program): | ||
| x = paddle.static.data(name='input', dtype='int64', shape=[1]) | ||
| out = paddle.static.data(name='out', dtype='float32', shape=[1]) | ||
| result = paddle.deg2rad(x, out=out) | ||
|
|
||
| place = get_device_place() | ||
| exe = base.Executor(place) | ||
| x_np = np.array([180]).astype(np.int64) | ||
| out_np = np.zeros([1]).astype(np.float32) | ||
| expected = np.deg2rad(180.0) | ||
|
|
||
| res, out_res = exe.run( | ||
| feed={'input': x_np, 'out': out_np}, | ||
| fetch_list=[result, out], | ||
| ) | ||
| np.testing.assert_allclose(out_res, expected, rtol=1e-05) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉