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 get_item where the index is a bool scalar tensor #40829

Merged
merged 2 commits into from
Mar 25, 2022

Conversation

FlyingQianMM
Copy link
Contributor

PR types

Bug fixes

PR changes

OPs

Describe

  • get_item() raise a error as bellow when the index is a bool scalar tensor:

code:

import paddle
data = paddle.to_tensor([[1,2]])
mask = paddle.to_tensor([1], dtype='bool')
print(data[mask])

error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.7/site-packages/paddle/fluid/dygraph/varbase_patch_methods.py", line 719, in __getitem__
    return _getitem_impl_(self, item)
  File "/opt/conda/lib/python3.7/site-packages/paddle/fluid/variable_index.py", line 474, in _getitem_impl_
    attrs=attrs)
  File "/opt/conda/lib/python3.7/site-packages/paddle/fluid/framework.py", line 3480, in append_op
    inplace_map)
  File "/opt/conda/lib/python3.7/site-packages/paddle/fluid/dygraph/tracer.py", line 130, in trace_op
    not stop_gradient, inplace_map if inplace_map else {})
ValueError: (InvaidArgument) The dtype of Tensor in list must be int32 or int64, but received: 0 (at /idg/paddle/Paddle/paddle/fluid/operators/utils.h:87)
  [operator < slice > error]
  • after we fix this error, the output can been returned correctly:
    code:
import paddle
data = paddle.to_tensor([[1,2]])
mask = paddle.to_tensor([1], dtype='bool')
print(data[mask])

image

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.

2 participants