Skip to content

Commit eb48a1f

Browse files
committed
add back the definition of bitwise_xor as delete it will cause failure
1 parent db75434 commit eb48a1f

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

python/paddle/_paddle_docs.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,52 @@ def asin(
30033003
""",
30043004
)
30053005

3006+
add_doc_and_signature(
3007+
"bitwise_xor",
3008+
r"""
3009+
3010+
Apply ``bitwise_xor`` on Tensor ``X`` and ``Y`` .
3011+
3012+
.. math::
3013+
Out = X ^\wedge Y
3014+
3015+
Note:
3016+
``paddle.bitwise_xor`` supports broadcasting. If you want know more about broadcasting, please refer to please refer to `Introduction to Tensor`_ .
3017+
3018+
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
3019+
3020+
Args:
3021+
x (Tensor): Input Tensor of ``bitwise_xor`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
3022+
Alias : ``input``
3023+
y (Tensor): Input Tensor of ``bitwise_xor`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
3024+
Alias: ``other``
3025+
out (Tensor|None, optional): Result of ``bitwise_xor`` . It is a N-D Tensor with the same data type of input Tensor. Default: None.
3026+
name (str|None, optional): The default value is None. Normally there is no need for
3027+
user to set this property. For more information, please refer to :ref:`api_guide_Name`.
3028+
3029+
Returns:
3030+
Tensor: Result of ``bitwise_xor`` . It is a N-D Tensor with the same data type of input Tensor.
3031+
3032+
Examples:
3033+
.. code-block:: python
3034+
3035+
>>> import paddle
3036+
>>> x = paddle.to_tensor([-5, -1, 1])
3037+
>>> y = paddle.to_tensor([4, 2, -3])
3038+
>>> res = paddle.bitwise_xor(x, y)
3039+
>>> print(res)
3040+
Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True,
3041+
[-1, -3, -4])
3042+
""",
3043+
"""
3044+
def bitwise_xor(
3045+
x: Tensor,
3046+
y: Tensor,
3047+
name: str | None = None,
3048+
) -> Tensor
3049+
""",
3050+
)
3051+
30063052
add_doc_and_signature(
30073053
"bitwise_xor_",
30083054
r"""
@@ -3029,30 +3075,28 @@ def asin(
30293075
30303076
Examples:
30313077
.. code-block:: python
3032-
30333078
>>> import paddle
3034-
30353079
>>> # Integer example
30363080
>>> x = paddle.to_tensor([-5, -1, 1], dtype='int64')
30373081
>>> y = paddle.to_tensor([ 4, 2, -3], dtype='int64')
30383082
>>> paddle.bitwise_xor_(x, y) # in-place; equivalent to x.bitwise_xor_(y)
30393083
>>> print(x)
30403084
Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True,
30413085
[-1, -3, -4])
3042-
30433086
>>> # Boolean example
30443087
>>> x = paddle.to_tensor([True, False, True], dtype='bool')
30453088
>>> y = paddle.to_tensor([True, True, False], dtype='bool')
30463089
>>> x.bitwise_xor_(y) # in-place
30473090
>>> print(x)
30483091
Tensor(shape=[3], dtype=bool, place=Place(cpu), stop_gradient=True,
30493092
[False, True, True])
3050-
""",
3093+
3094+
""",
30513095
"""
30523096
def bitwise_xor_(
30533097
x: Tensor,
30543098
y: Tensor,
30553099
name: str | None = None,
3056-
) -> Tensor
3100+
) -> Tensor:
30573101
""",
30583102
)

python/paddle/tensor/logic.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import paddle
2222
from paddle import _C_ops
2323
from paddle._C_ops import ( # noqa: F401
24-
bitwise_xor,
2524
greater_than,
2625
isclose,
2726
logical_and,
@@ -50,7 +49,6 @@
5049
if TYPE_CHECKING:
5150
from paddle import Tensor
5251

53-
5452
__all__ = []
5553

5654

@@ -1211,6 +1209,52 @@ def bitwise_or_(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
12111209
return _C_ops.bitwise_or_(x, y)
12121210

12131211

1212+
@param_two_alias(["x", "input"], ["y", "other"])
1213+
def bitwise_xor(
1214+
x: Tensor, y: Tensor, out: Tensor | None = None, name: str | None = None
1215+
) -> Tensor:
1216+
r"""
1217+
1218+
Apply ``bitwise_xor`` on Tensor ``X`` and ``Y`` .
1219+
1220+
.. math::
1221+
Out = X ^\wedge Y
1222+
1223+
Note:
1224+
``paddle.bitwise_xor`` supports broadcasting. If you want know more about broadcasting, please refer to please refer to `Introduction to Tensor`_ .
1225+
1226+
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
1227+
1228+
Args:
1229+
x (Tensor): Input Tensor of ``bitwise_xor`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
1230+
Alias : ``input``
1231+
y (Tensor): Input Tensor of ``bitwise_xor`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
1232+
Alias: ``other``
1233+
out (Tensor|None, optional): Result of ``bitwise_xor`` . It is a N-D Tensor with the same data type of input Tensor. Default: None.
1234+
name (str|None, optional): The default value is None. Normally there is no need for
1235+
user to set this property. For more information, please refer to :ref:`api_guide_Name`.
1236+
1237+
Returns:
1238+
Tensor: Result of ``bitwise_xor`` . It is a N-D Tensor with the same data type of input Tensor.
1239+
1240+
Examples:
1241+
.. code-block:: python
1242+
1243+
>>> import paddle
1244+
>>> x = paddle.to_tensor([-5, -1, 1])
1245+
>>> y = paddle.to_tensor([4, 2, -3])
1246+
>>> res = paddle.bitwise_xor(x, y)
1247+
>>> print(res)
1248+
Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True,
1249+
[-1, -3, -4])
1250+
"""
1251+
if in_dynamic_or_pir_mode() and out is None:
1252+
return _C_ops.bitwise_xor(x, y)
1253+
return _bitwise_op(
1254+
op_name="bitwise_xor", x=x, y=y, name=name, out=out, binary_op=True
1255+
)
1256+
1257+
12141258
def __rxor__(
12151259
x: Tensor,
12161260
y: int | bool,
@@ -1227,7 +1271,7 @@ def __rxor__(
12271271

12281272

12291273
@inplace_apis_in_dygraph_only
1230-
@ParamAliasDecorator({"x": ["input"], "y": ["other"]})
1274+
@param_two_alias(["x", "input"], ["y", "other"])
12311275
def bitwise_xor_(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
12321276
r"""
12331277
Inplace version of ``bitwise_xor`` API, the output Tensor will be inplaced with input ``x``.

0 commit comments

Comments
 (0)