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
86c243b4
Unverified
Commit
86c243b4
authored
Jun 23, 2020
by
Mufei Li
Committed by
GitHub
Jun 23, 2020
Browse files
Fix (#1684)
parent
85e660cb
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
269 additions
and
150 deletions
+269
-150
python/dgl/batched_heterograph.py
python/dgl/batched_heterograph.py
+241
-150
tests/compute/test_batched_heterograph.py
tests/compute/test_batched_heterograph.py
+28
-0
No files found.
python/dgl/batched_heterograph.py
View file @
86c243b4
This diff is collapsed.
Click to expand it.
tests/compute/test_batched_heterograph.py
View file @
86c243b4
import
dgl
import
backend
as
F
import
unittest
from
dgl.base
import
ALL
from
utils
import
parametrize_dtype
...
...
@@ -268,8 +269,35 @@ def test_batching_with_zero_nodes_edges(index_dtype):
g2
.
nodes
[
'u'
].
data
[
'x'
]
=
F
.
tensor
([
1
])
dgl
.
batch_hetero
([
g1
,
g2
])
@
unittest
.
skipIf
(
F
.
_default_context_str
==
'cpu'
,
reason
=
"Need gpu for this test"
)
@
parametrize_dtype
def
test_to_device
(
index_dtype
):
g1
=
dgl
.
heterograph
({
(
'user'
,
'plays'
,
'game'
):
[(
0
,
0
),
(
1
,
1
)]
},
index_dtype
=
index_dtype
)
g1
.
nodes
[
'user'
].
data
[
'h1'
]
=
F
.
copy_to
(
F
.
tensor
([[
0.
],
[
1.
]]),
F
.
cpu
())
g1
.
nodes
[
'user'
].
data
[
'h2'
]
=
F
.
copy_to
(
F
.
tensor
([[
3.
],
[
4.
]]),
F
.
cpu
())
g1
.
edges
[
'plays'
].
data
[
'h1'
]
=
F
.
copy_to
(
F
.
tensor
([[
2.
],
[
3.
]]),
F
.
cpu
())
g2
=
dgl
.
heterograph
({
(
'user'
,
'plays'
,
'game'
):
[(
0
,
0
),
(
1
,
0
)]
},
index_dtype
=
index_dtype
)
g2
.
nodes
[
'user'
].
data
[
'h1'
]
=
F
.
copy_to
(
F
.
tensor
([[
1.
],
[
2.
]]),
F
.
cpu
())
g2
.
nodes
[
'user'
].
data
[
'h2'
]
=
F
.
copy_to
(
F
.
tensor
([[
4.
],
[
5.
]]),
F
.
cpu
())
g2
.
edges
[
'plays'
].
data
[
'h1'
]
=
F
.
copy_to
(
F
.
tensor
([[
0.
],
[
1.
]]),
F
.
cpu
())
bg
=
dgl
.
batch_hetero
([
g1
,
g2
])
if
F
.
is_cuda_available
():
bg1
=
bg
.
to
(
F
.
cuda
())
assert
bg1
is
not
None
assert
bg
.
batch_size
==
bg1
.
batch_size
assert
bg
.
batch_num_nodes
(
'user'
)
==
bg1
.
batch_num_nodes
(
'user'
)
assert
bg
.
batch_num_edges
(
'plays'
)
==
bg1
.
batch_num_edges
(
'plays'
)
if
__name__
==
'__main__'
:
test_batching_hetero_topology
()
test_batching_hetero_and_batched_hetero_topology
()
test_batched_features
()
test_batching_with_zero_nodes_edges
()
# test_to_device()
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