|
26 | 26 | all, |
27 | 27 | amax, |
28 | 28 | amin, |
| 29 | + any, |
29 | 30 | isfinite, |
30 | 31 | isinf, |
31 | 32 | isnan, |
@@ -4977,109 +4978,6 @@ def increment(x: Tensor, value: float = 1.0, name: str | None = None) -> Tensor: |
4977 | 4978 | return x |
4978 | 4979 |
|
4979 | 4980 |
|
4980 | | -def any( |
4981 | | - x: Tensor, |
4982 | | - axis: int | Sequence[int] | None = None, |
4983 | | - keepdim: bool = False, |
4984 | | - name: str | None = None, |
4985 | | -) -> Tensor: |
4986 | | - """ |
4987 | | - Computes the ``logical or`` of tensor elements over the given dimension, and return the result. |
4988 | | -
|
4989 | | - Args: |
4990 | | - x (Tensor): An N-D Tensor, the input data type should be 'bool', 'float32', 'float64', 'int32', 'int64', 'complex64', 'complex128'. |
4991 | | - axis (int|list|tuple|None, optional): The dimensions along which the ``logical or`` is compute. If |
4992 | | - :attr:`None`, and all elements of :attr:`x` and return a |
4993 | | - Tensor with a single element, otherwise must be in the |
4994 | | - range :math:`[-rank(x), rank(x))`. If :math:`axis[i] < 0`, |
4995 | | - the dimension to reduce is :math:`rank + axis[i]`. |
4996 | | - keepdim (bool, optional): Whether to reserve the reduced dimension in the |
4997 | | - output Tensor. The result Tensor will have one fewer dimension |
4998 | | - than the :attr:`x` unless :attr:`keepdim` is true, default |
4999 | | - value is False. |
5000 | | - name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. |
5001 | | -
|
5002 | | - Returns: |
5003 | | - Tensor: Results the ``logical or`` on the specified axis of input Tensor `x`, it's data type is bool. |
5004 | | -
|
5005 | | - Examples: |
5006 | | - .. code-block:: python |
5007 | | -
|
5008 | | - >>> import paddle |
5009 | | -
|
5010 | | - >>> x = paddle.to_tensor([[1, 0], [1, 1]], dtype='int32') |
5011 | | - >>> x = paddle.assign(x) |
5012 | | - >>> x |
5013 | | - Tensor(shape=[2, 2], dtype=int32, place=Place(cpu), stop_gradient=True, |
5014 | | - [[1, 0], |
5015 | | - [1, 1]]) |
5016 | | - >>> x = paddle.cast(x, 'bool') |
5017 | | - >>> # x is a bool Tensor with following elements: |
5018 | | - >>> # [[True, False] |
5019 | | - >>> # [True, True]] |
5020 | | -
|
5021 | | - >>> # out1 should be True |
5022 | | - >>> out1 = paddle.any(x) |
5023 | | - >>> out1 |
5024 | | - Tensor(shape=[], dtype=bool, place=Place(cpu), stop_gradient=True, |
5025 | | - True) |
5026 | | -
|
5027 | | - >>> # out2 should be [True, True] |
5028 | | - >>> out2 = paddle.any(x, axis=0) |
5029 | | - >>> out2 |
5030 | | - Tensor(shape=[2], dtype=bool, place=Place(cpu), stop_gradient=True, |
5031 | | - [True, True]) |
5032 | | -
|
5033 | | - >>> # keepdim=False, out3 should be [True, True], out.shape should be (2,) |
5034 | | - >>> out3 = paddle.any(x, axis=-1) |
5035 | | - >>> out3 |
5036 | | - Tensor(shape=[2], dtype=bool, place=Place(cpu), stop_gradient=True, |
5037 | | - [True, True]) |
5038 | | -
|
5039 | | - >>> # keepdim=True, result should be [[True], [True]], out.shape should be (2,1) |
5040 | | - >>> out4 = paddle.any(x, axis=1, keepdim=True) |
5041 | | - >>> out4 |
5042 | | - Tensor(shape=[2, 1], dtype=bool, place=Place(cpu), stop_gradient=True, |
5043 | | - [[True], |
5044 | | - [True]]) |
5045 | | -
|
5046 | | - """ |
5047 | | - if in_dynamic_or_pir_mode(): |
5048 | | - return _C_ops.any(x, axis, keepdim) |
5049 | | - else: |
5050 | | - reduce_all, axis = _get_reduce_axis(axis, x) |
5051 | | - attrs = { |
5052 | | - 'dim': axis, |
5053 | | - 'keep_dim': keepdim, |
5054 | | - 'reduce_all': reduce_all, |
5055 | | - } |
5056 | | - check_variable_and_dtype( |
5057 | | - x, |
5058 | | - 'x', |
5059 | | - [ |
5060 | | - 'bool', |
5061 | | - 'float32', |
5062 | | - 'float64', |
5063 | | - 'int32', |
5064 | | - 'int64', |
5065 | | - 'complex64', |
5066 | | - 'complex128', |
5067 | | - ], |
5068 | | - 'any', |
5069 | | - ) |
5070 | | - check_type(axis, 'axis', (int, list, tuple, type(None)), 'any') |
5071 | | - |
5072 | | - helper = LayerHelper('any', **locals()) |
5073 | | - out = helper.create_variable_for_type_inference(dtype=paddle.bool) |
5074 | | - helper.append_op( |
5075 | | - type='reduce_any', |
5076 | | - inputs={'X': x}, |
5077 | | - outputs={'Out': out}, |
5078 | | - attrs=attrs, |
5079 | | - ) |
5080 | | - return out |
5081 | | - |
5082 | | - |
5083 | 4981 | def broadcast_shapes(*shapes: Sequence[int]) -> list[int]: |
5084 | 4982 | """ |
5085 | 4983 | The function returns the shape of doing operation with broadcasting on tensors of shape list. |
|
0 commit comments