Unverified Commit 14251504 authored by nv-dlasalle's avatar nv-dlasalle Committed by GitHub
Browse files

Fix test naming (#4023)


Co-authored-by: default avatarMufei Li <mufeili1996@gmail.com>
parent 7c598aac
......@@ -8,7 +8,7 @@ import backend as F
import networkx as nx
import unittest, pytest
from dgl import DGLError
from utils import parametrize_dtype
from test_utils import parametrize_idtype
def create_test_heterograph(num_nodes, num_adj, idtype):
if isinstance(num_adj, int):
......@@ -49,7 +49,7 @@ def check_sort(spm, tag_arr=None, tag_pos=None):
@unittest.skipIf(F._default_context_str == 'gpu', reason="GPU sorting by tag not implemented")
@parametrize_dtype
@parametrize_idtype
def test_sort_with_tag(idtype):
num_nodes, num_adj, num_tags = 200, [20, 50], 5
g = create_test_heterograph(num_nodes, num_adj, idtype=idtype)
......@@ -68,7 +68,7 @@ def test_sort_with_tag(idtype):
assert(not check_sort(old_csc, tag))
@unittest.skipIf(F._default_context_str == 'gpu', reason="GPU sorting by tag not implemented")
@parametrize_dtype
@parametrize_idtype
def test_sort_with_tag_bipartite(idtype):
num_nodes, num_adj, num_tags = 200, [20, 50], 5
g = create_test_heterograph(num_nodes, num_adj, idtype=idtype)
......
from dgl.ops import gspmm, gsddmm, edge_softmax, segment_reduce
from test_utils.graph_cases import get_cases
from utils import parametrize_dtype
from test_utils import parametrize_idtype
import dgl
import random
import pytest, unittest
......@@ -99,7 +99,7 @@ edge_softmax_shapes = [
@pytest.mark.parametrize('shp', spmm_shapes)
@pytest.mark.parametrize('msg', ['add', 'sub', 'mul', 'div', 'copy_lhs', 'copy_rhs'])
@pytest.mark.parametrize('reducer', ['sum', 'min', 'max'])
@parametrize_dtype
@parametrize_idtype
def test_spmm(idtype, g, shp, msg, reducer):
g = g.astype(idtype).to(F.ctx())
print(g)
......@@ -159,7 +159,7 @@ def test_spmm(idtype, g, shp, msg, reducer):
@pytest.mark.parametrize('lhs_target', ['u', 'v', 'e'])
@pytest.mark.parametrize('rhs_target', ['u', 'v', 'e'])
@pytest.mark.parametrize('msg', ['add', 'sub', 'mul', 'div', 'dot', 'copy_lhs', 'copy_rhs'])
@parametrize_dtype
@parametrize_idtype
def test_sddmm(g, shp, lhs_target, rhs_target, msg, idtype):
if lhs_target == rhs_target:
return
......@@ -229,7 +229,7 @@ def test_sddmm(g, shp, lhs_target, rhs_target, msg, idtype):
@pytest.mark.parametrize('g', get_cases(['clique']))
@pytest.mark.parametrize('norm_by', ['src', 'dst'])
@pytest.mark.parametrize('shp', edge_softmax_shapes)
@parametrize_dtype
@parametrize_idtype
def test_edge_softmax(g, norm_by, shp, idtype):
g = g.astype(idtype).to(F.ctx())
edata = F.tensor(np.random.rand(g.number_of_edges(), *shp))
......@@ -288,7 +288,7 @@ def test_segment_reduce(reducer):
print('backward passed')
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('feat_size', [1, 8, 16, 64, 256])
def test_segment_mm(idtype, feat_size):
import torch
......@@ -323,7 +323,7 @@ def test_segment_mm(idtype, feat_size):
assert torch.allclose(db, db_t, atol=1e-4, rtol=1e-4)
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('feat_size', [1, 8, 16, 64, 256])
def test_gather_mm_idx_b(idtype, feat_size):
import torch
......@@ -353,7 +353,7 @@ def test_gather_mm_idx_b(idtype, feat_size):
assert torch.allclose(db, db_t, atol=1e-4, rtol=1e-4)
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('feat_size', [1, 8, 16, 64, 256])
def _test_gather_mm_idx_a(idtype, feat_size):
# TODO(minjie): currently disabled due to bugs in the CUDA kernel. Need to fix it later.
......
......@@ -3,7 +3,7 @@ import scipy.sparse as sp
import dgl
import dgl.function as fn
import backend as F
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype
D = 5
......@@ -22,7 +22,7 @@ def generate_graph(idtype):
g.edata.update({'e1': weights, 'e2': F.unsqueeze(weights, 1)})
return g
@parametrize_dtype
@parametrize_idtype
def test_v2v_update_all(idtype):
def _test(fld):
def message_func(edges):
......@@ -62,7 +62,7 @@ def test_v2v_update_all(idtype):
# test 2d node features
_test('f2')
@parametrize_dtype
@parametrize_idtype
def test_v2v_snr(idtype):
u = F.tensor([0, 0, 0, 3, 4, 9], idtype)
v = F.tensor([1, 2, 3, 9, 9, 0], idtype)
......@@ -106,7 +106,7 @@ def test_v2v_snr(idtype):
_test('f2')
@parametrize_dtype
@parametrize_idtype
def test_v2v_pull(idtype):
nodes = F.tensor([1, 2, 3, 9], idtype)
def _test(fld):
......@@ -147,7 +147,7 @@ def test_v2v_pull(idtype):
# test 2d node features
_test('f2')
@parametrize_dtype
@parametrize_idtype
def test_update_all_multi_fallback(idtype):
# create a graph with zero in degree nodes
g = dgl.DGLGraph()
......@@ -193,7 +193,7 @@ def test_update_all_multi_fallback(idtype):
_afunc)
assert F.allclose(o2, g.ndata.pop('o2'))
@parametrize_dtype
@parametrize_idtype
def test_pull_multi_fallback(idtype):
# create a graph with zero in degree nodes
g = dgl.DGLGraph()
......@@ -247,7 +247,7 @@ def test_pull_multi_fallback(idtype):
nodes = [0, 1, 2, 9]
_pull_nodes(nodes)
@parametrize_dtype
@parametrize_idtype
def test_spmv_3d_feat(idtype):
def src_mul_edge_udf(edges):
return {'sum': edges.src['h'] * F.unsqueeze(F.unsqueeze(edges.data['h'], 1), 1)}
......
......@@ -6,7 +6,7 @@ import pytest
import dgl
import backend as F
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype
D = 5
......@@ -118,7 +118,7 @@ def create_test_heterograph(idtype):
return g
@unittest.skipIf(dgl.backend.backend_name == "mxnet", reason="MXNet doesn't support bool tensor")
@parametrize_dtype
@parametrize_idtype
def test_subgraph_mask(idtype):
g = create_test_heterograph(idtype)
g_graph = g['follows']
......@@ -158,7 +158,7 @@ def test_subgraph_mask(idtype):
'wishes': F.tensor([False, True], dtype=F.bool)})
_check_subgraph(g, sg2)
@parametrize_dtype
@parametrize_idtype
def test_subgraph1(idtype):
g = create_test_heterograph(idtype)
g_graph = g['follows']
......@@ -310,7 +310,7 @@ def test_subgraph1(idtype):
dst = F.asnumpy(dst)
assert np.array_equal(src, np.array([1]))
@parametrize_dtype
@parametrize_idtype
def test_in_subgraph(idtype):
hg = dgl.heterograph({
('user', 'follow', 'user'): ([1, 2, 3, 0, 2, 3, 0], [0, 0, 0, 1, 1, 1, 2]),
......@@ -377,7 +377,7 @@ def test_in_subgraph(idtype):
assert subg.num_nodes('coin') == 0
assert subg.num_edges('flips') == 0
@parametrize_dtype
@parametrize_idtype
def test_out_subgraph(idtype):
hg = dgl.heterograph({
('user', 'follow', 'user'): ([1, 2, 3, 0, 2, 3, 0], [0, 0, 0, 1, 1, 1, 2]),
......@@ -459,7 +459,7 @@ def test_subgraph_message_passing():
sg = g.subgraph([1, 2, 3]).to(F.ctx())
sg.update_all(lambda edges: {'x': edges.src['x']}, lambda nodes: {'y': F.sum(nodes.mailbox['x'], 1)})
@parametrize_dtype
@parametrize_idtype
def test_khop_in_subgraph(idtype):
g = dgl.graph(([1, 1, 2, 3, 4], [0, 2, 0, 4, 2]), idtype=idtype, device=F.ctx())
g.edata['w'] = F.tensor([
......@@ -535,7 +535,7 @@ def test_khop_in_subgraph(idtype):
assert F.array_equal(F.astype(inv['user'], idtype), F.tensor([0, 1], idtype))
assert F.array_equal(F.astype(inv['game'], idtype), F.tensor([0], idtype))
@parametrize_dtype
@parametrize_idtype
def test_khop_out_subgraph(idtype):
g = dgl.graph(([0, 2, 0, 4, 2], [1, 1, 2, 3, 4]), idtype=idtype, device=F.ctx())
g.edata['w'] = F.tensor([
......@@ -646,7 +646,7 @@ def test_subframes(parent_idx_device, child_device):
@unittest.skipIf(F._default_context_str != "gpu", reason="UVA only available on GPU")
@pytest.mark.parametrize('device', [F.cpu(), F.cuda()])
@unittest.skipIf(dgl.backend.backend_name != "pytorch", reason="UVA only supported for PyTorch")
@parametrize_dtype
@parametrize_idtype
def test_uva_subgraph(idtype, device):
g = create_test_heterograph(idtype)
g = g.to(F.cpu())
......
......@@ -26,7 +26,7 @@ import unittest
import math
import pytest
from test_utils.graph_cases import get_cases
from utils import parametrize_dtype
from test_utils import parametrize_idtype
from test_heterograph import create_test_heterograph3, create_test_heterograph4, create_test_heterograph5
......@@ -43,7 +43,7 @@ def test_line_graph1():
assert F.allclose(L.ndata['h'], G.edata['h'])
assert G.device == F.ctx()
@parametrize_dtype
@parametrize_idtype
def test_line_graph2(idtype):
g = dgl.heterograph({
('user', 'follows', 'user'): ([0, 1, 1, 2, 2],[2, 0, 2, 0, 1])
......@@ -105,7 +105,7 @@ def test_no_backtracking():
assert not L.has_edge_between(e2, e1)
# reverse graph related
@parametrize_dtype
@parametrize_idtype
def test_reverse(idtype):
g = dgl.DGLGraph()
g = g.astype(idtype).to(F.ctx())
......@@ -239,7 +239,7 @@ def test_reverse(idtype):
assert ('hhh' in g_r.edges['follows'].data) is True
@parametrize_dtype
@parametrize_idtype
def test_reverse_shared_frames(idtype):
g = dgl.DGLGraph()
g = g.astype(idtype).to(F.ctx())
......@@ -543,7 +543,7 @@ def test_partition_with_halo():
@unittest.skipIf(os.name == 'nt', reason='Do not support windows yet')
@unittest.skipIf(F._default_context_str == 'gpu', reason="METIS doesn't support GPU")
@parametrize_dtype
@parametrize_idtype
def test_metis_partition(idtype):
# TODO(zhengda) Metis fails to partition a small graph.
g = create_large_graph(1000, idtype=idtype)
......@@ -675,7 +675,7 @@ def test_reorder_nodes():
old_neighs2 = g.predecessors(old_nid)
assert np.all(np.sort(old_neighs1) == np.sort(F.asnumpy(old_neighs2)))
@parametrize_dtype
@parametrize_idtype
def test_compact(idtype):
g1 = dgl.heterograph({
('user', 'follow', 'user'): ([1, 3], [3, 5]),
......@@ -776,7 +776,7 @@ def test_compact(idtype):
_check(g4, new_g4, induced_nodes)
@unittest.skipIf(F._default_context_str == 'gpu', reason="GPU to simple not implemented")
@parametrize_dtype
@parametrize_idtype
def test_to_simple(idtype):
# homogeneous graph
g = dgl.graph((F.tensor([0, 1, 2, 1]), F.tensor([1, 2, 0, 2])))
......@@ -877,7 +877,7 @@ def test_to_simple(idtype):
sg = dgl.to_simple(g)
assert F.array_equal(sg.edge_ids(u, v), eids)
@parametrize_dtype
@parametrize_idtype
def test_to_block(idtype):
def check(g, bg, ntype, etype, dst_nodes, include_dst_in_src=True):
if dst_nodes is not None:
......@@ -1008,7 +1008,7 @@ def test_to_block(idtype):
@unittest.skipIf(F._default_context_str == 'gpu', reason="GPU not implemented")
@parametrize_dtype
@parametrize_idtype
def test_remove_edges(idtype):
def check(g1, etype, g, edges_removed):
src, dst, eid = g.edges(etype=etype, form='all')
......@@ -1061,7 +1061,7 @@ def test_remove_edges(idtype):
check(g4, 'AB', g, [3, 1, 2, 0])
check(g4, 'BA', g, [])
@parametrize_dtype
@parametrize_idtype
def test_add_edges(idtype):
# homogeneous graph
g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
......@@ -1239,7 +1239,7 @@ def test_add_edges(idtype):
assert F.array_equal(g.nodes['game'].data['h'], F.tensor([2, 2, 1, 1], dtype=idtype))
assert F.array_equal(g.edges['develops'].data['h'], F.tensor([0, 0, 2, 2], dtype=idtype))
@parametrize_dtype
@parametrize_idtype
def test_add_nodes(idtype):
# homogeneous Graphs
g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
......@@ -1277,7 +1277,7 @@ def test_add_nodes(idtype):
assert F.array_equal(g.nodes['user'].data['h'], F.tensor([1, 1, 1, 0], dtype=idtype))
assert F.array_equal(g.nodes['game'].data['h'], F.tensor([2, 2, 2, 2], dtype=idtype))
@parametrize_dtype
@parametrize_idtype
def test_remove_edges(idtype):
# homogeneous Graphs
g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
......@@ -1447,7 +1447,7 @@ def test_remove_edges(idtype):
assert F.array_equal(bg.batch_num_edges('follows'), bg_r.batch_num_edges('follows'))
assert F.array_equal(bg_r.batch_num_edges('plays'), F.tensor([1, 0, 1], dtype=F.int64))
@parametrize_dtype
@parametrize_idtype
def test_remove_nodes(idtype):
# homogeneous Graphs
g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
......@@ -1622,7 +1622,7 @@ def test_remove_nodes(idtype):
assert F.array_equal(bg.batch_num_edges('follows'), bg_r.batch_num_edges('follows'))
assert F.array_equal(bg_r.batch_num_edges('plays'), F.tensor([1, 0, 1], dtype=F.int64))
@parametrize_dtype
@parametrize_idtype
def test_add_selfloop(idtype):
# homogeneous graph
g = dgl.graph(([0, 0, 2], [2, 1, 0]), idtype=idtype, device=F.ctx())
......@@ -1666,7 +1666,7 @@ def test_add_selfloop(idtype):
raise_error = True
assert raise_error
@parametrize_dtype
@parametrize_idtype
def test_remove_selfloop(idtype):
# homogeneous graph
g = dgl.graph(([0, 0, 0, 1], [1, 0, 0, 2]), idtype=idtype, device=F.ctx())
......@@ -1707,7 +1707,7 @@ def test_remove_selfloop(idtype):
assert raise_error
@parametrize_dtype
@parametrize_idtype
def test_reorder_graph(idtype):
g = dgl.graph(([0, 1, 2, 3, 4], [2, 2, 3, 2, 3]),
idtype=idtype, device=F.ctx())
......@@ -1821,7 +1821,7 @@ def test_reorder_graph(idtype):
#assert 'csc' in sum(rfg.formats().values(), [])
@unittest.skipIf(dgl.backend.backend_name == "tensorflow", reason="TF doesn't support a slicing operation")
@parametrize_dtype
@parametrize_idtype
def test_norm_by_dst(idtype):
# Case1: A homogeneous graph
g = dgl.graph(([0, 1, 1], [1, 1, 2]), idtype=idtype, device=F.ctx())
......@@ -1836,7 +1836,7 @@ def test_norm_by_dst(idtype):
eweight = dgl.norm_by_dst(g, etype=('user', 'plays', 'game'))
assert F.allclose(eweight, F.tensor([0.5, 0.5, 1.0]))
@parametrize_dtype
@parametrize_idtype
def test_module_add_self_loop(idtype):
g = dgl.graph(([1, 1], [1, 2]), idtype=idtype, device=F.ctx())
g.ndata['h'] = F.randn((g.num_nodes(), 2))
......@@ -1914,7 +1914,7 @@ def test_module_add_self_loop(idtype):
assert 'w1' in new_g.edges['plays'].data
assert 'w2' in new_g.edges['follows'].data
@parametrize_dtype
@parametrize_idtype
def test_module_remove_self_loop(idtype):
transform = dgl.RemoveSelfLoop()
......@@ -1957,7 +1957,7 @@ def test_module_remove_self_loop(idtype):
assert 'w1' in new_g.edges['plays'].data
assert 'w2' in new_g.edges['follows'].data
@parametrize_dtype
@parametrize_idtype
def test_module_add_reverse(idtype):
transform = dgl.AddReverse()
......@@ -2044,7 +2044,7 @@ def test_module_add_reverse(idtype):
assert eset == {(2, 1), (2, 2)}
@unittest.skipIf(F._default_context_str == 'gpu', reason="GPU not supported for to_simple")
@parametrize_dtype
@parametrize_idtype
def test_module_to_simple(idtype):
transform = dgl.ToSimple()
g = dgl.graph(([0, 1, 1], [1, 2, 2]), idtype=idtype, device=F.ctx())
......@@ -2083,7 +2083,7 @@ def test_module_to_simple(idtype):
eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
assert eset == {(0, 1), (1, 1)}
@parametrize_dtype
@parametrize_idtype
def test_module_line_graph(idtype):
transform = dgl.LineGraph()
g = dgl.graph(([0, 1, 1], [1, 0, 2]), idtype=idtype, device=F.ctx())
......@@ -2106,7 +2106,7 @@ def test_module_line_graph(idtype):
eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
assert eset == {(0, 2)}
@parametrize_dtype
@parametrize_idtype
def test_module_khop_graph(idtype):
transform = dgl.KHopGraph(2)
g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
......@@ -2120,7 +2120,7 @@ def test_module_khop_graph(idtype):
eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
assert eset == {(0, 2)}
@parametrize_dtype
@parametrize_idtype
def test_module_add_metapaths(idtype):
g = dgl.heterograph({
('person', 'author', 'paper'): ([0, 0, 1], [1, 2, 2]),
......@@ -2179,7 +2179,7 @@ def test_module_add_metapaths(idtype):
eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
assert eset == {(0, 1), (1, 1)}
@parametrize_dtype
@parametrize_idtype
def test_module_compose(idtype):
g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
transform = dgl.Compose([dgl.AddReverse(), dgl.AddSelfLoop()])
......@@ -2192,7 +2192,7 @@ def test_module_compose(idtype):
eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
assert eset == {(0, 1), (1, 2), (1, 0), (2, 1), (0, 0), (1, 1), (2, 2)}
@parametrize_dtype
@parametrize_idtype
def test_module_gcnnorm(idtype):
g = dgl.heterograph({
('A', 'r1', 'A'): ([0, 1, 2], [0, 0, 1]),
......@@ -2208,7 +2208,7 @@ def test_module_gcnnorm(idtype):
assert F.allclose(new_g.edges[('B', 'r3', 'B')].data['w'], F.tensor([1./3, 2./3, 0.]))
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
def test_module_ppr(idtype):
g = dgl.graph(([0, 1, 2, 3, 4], [2, 3, 4, 5, 3]), idtype=idtype, device=F.ctx())
g.ndata['h'] = F.randn((6, 2))
......@@ -2233,7 +2233,7 @@ def test_module_ppr(idtype):
(3, 3), (3, 5), (4, 3), (4, 4), (4, 5), (5, 5)}
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
def test_module_heat_kernel(idtype):
# Case1: directed graph
g = dgl.graph(([0, 1, 2, 3, 4], [2, 3, 4, 5, 3]), idtype=idtype, device=F.ctx())
......@@ -2255,7 +2255,7 @@ def test_module_heat_kernel(idtype):
assert eset == {(0, 0), (1, 1), (2, 2), (3, 3)}
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
def test_module_gdc(idtype):
transform = dgl.GDC([0.1, 0.2, 0.1], avg_degree=1)
g = dgl.graph(([0, 1, 2, 3, 4], [2, 3, 4, 5, 3]), idtype=idtype, device=F.ctx())
......@@ -2278,7 +2278,7 @@ def test_module_gdc(idtype):
eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
assert eset == {(0, 0), (1, 1), (2, 2), (3, 3), (4, 3), (4, 4), (5, 5)}
@parametrize_dtype
@parametrize_idtype
def test_module_node_shuffle(idtype):
transform = dgl.NodeShuffle()
g = dgl.heterograph({
......@@ -2287,7 +2287,7 @@ def test_module_node_shuffle(idtype):
new_g = transform(g)
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
def test_module_drop_node(idtype):
transform = dgl.DropNode()
g = dgl.heterograph({
......@@ -2300,7 +2300,7 @@ def test_module_drop_node(idtype):
assert new_g.canonical_etypes == g.canonical_etypes
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
def test_module_drop_edge(idtype):
transform = dgl.DropEdge()
g = dgl.heterograph({
......@@ -2313,7 +2313,7 @@ def test_module_drop_edge(idtype):
assert new_g.ntypes == g.ntypes
assert new_g.canonical_etypes == g.canonical_etypes
@parametrize_dtype
@parametrize_idtype
def test_module_add_edge(idtype):
transform = dgl.AddEdge()
g = dgl.heterograph({
......@@ -2328,7 +2328,7 @@ def test_module_add_edge(idtype):
assert new_g.ntypes == g.ntypes
assert new_g.canonical_etypes == g.canonical_etypes
@parametrize_dtype
@parametrize_idtype
def test_module_random_walk_pe(idtype):
transform = dgl.RandomWalkPE(2, 'rwpe')
g = dgl.graph(([0, 1, 1], [1, 1, 0]), idtype=idtype, device=F.ctx())
......@@ -2336,7 +2336,7 @@ def test_module_random_walk_pe(idtype):
tgt = F.copy_to(F.tensor([[0., 0.5],[0.5, 0.75]]), g.device)
assert F.allclose(new_g.ndata['rwpe'], tgt)
@parametrize_dtype
@parametrize_idtype
def test_module_laplacian_pe(idtype):
transform = dgl.LaplacianPE(2, 'lappe')
g = dgl.graph(([2, 1, 0, 3, 1, 1],[3, 0, 1, 3, 3, 1]), idtype=idtype, device=F.ctx())
......@@ -2422,7 +2422,7 @@ def test_module_sign(g):
assert torch.allclose(g.ndata['out_feat_1'], target)
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
def test_module_row_feat_normalizer(idtype):
# Case1: Normalize features of a homogeneous graph.
transform = dgl.RowFeatNormalizer(subtract_min=True)
......@@ -2457,7 +2457,7 @@ def test_module_row_feat_normalizer(idtype):
assert F.allclose(g.edata['w'][('player', 'plays', 'game')].sum(1), F.tensor([1.0, 1.0]))
@unittest.skipIf(dgl.backend.backend_name != 'pytorch', reason='Only support PyTorch for now')
@parametrize_dtype
@parametrize_idtype
def test_module_feat_mask(idtype):
# Case1: Mask node and edge feature tensors of a homogeneous graph.
transform = dgl.FeatMask()
......
......@@ -10,7 +10,7 @@ import scipy.sparse as sp
import backend as F
import itertools
from utils import parametrize_dtype
from test_utils import parametrize_idtype
np.random.seed(42)
......@@ -18,7 +18,7 @@ def toset(x):
# F.zerocopy_to_numpy may return a int
return set(F.zerocopy_to_numpy(x).tolist())
@parametrize_dtype
@parametrize_idtype
def test_bfs(idtype, n=100):
def _bfs_nx(g_nx, src):
edges = nx.bfs_edges(g_nx, src)
......@@ -59,7 +59,7 @@ def test_bfs(idtype, n=100):
assert len(edges_dgl) == len(edges_nx)
assert all(toset(x) == y for x, y in zip(edges_dgl, edges_nx))
@parametrize_dtype
@parametrize_idtype
def test_topological_nodes(idtype, n=100):
a = sp.random(n, n, 3 / n, data_rvs=lambda n: np.ones(n))
b = sp.tril(a, -1).tocoo()
......@@ -86,7 +86,7 @@ def test_topological_nodes(idtype, n=100):
assert all(toset(x) == toset(y) for x, y in zip(layers_dgl, layers_spmv))
DFS_LABEL_NAMES = ['forward', 'reverse', 'nontree']
@parametrize_dtype
@parametrize_idtype
def test_dfs_labeled_edges(idtype, example=False):
dgl_g = dgl.DGLGraph().astype(idtype)
dgl_g.add_nodes(6)
......
......@@ -3,12 +3,6 @@ import backend as F
import dgl
from dgl.base import is_internal_column
if F._default_context_str == 'cpu':
parametrize_dtype = pytest.mark.parametrize("idtype", [F.int32, F.int64])
else:
# only test int32 on GPU because many graph operators are not supported for int64.
parametrize_dtype = pytest.mark.parametrize("idtype", [F.int32, F.int64])
def check_fail(fn, *args, **kwargs):
try:
fn(*args, **kwargs)
......
......@@ -8,7 +8,7 @@ import dgl.nn.mxnet as nn
import dgl.function as fn
import backend as F
from test_utils.graph_cases import get_cases, random_graph, random_bipartite, random_dglgraph
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype
from mxnet import autograd, gluon, nd
def check_close(a, b):
......@@ -19,7 +19,7 @@ def _AXWb(A, X, W, b):
Y = mx.nd.dot(A, X.reshape(X.shape[0], -1)).reshape(X.shape)
return Y + b.data(X.context)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('out_dim', [1, 2])
def test_graph_conv(idtype, out_dim):
g = dgl.from_networkx(nx.path_graph(3))
......@@ -79,7 +79,7 @@ def test_graph_conv(idtype, out_dim):
assert "h" in g.ndata
check_close(g.ndata['h'], 2 * F.ones((3, 1)))
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right', 'left'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -99,7 +99,7 @@ def test_graph_conv2(idtype, g, norm, weight, bias, out_dim):
h_out = conv(g, h, ext_w)
assert h_out.shape == (ndst, out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -161,7 +161,7 @@ def test_tagconv(out_dim):
h1 = conv(g, h0)
assert h1.shape[-1] == out_dim
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 20])
@pytest.mark.parametrize('num_heads', [1, 5])
......@@ -182,7 +182,7 @@ def test_gat_conv(g, idtype, out_dim, num_heads):
gat.initialize(ctx=ctx)
h = gat(g, feat)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -197,7 +197,7 @@ def test_gat_conv_bi(g, idtype, out_dim, num_heads):
_, a = gat(g, feat, True)
assert a.shape == (g.number_of_edges(), num_heads, 1)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite']))
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn'])
@pytest.mark.parametrize('out_dim', [1, 10])
......@@ -210,7 +210,7 @@ def test_sage_conv(idtype, g, aggre_type, out_dim):
h = sage(g, feat)
assert h.shape[-1] == out_dim
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite']))
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn'])
@pytest.mark.parametrize('out_dim', [1, 2])
......@@ -225,7 +225,7 @@ def test_sage_conv_bi(idtype, g, aggre_type, out_dim):
assert h.shape[-1] == out_dim
assert h.shape[0] == g.number_of_dst_nodes()
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn'])
@pytest.mark.parametrize('out_dim', [1, 2])
def test_sage_conv_bi2(idtype, aggre_type, out_dim):
......@@ -275,7 +275,7 @@ def test_cheb_conv(out_dim):
h1 = cheb(g, h0)
assert h1.shape == (20, out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
def test_agnn_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -287,7 +287,7 @@ def test_agnn_conv(g, idtype):
h = agnn_conv(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 10)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
def test_agnn_conv_bi(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -335,7 +335,7 @@ def test_dense_cheb_conv(out_dim):
out_dense_cheb = dense_cheb(adj, feat, 2.0)
assert F.allclose(out_cheb, out_dense_cheb)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('norm_type', ['both', 'right', 'none'])
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
......@@ -356,7 +356,7 @@ def test_dense_graph_conv(idtype, g, norm_type, out_dim):
out_dense_conv = dense_conv(adj, feat)
assert F.allclose(out_conv, out_dense_conv)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'bipartite', 'block-bipartite']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_dense_sage_conv(idtype, g, out_dim):
......@@ -383,7 +383,7 @@ def test_dense_sage_conv(idtype, g, out_dim):
out_dense_sage = dense_sage(adj, feat)
assert F.allclose(out_sage, out_dense_sage)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_edge_conv(g, idtype, out_dim):
......@@ -397,7 +397,7 @@ def test_edge_conv(g, idtype, out_dim):
h1 = edge_conv(g, h0)
assert h1.shape == (g.number_of_dst_nodes(), out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_edge_conv_bi(g, idtype, out_dim):
......@@ -412,7 +412,7 @@ def test_edge_conv_bi(g, idtype, out_dim):
h1 = edge_conv(g, (h0, x0))
assert h1.shape == (g.number_of_dst_nodes(), out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite']))
@pytest.mark.parametrize('aggregator_type', ['mean', 'max', 'sum'])
def test_gin_conv(g, idtype, aggregator_type):
......@@ -428,7 +428,7 @@ def test_gin_conv(g, idtype, aggregator_type):
h = gin_conv(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 5)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite']))
@pytest.mark.parametrize('aggregator_type', ['mean', 'max', 'sum'])
def test_gin_conv_bi(g, idtype, aggregator_type):
......@@ -445,7 +445,7 @@ def test_gin_conv_bi(g, idtype, aggregator_type):
return h.shape == (g.number_of_dst_nodes(), 5)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
def test_gmm_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -457,7 +457,7 @@ def test_gmm_conv(g, idtype):
h1 = gmm_conv(g, h0, pseudo)
assert h1.shape == (g.number_of_dst_nodes(), 2)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
def test_gmm_conv_bi(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -471,7 +471,7 @@ def test_gmm_conv_bi(g, idtype):
h1 = gmm_conv(g, (h0, hd), pseudo)
assert h1.shape == (g.number_of_dst_nodes(), 2)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite']))
def test_nn_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -484,7 +484,7 @@ def test_nn_conv(g, idtype):
h1 = nn_conv(g, h0, etypes)
assert h1.shape == (g.number_of_dst_nodes(), 2)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite']))
def test_nn_conv_bi(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -715,7 +715,7 @@ def myagg(alist, dsttype):
rst = rst + (i + 1) * alist[i]
return rst
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('agg', ['sum', 'max', 'min', 'mean', 'stack', myagg])
def test_hetero_conv(agg, idtype):
g = dgl.heterograph({
......
......@@ -10,7 +10,7 @@ from torch.utils.data import DataLoader
from collections import defaultdict
from collections.abc import Iterator, Mapping
from itertools import product
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype
import pytest
......@@ -128,7 +128,7 @@ def _check_device(data):
else:
assert data.device == F.ctx()
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('sampler_name', ['full', 'neighbor', 'neighbor2'])
@pytest.mark.parametrize('pin_graph', [None, 'cuda_indices', 'cpu_indices'])
def test_node_dataloader(idtype, sampler_name, pin_graph):
......
......@@ -7,7 +7,7 @@ import torch as th
from dgl import DGLError
from dgl.base import DGLWarning
from dgl.geometry import neighbor_matching, farthest_point_sampler
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype
from test_utils.graph_cases import get_cases
......@@ -181,7 +181,7 @@ def test_knn_cuda(algorithm, dist):
g = kg(x_empty, [3, 5], algorithm, dist)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['dglgraph']))
@pytest.mark.parametrize('weight', [True, False])
@pytest.mark.parametrize('relabel', [True, False])
......
......@@ -7,7 +7,7 @@ import dgl.function as fn
import backend as F
import pytest
from test_utils.graph_cases import get_cases, random_graph, random_bipartite, random_dglgraph
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype
from copy import deepcopy
import pickle
......@@ -79,7 +79,7 @@ def test_graph_conv0(out_dim):
new_weight = conv.weight.data
assert not F.allclose(old_weight, new_weight)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'bipartite'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right', 'left'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -99,7 +99,7 @@ def test_graph_conv(idtype, g, norm, weight, bias, out_dim):
h_out = conv(g, h, weight=ext_w)
assert h_out.shape == (ndst, out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['has_scalar_e_feature'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -119,7 +119,7 @@ def test_graph_conv_e_weight(idtype, g, norm, weight, bias, out_dim):
h_out = conv(g, h, weight=ext_w, edge_weight=e_w)
assert h_out.shape == (ndst, out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['has_scalar_e_feature'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -144,7 +144,7 @@ def test_graph_conv_e_weight_norm(idtype, g, norm, weight, bias, out_dim):
h_out = conv(g, h, weight=ext_w, edge_weight=norm_weight)
assert h_out.shape == (ndst, out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -356,7 +356,7 @@ def test_set_trans():
h2 = st_dec(bg, h1)
assert h2.shape[0] == 3 and h2.shape[1] == 200 and h2.dim() == 2
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('O', [1, 8, 32])
def test_rgcn(idtype, O):
ctx = F.ctx()
......@@ -413,7 +413,7 @@ def test_rgcn(idtype, O):
assert h_new.shape == (100, O)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 5])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -437,7 +437,7 @@ def test_gat_conv(g, idtype, out_dim, num_heads):
gat = gat.to(ctx)
h = gat(g, feat)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -452,7 +452,7 @@ def test_gat_conv_bi(g, idtype, out_dim, num_heads):
_, a = gat(g, feat, get_attention=True)
assert a.shape == (g.number_of_edges(), num_heads, 1)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 5])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -476,7 +476,7 @@ def test_gatv2_conv(g, idtype, out_dim, num_heads):
gat = gat.to(ctx)
h = gat(g, feat)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -491,7 +491,7 @@ def test_gatv2_conv_bi(g, idtype, out_dim, num_heads):
_, a = gat(g, feat, get_attention=True)
assert a.shape == (g.number_of_edges(), num_heads, 1)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_node_feats', [1, 5])
@pytest.mark.parametrize('out_edge_feats', [1, 5])
......@@ -513,7 +513,7 @@ def test_egat_conv(g, idtype, out_node_feats, out_edge_feats, num_heads):
th.save(egat, tmp_buffer)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite']))
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn', 'lstm'])
def test_sage_conv(idtype, g, aggre_type):
......@@ -526,7 +526,7 @@ def test_sage_conv(idtype, g, aggre_type):
h = sage(g, feat)
assert h.shape[-1] == 10
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite']))
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn', 'lstm'])
@pytest.mark.parametrize('out_dim', [1, 2])
......@@ -540,7 +540,7 @@ def test_sage_conv_bi(idtype, g, aggre_type, out_dim):
assert h.shape[-1] == out_dim
assert h.shape[0] == g.number_of_dst_nodes()
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('out_dim', [1, 2])
def test_sage_conv2(idtype, out_dim):
# TODO: add test for blocks
......@@ -562,7 +562,7 @@ def test_sage_conv2(idtype, out_dim):
assert h.shape[-1] == out_dim
assert h.shape[0] == 3
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_sgc_conv(g, idtype, out_dim):
......@@ -588,7 +588,7 @@ def test_sgc_conv(g, idtype, out_dim):
assert F.allclose(h_0, h_1)
assert h_0.shape[-1] == out_dim
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_appnp_conv(g, idtype):
ctx = F.ctx()
......@@ -604,7 +604,7 @@ def test_appnp_conv(g, idtype):
assert h.shape[-1] == 5
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_appnp_conv_e_weight(g, idtype):
ctx = F.ctx()
......@@ -617,7 +617,7 @@ def test_appnp_conv_e_weight(g, idtype):
h = appnp(g, feat, edge_weight=eweight)
assert h.shape[-1] == 5
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_gcn2conv_e_weight(g, idtype):
ctx = F.ctx()
......@@ -632,7 +632,7 @@ def test_gcn2conv_e_weight(g, idtype):
assert h.shape[-1] == 5
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_sgconv_e_weight(g, idtype):
ctx = F.ctx()
......@@ -644,7 +644,7 @@ def test_sgconv_e_weight(g, idtype):
h = sgconv(g, feat, edge_weight=eweight)
assert h.shape[-1] == 5
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_tagconv_e_weight(g, idtype):
ctx = F.ctx()
......@@ -657,7 +657,7 @@ def test_tagconv_e_weight(g, idtype):
h = conv(g, feat, edge_weight=eweight)
assert h.shape[-1] == 5
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('aggregator_type', ['mean', 'max', 'sum'])
def test_gin_conv(g, idtype, aggregator_type):
......@@ -682,7 +682,7 @@ def test_gin_conv(g, idtype, aggregator_type):
gin = gin.to(ctx)
h = gin(g, feat)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite']))
def test_gine_conv(g, idtype):
ctx = F.ctx()
......@@ -705,7 +705,7 @@ def test_gine_conv(g, idtype):
gine = gine.to(ctx)
h = gine(g, nfeat, efeat)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('aggregator_type', ['mean', 'max', 'sum'])
def test_gin_conv_bi(g, idtype, aggregator_type):
......@@ -720,7 +720,7 @@ def test_gin_conv_bi(g, idtype, aggregator_type):
h = gin(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 12)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
def test_agnn_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -731,7 +731,7 @@ def test_agnn_conv(g, idtype):
h = agnn(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 5)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
def test_agnn_conv_bi(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -742,7 +742,7 @@ def test_agnn_conv_bi(g, idtype):
h = agnn(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 5)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_gated_graph_conv(g, idtype):
ctx = F.ctx()
......@@ -757,7 +757,7 @@ def test_gated_graph_conv(g, idtype):
# current we only do shape check
assert h.shape[-1] == 10
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_gated_graph_conv_one_etype(g, idtype):
ctx = F.ctx()
......@@ -774,7 +774,7 @@ def test_gated_graph_conv_one_etype(g, idtype):
assert F.allclose(h, h2)
assert h.shape[-1] == 10
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
def test_nn_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -788,7 +788,7 @@ def test_nn_conv(g, idtype):
# currently we only do shape check
assert h.shape[-1] == 10
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
def test_nn_conv_bi(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -803,7 +803,7 @@ def test_nn_conv_bi(g, idtype):
# currently we only do shape check
assert h.shape[-1] == 10
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_gmm_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -816,7 +816,7 @@ def test_gmm_conv(g, idtype):
# currently we only do shape check
assert h.shape[-1] == 10
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite', 'block-bipartite'], exclude=['zero-degree']))
def test_gmm_conv_bi(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -830,7 +830,7 @@ def test_gmm_conv_bi(g, idtype):
# currently we only do shape check
assert h.shape[-1] == 10
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('norm_type', ['both', 'right', 'none'])
@pytest.mark.parametrize('g', get_cases(['homo', 'bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
......@@ -850,7 +850,7 @@ def test_dense_graph_conv(norm_type, g, idtype, out_dim):
out_dense_conv = dense_conv(adj, feat)
assert F.allclose(out_conv, out_dense_conv)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'bipartite']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_dense_sage_conv(g, idtype, out_dim):
......@@ -874,7 +874,7 @@ def test_dense_sage_conv(g, idtype, out_dim):
out_dense_sage = dense_sage(adj, feat)
assert F.allclose(out_sage, out_dense_sage), g
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_edge_conv(g, idtype, out_dim):
......@@ -890,7 +890,7 @@ def test_edge_conv(g, idtype, out_dim):
h1 = edge_conv(g, h0)
assert h1.shape == (g.number_of_dst_nodes(), out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_edge_conv_bi(g, idtype, out_dim):
......@@ -903,7 +903,7 @@ def test_edge_conv_bi(g, idtype, out_dim):
h1 = edge_conv(g, (h0, x0))
assert h1.shape == (g.number_of_dst_nodes(), out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -922,7 +922,7 @@ def test_dotgat_conv(g, idtype, out_dim, num_heads):
_, a = dotgat(g, feat, get_attention=True)
assert a.shape == (g.number_of_edges(), num_heads, 1)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -1008,7 +1008,7 @@ def test_sequential():
n_feat = net([g1, g2, g3], n_feat)
assert n_feat.shape == (4, 4)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_atomic_conv(g, idtype):
g = g.astype(idtype).to(F.ctx())
......@@ -1029,7 +1029,7 @@ def test_atomic_conv(g, idtype):
# current we only do shape check
assert h.shape[-1] == 4
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 3])
def test_cf_conv(g, idtype, out_dim):
......@@ -1061,7 +1061,7 @@ def myagg(alist, dsttype):
rst = rst + (i + 1) * alist[i]
return rst
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('agg', ['sum', 'max', 'min', 'mean', 'stack', myagg])
def test_hetero_conv(agg, idtype):
g = dgl.heterograph({
......@@ -1186,7 +1186,7 @@ def test_hetero_embedding(out_dim):
assert embeds['user'].shape == (1, out_dim)
assert embeds[('user', 'follows', 'user')].shape == (2, out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_gnnexplainer(g, idtype, out_dim):
......@@ -1317,7 +1317,7 @@ def test_typed_linear(feat_size, regularizer, num_bases):
assert th.allclose(y, y_sorted[rev_idx], atol=1e-4, rtol=1e-4)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('in_size', [4])
@pytest.mark.parametrize('num_heads', [1])
def test_hgt(idtype, in_size, num_heads):
......@@ -1433,7 +1433,7 @@ def test_radius_graph(self_loop, get_distances):
if get_distances:
assert th.allclose(dists, dists_target, rtol=1e-03)
@parametrize_dtype
@parametrize_idtype
def test_group_rev_res(idtype):
dev = F.ctx()
......
......@@ -7,7 +7,7 @@ import dgl.nn.tensorflow as nn
import dgl.function as fn
import backend as F
from test_utils.graph_cases import get_cases, random_graph, random_bipartite, random_dglgraph
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype
from copy import deepcopy
import numpy as np
......@@ -72,7 +72,7 @@ def test_graph_conv(out_dim):
# new_weight = conv.weight.data
# assert not F.allclose(old_weight, new_weight)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right', 'left'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -92,7 +92,7 @@ def test_graph_conv2(idtype, g, norm, weight, bias, out_dim):
h_out = conv(g, h, weight=ext_w)
assert h_out.shape == (ndst, out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree', 'dglgraph']))
@pytest.mark.parametrize('norm', ['none', 'both', 'right'])
@pytest.mark.parametrize('weight', [True, False])
......@@ -262,7 +262,7 @@ def test_rgcn(O):
assert list(h_new_low.shape) == [100, O]
assert F.allclose(h_new, h_new_low)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -280,7 +280,7 @@ def test_gat_conv(g, idtype, out_dim, num_heads):
gat = nn.GATConv(5, out_dim, num_heads, residual=True)
h = gat(g, feat)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
@pytest.mark.parametrize('num_heads', [1, 4])
......@@ -294,7 +294,7 @@ def test_gat_conv_bi(g, idtype, out_dim, num_heads):
_, a = gat(g, feat, get_attention=True)
assert a.shape == (g.number_of_edges(), num_heads, 1)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite']))
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn'])
@pytest.mark.parametrize('out_dim', [1, 10])
......@@ -305,7 +305,7 @@ def test_sage_conv(idtype, g, aggre_type, out_dim):
h = sage(g, feat)
assert h.shape[-1] == out_dim
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite']))
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn'])
@pytest.mark.parametrize('out_dim', [1, 2])
......@@ -318,7 +318,7 @@ def test_sage_conv_bi(idtype, g, aggre_type, out_dim):
assert h.shape[-1] == out_dim
assert h.shape[0] == g.number_of_dst_nodes()
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('aggre_type', ['mean', 'pool', 'gcn'])
@pytest.mark.parametrize('out_dim', [1, 2])
def test_sage_conv_bi_empty(idtype, aggre_type, out_dim):
......@@ -337,7 +337,7 @@ def test_sage_conv_bi_empty(idtype, aggre_type, out_dim):
assert h.shape[-1] == out_dim
assert h.shape[0] == 3
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_sgc_conv(g, idtype, out_dim):
......@@ -357,7 +357,7 @@ def test_sgc_conv(g, idtype, out_dim):
assert F.allclose(h_0, h_1)
assert h_0.shape[-1] == out_dim
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo'], exclude=['zero-degree']))
def test_appnp_conv(g, idtype):
ctx = F.ctx()
......@@ -368,7 +368,7 @@ def test_appnp_conv(g, idtype):
h = appnp(g, feat)
assert h.shape[-1] == 5
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite']))
@pytest.mark.parametrize('aggregator_type', ['mean', 'max', 'sum'])
def test_gin_conv(g, idtype, aggregator_type):
......@@ -382,7 +382,7 @@ def test_gin_conv(g, idtype, aggregator_type):
h = gin(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 12)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite']))
@pytest.mark.parametrize('aggregator_type', ['mean', 'max', 'sum'])
def test_gin_conv_bi(g, idtype, aggregator_type):
......@@ -395,7 +395,7 @@ def test_gin_conv_bi(g, idtype, aggregator_type):
h = gin(g, feat)
assert h.shape == (g.number_of_dst_nodes(), 12)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['homo', 'block-bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_edge_conv(g, idtype, out_dim):
......@@ -406,7 +406,7 @@ def test_edge_conv(g, idtype, out_dim):
h1 = edge_conv(g, h0)
assert h1.shape == (g.number_of_dst_nodes(), out_dim)
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('g', get_cases(['bipartite'], exclude=['zero-degree']))
@pytest.mark.parametrize('out_dim', [1, 2])
def test_edge_conv_bi(g, idtype, out_dim):
......@@ -425,7 +425,7 @@ def myagg(alist, dsttype):
rst = rst + (i + 1) * alist[i]
return rst
@parametrize_dtype
@parametrize_idtype
@pytest.mark.parametrize('agg', ['sum', 'max', 'min', 'mean', 'stack', myagg])
def test_hetero_conv(agg, idtype):
g = dgl.heterograph({
......
import pytest
import backend as F
if F._default_context_str == 'cpu':
parametrize_dtype = pytest.mark.parametrize("idtype", [F.int32, F.int64])
else:
# only test int32 on GPU because many graph operators are not supported for int64.
parametrize_dtype = pytest.mark.parametrize("idtype", [F.int32, F.int64])
parametrize_idtype = pytest.mark.parametrize("idtype", [F.int32, F.int64])
from .checks import *
from .graph_cases import get_cases
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