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
cf829dc3
Unverified
Commit
cf829dc3
authored
Aug 09, 2023
by
Andrei Ivanov
Committed by
GitHub
Aug 10, 2023
Browse files
Fixing some unittest warnings. (#6122)
Co-authored-by:
Hongzhi (Steve), Chen
<
chenhongzhi.nkcs@gmail.com
>
parent
77c84834
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
16 deletions
+15
-16
python/dgl/backend/pytorch/tensor.py
python/dgl/backend/pytorch/tensor.py
+1
-0
python/dgl/convert.py
python/dgl/convert.py
+10
-12
tests/python/common/test_propagate.py
tests/python/common/test_propagate.py
+1
-1
tests/python/common/test_subgraph.py
tests/python/common/test_subgraph.py
+2
-2
tests/python/common/test_traversal.py
tests/python/common/test_traversal.py
+1
-1
No files found.
python/dgl/backend/pytorch/tensor.py
View file @
cf829dc3
...
@@ -509,6 +509,7 @@ def backward(x, head_gradient=None):
...
@@ -509,6 +509,7 @@ def backward(x, head_gradient=None):
def
grad
(
x
):
def
grad
(
x
):
x
.
retain_grad
()
return
x
.
grad
return
x
.
grad
...
...
python/dgl/convert.py
View file @
cf829dc3
...
@@ -1231,6 +1231,16 @@ def bipartite_from_scipy(
...
@@ -1231,6 +1231,16 @@ def bipartite_from_scipy(
return
g
.
to
(
device
)
return
g
.
to
(
device
)
def
_batcher
(
lst
):
if
F
.
is_tensor
(
lst
[
0
]):
return
F
.
cat
([
F
.
unsqueeze
(
x
,
0
)
for
x
in
lst
],
dim
=
0
)
if
isinstance
(
lst
[
0
],
np
.
ndarray
):
return
F
.
tensor
(
np
.
array
(
lst
))
return
F
.
tensor
(
lst
)
def
from_networkx
(
def
from_networkx
(
nx_graph
,
nx_graph
,
node_attrs
=
None
,
node_attrs
=
None
,
...
@@ -1367,12 +1377,6 @@ def from_networkx(
...
@@ -1367,12 +1377,6 @@ def from_networkx(
# handle features
# handle features
# copy attributes
# copy attributes
def
_batcher
(
lst
):
if
F
.
is_tensor
(
lst
[
0
]):
return
F
.
cat
([
F
.
unsqueeze
(
x
,
0
)
for
x
in
lst
],
dim
=
0
)
else
:
return
F
.
tensor
(
lst
)
if
node_attrs
is
not
None
:
if
node_attrs
is
not
None
:
# mapping from feature name to a list of tensors to be concatenated
# mapping from feature name to a list of tensors to be concatenated
attr_dict
=
defaultdict
(
list
)
attr_dict
=
defaultdict
(
list
)
...
@@ -1592,12 +1596,6 @@ def bipartite_from_networkx(
...
@@ -1592,12 +1596,6 @@ def bipartite_from_networkx(
# handle features
# handle features
# copy attributes
# copy attributes
def
_batcher
(
lst
):
if
F
.
is_tensor
(
lst
[
0
]):
return
F
.
cat
([
F
.
unsqueeze
(
x
,
0
)
for
x
in
lst
],
dim
=
0
)
else
:
return
F
.
tensor
(
lst
)
if
u_attrs
is
not
None
:
if
u_attrs
is
not
None
:
# mapping from feature name to a list of tensors to be concatenated
# mapping from feature name to a list of tensors to be concatenated
src_attr_dict
=
defaultdict
(
list
)
src_attr_dict
=
defaultdict
(
list
)
...
...
tests/python/common/test_propagate.py
View file @
cf829dc3
...
@@ -89,7 +89,7 @@ def test_prop_nodes_topo(idtype):
...
@@ -89,7 +89,7 @@ def test_prop_nodes_topo(idtype):
assert
check_fail
(
dgl
.
prop_nodes_topo
,
g
)
# has loop
assert
check_fail
(
dgl
.
prop_nodes_topo
,
g
)
# has loop
# tree
# tree
tree
=
dgl
.
DGLG
raph
()
tree
=
dgl
.
g
raph
(
[]
)
tree
.
add_nodes
(
5
)
tree
.
add_nodes
(
5
)
tree
.
add_edges
(
1
,
0
)
tree
.
add_edges
(
1
,
0
)
tree
.
add_edges
(
2
,
0
)
tree
.
add_edges
(
2
,
0
)
...
...
tests/python/common/test_subgraph.py
View file @
cf829dc3
...
@@ -13,7 +13,7 @@ D = 5
...
@@ -13,7 +13,7 @@ D = 5
def
generate_graph
(
grad
=
False
,
add_data
=
True
):
def
generate_graph
(
grad
=
False
,
add_data
=
True
):
g
=
dgl
.
DGLG
raph
().
to
(
F
.
ctx
())
g
=
dgl
.
g
raph
(
[]
).
to
(
F
.
ctx
())
g
.
add_nodes
(
10
)
g
.
add_nodes
(
10
)
# create a graph where 0 is the source and 9 is the sink
# create a graph where 0 is the source and 9 is the sink
for
i
in
range
(
1
,
9
):
for
i
in
range
(
1
,
9
):
...
@@ -111,7 +111,7 @@ def test_subgraph_relabel_nodes(relabel_nodes):
...
@@ -111,7 +111,7 @@ def test_subgraph_relabel_nodes(relabel_nodes):
def
_test_map_to_subgraph
():
def
_test_map_to_subgraph
():
g
=
dgl
.
DGLG
raph
()
g
=
dgl
.
g
raph
(
[]
)
g
.
add_nodes
(
10
)
g
.
add_nodes
(
10
)
g
.
add_edges
(
F
.
arange
(
0
,
9
),
F
.
arange
(
1
,
10
))
g
.
add_edges
(
F
.
arange
(
0
,
9
),
F
.
arange
(
1
,
10
))
h
=
g
.
subgraph
([
0
,
1
,
2
,
5
,
8
])
h
=
g
.
subgraph
([
0
,
1
,
2
,
5
,
8
])
...
...
tests/python/common/test_traversal.py
View file @
cf829dc3
...
@@ -95,7 +95,7 @@ DFS_LABEL_NAMES = ["forward", "reverse", "nontree"]
...
@@ -95,7 +95,7 @@ DFS_LABEL_NAMES = ["forward", "reverse", "nontree"]
@
parametrize_idtype
@
parametrize_idtype
def
test_dfs_labeled_edges
(
idtype
,
example
=
False
):
def
test_dfs_labeled_edges
(
idtype
,
example
=
False
):
dgl_g
=
dgl
.
DGLG
raph
().
astype
(
idtype
)
dgl_g
=
dgl
.
g
raph
(
[]
).
astype
(
idtype
)
dgl_g
.
add_nodes
(
6
)
dgl_g
.
add_nodes
(
6
)
dgl_g
.
add_edges
([
0
,
1
,
0
,
3
,
3
],
[
1
,
2
,
2
,
4
,
5
])
dgl_g
.
add_edges
([
0
,
1
,
0
,
3
,
3
],
[
1
,
2
,
2
,
4
,
5
])
dgl_edges
,
dgl_labels
=
dgl
.
dfs_labeled_edges_generator
(
dgl_edges
,
dgl_labels
=
dgl
.
dfs_labeled_edges_generator
(
...
...
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