8000 [numpy] torch.nonzero is similar to np.argwhere not np.nonzero · Issue #64502 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[numpy] torch.nonzero is similar to np.argwhere not np.nonzero #64502

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

Open
kshitij12345 opened this issue Sep 4, 2021 · 5 comments
Open

[numpy] torch.nonzero is similar to np.argwhere not np.nonzero #64502

kshitij12345 opened this issue Sep 4, 2021 · 5 comments
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@kshitij12345
Copy link
Collaborator
kshitij12345 commented Sep 4, 2021
import torch
import numpy as np

t = torch.tensor([1, 0, 1, 0])
# t = torch.tensor([[1, 0, 1, 0], [0, 1, 0, 0]])
# t = torch.ones(3, 3, 1)

torch.testing.assert_allclose(torch.nonzero(t), np.argwhere(t.numpy()), rtol=0, atol=0)
torch.testing.assert_allclose(torch.nonzero(t), np.nonzero(t.numpy()), rtol=0, atol=0) # error

cc: @mruberry

cc @mruberry @rgommers @heitorschueroff

@kshitij12345 kshitij12345 added the module: numpy Related to numpy support, and also numpy compatibility of our operators label Sep 4, 2021
@kshitij12345 kshitij12345 changed the title [numpy] torch.nonzero is similar np.argwhere not np.nonzero [numpy] torch.nonzero is similar to np.argwhere not np.nonzero Sep 4, 2021
@mruberry mruberry added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 5, 2021
@mruberry
Copy link
Collaborator
mruberry commented Sep 5, 2021

cc @saketh-are who's been looking at implementing argwhere

@kshitij12345
Copy link
Collaborator Author

I have a draft for the same

@rgommers
Copy link
Collaborator
rgommers commented Sep 5, 2021

It doesn't match the numpy default because of the default value of the as_tuple keyword. That is discussed in detail in gh-45499.

@rgommers
Copy link
Collaborator
rgommers commented Jan 3, 2022

For the decision of making a backwards-incompatible change to nonzero or not, see gh-68174.

@mruberry
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants
0