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

[Code Coverage] PNAConv and DegreeScalerAggregation #6600

Merged
merged 9 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 3 additions & 2 deletions test/nn/aggr/test_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from torch_geometric.nn import DegreeScalerAggregation


def test_degree_scaler_aggregation():
@pytest.mark.parametrize("train_norm", [True, False])
rusty1s marked this conversation as resolved.
Show resolved Hide resolved
def test_degree_scaler_aggregation(train_norm):
x = torch.randn(6, 16)
index = torch.tensor([0, 0, 1, 1, 1, 2])
ptr = torch.tensor([0, 2, 5, 6])
Expand All @@ -14,7 +15,7 @@ def test_degree_scaler_aggregation():
scaler = [
'identity', 'amplification', 'attenuation', 'linear', 'inverse_linear'
]
aggr = DegreeScalerAggregation(aggr, scaler, deg)
aggr = DegreeScalerAggregation(aggr, scaler, deg, train_norm=train_norm)
assert str(aggr) == 'DegreeScalerAggregation()'

out = aggr(x, index)
Expand Down
12 changes: 7 additions & 5 deletions test/nn/conv/test_pna_conv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import torch
from torch_sparse import SparseTensor

Expand All @@ -12,16 +13,17 @@
]


def test_pna_conv():
@pytest.mark.parametrize("divide_input", [True, False])
rusty1s marked this conversation as resolved.
Show resolved Hide resolved
def test_pna_conv(divide_input):
x = torch.randn(4, 16)
edge_index = torch.tensor([[0, 0, 0, 1, 2, 3], [1, 2, 3, 0, 0, 0]])
deg = torch.tensor([0, 3, 0, 1])
row, col = edge_index
value = torch.rand(row.size(0), 3)
adj = SparseTensor(row=row, col=col, value=value, sparse_sizes=(4, 4))

conv = PNAConv(16, 32, aggregators, scalers,
deg=torch.tensor([0, 3, 0, 1]), edge_dim=3, towers=4)
assert conv.__repr__() == 'PNAConv(16, 32, towers=4, edge_dim=3)'
conv = PNAConv(16, 32, aggregators, scalers, deg=deg, edge_dim=3, towers=4,
pre_layers=2, post_layers=2, divide_input=divide_input)
assert str(conv) == 'PNAConv(16, 32, towers=4, edge_dim=3)'
out = conv(x, edge_index, value)
assert out.size() == (4, 32)
assert torch.allclose(conv(x, adj.t()), out, atol=1e-6)
Expand Down