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

Function test_level2

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

Source from the content-addressed store, hash-verified

1843
1844@parametrize_idtype
1845def test_level2(idtype):
1846 # edges = {
1847 # 'follows': ([0, 1], [1, 2]),
1848 # 'plays': ([0, 1, 2, 1], [0, 0, 1, 1]),
1849 # 'wishes': ([0, 2], [1, 0]),
1850 # 'develops': ([0, 1], [0, 1]),
1851 # }
1852 g = create_test_heterograph(idtype)
1853
1854 def rfunc(nodes):
1855 return {"y": F.sum(nodes.mailbox["m"], 1)}
1856
1857 def rfunc2(nodes):
1858 return {"y": F.max(nodes.mailbox["m"], 1)}
1859
1860 def mfunc(edges):
1861 return {"m": edges.src["h"]}
1862
1863 def afunc(nodes):
1864 return {"y": nodes.data["y"] + 1}
1865
1866 #############################################################
1867 # send_and_recv
1868 #############################################################
1869
1870 g.nodes["user"].data["h"] = F.ones((3, 2))
1871 g.send_and_recv([2, 3], mfunc, rfunc, etype="plays")
1872 y = g.nodes["game"].data["y"]
1873 assert F.array_equal(y, F.tensor([[0.0, 0.0], [2.0, 2.0]]))
1874
1875 # only one type
1876 g["plays"].send_and_recv([2, 3], mfunc, rfunc)
1877 y = g.nodes["game"].data["y"]
1878 assert F.array_equal(y, F.tensor([[0.0, 0.0], [2.0, 2.0]]))
1879
1880 # test fail case
1881 # fail due to multiple types
1882 with pytest.raises(DGLError):
1883 g.send_and_recv([2, 3], mfunc, rfunc)
1884
1885 g.nodes["game"].data.clear()
1886
1887 #############################################################
1888 # pull
1889 #############################################################
1890
1891 g.nodes["user"].data["h"] = F.ones((3, 2))
1892 g.pull(1, mfunc, rfunc, etype="plays")
1893 y = g.nodes["game"].data["y"]
1894 assert F.array_equal(y, F.tensor([[0.0, 0.0], [2.0, 2.0]]))
1895
1896 # only one type
1897 g["plays"].pull(1, mfunc, rfunc)
1898 y = g.nodes["game"].data["y"]
1899 assert F.array_equal(y, F.tensor([[0.0, 0.0], [2.0, 2.0]]))
1900
1901 # test fail case
1902 with pytest.raises(DGLError):

Callers

nothing calls this directly

Calls 7

get_redfnFunction · 0.85
send_and_recvMethod · 0.80
update_allMethod · 0.80
multi_update_allMethod · 0.80
create_test_heterographFunction · 0.70
clearMethod · 0.45
pullMethod · 0.45

Tested by

no test coverage detected