-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add unique_consecutive_op #34334
add unique_consecutive_op #34334
Conversation
✅ This PR's description meets the template requirements! |
Thanks for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python/paddle/tensor/__init__.py
Outdated
@@ -88,6 +88,7 @@ | |||
from .manipulation import stack # noqa: F401 | |||
from .manipulation import strided_slice # noqa: F401 | |||
from .manipulation import unique # noqa: F401 | |||
from .manipulation import unique_consecutive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要按格式,加上 “# noqa: F401”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
python/paddle/tensor/__init__.py
Outdated
@@ -331,6 +332,7 @@ | |||
'strided_slice', | |||
'transpose', | |||
'unique', | |||
'unique_consecutive' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
少了 ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
.. 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args 前需要加空行,Returns:、Example: 同理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也需要加一行空行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Else XXX。Default is False。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Else XXX。Default is False。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
0d7f284
to
2b9cfb0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
||
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不用返回numpy,参考paddle.add,用下面这种写法就行:
z = paddle.add(x, y)
print(z) # [3., 8., 6. ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm for op_function_generator
@@ -0,0 +1,142 @@ | |||
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2019->2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.