Skip to content

Commit 9211d34

Browse files
authored
[BugFix] Fix khop_adj (#5754)
1 parent b0308c8 commit 9211d34

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

python/dgl/transforms/functional.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1152,21 +1152,22 @@ def khop_adj(g, k):
11521152
>>> import dgl
11531153
>>> g = dgl.graph(([0,1,2,3,4,0,1,2,3,4], [0,1,2,3,4,1,2,3,4,0]))
11541154
>>> dgl.khop_adj(g, 1)
1155-
tensor([[1., 0., 0., 0., 1.],
1156-
[1., 1., 0., 0., 0.],
1155+
tensor([[1., 1., 0., 0., 0.],
11571156
[0., 1., 1., 0., 0.],
11581157
[0., 0., 1., 1., 0.],
1159-
[0., 0., 0., 1., 1.]])
1158+
[0., 0., 0., 1., 1.],
1159+
[1., 0., 0., 0., 1.]])
11601160
>>> dgl.khop_adj(g, 3)
1161-
tensor([[1., 0., 1., 3., 3.],
1161+
tensor([[1., 3., 3., 1., 0.],
1162+
[0., 1., 3., 3., 1.],
1163+
[1., 0., 1., 3., 3.],
11621164
[3., 1., 0., 1., 3.],
1163-
[3., 3., 1., 0., 1.],
1164-
[1., 3., 3., 1., 0.],
1165-
[0., 1., 3., 3., 1.]])
1165+
[3., 3., 1., 0., 1.]])
11661166
"""
11671167
assert g.is_homogeneous, "only homogeneous graph is supported"
11681168
adj_k = (
1169-
g.adj_external(transpose=True, scipy_fmt=g.formats()["created"][0]) ** k
1169+
g.adj_external(transpose=False, scipy_fmt=g.formats()["created"][0])
1170+
** k
11701171
)
11711172
return F.tensor(adj_k.todense().astype(np.float32))
11721173

tests/python/common/transforms/test_transform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def _test(g):
649649
def test_khop_adj():
650650
N = 20
651651
feat = F.randn((N, 5))
652-
g = dgl.DGLGraph(nx.erdos_renyi_graph(N, 0.3))
652+
g = dgl.DGLGraph(nx.erdos_renyi_graph(N, 0.3, directed=True))
653653
for k in range(3):
654654
adj = F.tensor(F.swapaxes(dgl.khop_adj(g, k), 0, 1))
655655
# use original graph to do message passing for k times.

0 commit comments

Comments
 (0)