Eliminates all but the first element from every consecutive group of equivalent elements. Note: This function is different from :ref:`api_paddle_unique` in the sense that this function only eliminates consecutive duplicate values. This semantics is similar to :ref:`api_padd
(
x: Tensor,
return_inverse: bool = False,
return_counts: bool = False,
axis: int | None = None,
dtype: DTypeLike = 'int64',
name: str | None = None,
)
| 3553 | |
| 3554 | @param_two_alias(["x", "input"], ["axis", "dim"]) |
| 3555 | def unique_consecutive( |
| 3556 | x: Tensor, |
| 3557 | return_inverse: bool = False, |
| 3558 | return_counts: bool = False, |
| 3559 | axis: int | None = None, |
| 3560 | dtype: DTypeLike = 'int64', |
| 3561 | name: str | None = None, |
| 3562 | ) -> tuple[Tensor, Tensor, Tensor]: |
| 3563 | """ |
| 3564 | Eliminates all but the first element from every consecutive group of equivalent elements. |
| 3565 | |
| 3566 | Note: |
| 3567 | This function is different from :ref:`api_paddle_unique` in the sense that this function |
| 3568 | only eliminates consecutive duplicate values. This semantics is similar to :ref:`api_paddle_unique` in C++. |
| 3569 | |
| 3570 | .. note:: |
| 3571 | Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``. |
| 3572 | For example, ``unique_consecutive(input=tensor_x, dim=1, ...)`` is equivalent to ``unique_consecutive(x=tensor_x, axis=1, ...)``. |
| 3573 | |
| 3574 | Args: |
| 3575 | x(Tensor): the input tensor, it's data type should be float32, float64, int32, int64. |
| 3576 | alias: ``input``. |
| 3577 | return_inverse(bool, optional): If True, also return the indices for where elements in |
| 3578 | the original input ended up in the returned unique consecutive tensor. Default is False. |
| 3579 | return_counts(bool, optional): If True, also return the counts for each unique consecutive element. |
| 3580 | Default is False. |
| 3581 | axis(int, optional): The axis to apply unique consecutive. If None, the input will be flattened. |
| 3582 | Default is None. |
| 3583 | dtype(str|paddle.dtype|np.dtype, optional):The data type `inverse` tensor: int32 or int64. |
| 3584 | Default: int64. |
| 3585 | name(str|None, optional): Name for the operation. For more information, please refer to |
| 3586 | :ref:`api_guide_Name`. Default is None. |
| 3587 | |
| 3588 | Returns: |
| 3589 | - out (Tensor), the unique consecutive tensor for x. |
| 3590 | - inverse (Tensor), the element of the input tensor corresponds to |
| 3591 | the index of the elements in the unique consecutive tensor for x. |
| 3592 | inverse is provided only if return_inverse is True. |
| 3593 | - counts (Tensor), the counts of the every unique consecutive element in the input tensor. |
| 3594 | counts is provided only if return_counts is True. |
| 3595 | |
| 3596 | Examples: |
| 3597 | .. code-block:: pycon |
| 3598 | |
| 3599 | >>> import paddle |
| 3600 | |
| 3601 | >>> x = paddle.to_tensor([1, 1, 2, 2, 3, 1, 1, 2]) |
| 3602 | >>> output = paddle.unique_consecutive(x) |
| 3603 | >>> print(output) |
| 3604 | Tensor(shape=[5], dtype=int64, place=Place(cpu), stop_gradient=True, |
| 3605 | [1, 2, 3, 1, 2]) |
| 3606 | |
| 3607 | >>> _, inverse, counts = paddle.unique_consecutive(x, return_inverse=True, return_counts=True) |
| 3608 | >>> print(inverse) |
| 3609 | Tensor(shape=[8], dtype=int64, place=Place(cpu), stop_gradient=True, |
| 3610 | [0, 0, 1, 1, 2, 3, 3, 4]) |
| 3611 | >>> print(counts) |
| 3612 | Tensor(shape=[5], dtype=int64, place=Place(cpu), stop_gradient=True, |
nothing calls this directly
no test coverage detected