(idtype)
| 235 | |
| 236 | @parametrize_idtype |
| 237 | def test_subgraph1(idtype): |
| 238 | g = create_test_heterograph(idtype) |
| 239 | g_graph = g["follows"] |
| 240 | g_bipartite = g["plays"] |
| 241 | |
| 242 | x = F.randn((3, 5)) |
| 243 | y = F.randn((2, 4)) |
| 244 | g.nodes["user"].data["h"] = x |
| 245 | g.edges["follows"].data["h"] = y |
| 246 | |
| 247 | def _check_subgraph(g, sg): |
| 248 | assert sg.idtype == g.idtype |
| 249 | assert sg.device == g.device |
| 250 | assert sg.ntypes == g.ntypes |
| 251 | assert sg.etypes == g.etypes |
| 252 | assert sg.canonical_etypes == g.canonical_etypes |
| 253 | assert F.array_equal( |
| 254 | F.tensor(sg.nodes["user"].data[dgl.NID]), F.tensor([1, 2], g.idtype) |
| 255 | ) |
| 256 | assert F.array_equal( |
| 257 | F.tensor(sg.nodes["game"].data[dgl.NID]), F.tensor([0], g.idtype) |
| 258 | ) |
| 259 | assert F.array_equal( |
| 260 | F.tensor(sg.edges["follows"].data[dgl.EID]), F.tensor([1], g.idtype) |
| 261 | ) |
| 262 | assert F.array_equal( |
| 263 | F.tensor(sg.edges["plays"].data[dgl.EID]), F.tensor([1], g.idtype) |
| 264 | ) |
| 265 | assert F.array_equal( |
| 266 | F.tensor(sg.edges["wishes"].data[dgl.EID]), F.tensor([1], g.idtype) |
| 267 | ) |
| 268 | assert sg.num_nodes("developer") == 0 |
| 269 | assert sg.num_edges("develops") == 0 |
| 270 | assert F.array_equal( |
| 271 | sg.nodes["user"].data["h"], g.nodes["user"].data["h"][1:3] |
| 272 | ) |
| 273 | assert F.array_equal( |
| 274 | sg.edges["follows"].data["h"], g.edges["follows"].data["h"][1:2] |
| 275 | ) |
| 276 | |
| 277 | sg1 = g.subgraph({"user": [1, 2], "game": [0]}) |
| 278 | _check_subgraph(g, sg1) |
| 279 | sg2 = g.edge_subgraph({"follows": [1], "plays": [1], "wishes": [1]}) |
| 280 | _check_subgraph(g, sg2) |
| 281 | |
| 282 | # backend tensor input |
| 283 | sg1 = g.subgraph( |
| 284 | { |
| 285 | "user": F.tensor([1, 2], dtype=idtype), |
| 286 | "game": F.tensor([0], dtype=idtype), |
| 287 | } |
| 288 | ) |
| 289 | _check_subgraph(g, sg1) |
| 290 | sg2 = g.edge_subgraph( |
| 291 | { |
| 292 | "follows": F.tensor([1], dtype=idtype), |
| 293 | "plays": F.tensor([1], dtype=idtype), |
| 294 | "wishes": F.tensor([1], dtype=idtype), |
nothing calls this directly
no test coverage detected