MCPcopy Index your code
hub / github.com/dmlc/dgl / generate_graph

Function generate_graph

tests/python/common/cuda/test_gpu_cache.py:27–49  ·  view source on GitHub ↗
(idtype, grad=False, add_data=True)

Source from the content-addressed store, hash-verified

25
26
27def generate_graph(idtype, grad=False, add_data=True):
28 g = dgl.graph([]).to(F.ctx(), dtype=idtype)
29 g.add_nodes(10)
30 u, v = [], []
31 # create a graph where 0 is the source and 9 is the sink
32 for i in range(1, 9):
33 u.append(0)
34 v.append(i)
35 u.append(i)
36 v.append(9)
37 # add a back flow from 9 to 0
38 u.append(9)
39 v.append(0)
40 g.add_edges(u, v)
41 if add_data:
42 ncol = F.randn((10, D))
43 ecol = F.randn((17, D))
44 if grad:
45 ncol = F.attach_grad(ncol)
46 ecol = F.attach_grad(ecol)
47 g.ndata["h"] = ncol
48 g.edata["l"] = ecol
49 return g
50
51
52@unittest.skipIf(not F.gpu_ctx(), reason="only necessary with GPU")

Callers 1

test_gpu_cacheFunction · 0.70

Calls 6

appendMethod · 0.80
toMethod · 0.45
graphMethod · 0.45
ctxMethod · 0.45
add_nodesMethod · 0.45
add_edgesMethod · 0.45

Tested by

no test coverage detected