Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
9211d34f
Unverified
Commit
9211d34f
authored
Jun 07, 2023
by
rudongyu
Committed by
GitHub
Jun 07, 2023
Browse files
[BugFix] Fix khop_adj (#5754)
parent
b0308c85
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
python/dgl/transforms/functional.py
python/dgl/transforms/functional.py
+9
-8
tests/python/common/transforms/test_transform.py
tests/python/common/transforms/test_transform.py
+1
-1
No files found.
python/dgl/transforms/functional.py
View file @
9211d34f
...
@@ -1152,21 +1152,22 @@ def khop_adj(g, k):
...
@@ -1152,21 +1152,22 @@ def khop_adj(g, k):
>>> import dgl
>>> import dgl
>>> g = dgl.graph(([0,1,2,3,4,0,1,2,3,4], [0,1,2,3,4,1,2,3,4,0]))
>>> g = dgl.graph(([0,1,2,3,4,0,1,2,3,4], [0,1,2,3,4,1,2,3,4,0]))
>>> dgl.khop_adj(g, 1)
>>> dgl.khop_adj(g, 1)
tensor([[1., 0., 0., 0., 1.],
tensor([[1., 1., 0., 0., 0.],
[1., 1., 0., 0., 0.],
[0., 1., 1., 0., 0.],
[0., 1., 1., 0., 0.],
[0., 0., 1., 1., 0.],
[0., 0., 1., 1., 0.],
[0., 0., 0., 1., 1.]])
[0., 0., 0., 1., 1.],
[1., 0., 0., 0., 1.]])
>>> dgl.khop_adj(g, 3)
>>> dgl.khop_adj(g, 3)
tensor([[1., 0., 1., 3., 3.],
tensor([[1., 3., 3., 1., 0.],
[0., 1., 3., 3., 1.],
[1., 0., 1., 3., 3.],
[3., 1., 0., 1., 3.],
[3., 1., 0., 1., 3.],
[3., 3., 1., 0., 1.],
[3., 3., 1., 0., 1.]])
[1., 3., 3., 1., 0.],
[0., 1., 3., 3., 1.]])
"""
"""
assert
g
.
is_homogeneous
,
"only homogeneous graph is supported"
assert
g
.
is_homogeneous
,
"only homogeneous graph is supported"
adj_k
=
(
adj_k
=
(
g
.
adj_external
(
transpose
=
True
,
scipy_fmt
=
g
.
formats
()[
"created"
][
0
])
**
k
g
.
adj_external
(
transpose
=
False
,
scipy_fmt
=
g
.
formats
()[
"created"
][
0
])
**
k
)
)
return
F
.
tensor
(
adj_k
.
todense
().
astype
(
np
.
float32
))
return
F
.
tensor
(
adj_k
.
todense
().
astype
(
np
.
float32
))
...
...
tests/python/common/transforms/test_transform.py
View file @
9211d34f
...
@@ -649,7 +649,7 @@ def test_khop_graph():
...
@@ -649,7 +649,7 @@ def test_khop_graph():
def
test_khop_adj
():
def
test_khop_adj
():
N
=
20
N
=
20
feat
=
F
.
randn
((
N
,
5
))
feat
=
F
.
randn
((
N
,
5
))
g
=
dgl
.
DGLGraph
(
nx
.
erdos_renyi_graph
(
N
,
0.3
))
g
=
dgl
.
DGLGraph
(
nx
.
erdos_renyi_graph
(
N
,
0.3
,
directed
=
True
))
for
k
in
range
(
3
):
for
k
in
range
(
3
):
adj
=
F
.
tensor
(
F
.
swapaxes
(
dgl
.
khop_adj
(
g
,
k
),
0
,
1
))
adj
=
F
.
tensor
(
F
.
swapaxes
(
dgl
.
khop_adj
(
g
,
k
),
0
,
1
))
# use original graph to do message passing for k times.
# use original graph to do message passing for k times.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment