"...git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "0d68ddf3275b20b0d12cfd3d0a9f002fecfe001c"
Unverified Commit dd768a57 authored by galogm's avatar galogm Committed by GitHub
Browse files

[Bugfix] `dgl.linkx_homophily` calculation fails when all class homophily=0 (#5720)


Co-authored-by: default avatarMufei Li <mufeili1996@gmail.com>
parent af8451c2
...@@ -177,7 +177,7 @@ def linkx_homophily(graph, y): ...@@ -177,7 +177,7 @@ def linkx_homophily(graph, y):
num_nodes = graph.num_nodes() num_nodes = graph.num_nodes()
num_classes = y.max(dim=0).values.item() + 1 num_classes = y.max(dim=0).values.item() + 1
value = 0 value = torch.tensor(0.0).to(graph.device)
for k in range(num_classes): for k in range(num_classes):
# Get the nodes that belong to class k. # Get the nodes that belong to class k.
class_mask = y == k class_mask = y == k
......
...@@ -48,3 +48,6 @@ def test_linkx_homophily(idtype): ...@@ -48,3 +48,6 @@ def test_linkx_homophily(idtype):
graph = dgl.graph(([0, 1, 2, 3], [1, 2, 0, 4]), device=device) graph = dgl.graph(([0, 1, 2, 3], [1, 2, 0, 4]), device=device)
y = F.tensor([0, 0, 0, 0, 1]) y = F.tensor([0, 0, 0, 0, 1])
assert math.isclose(dgl.linkx_homophily(graph, y), 0.19999998807907104) assert math.isclose(dgl.linkx_homophily(graph, y), 0.19999998807907104)
y = F.tensor([0, 1, 2, 3, 4])
assert math.isclose(dgl.linkx_homophily(graph, y), 0.0000000000000000)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment