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

Function test_incmat

tests/python/common/test_heterograph-misc.py:311–357  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

309
310
311def test_incmat():
312 g = dgl.graph([])
313 g.add_nodes(4)
314 g.add_edges(0, 1) # 0
315 g.add_edges(0, 2) # 1
316 g.add_edges(0, 3) # 2
317 g.add_edges(2, 3) # 3
318 g.add_edges(1, 1) # 4
319 inc_in = F.sparse_to_numpy(g.incidence_matrix("in"))
320 inc_out = F.sparse_to_numpy(g.incidence_matrix("out"))
321 inc_both = F.sparse_to_numpy(g.incidence_matrix("both"))
322 print(inc_in)
323 print(inc_out)
324 print(inc_both)
325 assert np.allclose(
326 inc_in,
327 np.array(
328 [
329 [0.0, 0.0, 0.0, 0.0, 0.0],
330 [1.0, 0.0, 0.0, 0.0, 1.0],
331 [0.0, 1.0, 0.0, 0.0, 0.0],
332 [0.0, 0.0, 1.0, 1.0, 0.0],
333 ]
334 ),
335 )
336 assert np.allclose(
337 inc_out,
338 np.array(
339 [
340 [1.0, 1.0, 1.0, 0.0, 0.0],
341 [0.0, 0.0, 0.0, 0.0, 1.0],
342 [0.0, 0.0, 0.0, 1.0, 0.0],
343 [0.0, 0.0, 0.0, 0.0, 0.0],
344 ]
345 ),
346 )
347 assert np.allclose(
348 inc_both,
349 np.array(
350 [
351 [-1.0, -1.0, -1.0, 0.0, 0.0],
352 [1.0, 0.0, 0.0, 0.0, 0.0],
353 [0.0, 1.0, 0.0, -1.0, 0.0],
354 [0.0, 0.0, 1.0, 1.0, 0.0],
355 ]
356 ),
357 )
358
359
360def test_find_edges():

Callers 1

Calls 4

graphMethod · 0.45
add_nodesMethod · 0.45
add_edgesMethod · 0.45
incidence_matrixMethod · 0.45

Tested by

no test coverage detected