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

fixing edge mask for directed graphs in k_hop_subgraph #9756

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ryoji-kubo
Copy link

Example use case:

from torch_geometric.utils import k_hop_subgraph
import torch

edge_index = torch.tensor([[1, 2, 3],
                           [0, 1, 1]])
# get the 2-hop neighbors of node 0 in the directed graph.
_, edge_index, _, edge_mask = k_hop_subgraph(0, 2, edge_index, relabel_nodes=False, directed=True)

This gives the following result:

Expected Outcome:

>>> edge_index
tensor([[1, 2, 3],
        [0, 1, 1]])

>>> edge_mask
tensor([True,  True,  True])

Actual Outcome:

>>> edge_index
tensor([[2, 3],
        [1, 1]])
>>> edge_mask
tensor([False,  True,  True])

This stems from the fact that the line torch.index_select(node_mask, 0, row, out=edge_mask) overwrites edge_mask, effectively only marking the edges used in the final hop as True.

To fix this, I have added preserved_edge_mask that will mark the edges used in each hop as True.

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

Successfully merging this pull request may close these issues.

1 participant