Skip to content

Conversation

FlamingoPg
Copy link
Contributor

PR Category

Others

PR Types

Improvements

Description

为paddle round进行功能增强,添加round参数
和PyTorch的对比:

torch.set_printoptions(precision=8)
a = torch.Tensor([-0.543, -0.256, 0.678, 1.456])

torch.round(a, decimals=0)
>>> tensor([-1., -0.,  1.,  1.])

torch.round(a, decimals=1)
>>> tensor([-0.50000000, -0.30000001,  0.69999999,  1.50000000])

torch.round(a, decimals=2)
>>> tensor([-0.54000002, -0.25999999,  0.68000001,  1.46000004])

torch.round(a, decimals=3)
>>> tensor([-0.54299998, -0.25600001,  0.67799997,  1.45599997])

torch.round(a, decimals=-1)
>>> tensor([-0., -0., 0., 0.])

paddle:

a = paddle.to_tensor([-0.543, -0.256, 0.678, 1.456])
>>> paddle.round(a, decimals=0)
Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [-1., -0.,  1.,  1.])

>>> paddle.round(a, decimals=1)
Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [-0.50000000, -0.30000001,  0.69999999,  1.50000000])

>>> paddle.round(a, decimals=2)
Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [-0.54000002, -0.25999999,  0.68000001,  1.46000004])

>>> paddle.round(a, decimals=3)
Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [-0.54299998, -0.25600001,  0.67799997,  1.45599997])

>>> paddle.round(a, decimals=-1)
Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [-0., -0., 0. , 0. ])

Copy link

paddle-bot bot commented May 17, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label May 17, 2024
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators May 20, 2024
@PaddlePaddle PaddlePaddle unlocked this conversation May 20, 2024
Copy link

paddle-ci-bot bot commented May 30, 2024

Sorry to inform you that c5452f1's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@luotao1
Copy link
Contributor

luotao1 commented Jul 4, 2024

close due to the following PR is merged:

@luotao1 luotao1 closed this Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants