8000 [feature request] Add boolean reduce operations · Issue #7539 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[feature request] Add boolean reduce operations #7539

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

Closed
zasdfgbnm opened this issue May 13, 2018 · 2 comments
Closed

[feature request] Add boolean reduce operations #7539

zasdfgbnm opened this issue May 13, 2018 · 2 comments

Comments

@zasdfgbnm
Copy link
Collaborator

Hi, I just want to ask if it is contribute welcome for adding two boolean reduce operations torch.all and torch.any. The API is the the same as torch.sum and torch.prod. These two ops treat the input tensor as boolean tensor and compute the and and or along the the specified dimension.

torch.all can be implemented as torch.prod, but implementing torch.any as torch.sum is dangerous because it is possible that there happen to be 256 1s in the tensor, which would gives a 0 instead of some non-zero value and in my application, I'm using a workaround for torch.any that looks like

torch.sum(x.dtype(torch.float), dim) > 0
@apaszke
Copy link
Contributor
apaszke commented May 13, 2018

We already have them, although they are present only as methods of Boolean tensors (.all(), .any()). Since they’re limited to a single type only I think it’s better to avoid adding them to the main namespace. Thanks for the proposal!

@apaszke apaszke closed this as completed May 13, 2018
@zasdfgbnm
Copy link
Collaborator Author

Ahh, version 0.5 add dim support. Thanks!

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

No branches or pull requests

2 participants
0