Skip to content

Support empty graph and isolated nodes in to_dgl #9188

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

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed

- Fixed empty graph and isolated node handling in `to_dgl` ([#9188](https://github.com/pyg-team/pytorch_geometric/pull/9188))
- Fixed bug in `to_scipy_sparse_matrix` when cuda is set as default torch device ([#9146](https://github.com/pyg-team/pytorch_geometric/pull/9146))
- Fixed `MetaPath2Vec` in case the last node is isolated ([#9145](https://github.com/pyg-team/pytorch_geometric/pull/9145))
- Ensure backward compatibility in `MessagePassing` via `torch.load` ([#9105](https://github.com/pyg-team/pytorch_geometric/pull/9105))
Expand Down
8 changes: 6 additions & 2 deletions torch_geometric/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,14 @@ def to_dgl(
if isinstance(data, Data):
if data.edge_index is not None:
row, col = data.edge_index
else:
elif 'adj' in data:
row, col, _ = data.adj.coo()
elif 'adj_t' in data:
row, col, _ = data.adj_t.t().coo()
else:
row, col = [], []

g = dgl.graph((row, col))
g = dgl.graph((row, col), num_nodes=data.num_nodes)

for attr in data.node_attrs():
g.ndata[attr] = data[attr]
Expand Down