Skip to content

Commit

Permalink
refact: 复用 less_than 实现 less,而不是直接 import as (#69449)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXnneHang authored Nov 19, 2024
1 parent 415719a commit f800086
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@
is_empty,
is_tensor,
isclose,
less,
less_,
less_equal,
less_equal_,
less_than,
less_than as less,
less_than_,
less_than_ as less_,
logical_and,
logical_and_,
logical_not,
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@
is_empty,
is_tensor,
isclose,
less,
less_,
less_equal,
less_equal_,
less_than,
less_than as less,
less_than as less_,
less_than_,
logical_and,
logical_and_,
Expand Down
43 changes: 43 additions & 0 deletions python/paddle/tensor/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,49 @@ def less_than_(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
return _C_ops.less_than_(x, y)


def less(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
"""
Returns the truth value of :math:`x < y` elementwise, which is equivalent function to the overloaded operator `<`.
Note:
The output has no gradient.
Args:
x (Tensor): First input to compare which is N-D tensor. The input data type should be bool, bfloat16, float16, float32, float64, uint8, int8, int16, int32, int64.
y (Tensor): Second input to compare which is N-D tensor. The input data type should be bool, bfloat16, float16, float32, float64, uint8, int8, int16, int32, int64.
name (str|None, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
Tensor: The output shape is same as input :attr:`x`. The output data type is bool.
Examples:
.. code-block:: python
>>> import paddle
>>> x = paddle.to_tensor([1, 2, 3])
>>> y = paddle.to_tensor([1, 3, 2])
>>> result1 = paddle.less(x, y)
>>> print(result1)
Tensor(shape=[3], dtype=bool, place=Place(cpu), stop_gradient=True,
[False, True , False])
"""

# Directly call less_than API
return less_than(x, y, name)


@inplace_apis_in_dygraph_only
def less_(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
r"""
Inplace version of ``less_`` API, the output Tensor will be inplaced with input ``x``.
Please refer to :ref:`api_paddle_less`.
"""

# Directly call less_than_ API
return less_than_(x, y, name)


def not_equal(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
"""
Returns the truth value of :math:`x != y` elementwise, which is equivalent function to the overloaded operator `!=`.
Expand Down

0 comments on commit f800086

Please sign in to comment.