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

inconsistent behavior of as_tuple in nonzero method between open3d and pytorch #7166

Open
3 tasks done
vincentme opened this issue Feb 9, 2025 · 0 comments
Open
3 tasks done
Labels
bug Not a build issue, this is likely a bug.

Comments

@vincentme
Copy link

vincentme commented Feb 9, 2025

Checklist

Describe the issue

Seems that the behavior of as_tuple in nonzero method is not consistent with pytorch, and it is reversed from the meaning of as_tuple.

For instance, a.nonzero(as_tuple=True) retur a tensor and a.nonzero(as_tuple=False) return a list of tensors.

Steps to reproduce the bug

import open3d.core as o3c

a = o3c.Tensor([[3, 0, 0], [0, 4, 0], [5, 6, 0]])

print("a = \n{}\n".format(a))
print("a.nonzero() = \n{}\n".format(a.nonzero()))
print("a.nonzero(as_tuple = True) = \n{}".format(a.nonzero(as_tuple=True)))


import torch

a_tr = torch.Tensor([[3, 0, 0], [0, 4, 0], [5, 6, 0]])

print()
print("a_tr = \n{}\n".format(a_tr))
print("a_tr.nonzero() = \n{}\n".format(a_tr.nonzero()))
print("a_tr.nonzero(as_tuple = True) = \n{}".format(a_tr.nonzero(as_tuple=True)))

Error message

a = 
[[3 0 0],
 [0 4 0],
 [5 6 0]]
Tensor[shape={3, 3}, stride={3, 1}, Int64, CPU:0, 0x55d13980e480]

a.nonzero() = 
[[0 1 2 2]
Tensor[shape={4}, stride={1}, Int64, CPU:0, 0x55d139807770], [0 1 0 1]
Tensor[shape={4}, stride={1}, Int64, CPU:0, 0x55d134c006a0]]

a.nonzero(as_tuple = True) = 
[[0 1 2 2],
 [0 1 0 1]]
Tensor[shape={2, 4}, stride={4, 1}, Int64, CPU:0, 0x55d139b75c00]

a_tr = 
tensor([[3., 0., 0.],
        [0., 4., 0.],
        [5., 6., 0.]])

a_tr.nonzero() = 
tensor([[0, 0],
        [1, 1],
        [2, 0],
        [2, 1]])

a_tr.nonzero(as_tuple = True) = 
(tensor([0, 1, 2, 2]), tensor([0, 1, 0, 1]))

Expected behavior

No response

Open3D, Python and System information

- Operating system: Ubuntu 24.04 
- Python version: Python 3.12
- Open3D version: output from python: 0.19
- System architecture: x86 
- Is this a remote workstation?: no
- How did you install Open3D?: pip

Additional information

No response

@vincentme vincentme added the bug Not a build issue, this is likely a bug. label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not a build issue, this is likely a bug.
Projects
None yet
Development

No branches or pull requests

1 participant