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
d6a9265d
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "09e1b0b46f75d340deb0b48eb90fe642b3178243"
Commit
d6a9265d
authored
Jun 11, 2019
by
Zihao Ye
Committed by
Minjie Wang
Jun 10, 2019
Browse files
[Doc] docstring for node/edge removal APIs (#639)
parent
fb9dcc51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
1 deletion
+80
-1
python/dgl/graph.py
python/dgl/graph.py
+80
-1
No files found.
python/dgl/graph.py
View file @
d6a9265d
...
...
@@ -1114,12 +1114,53 @@ class DGLGraph(DGLBaseGraph):
self
.
_msg_frame
.
add_rows
(
num
)
def
remove_nodes
(
self
,
vids
):
"""Remove multiple nodes.
"""Remove multiple nodes
, edges that have connection with these nodes would also be removed
.
Parameters
----------
vids: list, tensor
The id of nodes to remove.
Notes
-----
The nodes and edges in the graph would be re-indexed after the removal.
Examples
--------
The following example uses PyTorch backend.
>>> import torch as th
>>> G = dgl.DGLGraph()
>>> G.add_nodes(5, {'x': th.arange(5) * 2})
>>> G.add_edges([0, 1, 2, 3, 4], [1, 2, 3, 4, 0], {'x': th.arange(15).view(5, 3)})
>>> G.nodes()
tensor([0, 1, 2, 3, 4])
>>> G.edges()
(tensor([0, 1, 2, 3, 4]), tensor([1, 2, 3, 4, 0]))
>>> G.ndata['x']
tensor([0, 2, 4, 6, 8])
>>> G.edata['x']
tensor([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11],
[12, 13, 14]])
>>> G.remove_nodes([2, 3])
>>> G.nodes()
tensor([0, 1, 2]
>>> G.edges()
(tensor([0, 2]), tensor([1, 0]))
>>> G.ndata['x']
tensor([0, 2, 8])
>>> G.edata['x']
tensor([[ 0, 1, 2],
[12, 13, 14]])
See Also
--------
add_nodes
add_edges
remove_edges
"""
if
self
.
is_readonly
:
raise
DGLError
(
"remove_nodes is not supported by read-only graph."
)
...
...
@@ -1145,6 +1186,44 @@ class DGLGraph(DGLBaseGraph):
----------
eids: list, tensor
The id of edges to remove.
Notes
-----
The nodes and edges in the graph would be re-indexed after the removal.
Examples
--------
The following example uses PyTorch backend.
>>> import torch as th
>>> G = dgl.DGLGraph()
>>> G.add_nodes(5)
>>> G.add_edges([0, 1, 2, 3, 4], [1, 2, 3, 4, 0], {'x': th.arange(15).view(5, 3)})
>>> G.nodes()
tensor([0, 1, 2, 3, 4])
>>> G.edges()
(tensor([0, 1, 2, 3, 4]), tensor([1, 2, 3, 4, 0]))
>>> G.edata['x']
tensor([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11],
[12, 13, 14]])
>>> G.remove_edges([1, 2])
>>> G.nodes()
tensor([0, 1, 2, 3, 4])
>>> G.edges()
(tensor([0, 3, 4]), tensor([1, 4, 0]))
>>> G.edata['x']
tensor([[ 0, 1, 2],
[ 9, 10, 11],
[12, 13, 14]])
See Also
--------
add_nodes
add_edges
remove_nodes
"""
if
self
.
is_readonly
:
raise
DGLError
(
"remove_edges is not supported by read-only graph."
)
...
...
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