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
745078e7
Unverified
Commit
745078e7
authored
Aug 29, 2020
by
Quan (Andy) Gan
Committed by
GitHub
Aug 29, 2020
Browse files
new code block style (#2113)
Co-authored-by:
Jinjing Zhou
<
VoVAllen@users.noreply.github.com
>
parent
642bdbaf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
23 deletions
+29
-23
docs/source/conf.py
docs/source/conf.py
+5
-0
docs/source/guide/graph-feature.rst
docs/source/guide/graph-feature.rst
+24
-23
No files found.
docs/source/conf.py
View file @
745078e7
...
@@ -47,6 +47,7 @@ extensions = [
...
@@ -47,6 +47,7 @@ extensions = [
'sphinx.ext.intersphinx'
,
'sphinx.ext.intersphinx'
,
'sphinx.ext.graphviz'
,
'sphinx.ext.graphviz'
,
'sphinx_gallery.gen_gallery'
,
'sphinx_gallery.gen_gallery'
,
'sphinx_copybutton'
,
]
]
# Add any paths that contain templates here, relative to this directory.
# Add any paths that contain templates here, relative to this directory.
...
@@ -221,3 +222,7 @@ if dglbackend == 'mxnet':
...
@@ -221,3 +222,7 @@ if dglbackend == 'mxnet':
sphinx_gallery_conf
[
'filename_pattern'
]
=
"/*(?<=mx)\.py"
sphinx_gallery_conf
[
'filename_pattern'
]
=
"/*(?<=mx)\.py"
if
dglbackend
==
'pytorch'
:
if
dglbackend
==
'pytorch'
:
sphinx_gallery_conf
[
'filename_pattern'
]
=
"/*(?<!mx)\.py"
sphinx_gallery_conf
[
'filename_pattern'
]
=
"/*(?<!mx)\.py"
# sphinx-copybutton tool
copybutton_prompt_text
=
r
'>>> |\.\.\. '
copybutton_prompt_is_regexp
=
True
docs/source/guide/graph-feature.rst
View file @
745078e7
...
@@ -6,28 +6,29 @@
...
@@ -6,28 +6,29 @@
The nodes and edges of a :class:`~dgl.DGLGraph` can have several user-defined named features for
The nodes and edges of a :class:`~dgl.DGLGraph` can have several user-defined named features for
storing graph-specific properties of the nodes and edges. These features can be accessed
storing graph-specific properties of the nodes and edges. These features can be accessed
via the :py:attr:`~dgl.DGLGraph.ndata` and :py:attr:`~dgl.DGLGraph.edata` interface. For example, the following code creates two node
via the :py:attr:`~dgl.DGLGraph.ndata` and :py:attr:`~dgl.DGLGraph.edata` interface. For example, the following code creates two node
features (named ``'x'`` and ``'y'`` in lines
5
and
9
) and one edge feature (named ``'x'`` in line
6
).
features (named ``'x'`` and ``'y'`` in lines
8
and
15
) and one edge feature (named ``'x'`` in line
9
).
.. code::
.. code-block:: python
:linenos:
01.
>>> import dgl
>>> import dgl
02.
>>> import torch as th
>>> import torch as th
03.
>>> g = dgl.graph(([0, 0, 1, 5], [1, 2, 2, 0])) # 6 nodes, 4 edges
>>> g = dgl.graph(([0, 0, 1, 5], [1, 2, 2, 0])) # 6 nodes, 4 edges
04.
>>> g
>>> g
Graph(num_nodes=6, num_edges=4,
Graph(num_nodes=6, num_edges=4,
ndata_schemes={}
ndata_schemes={}
edata_schemes={})
edata_schemes={})
05.
>>> g.ndata['x'] = th.ones(g.num_nodes(), 3) # node feature of length 3
>>> g.ndata['x'] = th.ones(g.num_nodes(), 3) # node feature of length 3
06.
>>> g.edata['x'] = th.ones(g.num_edges(), dtype=th.int32) # scalar integer feature
>>> g.edata['x'] = th.ones(g.num_edges(), dtype=th.int32) # scalar integer feature
07.
>>> g
>>> g
Graph(num_nodes=6, num_edges=4,
Graph(num_nodes=6, num_edges=4,
ndata_schemes={'x' : Scheme(shape=(3,), dtype=torch.float32)}
ndata_schemes={'x' : Scheme(shape=(3,), dtype=torch.float32)}
edata_schemes={'x' : Scheme(shape=(,), dtype=torch.int32)})
edata_schemes={'x' : Scheme(shape=(,), dtype=torch.int32)})
08.
>>> # different names can have different shapes
>>> # different names can have different shapes
09.
>>> g.ndata['y'] = th.randn(g.num_nodes(), 5)
>>> g.ndata['y'] = th.randn(g.num_nodes(), 5)
10.
>>> g.ndata['x'][1] # get node 1's feature
>>> g.ndata['x'][1] # get node 1's feature
tensor([1., 1., 1.])
tensor([1., 1., 1.])
11.
>>> g.edata['x'][th.tensor([0, 3])] # get features of edge 0 and 3
>>> g.edata['x'][th.tensor([0, 3])] # get features of edge 0 and 3
tensor([1, 1], dtype=torch.int32)
tensor([1, 1], dtype=torch.int32)
Important facts about the :py:attr:`~dgl.DGLGraph.ndata`/:py:attr:`~dgl.DGLGraph.edata` interface:
Important facts about the :py:attr:`~dgl.DGLGraph.ndata`/:py:attr:`~dgl.DGLGraph.edata` interface:
...
@@ -46,7 +47,7 @@ Important facts about the :py:attr:`~dgl.DGLGraph.ndata`/:py:attr:`~dgl.DGLGraph
...
@@ -46,7 +47,7 @@ Important facts about the :py:attr:`~dgl.DGLGraph.ndata`/:py:attr:`~dgl.DGLGraph
For weighted graphs, one can store the weights as an edge feature as below.
For weighted graphs, one can store the weights as an edge feature as below.
.. code
::
.. code
-block:: python
>>> # edges 0->1, 0->2, 0->3, 1->3
>>> # edges 0->1, 0->2, 0->3, 1->3
>>> edges = th.tensor([0, 0, 0, 1]), th.tensor([1, 2, 3, 3])
>>> edges = th.tensor([0, 0, 0, 1]), th.tensor([1, 2, 3, 3])
...
...
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