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
17141dd3
Unverified
Commit
17141dd3
authored
Jun 14, 2021
by
Jinjing Zhou
Committed by
GitHub
Jun 14, 2021
Browse files
[Fix] Fix to_homo for graph with zero nodes ntype (#3011)
* fix #2870 * lint * fix
parent
8b64ae59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
python/dgl/heterograph.py
python/dgl/heterograph.py
+8
-7
tests/compute/test_heterograph.py
tests/compute/test_heterograph.py
+13
-0
No files found.
python/dgl/heterograph.py
View file @
17141dd3
...
@@ -5985,13 +5985,14 @@ def combine_frames(frames, ids, col_names=None):
...
@@ -5985,13 +5985,14 @@ def combine_frames(frames, ids, col_names=None):
schemes
=
{
key
:
frames
[
ids
[
0
]].
schemes
[
key
]
for
key
in
col_names
}
schemes
=
{
key
:
frames
[
ids
[
0
]].
schemes
[
key
]
for
key
in
col_names
}
for
frame_id
in
ids
:
for
frame_id
in
ids
:
frame
=
frames
[
frame_id
]
frame
=
frames
[
frame_id
]
for
key
,
scheme
in
list
(
schemes
.
items
()):
if
frame
.
num_rows
!=
0
:
if
key
in
frame
.
schemes
:
for
key
,
scheme
in
list
(
schemes
.
items
()):
if
frame
.
schemes
[
key
]
!=
scheme
:
if
key
in
frame
.
schemes
:
raise
DGLError
(
'Cannot concatenate column %s with shape %s and shape %s'
%
if
frame
.
schemes
[
key
]
!=
scheme
:
(
key
,
frame
.
schemes
[
key
],
scheme
))
raise
DGLError
(
'Cannot concatenate column %s with shape %s and shape %s'
%
else
:
(
key
,
frame
.
schemes
[
key
],
scheme
))
del
schemes
[
key
]
else
:
del
schemes
[
key
]
if
len
(
schemes
)
==
0
:
if
len
(
schemes
)
==
0
:
return
None
return
None
...
...
tests/compute/test_heterograph.py
View file @
17141dd3
...
@@ -1082,6 +1082,19 @@ def test_convert(idtype):
...
@@ -1082,6 +1082,19 @@ def test_convert(idtype):
assert
hg
.
device
==
g
.
device
assert
hg
.
device
==
g
.
device
assert
g
.
number_of_nodes
()
==
5
assert
g
.
number_of_nodes
()
==
5
@
unittest
.
skipIf
(
F
.
_default_context_str
==
'gpu'
,
reason
=
"Test on cpu is enough"
)
@
parametrize_dtype
def
test_to_homo_zero_nodes
(
idtype
):
# Fix gihub issue #2870
g
=
dgl
.
heterograph
({
(
'A'
,
'AB'
,
'B'
):
(
np
.
random
.
randint
(
0
,
200
,
(
1000
,)),
np
.
random
.
randint
(
0
,
200
,
(
1000
,))),
(
'B'
,
'BA'
,
'A'
):
(
np
.
random
.
randint
(
0
,
200
,
(
1000
,)),
np
.
random
.
randint
(
0
,
200
,
(
1000
,))),
},
num_nodes_dict
=
{
'A'
:
200
,
'B'
:
200
,
'C'
:
0
},
idtype
=
idtype
)
g
.
nodes
[
'A'
].
data
[
'x'
]
=
F
.
randn
((
200
,
3
))
g
.
nodes
[
'B'
].
data
[
'x'
]
=
F
.
randn
((
200
,
3
))
gg
=
dgl
.
to_homogeneous
(
g
,
[
'x'
])
assert
'x'
in
gg
.
ndata
@
parametrize_dtype
@
parametrize_dtype
def
test_to_homo2
(
idtype
):
def
test_to_homo2
(
idtype
):
# test the result homogeneous graph has nodes and edges sorted by their types
# test the result homogeneous graph has nodes and edges sorted by their types
...
...
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