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

[PIR] Adaptation of TestNoBackwardAPIStatic.test_unique* #62794

Merged
merged 4 commits into from
Mar 17, 2024
Merged
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
73 changes: 47 additions & 26 deletions test/legacy_test/test_zero_dim_no_backward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,37 +487,58 @@ def test_one_hot_label(self):
self.assertEqual(res[0].shape, (4,))
self.assertEqual(res[0][2], 1)

@test_with_pir_api
def test_unique_consecutive(self):
x = paddle.rand([])
y, inverse, counts = paddle.unique_consecutive(
x, return_inverse=True, return_counts=True
)
main_program = paddle.static.Program()
startup_program = paddle.static.Program()
with paddle.static.program_guard(main_program, startup_program):
x = paddle.rand([])
y, inverse, counts = paddle.unique_consecutive(
x, return_inverse=True, return_counts=True
)

prog = paddle.static.default_main_program()
res = self.exe.run(prog, fetch_list=[y, inverse, counts])
self.assertEqual(y, x)
self.assertEqual(inverse, 0)
self.assertEqual(counts, 1)
self.assertEqual(res[0].shape, (1,))
self.assertEqual(res[1].shape, (1,))
self.assertEqual(res[2].shape, (1,))
(
x_res,
y_res,
inverse_res,
counts_res,
) = paddle.static.Executor().run(
main_program, fetch_list=[x, y, inverse, counts]
)
self.assertEqual(x_res, y_res)
self.assertEqual(inverse_res, 0)
self.assertEqual(counts_res, 1)
self.assertEqual(y_res.shape, (1,))
self.assertEqual(inverse_res.shape, (1,))
self.assertEqual(counts_res.shape, (1,))

@test_with_pir_api
def test_unique(self):
x = paddle.rand([])
y, index, inverse, counts = paddle.unique(
x, return_index=True, return_inverse=True, return_counts=True
)
main_program = paddle.static.Program()
startup_program = paddle.static.Program()
with paddle.static.program_guard(main_program, startup_program):
x = paddle.rand([])
y, index, inverse, counts = paddle.unique(
x, return_index=True, return_inverse=True, return_counts=True
)

prog = paddle.static.default_main_program()
res = self.exe.run(prog, fetch_list=[y, index, inverse, counts])
self.assertEqual(y, x)
self.assertEqual(index, 0)
self.assertEqual(inverse, 0)
self.assertEqual(counts, 1)
self.assertEqual(res[0].shape, (1,))
self.assertEqual(res[1].shape, (1,))
self.assertEqual(res[2].shape, (1,))
self.assertEqual(res[3].shape, (1,))
(
x_res,
y_res,
index_res,
inverse_res,
counts_res,
) = paddle.static.Executor().run(
main_program, fetch_list=[x, y, index, inverse, counts]
)
self.assertEqual(x_res, y_res)
self.assertEqual(index_res, 0)
self.assertEqual(inverse_res, 0)
self.assertEqual(counts_res, 1)
self.assertEqual(y_res.shape, (1,))
self.assertEqual(index_res.shape, (1,))
self.assertEqual(inverse_res.shape, (1,))
self.assertEqual(counts_res.shape, (1,))

@test_with_pir_api
def test_static_matrix_rank(self):
Expand Down