Skip to content

Commit

Permalink
【PIR API adaptor No.7】Migrate paddle.angle into pir (PaddlePaddle#58587)
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatV committed Nov 2, 2023
1 parent 75a5999 commit 1cb50fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -5943,7 +5943,7 @@ def angle(x, name=None):
[-1.10714877, -0.78539819, 0. , 0.78539819]])
"""

if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.angle(x)
else:
check_variable_and_dtype(
Expand Down
11 changes: 8 additions & 3 deletions test/legacy_test/test_angle_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import paddle
from paddle import static
from paddle.base import core, dygraph
from paddle.pir_utils import test_with_pir_api

paddle.enable_static()

Expand Down Expand Up @@ -49,7 +50,7 @@ def setUp(self):
self.outputs = {'Out': out_ref}

def test_check_output(self):
self.check_output()
self.check_output(check_pir=True)

def test_check_grad(self):
self.check_grad(
Expand All @@ -58,6 +59,7 @@ def test_check_grad(self):
user_defined_grads=[
angle_grad(self.x, np.ones_like(self.x) / self.x.size)
],
check_pir=True,
)


Expand Down Expand Up @@ -93,7 +95,7 @@ def setUp(self):
self.place = core.CUDAPlace(0)

def test_check_output(self):
self.check_output_with_place(self.place)
self.check_output_with_place(self.place, check_pir=True)

def test_check_grad(self):
self.check_grad_with_place(
Expand All @@ -103,6 +105,7 @@ def test_check_grad(self):
user_defined_grads=[
angle_grad(self.x, np.ones_like(self.x) / self.x.size)
],
check_pir=True,
)


Expand All @@ -119,7 +122,7 @@ def setUp(self):
self.outputs = {'Out': out_ref}

def test_check_output(self):
self.check_output()
self.check_output(check_pir=True)

def test_check_grad(self):
self.check_grad(
Expand All @@ -128,6 +131,7 @@ def test_check_grad(self):
user_defined_grads=[
angle_grad(self.x, np.ones_like(self.x) / self.x.size)
],
check_pir=True,
)


Expand All @@ -142,6 +146,7 @@ def test_dygraph(self):
out_np = paddle.angle(x).numpy()
np.testing.assert_allclose(self.out, out_np, rtol=1e-05)

@test_with_pir_api
def test_static(self):
mp, sp = static.Program(), static.Program()
with static.program_guard(mp, sp):
Expand Down

0 comments on commit 1cb50fb

Please sign in to comment.