Skip to content
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

【PaddlePaddle Hackathon 3 No.16】为 Paddle 新增 API paddle.take #44741

Merged
merged 29 commits into from Aug 30, 2022
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
982d01e
add paddle.take api
S-HuaBomb Jul 15, 2022
69b0a3e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Jul 15, 2022
b07c062
fix paddle.take
S-HuaBomb Jul 29, 2022
09d2836
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Jul 29, 2022
c8482f6
remove from pip import main
S-HuaBomb Jul 29, 2022
0665e50
test index out of range error
S-HuaBomb Aug 4, 2022
c5a9e16
test index out of range error and fix conflict
S-HuaBomb Aug 4, 2022
10b41c4
fix Examples
S-HuaBomb Aug 5, 2022
6852760
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 5, 2022
9649b87
fix Examples
S-HuaBomb Aug 5, 2022
ec1cfd7
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 5, 2022
6806a8f
add param mode to take api
S-HuaBomb Aug 22, 2022
27b6943
fix conflict ad merge
S-HuaBomb Aug 22, 2022
5d32c52
add example code
S-HuaBomb Aug 22, 2022
b35d831
fix test using np.testing.assert_allclose
S-HuaBomb Aug 23, 2022
cc2f4f4
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 23, 2022
c4161f2
add annotation
S-HuaBomb Aug 23, 2022
aaee858
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 23, 2022
ca2604f
fix typo
S-HuaBomb Aug 23, 2022
5979d5f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 23, 2022
7b3fc1d
fix 嵌套列表
S-HuaBomb Aug 24, 2022
668964d
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 24, 2022
64b688a
fix Tensor,
S-HuaBomb Aug 24, 2022
cdd1080
fix docs warning
S-HuaBomb Aug 25, 2022
eca0483
fix conflict
S-HuaBomb Aug 25, 2022
4ca5c41
fix raise bug
S-HuaBomb Aug 27, 2022
9fb6896
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 27, 2022
7fd6c85
add test case for negative index out of range error
S-HuaBomb Aug 29, 2022
046ff44
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
S-HuaBomb Aug 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions python/paddle/tensor/math.py
Expand Up @@ -4863,9 +4863,7 @@ def take(x, index, mode='raise', name=None):

if mode == 'raise':
# This processing enables 'take' to handle negative indexes within the correct range.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以补充下注释,negative indexes可以enable,但越界的索引会在下面的index_select报错

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THX,Done

# Negative indexes can be enabled,
# but out-of-range indexes will report an error in the following paddle.index_select
index_1d = paddle.where(index_1d < 0, index_1d % max_index, index_1d)
index_1d = paddle.where(index_1d < 0, index_1d + max_index, index_1d)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@S-HuaBomb 这个修改是哪个case会出bug呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里本来就应该是 + 号,这样确保负值索引是在合理范围内的,我只需要 + 号把它转成对应的负值索引。如果使用取余 %,那么超出范围的负值索引也会被约束到合理范围,那样是不对的。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那么超出范围的负值索引也会被约束到合理范围,那样是不对的。

Got it. 可以针对这个case补充一个报错的单测么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已加,done.

elif mode == 'wrap':
# The out of range indices are constrained by taking the remainder.
index_1d = paddle.where(index_1d < 0,
Expand Down