From 3eefb09768c96116d2a2f2f3fac8a9432ddd12d7 Mon Sep 17 00:00:00 2001 From: phlrain Date: Wed, 16 Mar 2022 14:41:35 +0000 Subject: [PATCH] update; test=develop --- .../fluid/tests/unittests/test_bitwise_op.py | 6 +++ python/paddle/tensor/logic.py | 11 ++++- python/paddle/utils/code_gen/api.yaml | 46 +++++++++---------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_bitwise_op.py b/python/paddle/fluid/tests/unittests/test_bitwise_op.py index 67070602c2c..4f01d31fb1c 100644 --- a/python/paddle/fluid/tests/unittests/test_bitwise_op.py +++ b/python/paddle/fluid/tests/unittests/test_bitwise_op.py @@ -24,6 +24,7 @@ paddle.enable_static() class TestBitwiseAnd(OpTest): def setUp(self): self.op_type = "bitwise_and" + self.python_api = paddle.bitwise_and self.init_dtype() self.init_shape() self.init_bound() @@ -94,6 +95,7 @@ class TestBitwiseAndInt64(TestBitwiseAnd): class TestBitwiseAndBool(TestBitwiseAnd): def setUp(self): self.op_type = "bitwise_and" + self.python_api = paddle.bitwise_and self.init_shape() x = np.random.choice([True, False], self.x_shape) @@ -108,6 +110,7 @@ class TestBitwiseAndBool(TestBitwiseAnd): class TestBitwiseOr(OpTest): def setUp(self): self.op_type = "bitwise_or" + self.python_api = paddle.bitwise_or self.init_dtype() self.init_shape() self.init_bound() @@ -178,6 +181,7 @@ class TestBitwiseOrInt64(TestBitwiseOr): class TestBitwiseOrBool(TestBitwiseOr): def setUp(self): self.op_type = "bitwise_or" + self.python_api = paddle.bitwise_or self.init_shape() x = np.random.choice([True, False], self.x_shape) @@ -192,6 +196,7 @@ class TestBitwiseOrBool(TestBitwiseOr): class TestBitwiseXor(OpTest): def setUp(self): self.op_type = "bitwise_xor" + self.python_api = paddle.bitwise_xor self.init_dtype() self.init_shape() self.init_bound() @@ -262,6 +267,7 @@ class TestBitwiseXorInt64(TestBitwiseXor): class TestBitwiseXorBool(TestBitwiseXor): def setUp(self): self.op_type = "bitwise_xor" + self.python_api = paddle.bitwise_xor self.init_shape() x = np.random.choice([True, False], self.x_shape) diff --git a/python/paddle/tensor/logic.py b/python/paddle/tensor/logic.py index a07c1d9c103..545f0e9bd5f 100755 --- a/python/paddle/tensor/logic.py +++ b/python/paddle/tensor/logic.py @@ -503,6 +503,9 @@ def bitwise_and(x, y, out=None, name=None): res = paddle.bitwise_and(x, y) print(res) # [0, 2, 1] """ + if _in_eager_mode() and out == None: + return _C_ops.final_state_bitwise_and(x, y) + return _bitwise_op( op_name="bitwise_and", x=x, y=y, name=name, out=out, binary_op=True) @@ -529,6 +532,9 @@ def bitwise_or(x, y, out=None, name=None): res = paddle.bitwise_or(x, y) print(res) # [-1, -1, -3] """ + if _in_eager_mode() and out == None: + return _C_ops.final_state_bitwise_or(x, y) + return _bitwise_op( op_name="bitwise_or", x=x, y=y, name=name, out=out, binary_op=True) @@ -555,6 +561,9 @@ def bitwise_xor(x, y, out=None, name=None): res = paddle.bitwise_xor(x, y) print(res) # [-1, -3, -4] """ + if _in_eager_mode() and out == None: + return _C_ops.final_state_bitwise_xor(x, y) + return _bitwise_op( op_name="bitwise_xor", x=x, y=y, name=name, out=out, binary_op=True) @@ -580,7 +589,7 @@ def bitwise_not(x, out=None, name=None): print(res) # [4, 0, -2] """ if _in_eager_mode() and out == None: - return _C_op.final_state_bitwise_not(x) + return _C_ops.final_state_bitwise_not(x) return _bitwise_op( op_name="bitwise_not", x=x, y=None, name=name, out=out, binary_op=False) diff --git a/python/paddle/utils/code_gen/api.yaml b/python/paddle/utils/code_gen/api.yaml index 6479025e71c..998a9425d41 100644 --- a/python/paddle/utils/code_gen/api.yaml +++ b/python/paddle/utils/code_gen/api.yaml @@ -538,32 +538,32 @@ # bitwise_and -# - api : bitwise_and -# args : (Tensor x, Tensor y) -# output : Tensor -# infer_meta : -# func : BitwiseInferMeta -# kernel : -# func : bitwise_and +- api : bitwise_and + args : (Tensor x, Tensor y) + output : Tensor + infer_meta : + func : ElementwiseInferMeta + kernel : + func : bitwise_and -# # bitwise_or -# - api : bitwise_or -# args : (Tensor x, Tensor y) -# output : Tensor -# infer_meta : -# func : BitwiseInferMeta -# kernel : -# func : bitwise_or +# bitwise_or +- api : bitwise_or + args : (Tensor x, Tensor y) + output : Tensor + infer_meta : + func : ElementwiseInferMeta + kernel : + func : bitwise_or -# # bitwise_xor -# - api : bitwise_xor -# args : (Tensor x, Tensor y) -# output : Tensor -# infer_meta : -# func : BitwiseInferMeta -# kernel : -# func : bitwise_xor +# bitwise_xor +- api : bitwise_xor + args : (Tensor x, Tensor y) + output : Tensor + infer_meta : + func : ElementwiseInferMeta + kernel : + func : bitwise_xor # bitwise_not - api : bitwise_not -- GitLab