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

Function test_batch_setter_getter

tests/python/common/function/test_basics.py:100–179  ·  view source on GitHub ↗
(idtype)

Source from the content-addressed store, hash-verified

98
99@parametrize_idtype
100def test_batch_setter_getter(idtype):
101 def _pfc(x):
102 return list(F.zerocopy_to_numpy(x)[:, 0])
103
104 g = generate_graph(idtype)
105 # set all nodes
106 g.ndata["h"] = F.zeros((10, D))
107 assert F.allclose(g.ndata["h"], F.zeros((10, D)))
108 # pop nodes
109 old_len = len(g.ndata)
110 g.ndata.pop("h")
111 assert len(g.ndata) == old_len - 1
112 g.ndata["h"] = F.zeros((10, D))
113 # set partial nodes
114 u = F.tensor([1, 3, 5], g.idtype)
115 g.nodes[u].data["h"] = F.ones((3, D))
116 assert _pfc(g.ndata["h"]) == [
117 0.0,
118 1.0,
119 0.0,
120 1.0,
121 0.0,
122 1.0,
123 0.0,
124 0.0,
125 0.0,
126 0.0,
127 ]
128 # get partial nodes
129 u = F.tensor([1, 2, 3], g.idtype)
130 assert _pfc(g.nodes[u].data["h"]) == [1.0, 0.0, 1.0]
131
132 """
133 s, d, eid
134 0, 1, 0
135 1, 9, 1
136 0, 2, 2
137 2, 9, 3
138 0, 3, 4
139 3, 9, 5
140 0, 4, 6
141 4, 9, 7
142 0, 5, 8
143 5, 9, 9
144 0, 6, 10
145 6, 9, 11
146 0, 7, 12
147 7, 9, 13
148 0, 8, 14
149 8, 9, 15
150 9, 0, 16
151 """
152 # set all edges
153 g.edata["l"] = F.zeros((17, D))
154 assert _pfc(g.edata["l"]) == [0.0] * 17
155 # pop edges
156 old_len = len(g.edata)
157 g.edata.pop("l")

Callers

nothing calls this directly

Calls 2

_pfcFunction · 0.85
generate_graphFunction · 0.70

Tested by

no test coverage detected