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

Fix: num_nodes in FixedPoints transform #4394

Merged
merged 1 commit into from
Apr 1, 2022
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
19 changes: 13 additions & 6 deletions test/transforms/test_fixed_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,53 @@ def test_fixed_points():
x=torch.randn(100, 16),
y=torch.randn(1),
edge_attr=torch.randn(100, 3),
num_nodes=100,
)

out = FixedPoints(50, replace=True)(copy(data))
assert len(out) == 4
assert len(out) == 5
assert out.pos.size() == (50, 3)
assert out.x.size() == (50, 16)
assert out.y.size() == (1, )
assert out.edge_attr.size() == (100, 3)
assert out.num_nodes == 50

out = FixedPoints(200, replace=True)(copy(data))
assert len(out) == 4
assert len(out) == 5
assert out.pos.size() == (200, 3)
assert out.x.size() == (200, 16)
assert out.y.size() == (1, )
assert out.edge_attr.size() == (100, 3)
assert out.num_nodes == 200

out = FixedPoints(50, replace=False, allow_duplicates=False)(copy(data))
assert len(out) == 4
assert len(out) == 5
assert out.pos.size() == (50, 3)
assert out.x.size() == (50, 16)
assert out.y.size() == (1, )
assert out.edge_attr.size() == (100, 3)
assert out.num_nodes == 50

out = FixedPoints(200, replace=False, allow_duplicates=False)(copy(data))
assert len(out) == 4
assert len(out) == 5
assert out.pos.size() == (100, 3)
assert out.x.size() == (100, 16)
assert out.y.size() == (1, )
assert out.edge_attr.size() == (100, 3)
assert out.num_nodes == 100

out = FixedPoints(50, replace=False, allow_duplicates=True)(copy(data))
assert len(out) == 4
assert len(out) == 5
assert out.pos.size() == (50, 3)
assert out.x.size() == (50, 16)
assert out.y.size() == (1, )
assert out.edge_attr.size() == (100, 3)
assert out.num_nodes == 50

out = FixedPoints(200, replace=False, allow_duplicates=True)(copy(data))
assert len(out) == 4
assert len(out) == 5
assert out.pos.size() == (200, 3)
assert out.x.size() == (200, 16)
assert out.y.size() == (1, )
assert out.edge_attr.size() == (100, 3)
assert out.num_nodes == 200
8 changes: 5 additions & 3 deletions torch_geometric/transforms/fixed_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ def __call__(self, data):
], dim=0)[:self.num]

for key, item in data:
if bool(re.search('edge', key)):
if key == 'num_nodes':
data.num_nodes = choice.size(0)
elif bool(re.search('edge', key)):
continue
if (torch.is_tensor(item) and item.size(0) == num_nodes
and item.size(0) != 1):
elif (torch.is_tensor(item) and item.size(0) == num_nodes
and item.size(0) != 1):
data[key] = item[choice]

return data
Expand Down