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
70dc7cd1
Commit
70dc7cd1
authored
Nov 30, 2018
by
Haibin Lin
Committed by
Minjie Wang
Nov 30, 2018
Browse files
[Doc] Dgl glance tutorial improvement (#197)
* update dgl at a glance * update title * Update 1_first.py
parent
bcf8e119
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
9 deletions
+16
-9
tutorials/1_first.py
tutorials/1_first.py
+16
-9
No files found.
tutorials/1_first.py
View file @
70dc7cd1
"""
.. currentmodule:: dgl
DGL at a
g
lance
DGL at a
G
lance
=========================
**Author**: `Minjie Wang <https://jermainewang.github.io/>`_, Quan Gan, `Jake
...
...
@@ -112,33 +112,40 @@ plt.show()
def
super_useful_comp
(
g
):
def
send_source
(
edges
):
# 1. pass the source node feature 'x' weighted by edge feature 'w'
return
{
'msg'
:
edges
.
src
[
'x'
]
*
edges
.
data
[
'w'
]}
def
simple_reduce
(
nodes
):
# 2. perform reduction on received messages and update feature 'x'
msgs
=
nodes
.
mailbox
[
'msg'
]
return
{
'x'
:
msgs
.
sum
(
1
)
+
nodes
.
data
[
'x'
]}
def
readout
(
g
):
return
th
.
sum
(
g
.
ndata
[
'x'
],
dim
=
0
)
g
.
register_message_func
(
send_source
)
g
.
register_reduce_func
(
simple_reduce
)
g
.
send
(
g
.
edges
())
g
.
recv
(
g
.
nodes
())
return
readout
(
g
)
def
readout
(
g
):
# 3. read the aggregated node feature 'x' on graph
return
th
.
sum
(
g
.
ndata
[
'x'
],
dim
=
0
)
###############################################################################
# See the python wrapper:
g_boring
=
a_boring_graph
()
graph_sum
=
super_useful_comp
(
g_boring
)
print
(
"graph sum is: "
,
graph_sum
)
graph_sum
=
readout
(
g_boring
)
print
(
"graph sum before send() and recv() is: "
,
graph_sum
)
super_useful_comp
(
g_boring
)
graph_sum
=
readout
(
g_boring
)
print
(
"graph sum after send() and recv() is: "
,
graph_sum
)
g_better
=
an_interesting_graph
()
graph_sum
=
super_useful_comp
(
g_better
)
print
(
"graph sum is: "
,
graph_sum
)
graph_sum
=
readout
(
g_better
)
print
(
"graph sum before send() and recv() is: "
,
graph_sum
)
super_useful_comp
(
g_better
)
graph_sum
=
readout
(
g_better
)
print
(
"graph sum after send() and recv() is: "
,
graph_sum
)
###############################################################################
# Next steps
...
...
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