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

remove redundant equal in bool tensor indexing #57986

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions python/paddle/base/variable_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,10 @@ def get_value_for_bool_tensor(var, item):
empty_shape = [0] + list(var.shape[i:])

def idx_not_empty(var, item):
from ..tensor import gather_nd
bool_2_idx = paddle.nonzero(item)
return paddle.gather_nd(var, bool_2_idx)

bool_2_idx = paddle.nonzero(item == True)
return gather_nd(var, bool_2_idx)

from paddle.static.nn import cond

return cond(
return paddle.static.nn.cond(
item.any(),
lambda: idx_not_empty(var, item),
lambda: paddle.empty(empty_shape, var.dtype),
Expand Down