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

unbatch_edge_index returns less splits than number of batches #7849

Closed
hcagri opened this issue Aug 4, 2023 · 1 comment · Fixed by #7851
Closed

unbatch_edge_index returns less splits than number of batches #7849

hcagri opened this issue Aug 4, 2023 · 1 comment · Fixed by #7851
Labels

Comments

@hcagri
Copy link

hcagri commented Aug 4, 2023

🐛 Describe the bug

The issue I am encountering with the unbatch_edge_index function from PyTorch Geometric is that there is a discrepancy between the number of batches I provide and the number of edge indices returned by the function.

Currently, the function seems to omit empty edge_index tensors for the last batch if it does not have any edges. As a result, the number of returned edge indices is less than the total number of batches.

The problem can be reproduced by the simple script provided below.

from torch_geometric.utils import  unbatch_edge_index
import torch 

x = torch.tensor([0,1,2,3,4,5])
batch = torch.tensor([0, 0, 1, 1, 2, 2])
edge_index = torch.tensor([[0,2],[1,3]])
edge_index_splits = unbatch_edge_index(edge_index, batch)

print("Number of Batches: ", len(torch.unique(batch)))
print("Number of Edge Indices: ", len(edge_index_splits))

Environment

  • PyG version: 2.3.0
  • PyTorch version: 2.0.1
  • OS: Ubuntu 20.04.2 LTS
  • Python Version: 3.9.16
@hcagri hcagri added the bug label Aug 4, 2023
@rusty1s
Copy link
Member

rusty1s commented Aug 5, 2023

Thanks for reporting. Will be fixed via #7851.

@rusty1s rusty1s linked a pull request Aug 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants