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

Function test_adj_external

tests/python/common/test_heterograph.py:728–764  ·  view source on GitHub ↗
(idtype)

Source from the content-addressed store, hash-verified

726
727@parametrize_idtype
728def test_adj_external(idtype):
729 g = create_test_heterograph(idtype)
730 adj = F.sparse_to_numpy(g.adj_external(transpose=True, etype="follows"))
731 assert np.allclose(
732 adj, np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
733 )
734 adj = F.sparse_to_numpy(g.adj_external(transpose=False, etype="follows"))
735 assert np.allclose(
736 adj, np.array([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 0.0]])
737 )
738 adj = F.sparse_to_numpy(g.adj_external(transpose=True, etype="plays"))
739 assert np.allclose(adj, np.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0]]))
740 adj = F.sparse_to_numpy(g.adj_external(transpose=False, etype="plays"))
741 assert np.allclose(adj, np.array([[1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]))
742
743 adj = g.adj_external(transpose=True, scipy_fmt="csr", etype="follows")
744 assert np.allclose(
745 adj.todense(),
746 np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]),
747 )
748 adj = g.adj_external(transpose=True, scipy_fmt="coo", etype="follows")
749 assert np.allclose(
750 adj.todense(),
751 np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]),
752 )
753 adj = g.adj_external(transpose=True, scipy_fmt="csr", etype="plays")
754 assert np.allclose(
755 adj.todense(), np.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0]])
756 )
757 adj = g.adj_external(transpose=True, scipy_fmt="coo", etype="plays")
758 assert np.allclose(
759 adj.todense(), np.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0]])
760 )
761 adj = F.sparse_to_numpy(g["follows"].adj_external(transpose=True))
762 assert np.allclose(
763 adj, np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
764 )
765
766
767@parametrize_idtype

Callers

nothing calls this directly

Calls 2

adj_externalMethod · 0.80
create_test_heterographFunction · 0.70

Tested by

no test coverage detected