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

Function test_graph_serialize_with_labels

tests/python/common/data/test_serialize.py:107–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

105
106@unittest.skipIf(F._default_context_str == "gpu", reason="GPU not implemented")
107def test_graph_serialize_with_labels():
108 num_graphs = 100
109 g_list = [generate_rand_graph(30) for _ in range(num_graphs)]
110 labels = {"label": F.zeros((num_graphs, 1))}
111
112 # create a temporary file and immediately release it so DGL can open it.
113 f = tempfile.NamedTemporaryFile(delete=False)
114 path = f.name
115 f.close()
116
117 dgl.save_graphs(path, g_list, labels)
118
119 idx_list = np.random.permutation(np.arange(num_graphs)).tolist()
120 loadg_list, l_labels0 = dgl.load_graphs(path, idx_list)
121 l_labels = load_labels(path)
122 assert F.allclose(l_labels["label"], labels["label"])
123 assert F.allclose(l_labels0["label"], labels["label"])
124
125 idx = idx_list[0]
126 load_g = loadg_list[0]
127
128 assert F.allclose(load_g.nodes(), g_list[idx].nodes())
129
130 load_edges = load_g.all_edges("uv", "eid")
131 g_edges = g_list[idx].all_edges("uv", "eid")
132 assert F.allclose(load_edges[0], g_edges[0])
133 assert F.allclose(load_edges[1], g_edges[1])
134
135 os.unlink(path)
136
137
138def test_serialize_tensors():

Callers

nothing calls this directly

Calls 5

generate_rand_graphFunction · 0.85
load_labelsFunction · 0.85
all_edgesMethod · 0.80
closeMethod · 0.45
nodesMethod · 0.45

Tested by

no test coverage detected