Skip to content

Commit

Permalink
Merge branch 'master' into dataset_reload
Browse files Browse the repository at this point in the history
  • Loading branch information
EdisonLeeeee authored Nov 9, 2023
2 parents 1f44910 + 402891b commit 0ee833f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/latest_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Install main package
if: steps.changed-files-specific.outputs.only_changed != 'true'
run: |
pip install -e .[full,test]
pip install -e .[test]
- name: Run tests
if: steps.changed-files-specific.outputs.only_changed != 'true'
Expand Down
3 changes: 2 additions & 1 deletion test/nn/conv/test_ppf_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def test_ppf_conv():

if torch_geometric.typing.WITH_TORCH_SPARSE:
adj2 = SparseTensor.from_edge_index(edge_index, sparse_sizes=(4, 2))
assert torch.allclose(conv(x1, (pos1, pos2), (n1, n2), adj2.t()), out)
assert torch.allclose(conv(x1, (pos1, pos2), (n1, n2), adj2.t()), out,
atol=1e-3)
assert torch.allclose(
conv((x1, None), (pos1, pos2), (n1, n2), adj2.t()), out, atol=1e-3)

Expand Down
113 changes: 62 additions & 51 deletions test/transforms/test_gdc.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,101 @@
import torch

from torch_geometric.data import Data
from torch_geometric.datasets import KarateClub
from torch_geometric.testing import withPackage
from torch_geometric.transforms import GDC
from torch_geometric.utils import to_dense_adj


@withPackage('numba')
def test_gdc():
edge_index = torch.tensor([[0, 0, 1, 1, 2, 2, 2, 3, 3, 4],
[1, 2, 0, 2, 0, 1, 3, 2, 4, 3]])
data = KarateClub()[0]

data = Data(edge_index=edge_index, num_nodes=5)
gdc = GDC(self_loop_weight=1, normalization_in='sym',
normalization_out='sym',
diffusion_kwargs=dict(method='ppr', alpha=0.15),
sparsification_kwargs=dict(method='threshold',
avg_degree=2), exact=True)
data = gdc(data)
mat = to_dense_adj(data.edge_index, edge_attr=data.edge_attr).squeeze()
gdc = GDC(
self_loop_weight=1,
normalization_in='sym',
normalization_out='sym',
diffusion_kwargs=dict(method='ppr', alpha=0.15),
sparsification_kwargs=dict(method='threshold', avg_degree=2),
exact=True,
)
out = gdc(data)
mat = to_dense_adj(out.edge_index, edge_attr=out.edge_attr).squeeze()
assert torch.all(mat >= -1e-8)
assert torch.allclose(mat, mat.t(), atol=1e-4)

data = Data(edge_index=edge_index, num_nodes=5)
gdc = GDC(self_loop_weight=1, normalization_in='sym',
normalization_out='sym',
diffusion_kwargs=dict(method='heat', t=10),
sparsification_kwargs=dict(method='threshold',
avg_degree=2), exact=True)
data = gdc(data)
mat = to_dense_adj(data.edge_index, edge_attr=data.edge_attr).squeeze()
gdc = GDC(
self_loop_weight=1,
normalization_in='sym',
normalization_out='sym',
diffusion_kwargs=dict(method='heat', t=10),
sparsification_kwargs=dict(method='threshold', avg_degree=2),
exact=True,
)
out = gdc(data)
mat = to_dense_adj(out.edge_index, edge_attr=out.edge_attr).squeeze()
assert torch.all(mat >= -1e-8)
assert torch.allclose(mat, mat.t(), atol=1e-4)

data = Data(edge_index=edge_index, num_nodes=5)
gdc = GDC(self_loop_weight=1, normalization_in='col',
normalization_out='col',
diffusion_kwargs=dict(method='heat', t=10),
sparsification_kwargs=dict(method='topk', k=2,
dim=0), exact=True)
data = gdc(data)
mat = to_dense_adj(data.edge_index, edge_attr=data.edge_attr).squeeze()
gdc = GDC(
self_loop_weight=1,
normalization_in='col',
normalization_out='col',
diffusion_kwargs=dict(method='heat', t=10),
sparsification_kwargs=dict(method='topk', k=2, dim=0),
exact=True,
)
out = gdc(data)
mat = to_dense_adj(out.edge_index, edge_attr=out.edge_attr).squeeze()
col_sum = mat.sum(0)
assert torch.all(mat >= -1e-8)
assert torch.all(
torch.isclose(col_sum, torch.tensor(1.0))
| torch.isclose(col_sum, torch.tensor(0.0)))
assert torch.all((~torch.isclose(mat, torch.tensor(0.0))).sum(0) == 2)

data = Data(edge_index=edge_index, num_nodes=5)
gdc = GDC(self_loop_weight=1, normalization_in='row',
normalization_out='row',
diffusion_kwargs=dict(method='heat', t=5),
sparsification_kwargs=dict(method='topk', k=2,
dim=1), exact=True)
data = gdc(data)
mat = to_dense_adj(data.edge_index, edge_attr=data.edge_attr).squeeze()
gdc = GDC(
self_loop_weight=1,
normalization_in='row',
normalization_out='row',
diffusion_kwargs=dict(method='heat', t=5),
sparsification_kwargs=dict(method='topk', k=2, dim=1),
exact=True,
)
out = gdc(data)
mat = to_dense_adj(out.edge_index, edge_attr=out.edge_attr).squeeze()
row_sum = mat.sum(1)
assert torch.all(mat >= -1e-8)
assert torch.all(
torch.isclose(row_sum, torch.tensor(1.0))
| torch.isclose(row_sum, torch.tensor(0.0)))
assert torch.all((~torch.isclose(mat, torch.tensor(0.0))).sum(1) == 2)

data = Data(edge_index=edge_index, num_nodes=5)
gdc = GDC(self_loop_weight=1, normalization_in='row',
normalization_out='row',
diffusion_kwargs=dict(method='coeff', coeffs=[0.8, 0.3, 0.1]),
sparsification_kwargs=dict(method='threshold',
eps=0.1), exact=True)
data = gdc(data)
mat = to_dense_adj(data.edge_index, edge_attr=data.edge_attr).squeeze()
gdc = GDC(
self_loop_weight=1,
normalization_in='row',
normalization_out='row',
diffusion_kwargs=dict(method='coeff', coeffs=[0.8, 0.3, 0.1]),
sparsification_kwargs=dict(method='threshold', eps=0.1),
exact=True,
)
out = gdc(data)
mat = to_dense_adj(out.edge_index, edge_attr=out.edge_attr).squeeze()
row_sum = mat.sum(1)
assert torch.all(mat >= -1e-8)
assert torch.all(
torch.isclose(row_sum, torch.tensor(1.0))
| torch.isclose(row_sum, torch.tensor(0.0)))

data = Data(edge_index=edge_index, num_nodes=5)
gdc = GDC(self_loop_weight=1, normalization_in='sym',
normalization_out='col',
diffusion_kwargs=dict(method='ppr', alpha=0.15, eps=1e-4),
sparsification_kwargs=dict(method='threshold',
avg_degree=2), exact=False)
data = gdc(data)
mat = to_dense_adj(data.edge_index, edge_attr=data.edge_attr).squeeze()
gdc = GDC(
self_loop_weight=1,
normalization_in='sym',
normalization_out='col',
diffusion_kwargs=dict(method='ppr', alpha=0.15, eps=1e-4),
sparsification_kwargs=dict(method='threshold', avg_degree=2),
exact=False,
)
out = gdc(data)
mat = to_dense_adj(out.edge_index, edge_attr=out.edge_attr).squeeze()
col_sum = mat.sum(0)
assert torch.all(mat >= -1e-8)
assert torch.all(
Expand Down

0 comments on commit 0ee833f

Please sign in to comment.