Unverified Commit ce6e19f2 authored by Quan (Andy) Gan's avatar Quan (Andy) Gan Committed by GitHub
Browse files

[Bugfix] Allows node types with no inbound/outbound edges (#1323)

* add num nodes in ctors

* fix

* lint

* addresses comments

* replace with constexpr

* remove function with rvalue reference

* address comments
parent ac74233c
......@@ -1448,6 +1448,31 @@ def test_stack_reduce():
'stack')
assert g.nodes['game'].data['y'].shape == (g.number_of_nodes('game'), 1, 200)
def test_isolated_ntype():
g = dgl.heterograph({
('A', 'AB', 'B'): [(0, 1), (1, 2), (2, 3)]},
num_nodes_dict={'A': 3, 'B': 4, 'C': 4})
assert g.number_of_nodes('A') == 3
assert g.number_of_nodes('B') == 4
assert g.number_of_nodes('C') == 4
g = dgl.heterograph({
('A', 'AC', 'C'): [(0, 1), (1, 2), (2, 3)]},
num_nodes_dict={'A': 3, 'B': 4, 'C': 4})
assert g.number_of_nodes('A') == 3
assert g.number_of_nodes('B') == 4
assert g.number_of_nodes('C') == 4
G = dgl.DGLGraph()
G.add_nodes(11)
G.add_edges([0, 1, 2], [4, 5, 6])
G.ndata[dgl.NTYPE] = F.tensor([0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], dtype=F.int64)
G.edata[dgl.ETYPE] = F.tensor([0, 0, 0], dtype=F.int64)
g = dgl.to_hetero(G, ['A', 'B', 'C'], ['AB'])
assert g.number_of_nodes('A') == 3
assert g.number_of_nodes('B') == 4
assert g.number_of_nodes('C') == 4
if __name__ == '__main__':
test_create()
test_query()
......@@ -1470,3 +1495,4 @@ if __name__ == '__main__':
test_empty_heterograph()
test_types_in_function()
test_stack_reduce()
test_isolated_ntype()
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