Skip to content

Commit

Permalink
【PIR API adaptor No.133-135】Migrate paddle.logical_not/logical_or/log…
Browse files Browse the repository at this point in the history
…ical_xor into pir (PaddlePaddle#58781)
  • Loading branch information
ccsuzzh authored Nov 10, 2023
1 parent 80ceec3 commit 4c37217
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions python/paddle/tensor/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def logical_or(x, y, out=None, name=None):
[[True , True ],
[True , False]])
"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.logical_or(x, y)
return _logical_op(
op_name="logical_or", x=x, y=y, name=name, out=out, binary_op=True
Expand Down Expand Up @@ -262,7 +262,7 @@ def logical_xor(x, y, out=None, name=None):
[[False, True ],
[True , False]])
"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.logical_xor(x, y)

return _logical_op(
Expand Down Expand Up @@ -322,7 +322,7 @@ def logical_not(x, out=None, name=None):
Tensor(shape=[4], dtype=bool, place=Place(cpu), stop_gradient=True,
[False, True , False, True ])
"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.logical_not(x)
return _logical_op(
op_name="logical_not", x=x, y=None, name=name, out=out, binary_op=False
Expand Down
12 changes: 6 additions & 6 deletions test/legacy_test/test_logical_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import paddle
from paddle.framework import in_dynamic_mode
from paddle.static import Executor, Program, program_guard
from paddle.pir_utils import test_with_pir_api

SUPPORTED_DTYPES = [
bool,
Expand Down Expand Up @@ -67,16 +67,15 @@
}


# @test_with_pir_api
def run_static(x_np, y_np, op_str, use_gpu=False, binary_op=True):
paddle.enable_static()
startup_program = Program()
main_program = Program()
startup_program = paddle.static.Program()
main_program = paddle.static.Program()
place = paddle.CPUPlace()
if use_gpu and paddle.is_compiled_with_cuda():
place = paddle.CUDAPlace(0)
exe = Executor(place)
with program_guard(main_program, startup_program):
exe = paddle.static.Executor(place)
with paddle.static.program_guard(main_program, startup_program):
x = paddle.static.data(name='x', shape=x_np.shape, dtype=x_np.dtype)
op = getattr(paddle, op_str)
feed_list = {'x': x_np}
Expand Down Expand Up @@ -135,6 +134,7 @@ def np_data_generator(np_shape, dtype, *args, **kwargs):
return np.random.normal(0, 1, np_shape).astype(dtype)


@test_with_pir_api
def test(unit_test, use_gpu=False, test_error=False):
for op_data in TEST_META_OP_DATA:
meta_data = dict(op_data)
Expand Down

0 comments on commit 4c37217

Please sign in to comment.