Skip to content
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

Zero-dim support of histogram kernel, test=develop #49884

Merged
merged 1 commit into from
Jan 18, 2023
Merged
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
8 changes: 8 additions & 0 deletions python/paddle/fluid/tests/unittests/test_histogram_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def test_check_output(self):
self.check_output(check_eager=True)


class TestHistogramOp_ZeroDim(TestHistogramOp):
def init_test_case(self):
self.in_shape = []
self.bins = 5
self.min = 1
self.max = 5


if __name__ == "__main__":
paddle.enable_static()
unittest.main()
15 changes: 15 additions & 0 deletions python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,11 @@ def test_flatten(self):
self.assertEqual(out.grad.shape, [1])
self.assertEqual(x.grad.shape, [])

def test_histogram(self):
x = paddle.rand([])
out = paddle.histogram(x, bins=5, min=1, max=5)
self.assertEqual(out.shape, [5])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

histogram算子没有反向kernel的实现,因此这里不对反向输出shape做检查

def test_scale(self):
x = paddle.rand([])
x.stop_gradient = False
Expand Down Expand Up @@ -1516,6 +1521,16 @@ def test_flatten(self):
self.assertEqual(res[1].shape, ())
self.assertEqual(res[2].shape, (1,))

@prog_scope()
def test_histogram(self):
x = paddle.full([], 1, 'float32')
out = paddle.histogram(x, bins=5, min=1, max=5)

prog = paddle.static.default_main_program()
res = self.exe.run(prog, feed={}, fetch_list=[out])

self.assertEqual(res[0].shape, (5,))

@prog_scope()
def test_scale(self):
x = paddle.rand([])
Expand Down