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

Function test_view

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

Source from the content-addressed store, hash-verified

790
791@parametrize_idtype
792def test_view(idtype):
793 # test single node type
794 g = dgl.heterograph(
795 {("user", "follows", "user"): ([0, 1], [1, 2])},
796 idtype=idtype,
797 device=F.ctx(),
798 )
799 f1 = F.randn((3, 6))
800 g.ndata["h"] = f1
801 f2 = g.nodes["user"].data["h"]
802 assert F.array_equal(f1, f2)
803 fail = False
804 try:
805 g.ndata["h"] = {"user": f1}
806 except Exception:
807 fail = True
808 assert fail
809
810 # test single edge type
811 f3 = F.randn((2, 4))
812 g.edata["h"] = f3
813 f4 = g.edges["follows"].data["h"]
814 assert F.array_equal(f3, f4)
815 fail = False
816 try:
817 g.edata["h"] = {"follows": f3}
818 except Exception:
819 fail = True
820 assert fail
821
822 # test data view
823 g = create_test_heterograph(idtype)
824
825 f1 = F.randn((3, 6))
826 g.nodes["user"].data["h"] = f1 # ok
827 f2 = g.nodes["user"].data["h"]
828 assert F.array_equal(f1, f2)
829 assert F.array_equal(g.nodes("user"), F.arange(0, 3, idtype))
830 g.nodes["user"].data.pop("h")
831
832 # multi type ndata
833 f1 = F.randn((3, 6))
834 f2 = F.randn((2, 6))
835 fail = False
836 try:
837 g.ndata["h"] = f1
838 except Exception:
839 fail = True
840 assert fail
841
842 f3 = F.randn((2, 4))
843 g.edges["user", "follows", "user"].data["h"] = f3
844 f4 = g.edges["user", "follows", "user"].data["h"]
845 f5 = g.edges["follows"].data["h"]
846 assert F.array_equal(f3, f4)
847 assert F.array_equal(f3, f5)
848 assert F.array_equal(
849 g.edges(etype="follows", form="eid"), F.arange(0, 2, idtype)

Callers

nothing calls this directly

Calls 6

srcnodesMethod · 0.80
dstnodesMethod · 0.80
create_test_heterographFunction · 0.70
ctxMethod · 0.45
nodesMethod · 0.45
edgesMethod · 0.45

Tested by

no test coverage detected