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

Add unbatch functionality #4628

Merged
merged 26 commits into from
May 16, 2022
Merged
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5d16319
Add unbatching tool
tzuhanchang May 12, 2022
62e606c
Add an unbatching tool
tzuhanchang May 12, 2022
24c412f
Add an unbatching tool
tzuhanchang May 12, 2022
0e9d10d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 12, 2022
044d16d
Merge branch 'master' into master
rusty1s May 14, 2022
09bb871
Add unbatch to utils
tzuhanchang May 15, 2022
06871c8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 15, 2022
084ecb9
Revert changes to loader/utils.py
tzuhanchang May 16, 2022
eb034a7
Update unbatch.py
tzuhanchang May 16, 2022
1ab59b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 16, 2022
b807908
Update unbatch.py
tzuhanchang May 16, 2022
00cad09
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 16, 2022
8fc94bb
Create test_unbatch.py
tzuhanchang May 16, 2022
ebe17d9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 16, 2022
7ace865
Add unbatch
tzuhanchang May 16, 2022
7da2807
Update test_unbatch.py
tzuhanchang May 16, 2022
ef66115
Update unbatch.py
tzuhanchang May 16, 2022
c1392d9
Update unbatch.py
tzuhanchang May 16, 2022
2a430a6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 16, 2022
74d3ccc
merge
rusty1s May 16, 2022
fd46637
Merge branch 'master' of github.com:tzuhanchang/pytorch_geometric
rusty1s May 16, 2022
a83f0b0
update
rusty1s May 16, 2022
ed634fc
changelog
rusty1s May 16, 2022
7365414
Merge branch 'master' into master
rusty1s May 16, 2022
d1331a0
typo
rusty1s May 16, 2022
3992f87
Merge branch 'master' of github.com:tzuhanchang/pytorch_geometric
rusty1s May 16, 2022
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
17 changes: 17 additions & 0 deletions torch_geometric/loader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
from typing import Dict, Optional, Tuple, Union

import pandas
import torch
from torch import Tensor
from torch_sparse import SparseTensor
Expand All @@ -24,6 +25,22 @@ def index_select(value: Tensor, index: Tensor, dim: int = 0) -> Tensor:
return torch.index_select(value, 0, index, out=out)


def unbatcher(src: torch.tensor, index: torch.tensor, dim: int = -1) -> list:
tzuhanchang marked this conversation as resolved.
Show resolved Hide resolved
scatter = pandas.DataFrame(
index, columns=['scatter']).reset_index().groupby('scatter').tail(1)
tzuhanchang marked this conversation as resolved.
Show resolved Hide resolved
indices = []
index_i = 0 # index starts for a graph
index_f = 0 # index ends for a graph
for i in range(0, len(scatter)):
tzuhanchang marked this conversation as resolved.
Show resolved Hide resolved
index_f = scatter['index'].iloc[i] + 1
indices.append(torch.tensor(range(index_i, index_f)))
index_i = index_f
unbatched = []
for i in range(0, len(indices)):
unbatched.append(torch.index_select(src, dim, indices[i]))
return unbatched


def edge_type_to_str(edge_type: Union[EdgeType, str]) -> str:
# Since C++ cannot take dictionaries with tuples as key as input, edge type
# triplets need to be converted into single strings.
Expand Down