Unverified Commit 5c7681b2 authored by Andrei Ivanov's avatar Andrei Ivanov Committed by GitHub
Browse files

Removing warnings appearing in heterograph tests (#6095)


Co-authored-by: default avatarXin Yao <xiny@nvidia.com>
parent 8b35cbc8
...@@ -89,7 +89,7 @@ def generate_feature(g, broadcast="none", binary_op="none"): ...@@ -89,7 +89,7 @@ def generate_feature(g, broadcast="none", binary_op="none"):
def test_copy_src_reduce(): def test_copy_src_reduce():
def _test(red, partial): def _test(red, partial):
g = dgl.DGLGraph(nx.erdos_renyi_graph(100, 0.1)) g = dgl.from_networkx(nx.erdos_renyi_graph(100, 0.1))
# NOTE(zihao): add self-loop to avoid zero-degree nodes. # NOTE(zihao): add self-loop to avoid zero-degree nodes.
# https://github.com/dmlc/dgl/issues/761 # https://github.com/dmlc/dgl/issues/761
g.add_edges(g.nodes(), g.nodes()) g.add_edges(g.nodes(), g.nodes())
...@@ -157,7 +157,7 @@ def test_copy_src_reduce(): ...@@ -157,7 +157,7 @@ def test_copy_src_reduce():
def test_copy_edge_reduce(): def test_copy_edge_reduce():
def _test(red, partial): def _test(red, partial):
g = dgl.DGLGraph(nx.erdos_renyi_graph(100, 0.1)) g = dgl.from_networkx(nx.erdos_renyi_graph(100, 0.1))
# NOTE(zihao): add self-loop to avoid zero-degree nodes. # NOTE(zihao): add self-loop to avoid zero-degree nodes.
g.add_edges(g.nodes(), g.nodes()) g.add_edges(g.nodes(), g.nodes())
g = g.to(F.ctx()) g = g.to(F.ctx())
...@@ -360,7 +360,7 @@ def test_all_binary_builtins(): ...@@ -360,7 +360,7 @@ def test_all_binary_builtins():
_print_error(rhs_grad_1, rhs_grad_2) _print_error(rhs_grad_1, rhs_grad_2)
assert F.allclose(rhs_grad_1, rhs_grad_2, rtol, atol) assert F.allclose(rhs_grad_1, rhs_grad_2, rtol, atol)
g = dgl.DGLGraph() g = dgl.graph([])
g.add_nodes(20) g.add_nodes(20)
# NOTE(zihao): add self-loop to avoid zero-degree nodes. # NOTE(zihao): add self-loop to avoid zero-degree nodes.
g.add_edges(g.nodes(), g.nodes()) g.add_edges(g.nodes(), g.nodes())
......
...@@ -54,17 +54,13 @@ def scipy_csr_input(): ...@@ -54,17 +54,13 @@ def scipy_csr_input():
def gen_by_mutation(): def gen_by_mutation():
g = dgl.DGLGraph() g = dgl.graph([])
src, dst = edge_pair_input() src, dst = edge_pair_input()
g.add_nodes(10) g.add_nodes(10)
g.add_edges(src, dst) g.add_edges(src, dst)
return g return g
def gen_from_data(data, readonly, sort):
return dgl.DGLGraph(data, readonly=readonly, sort_csr=True)
def test_query(): def test_query():
def _test_one(g): def _test_one(g):
assert g.num_nodes() == 10 assert g.num_nodes() == 10
...@@ -275,19 +271,14 @@ def test_query(): ...@@ -275,19 +271,14 @@ def test_query():
eid = g.edge_ids(0, 4) eid = g.edge_ids(0, 4)
_test(gen_by_mutation()) _test(gen_by_mutation())
_test(gen_from_data(elist_input(), False, False)) _test(dgl.graph(elist_input()))
_test(gen_from_data(elist_input(), True, False)) _test(dgl.from_scipy(scipy_coo_input()))
_test(gen_from_data(elist_input(), True, True)) _test_csr(dgl.from_scipy(scipy_csr_input()))
_test(gen_from_data(scipy_coo_input(), False, False))
_test(gen_from_data(scipy_coo_input(), True, False))
_test_csr(gen_from_data(scipy_csr_input(), False, False))
_test_csr(gen_from_data(scipy_csr_input(), True, False))
_test_edge_ids() _test_edge_ids()
def test_mutation(): def test_mutation():
g = dgl.DGLGraph() g = dgl.graph([])
g = g.to(F.ctx()) g = g.to(F.ctx())
# test add nodes with data # test add nodes with data
g.add_nodes(5) g.add_nodes(5)
...@@ -304,7 +295,7 @@ def test_mutation(): ...@@ -304,7 +295,7 @@ def test_mutation():
def test_scipy_adjmat(): def test_scipy_adjmat():
g = dgl.DGLGraph() g = dgl.graph([])
g.add_nodes(10) g.add_nodes(10)
g.add_edges(range(9), range(1, 10)) g.add_edges(range(9), range(1, 10))
...@@ -318,7 +309,7 @@ def test_scipy_adjmat(): ...@@ -318,7 +309,7 @@ def test_scipy_adjmat():
def test_incmat(): def test_incmat():
g = dgl.DGLGraph() g = dgl.graph([])
g.add_nodes(4) g.add_nodes(4)
g.add_edges(0, 1) # 0 g.add_edges(0, 1) # 0
g.add_edges(0, 2) # 1 g.add_edges(0, 2) # 1
...@@ -367,7 +358,7 @@ def test_incmat(): ...@@ -367,7 +358,7 @@ def test_incmat():
def test_find_edges(): def test_find_edges():
g = dgl.DGLGraph() g = dgl.graph([])
g.add_nodes(10) g.add_nodes(10)
g.add_edges(range(9), range(1, 10)) g.add_edges(range(9), range(1, 10))
e = g.find_edges([1, 3, 2, 4]) e = g.find_edges([1, 3, 2, 4])
...@@ -394,7 +385,7 @@ def test_find_edges(): ...@@ -394,7 +385,7 @@ def test_find_edges():
def test_ismultigraph(): def test_ismultigraph():
g = dgl.DGLGraph() g = dgl.graph([])
g.add_nodes(10) g.add_nodes(10)
assert g.is_multigraph == False assert g.is_multigraph == False
g.add_edges([0], [0]) g.add_edges([0], [0])
...@@ -406,7 +397,7 @@ def test_ismultigraph(): ...@@ -406,7 +397,7 @@ def test_ismultigraph():
def test_hypersparse_query(): def test_hypersparse_query():
g = dgl.DGLGraph() g = dgl.graph([])
g = g.to(F.ctx()) g = g.to(F.ctx())
g.add_nodes(1000001) g.add_nodes(1000001)
g.add_edges([0], [1]) g.add_edges([0], [1])
...@@ -425,7 +416,7 @@ def test_hypersparse_query(): ...@@ -425,7 +416,7 @@ def test_hypersparse_query():
def test_empty_data_initialized(): def test_empty_data_initialized():
g = dgl.DGLGraph() g = dgl.graph([])
g = g.to(F.ctx()) g = g.to(F.ctx())
g.ndata["ha"] = F.tensor([]) g.ndata["ha"] = F.tensor([])
g.add_nodes(1, {"hb": F.tensor([1])}) g.add_nodes(1, {"hb": F.tensor([1])})
...@@ -460,7 +451,7 @@ def test_is_sorted(): ...@@ -460,7 +451,7 @@ def test_is_sorted():
def test_default_types(): def test_default_types():
dg = dgl.DGLGraph() dg = dgl.graph([])
g = dgl.graph(([], [])) g = dgl.graph(([], []))
assert dg.ntypes == g.ntypes assert dg.ntypes == g.ntypes
assert dg.etypes == g.etypes assert dg.etypes == g.etypes
......
...@@ -5,11 +5,16 @@ import numpy as np ...@@ -5,11 +5,16 @@ import numpy as np
from utils import parametrize_idtype from utils import parametrize_idtype
def create_graph(idtype, num_node):
g = dgl.graph([])
g = g.astype(idtype).to(F.ctx())
g.add_nodes(num_node)
return g
@parametrize_idtype @parametrize_idtype
def test_node_removal(idtype): def test_node_removal(idtype):
g = dgl.DGLGraph() g = create_graph(idtype, 10)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(10)
g.add_edges(0, 0) g.add_edges(0, 0)
assert g.num_nodes() == 10 assert g.num_nodes() == 10
g.ndata["id"] = F.arange(0, 10) g.ndata["id"] = F.arange(0, 10)
...@@ -38,9 +43,7 @@ def test_node_removal(idtype): ...@@ -38,9 +43,7 @@ def test_node_removal(idtype):
@parametrize_idtype @parametrize_idtype
def test_multigraph_node_removal(idtype): def test_multigraph_node_removal(idtype):
g = dgl.DGLGraph() g = create_graph(idtype, 5)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(5)
for i in range(5): for i in range(5):
g.add_edges(i, i) g.add_edges(i, i)
g.add_edges(i, i) g.add_edges(i, i)
...@@ -67,9 +70,7 @@ def test_multigraph_node_removal(idtype): ...@@ -67,9 +70,7 @@ def test_multigraph_node_removal(idtype):
@parametrize_idtype @parametrize_idtype
def test_multigraph_edge_removal(idtype): def test_multigraph_edge_removal(idtype):
g = dgl.DGLGraph() g = create_graph(idtype, 5)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(5)
for i in range(5): for i in range(5):
g.add_edges(i, i) g.add_edges(i, i)
g.add_edges(i, i) g.add_edges(i, i)
...@@ -95,9 +96,7 @@ def test_multigraph_edge_removal(idtype): ...@@ -95,9 +96,7 @@ def test_multigraph_edge_removal(idtype):
@parametrize_idtype @parametrize_idtype
def test_edge_removal(idtype): def test_edge_removal(idtype):
g = dgl.DGLGraph() g = create_graph(idtype, 5)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(5)
for i in range(5): for i in range(5):
for j in range(5): for j in range(5):
g.add_edges(i, j) g.add_edges(i, j)
...@@ -133,9 +132,7 @@ def test_edge_removal(idtype): ...@@ -133,9 +132,7 @@ def test_edge_removal(idtype):
@parametrize_idtype @parametrize_idtype
def test_node_and_edge_removal(idtype): def test_node_and_edge_removal(idtype):
g = dgl.DGLGraph() g = create_graph(idtype, 10)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(10)
for i in range(10): for i in range(10):
for j in range(10): for j in range(10):
g.add_edges(i, j) g.add_edges(i, j)
...@@ -173,9 +170,7 @@ def test_node_and_edge_removal(idtype): ...@@ -173,9 +170,7 @@ def test_node_and_edge_removal(idtype):
@parametrize_idtype @parametrize_idtype
def test_node_frame(idtype): def test_node_frame(idtype):
g = dgl.DGLGraph() g = create_graph(idtype, 10)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(10)
data = np.random.rand(10, 3) data = np.random.rand(10, 3)
new_data = data.take([0, 1, 2, 7, 8, 9], axis=0) new_data = data.take([0, 1, 2, 7, 8, 9], axis=0)
g.ndata["h"] = F.tensor(data) g.ndata["h"] = F.tensor(data)
...@@ -187,9 +182,7 @@ def test_node_frame(idtype): ...@@ -187,9 +182,7 @@ def test_node_frame(idtype):
@parametrize_idtype @parametrize_idtype
def test_edge_frame(idtype): def test_edge_frame(idtype):
g = dgl.DGLGraph() g = create_graph(idtype, 10)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(10)
g.add_edges(list(range(10)), list(range(1, 10)) + [0]) g.add_edges(list(range(10)), list(range(1, 10)) + [0])
data = np.random.rand(10, 3) data = np.random.rand(10, 3)
new_data = data.take([0, 1, 2, 7, 8, 9], axis=0) new_data = data.take([0, 1, 2, 7, 8, 9], axis=0)
...@@ -204,18 +197,14 @@ def test_edge_frame(idtype): ...@@ -204,18 +197,14 @@ def test_edge_frame(idtype):
def test_issue1287(idtype): def test_issue1287(idtype):
# reproduce https://github.com/dmlc/dgl/issues/1287. # reproduce https://github.com/dmlc/dgl/issues/1287.
# setting features after remove nodes # setting features after remove nodes
g = dgl.DGLGraph() g = create_graph(idtype, 5)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(5)
g.add_edges([0, 2, 3, 1, 1], [1, 0, 3, 1, 0]) g.add_edges([0, 2, 3, 1, 1], [1, 0, 3, 1, 0])
g.remove_nodes([0, 1]) g.remove_nodes([0, 1])
g.ndata["h"] = F.randn((g.num_nodes(), 3)) g.ndata["h"] = F.randn((g.num_nodes(), 3))
g.edata["h"] = F.randn((g.num_edges(), 2)) g.edata["h"] = F.randn((g.num_edges(), 2))
# remove edges # remove edges
g = dgl.DGLGraph() g = create_graph(idtype, 5)
g = g.astype(idtype).to(F.ctx())
g.add_nodes(5)
g.add_edges([0, 2, 3, 1, 1], [1, 0, 3, 1, 0]) g.add_edges([0, 2, 3, 1, 1], [1, 0, 3, 1, 0])
g.remove_edges([0, 1]) g.remove_edges([0, 1])
g = g.to(F.ctx()) g = g.to(F.ctx())
......
...@@ -10,7 +10,7 @@ D = 5 ...@@ -10,7 +10,7 @@ D = 5
def generate_graph(idtype): def generate_graph(idtype):
g = dgl.DGLGraph() g = dgl.graph([])
g = g.astype(idtype).to(F.ctx()) g = g.astype(idtype).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
...@@ -183,7 +183,7 @@ def test_v2v_pull(idtype): ...@@ -183,7 +183,7 @@ def test_v2v_pull(idtype):
@parametrize_idtype @parametrize_idtype
def test_update_all_multi_fallback(idtype): def test_update_all_multi_fallback(idtype):
# create a graph with zero in degree nodes # create a graph with zero in degree nodes
g = dgl.DGLGraph() g = dgl.graph([])
g = g.astype(idtype).to(F.ctx()) g = g.astype(idtype).to(F.ctx())
g.add_nodes(10) g.add_nodes(10)
for i in range(1, 9): for i in range(1, 9):
...@@ -237,7 +237,7 @@ def test_update_all_multi_fallback(idtype): ...@@ -237,7 +237,7 @@ def test_update_all_multi_fallback(idtype):
@parametrize_idtype @parametrize_idtype
def test_pull_multi_fallback(idtype): def test_pull_multi_fallback(idtype):
# create a graph with zero in degree nodes # create a graph with zero in degree nodes
g = dgl.DGLGraph() g = dgl.graph([])
g = g.astype(idtype).to(F.ctx()) g = g.astype(idtype).to(F.ctx())
g.add_nodes(10) g.add_nodes(10)
for i in range(1, 9): for i in range(1, 9):
...@@ -317,7 +317,7 @@ def test_spmv_3d_feat(idtype): ...@@ -317,7 +317,7 @@ def test_spmv_3d_feat(idtype):
n = 100 n = 100
p = 0.1 p = 0.1
a = sp.random(n, n, p, data_rvs=lambda n: np.ones(n)) a = sp.random(n, n, p, data_rvs=lambda n: np.ones(n))
g = dgl.DGLGraph(a) g = dgl.from_scipy(a)
g = g.astype(idtype).to(F.ctx()) g = g.astype(idtype).to(F.ctx())
m = g.num_edges() m = g.num_edges()
......
...@@ -20,7 +20,7 @@ def test_pickling_batched_graph(): ...@@ -20,7 +20,7 @@ def test_pickling_batched_graph():
# NOTE: this is a test for a wierd bug mentioned in # NOTE: this is a test for a wierd bug mentioned in
# https://github.com/dmlc/dgl/issues/438 # https://github.com/dmlc/dgl/issues/438
glist = [nx.path_graph(i + 5) for i in range(5)] glist = [nx.path_graph(i + 5) for i in range(5)]
glist = [dgl.DGLGraph(g) for g in glist] glist = [dgl.from_networkx(g) for g in glist]
bg = dgl.batch(glist) bg = dgl.batch(glist)
bg.ndata["x"] = torch.randn((35, 5)) bg.ndata["x"] = torch.randn((35, 5))
bg.edata["y"] = torch.randn((60, 3)) bg.edata["y"] = torch.randn((60, 3))
......
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