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

Function _check_nx_feature

tests/python/common/function/test_basics.py:203–230  ·  view source on GitHub ↗
(nxg, nf, ef)

Source from the content-addressed store, hash-verified

201 # check conversion between networkx and DGLGraph
202
203 def _check_nx_feature(nxg, nf, ef):
204 # check node and edge feature of nxg
205 # this is used to check to_networkx
206 num_nodes = len(nxg)
207 num_edges = nxg.size()
208 if num_nodes > 0:
209 node_feat = ddict(list)
210 for nid, attr in nxg.nodes(data=True):
211 assert len(attr) == len(nf)
212 for k in nxg.nodes[nid]:
213 node_feat[k].append(F.unsqueeze(attr[k], 0))
214 for k in node_feat:
215 feat = F.cat(node_feat[k], 0)
216 assert F.allclose(feat, nf[k])
217 else:
218 assert len(nf) == 0
219 if num_edges > 0:
220 edge_feat = ddict(lambda: [0] * num_edges)
221 for u, v, attr in nxg.edges(data=True):
222 assert len(attr) == len(ef) + 1 # extra id
223 eid = attr["id"]
224 for k in ef:
225 edge_feat[k][eid] = F.unsqueeze(attr[k], 0)
226 for k in edge_feat:
227 feat = F.cat(edge_feat[k], 0)
228 assert F.allclose(feat, ef[k])
229 else:
230 assert len(ef) == 0
231
232 n1 = F.randn((5, 3))
233 n2 = F.randn((5, 10))

Callers 1

_test_nx_conversionFunction · 0.85

Calls 4

appendMethod · 0.80
sizeMethod · 0.45
nodesMethod · 0.45
edgesMethod · 0.45

Tested by

no test coverage detected