MCPcopy
hub / github.com/dmlc/dgl / check_random_walk

Function check_random_walk

tests/python/common/sampling/test_sampling.py:16–38  ·  view source on GitHub ↗
(g, metapath, traces, ntypes, prob=None, trace_eids=None)

Source from the content-addressed store, hash-verified

14
15
16def check_random_walk(g, metapath, traces, ntypes, prob=None, trace_eids=None):
17 traces = F.asnumpy(traces)
18 ntypes = F.asnumpy(ntypes)
19 for j in range(traces.shape[1] - 1):
20 assert ntypes[j] == g.get_ntype_id(g.to_canonical_etype(metapath[j])[0])
21 assert ntypes[j + 1] == g.get_ntype_id(
22 g.to_canonical_etype(metapath[j])[2]
23 )
24
25 for i in range(traces.shape[0]):
26 for j in range(traces.shape[1] - 1):
27 assert g.has_edges_between(
28 traces[i, j], traces[i, j + 1], etype=metapath[j]
29 )
30 if prob is not None and prob in g.edges[metapath[j]].data:
31 p = F.asnumpy(g.edges[metapath[j]].data["p"])
32 eids = g.edge_ids(
33 traces[i, j], traces[i, j + 1], etype=metapath[j]
34 )
35 assert p[eids] != 0
36 if trace_eids is not None:
37 u, v = g.find_edges(trace_eids[i, j], etype=metapath[j])
38 assert (u == traces[i, j]) and (v == traces[i, j + 1])
39
40
41@pytest.mark.parametrize("use_uva", [True, False])

Callers 3

test_uniform_random_walkFunction · 0.85
test_node2vecFunction · 0.85

Calls 6

asnumpyMethod · 0.80
get_ntype_idMethod · 0.45
to_canonical_etypeMethod · 0.45
has_edges_betweenMethod · 0.45
edge_idsMethod · 0.45
find_edgesMethod · 0.45

Tested by

no test coverage detected