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] D-23 Adapt randperm test_errors #62797

Merged
merged 7 commits into from
Mar 19, 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
16 changes: 12 additions & 4 deletions test/legacy_test/test_randperm_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import paddle
from paddle.base import core
from paddle.static import Program, program_guard
from paddle.base.framework import in_pir_mode
from paddle.pir_utils import test_with_pir_api


def check_randperm_out(n, data_np):
Expand Down Expand Up @@ -156,21 +157,28 @@ def verify_output(self, outs):


class TestRandpermOpError(unittest.TestCase):
@test_with_pir_api
def test_errors(self):
with program_guard(Program(), Program()):
self.assertRaises(ValueError, paddle.randperm, -3)
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
if not in_pir_mode():
self.assertRaises(ValueError, paddle.randperm, -3)
self.assertRaises(TypeError, paddle.randperm, 10, 'int8')


class TestRandpermAPI(unittest.TestCase):
@test_with_pir_api
def test_out(self):
n = 10
place = (
paddle.CUDAPlace(0)
if core.is_compiled_with_cuda()
else paddle.CPUPlace()
)
with program_guard(Program(), Program()):
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
x1 = paddle.randperm(n)
x2 = paddle.randperm(n, 'float32')

Expand Down