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
e2926544
Commit
e2926544
authored
Dec 16, 2018
by
Haibin Lin
Committed by
Minjie Wang
Dec 16, 2018
Browse files
[Graph] Better string repr (#311)
parent
30107407
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
0 deletions
+29
-0
python/dgl/graph.py
python/dgl/graph.py
+6
-0
tests/mxnet/test_basics.py
tests/mxnet/test_basics.py
+11
-0
tests/pytorch/test_basics.py
tests/pytorch/test_basics.py
+12
-0
No files found.
python/dgl/graph.py
View file @
e2926544
...
@@ -2907,3 +2907,9 @@ class DGLGraph(object):
...
@@ -2907,3 +2907,9 @@ class DGLGraph(object):
else
:
else
:
edges
=
F
.
tensor
(
edges
)
edges
=
F
.
tensor
(
edges
)
return
edges
[
e_mask
]
return
edges
[
e_mask
]
def
__repr__
(
self
):
s
=
'DGLGraph with {node} nodes and {edge} edges.
\n
Node data: {ndata}
\n
Edge data: {edata}'
return
s
.
format
(
node
=
self
.
number_of_nodes
(),
edge
=
self
.
number_of_edges
(),
ndata
=
str
(
self
.
node_attr_schemes
()),
edata
=
str
(
self
.
edge_attr_schemes
()))
tests/mxnet/test_basics.py
View file @
e2926544
...
@@ -439,6 +439,16 @@ def test_pull_0deg():
...
@@ -439,6 +439,16 @@ def test_pull_0deg():
check_pull_0deg
(
True
)
check_pull_0deg
(
True
)
check_pull_0deg
(
False
)
check_pull_0deg
(
False
)
def
test_repr
():
G
=
dgl
.
DGLGraph
()
G
.
add_nodes
(
10
)
G
.
add_edge
(
0
,
1
)
repr_string
=
G
.
__repr__
()
G
.
ndata
[
'x'
]
=
mx
.
nd
.
zeros
((
10
,
5
))
G
.
add_edges
([
0
,
1
],
2
)
G
.
edata
[
'y'
]
=
mx
.
nd
.
zeros
((
3
,
4
))
repr_string
=
G
.
__repr__
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_batch_setter_getter
()
test_batch_setter_getter
()
test_batch_setter_autograd
()
test_batch_setter_autograd
()
...
@@ -451,3 +461,4 @@ if __name__ == '__main__':
...
@@ -451,3 +461,4 @@ if __name__ == '__main__':
test_recv_0deg_newfld
()
test_recv_0deg_newfld
()
test_update_all_0deg
()
test_update_all_0deg
()
test_pull_0deg
()
test_pull_0deg
()
test_repr
()
tests/pytorch/test_basics.py
View file @
e2926544
...
@@ -615,6 +615,17 @@ def test_dynamic_addition():
...
@@ -615,6 +615,17 @@ def test_dynamic_addition():
assert
g
.
edata
[
'h1'
].
shape
[
0
]
==
g
.
edata
[
'h2'
].
shape
[
0
]
==
5
assert
g
.
edata
[
'h1'
].
shape
[
0
]
==
g
.
edata
[
'h2'
].
shape
[
0
]
==
5
def
test_repr
():
G
=
dgl
.
DGLGraph
()
G
.
add_nodes
(
10
)
G
.
add_edge
(
0
,
1
)
repr_string
=
G
.
__repr__
()
G
.
ndata
[
'x'
]
=
th
.
zeros
((
10
,
5
))
G
.
add_edges
([
0
,
1
],
2
)
G
.
edata
[
'y'
]
=
th
.
zeros
((
3
,
4
))
repr_string
=
G
.
__repr__
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_nx_conversion
()
test_nx_conversion
()
test_batch_setter_getter
()
test_batch_setter_getter
()
...
@@ -630,3 +641,4 @@ if __name__ == '__main__':
...
@@ -630,3 +641,4 @@ if __name__ == '__main__':
test_pull_0deg
()
test_pull_0deg
()
test_send_multigraph
()
test_send_multigraph
()
test_dynamic_addition
()
test_dynamic_addition
()
test_repr
()
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