Unverified Commit fbfcf1a8 authored by Armin Stepanjan's avatar Armin Stepanjan Committed by GitHub
Browse files

Doc: adapt send_and_recv example (#2822)



* adapt send_and_recv example

* lint fix

* Change title and example order

* Update heterograph.py
Co-authored-by: default avatarQuan (Andy) Gan <coin2028@hotmail.com>
parent 5498cf05
...@@ -4400,6 +4400,29 @@ class DGLHeteroGraph(object): ...@@ -4400,6 +4400,29 @@ class DGLHeteroGraph(object):
tensor([[0.], tensor([[0.],
[0.], [0.],
[1.]]) [1.]])
**``send_and_recv`` using user-defined functions**
>>> import torch as th
>>> g = dgl.graph(([0, 1], [1, 2]))
>>> g.ndata['x'] = th.tensor([[1.], [2.], [3.]])
>>> # Define the function for sending node features as messages.
>>> def send_source(edges):
... return {'m': edges.src['x']}
>>> # Sum the messages received and use this to replace the original node feature.
>>> def simple_reduce(nodes):
... return {'x': nodes.mailbox['m'].sum(1)}
Send and receive messages.
>>> g.send_and_recv(g.edges())
>>> g.ndata['x']
tensor([[1.],
[1.],
[2.]])
Note that the feature of node 0 remains the same as it has no incoming edges.
""" """
if inplace: if inplace:
raise DGLError('The `inplace` option is removed in v0.5.') raise DGLError('The `inplace` option is removed in v0.5.')
......
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