add unique_consecutive_op#34334
Merged
fuyinno4 merged 27 commits intoPaddlePaddle:developfrom Aug 16, 2021
Merged
Conversation
|
✅ This PR's description meets the template requirements! |
|
Thanks for your contribution! |
TCChenlong
reviewed
Jul 27, 2021
python/paddle/tensor/__init__.py
Outdated
| from .manipulation import stack # noqa: F401 | ||
| from .manipulation import strided_slice # noqa: F401 | ||
| from .manipulation import unique # noqa: F401 | ||
| from .manipulation import unique_consecutive |
Contributor
There was a problem hiding this comment.
需要按格式,加上 “# noqa: F401”
python/paddle/tensor/__init__.py
Outdated
| 'strided_slice', | ||
| 'transpose', | ||
| 'unique', | ||
| 'unique_consecutive' |
| .. note:: This function is different from :func:`paddle.unique` in the sense that this function | ||
| only eliminates consecutive duplicate values. This semantics is similar to `std::unique` | ||
| in C++. | ||
| Args: |
Contributor
There was a problem hiding this comment.
Args 前需要加空行,Returns:、Example: 同理
| name=None): | ||
| r""" | ||
| Eliminates all but the first element from every consecutive group of equivalent elements. | ||
| .. note:: This function is different from :func:`paddle.unique` in the sense that this function |
| in C++. | ||
| Args: | ||
| x(Tensor): the input tensor, it's data type should be float32, float64, int32, int64. | ||
| return_inverse(bool, optional): If True, also return the indices for where elements in |
Contributor
There was a problem hiding this comment.
Else XXX。Default is False。
| x(Tensor): the input tensor, it's data type should be float32, float64, int32, int64. | ||
| return_inverse(bool, optional): If True, also return the indices for where elements in | ||
| the original input ended up in the returned unique consecutive tensor. | ||
| return_counts(bool, optional): If True, also return the counts for each unique consecutive element. |
Contributor
There was a problem hiding this comment.
Else XXX。Default is False。
TCChenlong
previously approved these changes
Aug 2, 2021
0d7f284 to
2b9cfb0
Compare
TCChenlong
approved these changes
Aug 11, 2021
|
|
||
| x = paddle.to_tensor([1, 1, 2, 2, 3, 1, 1, 2]) | ||
| output = paddle.unique_consecutive(x) # | ||
| np_output = output.numpy() # [1 2 3 1 2] |
Contributor
There was a problem hiding this comment.
这里不用返回numpy,参考paddle.add,用下面这种写法就行:
z = paddle.add(x, y)
print(z) # [3., 8., 6. ]
zhiqiu
approved these changes
Aug 12, 2021
Contributor
zhiqiu
left a comment
There was a problem hiding this comment.
lgtm for op_function_generator
| @@ -0,0 +1,142 @@ | |||
| /* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. | |||
fuyinno4
approved these changes
Aug 12, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR types
New features
PR changes
OPs
Describe
add unique_consecutive op for support to eliminate all but the first element from every consecutive group of equivalent elements.