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

Support settiem by Bool index #35133

Merged
merged 18 commits into from
Sep 1, 2021
Merged

Support settiem by Bool index #35133

merged 18 commits into from
Sep 1, 2021

Conversation

zyfncg
Copy link
Contributor

@zyfncg zyfncg commented Aug 24, 2021

PR types

New features

PR changes

APIs

Describe

Support settiem by Bool index

Example:

x = paddle.to_tensor([[1, 2], [3, 4], [5, 6]])

# 1. 支持bool类型list索引赋值(一维list且长度与x的第0维相同)
x[[True, True, False]] = 0

# 2. 支持bool类型Tensor索引赋值(维度不超过x的维度,且从前到后每一维的长度需和x对应维度相同)
idx = paddle.to_tensor([[True, False], [False, False], [True, False]])
x[idx] = [0, 1]

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

idx = where(item)
gather_val = gather_nd(var, idx)
gather_val_new = value - gather_val
out = scatter_nd_add(var, idx, gather_val_new)
Copy link
Contributor

@hbwx24 hbwx24 Aug 27, 2021

Choose a reason for hiding this comment

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

scatter_nd_add 的API文档上写的支持float32, float64,这里是否需要做一下类型转换。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里先设置了类型检查,暂时只支持float32和float64数据类型使用bool索引,后续再根据scatter_nd_add的支持情况进行修改

Copy link
Contributor

@hbwx24 hbwx24 left a comment

Choose a reason for hiding this comment

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

LGTM

@chenwhql chenwhql merged commit d387820 into PaddlePaddle:develop Sep 1, 2021
@zyfncg zyfncg deleted the zyf_slice branch September 13, 2021 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants