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

Function _random_simple_graph

tests/python/common/test_sparse_ops-csr.py:15–41  ·  view source on GitHub ↗
(
    idtype, dtype, ctx, M, N, max_nnz, srctype, dsttype, etype
)

Source from the content-addressed store, hash-verified

13
14
15def _random_simple_graph(
16 idtype, dtype, ctx, M, N, max_nnz, srctype, dsttype, etype
17):
18 src = np.random.randint(0, M, (max_nnz,))
19 dst = np.random.randint(0, N, (max_nnz,))
20 val = np.random.randn(max_nnz)
21 a = ssp.csr_matrix((val, (src, dst)), shape=(M, N))
22 a.sum_duplicates()
23 a = a.tocoo()
24 # shuffle edges
25 perm = np.random.permutation(a.nnz)
26 row = a.row[perm]
27 col = a.col[perm]
28 val = a.data[perm]
29 a = ssp.csr_matrix((val, (row, col)), shape=(M, N))
30
31 A = dgl.heterograph(
32 {
33 (srctype, etype, dsttype): (
34 F.copy_to(F.tensor(row, dtype=idtype), ctx),
35 F.copy_to(F.tensor(col, dtype=idtype), ctx),
36 )
37 },
38 num_nodes_dict={srctype: a.shape[0], dsttype: a.shape[1]},
39 )
40 A.edata["w"] = F.copy_to(F.tensor(val, dtype=dtype), ctx)
41 return a, A
42
43
44@parametrize_idtype

Callers 6

test_csrmmFunction · 0.85
test_csrmm_backwardFunction · 0.85
test_csrsumFunction · 0.85
test_csrsum_backwardFunction · 0.85
test_csrmaskFunction · 0.85
test_csrmask_backwardFunction · 0.85

Calls 1

copy_toMethod · 0.45

Tested by

no test coverage detected