Unverified Commit 468c0ca4 authored by Rhett Ying's avatar Rhett Ying Committed by GitHub
Browse files

[BugFix] fix crash due to incorrect dtype in dgl.to_block() (#4487)

* [BugFix] fix crash due to incorrect dtype in dgl.to_block()

* fix test failure in TF
parent 86656a6b
...@@ -2317,7 +2317,7 @@ def to_block(g, dst_nodes=None, include_dst_in_src=True, src_nodes=None): ...@@ -2317,7 +2317,7 @@ def to_block(g, dst_nodes=None, include_dst_in_src=True, src_nodes=None):
'Graph has more than one node type; please specify a dict for src_nodes.') 'Graph has more than one node type; please specify a dict for src_nodes.')
src_nodes = {g.ntypes[0]: src_nodes} src_nodes = {g.ntypes[0]: src_nodes}
src_node_ids = [ src_node_ids = [
F.copy_to(F.tensor(src_nodes.get(ntype, []), dtype=g._idtype_str), \ F.copy_to(F.tensor(src_nodes.get(ntype, []), dtype=g.idtype), \
F.to_backend_ctx(g._graph.ctx)) \ F.to_backend_ctx(g._graph.ctx)) \
for ntype in g.ntypes] for ntype in g.ntypes]
src_node_ids_nd = [F.to_dgl_nd(nodes) for nodes in src_node_ids] src_node_ids_nd = [F.to_dgl_nd(nodes) for nodes in src_node_ids]
......
...@@ -913,6 +913,17 @@ def test_to_block(idtype): ...@@ -913,6 +913,17 @@ def test_to_block(idtype):
else: else:
check(g, bg, ntype, etype, None, include_dst_in_src) check(g, bg, ntype, etype, None, include_dst_in_src)
# homogeneous graph
g = dgl.graph((F.tensor([1, 2], dtype=idtype), F.tensor([2, 3], dtype=idtype)))
dst_nodes = F.tensor([3, 2], dtype=idtype)
bg = dgl.to_block(g, dst_nodes=dst_nodes)
check(g, bg, '_N', '_E', dst_nodes)
src_nodes = bg.srcnodes['_N'].data[dgl.NID]
bg = dgl.to_block(g, dst_nodes=dst_nodes, src_nodes=src_nodes)
check(g, bg, '_N', '_E', dst_nodes)
# heterogeneous graph
g = dgl.heterograph({ g = dgl.heterograph({
('A', 'AA', 'A'): ([0, 2, 1, 3], [1, 3, 2, 4]), ('A', 'AA', 'A'): ([0, 2, 1, 3], [1, 3, 2, 4]),
('A', 'AB', 'B'): ([0, 1, 3, 1], [1, 3, 5, 6]), ('A', 'AB', 'B'): ([0, 1, 3, 1], [1, 3, 5, 6]),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment