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

Function test_line_graph2

tests/python/common/transforms/test_transform.py:141–183  ·  view source on GitHub ↗
(idtype)

Source from the content-addressed store, hash-verified

139
140@parametrize_idtype
141def test_line_graph2(idtype):
142 g = dgl.heterograph(
143 {("user", "follows", "user"): ([0, 1, 1, 2, 2], [2, 0, 2, 0, 1])},
144 idtype=idtype,
145 )
146 lg = dgl.line_graph(g)
147 assert lg.num_nodes() == 5
148 assert lg.num_edges() == 8
149 row, col = lg.edges()
150 assert np.array_equal(F.asnumpy(row), np.array([0, 0, 1, 2, 2, 3, 4, 4]))
151 assert np.array_equal(F.asnumpy(col), np.array([3, 4, 0, 3, 4, 0, 1, 2]))
152
153 lg = dgl.line_graph(g, backtracking=False)
154 assert lg.num_nodes() == 5
155 assert lg.num_edges() == 4
156 row, col = lg.edges()
157 assert np.array_equal(F.asnumpy(row), np.array([0, 1, 2, 4]))
158 assert np.array_equal(F.asnumpy(col), np.array([4, 0, 3, 1]))
159 g = dgl.heterograph(
160 {("user", "follows", "user"): ([0, 1, 1, 2, 2], [2, 0, 2, 0, 1])},
161 idtype=idtype,
162 ).formats("csr")
163 lg = dgl.line_graph(g)
164 assert lg.num_nodes() == 5
165 assert lg.num_edges() == 8
166 row, col = lg.edges()
167 assert np.array_equal(F.asnumpy(row), np.array([0, 0, 1, 2, 2, 3, 4, 4]))
168 assert np.array_equal(F.asnumpy(col), np.array([3, 4, 0, 3, 4, 0, 1, 2]))
169
170 g = dgl.heterograph(
171 {("user", "follows", "user"): ([0, 1, 1, 2, 2], [2, 0, 2, 0, 1])},
172 idtype=idtype,
173 ).formats("csc")
174 lg = dgl.line_graph(g)
175 assert lg.num_nodes() == 5
176 assert lg.num_edges() == 8
177 row, col, eid = lg.edges("all")
178 row = F.asnumpy(row)
179 col = F.asnumpy(col)
180 eid = F.asnumpy(eid).astype(int)
181 order = np.argsort(eid)
182 assert np.array_equal(row[order], np.array([0, 0, 1, 2, 2, 3, 4, 4]))
183 assert np.array_equal(col[order], np.array([3, 4, 0, 3, 4, 0, 1, 2]))
184
185
186def test_no_backtracking():

Callers

nothing calls this directly

Calls 7

line_graphMethod · 0.80
asnumpyMethod · 0.80
num_nodesMethod · 0.45
num_edgesMethod · 0.45
edgesMethod · 0.45
formatsMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected