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

Function test_remove_edges

tests/python/common/transforms/test_transform.py:1130–1203  ·  view source on GitHub ↗
(idtype)

Source from the content-addressed store, hash-verified

1128@unittest.skipIf(F._default_context_str == "gpu", reason="GPU not implemented")
1129@parametrize_idtype
1130def test_remove_edges(idtype):
1131 def check(g1, etype, g, edges_removed):
1132 src, dst, eid = g.edges(etype=etype, form="all")
1133 src1, dst1 = g1.edges(etype=etype, order="eid")
1134 if etype is not None:
1135 eid1 = g1.edges[etype].data[dgl.EID]
1136 else:
1137 eid1 = g1.edata[dgl.EID]
1138 src1 = F.asnumpy(src1)
1139 dst1 = F.asnumpy(dst1)
1140 eid1 = F.asnumpy(eid1)
1141 src = F.asnumpy(src)
1142 dst = F.asnumpy(dst)
1143 eid = F.asnumpy(eid)
1144 sde_set = set(zip(src, dst, eid))
1145
1146 for s, d, e in zip(src1, dst1, eid1):
1147 assert (s, d, e) in sde_set
1148 assert not np.isin(edges_removed, eid1).any()
1149 assert g1.idtype == g.idtype
1150
1151 for fmt in ["coo", "csr", "csc"]:
1152 for edges_to_remove in [[2], [2, 2], [3, 2], [1, 3, 1, 2]]:
1153 g = dgl.graph(([0, 2, 1, 3], [1, 3, 2, 4]), idtype=idtype).formats(
1154 fmt
1155 )
1156 g1 = dgl.remove_edges(g, F.tensor(edges_to_remove, idtype))
1157 check(g1, None, g, edges_to_remove)
1158
1159 g = dgl.from_scipy(
1160 spsp.csr_matrix(
1161 ([1, 1, 1, 1], ([0, 2, 1, 3], [1, 3, 2, 4])), shape=(5, 5)
1162 ),
1163 idtype=idtype,
1164 ).formats(fmt)
1165 g1 = dgl.remove_edges(g, F.tensor(edges_to_remove, idtype))
1166 check(g1, None, g, edges_to_remove)
1167
1168 g = dgl.heterograph(
1169 {
1170 ("A", "AA", "A"): ([0, 2, 1, 3], [1, 3, 2, 4]),
1171 ("A", "AB", "B"): ([0, 1, 3, 1], [1, 3, 5, 6]),
1172 ("B", "BA", "A"): ([2, 3], [3, 2]),
1173 },
1174 idtype=idtype,
1175 )
1176 g2 = dgl.remove_edges(
1177 g,
1178 {
1179 "AA": F.tensor([2], idtype),
1180 "AB": F.tensor([3], idtype),
1181 "BA": F.tensor([1], idtype),
1182 },
1183 )
1184 check(g2, "AA", g, [2])
1185 check(g2, "AB", g, [3])
1186 check(g2, "BA", g, [1])
1187

Callers

nothing calls this directly

Calls 11

remove_edgesMethod · 0.80
batch_num_nodesMethod · 0.80
batch_num_edgesMethod · 0.80
checkFunction · 0.70
create_test_heterograph3Function · 0.70
formatsMethod · 0.45
graphMethod · 0.45
ctxMethod · 0.45
num_edgesMethod · 0.45
edgesMethod · 0.45
copy_toMethod · 0.45

Tested by

no test coverage detected