[Zero-Dim] support input 0D Tensor for std/var#49735
Merged
zhwesky2010 merged 54 commits intoPaddlePaddle:developfrom Feb 10, 2023
Merged
[Zero-Dim] support input 0D Tensor for std/var#49735zhwesky2010 merged 54 commits intoPaddlePaddle:developfrom
zhwesky2010 merged 54 commits intoPaddlePaddle:developfrom
Conversation
| 你的PR提交成功,感谢你对开源项目的贡献! |
zhwesky2010 reviewed Jan 16, 2023
Contributor
zhwesky2010 left a comment
There was a problem hiding this comment.
这两个直接加到reduce_api_list应该可以
zhwesky2010 reviewed Feb 8, 2023
| out.backward() | ||
| | ||
| # checkout shape of out | ||
| self.assertEqual(out.shape, []) |
| def test_std(self): | ||
| x = paddle.rand([]) | ||
| x.stop_gradient = False | ||
| out = paddle.std(x) |
Contributor
There was a problem hiding this comment.
再加一种 paddle.std(x, []) 的情形
| # checkout value of out | ||
| self.assertEqual(out, 0) | ||
| | ||
| def test_var(self): |
| self.assertEqual(res[2].shape, ()) | ||
| np.testing.assert_allclose(res[2], 1.0) | ||
| | ||
| @prog_scope() |
python/paddle/tensor/stat.py Outdated
| """ | ||
| if not in_dygraph_mode(): | ||
| check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'var') | ||
| if len(x.shape) == 0: |
Contributor
There was a problem hiding this comment.
这样写可能不太美观,如果直接通过原来的分支实现会有问题吗?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
PR types
New features
PR changes
APIs
Describe
[Zero-Dim] support input 0D Tensor for std/var:
为以下API支持输入0D Tensor,不修改其输出端行为,属于新增功能,无不兼容影响:
paddle.stdpaddle.var