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
d533e9ba
Commit
d533e9ba
authored
May 17, 2019
by
zengxy
Committed by
Da Zheng
May 16, 2019
Browse files
[BugFix] Fix getting src and dst id of ALL edges in NodeFlow.apply_block (#515)
parent
d8c69d53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
9 deletions
+15
-9
python/dgl/nodeflow.py
python/dgl/nodeflow.py
+5
-7
tests/compute/test_nodeflow.py
tests/compute/test_nodeflow.py
+10
-2
No files found.
python/dgl/nodeflow.py
View file @
d533e9ba
...
@@ -723,8 +723,8 @@ class NodeFlow(DGLBaseGraph):
...
@@ -723,8 +723,8 @@ class NodeFlow(DGLBaseGraph):
block_id : int
block_id : int
The specified block to update edge embeddings.
The specified block to update edge embeddings.
func : callable or None, optional
func : callable or None, optional
Apply function on the
nod
es. The function should be
Apply function on the
edg
es. The function should be
a :mod:`
Nod
e UDF <dgl.udf>`.
a
n
:mod:`
Edg
e UDF <dgl.udf>`.
edges : a list of edge Ids or ALL.
edges : a list of edge Ids or ALL.
The edges to run the edge update function.
The edges to run the edge update function.
inplace : bool, optional
inplace : bool, optional
...
@@ -734,12 +734,10 @@ class NodeFlow(DGLBaseGraph):
...
@@ -734,12 +734,10 @@ class NodeFlow(DGLBaseGraph):
func
=
self
.
_apply_edge_funcs
[
block_id
]
func
=
self
.
_apply_edge_funcs
[
block_id
]
assert
func
is
not
None
assert
func
is
not
None
def
_layer_local_nid
(
layer_id
):
return
F
.
arange
(
0
,
self
.
layer_size
(
layer_id
))
if
is_all
(
edges
):
if
is_all
(
edges
):
u
=
utils
.
toindex
(
_layer_local_nid
(
block_id
))
u
,
v
,
_
=
self
.
block_edges
(
block_id
)
v
=
utils
.
toindex
(
_layer_local_nid
(
block_id
+
1
))
u
=
utils
.
toindex
(
u
)
v
=
utils
.
toindex
(
v
)
eid
=
utils
.
toindex
(
slice
(
0
,
self
.
block_size
(
block_id
)))
eid
=
utils
.
toindex
(
slice
(
0
,
self
.
block_size
(
block_id
)))
elif
isinstance
(
edges
,
tuple
):
elif
isinstance
(
edges
,
tuple
):
u
,
v
=
edges
u
,
v
=
edges
...
...
tests/compute/test_nodeflow.py
View file @
d533e9ba
...
@@ -115,14 +115,22 @@ def check_apply_edges(create_node_flow):
...
@@ -115,14 +115,22 @@ def check_apply_edges(create_node_flow):
num_layers
=
2
num_layers
=
2
for
i
in
range
(
num_layers
):
for
i
in
range
(
num_layers
):
g
=
generate_rand_graph
(
100
)
g
=
generate_rand_graph
(
100
)
g
.
ndata
[
"f"
]
=
F
.
randn
((
100
,
10
))
nf
=
create_node_flow
(
g
,
num_layers
)
nf
=
create_node_flow
(
g
,
num_layers
)
nf
.
copy_from_parent
()
nf
.
copy_from_parent
()
new_feats
=
F
.
randn
((
nf
.
block_size
(
i
),
5
))
new_feats
=
F
.
randn
((
nf
.
block_size
(
i
),
5
))
def
update_func
(
nodes
):
return
{
'h2'
:
new_feats
}
def
update_func
(
edges
):
return
{
'h2'
:
new_feats
,
"f2"
:
edges
.
src
[
"f"
]
+
edges
.
dst
[
"f"
]}
nf
.
apply_block
(
i
,
update_func
)
nf
.
apply_block
(
i
,
update_func
)
assert
F
.
array_equal
(
nf
.
blocks
[
i
].
data
[
'h2'
],
new_feats
)
assert
F
.
array_equal
(
nf
.
blocks
[
i
].
data
[
'h2'
],
new_feats
)
eids
=
nf
.
block_parent_eid
(
i
)
srcs
,
dsts
=
g
.
find_edges
(
eids
)
expected_f_sum
=
g
.
ndata
[
"f"
][
srcs
]
+
g
.
ndata
[
"f"
][
dsts
]
assert
F
.
array_equal
(
nf
.
blocks
[
i
].
data
[
'f2'
],
expected_f_sum
)
def
test_apply_edges
():
def
test_apply_edges
():
check_apply_edges
(
create_full_nodeflow
)
check_apply_edges
(
create_full_nodeflow
)
...
...
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