Cast the graph to one with idtype int64 If the graph already has idtype int64, the function directly returns it. Otherwise, it returns a cloned graph of idtype int64 with features copied (shallow copy). Returns ------- DGLGraph The graph of idtyp
(self)
| 6299 | return DGLGraph(gidx, self.ntypes, self.etypes) |
| 6300 | |
| 6301 | def long(self): |
| 6302 | """Cast the graph to one with idtype int64 |
| 6303 | |
| 6304 | If the graph already has idtype int64, the function directly returns it. Otherwise, |
| 6305 | it returns a cloned graph of idtype int64 with features copied (shallow copy). |
| 6306 | |
| 6307 | Returns |
| 6308 | ------- |
| 6309 | DGLGraph |
| 6310 | The graph of idtype int64. |
| 6311 | |
| 6312 | Examples |
| 6313 | -------- |
| 6314 | |
| 6315 | The following example uses PyTorch backend. |
| 6316 | |
| 6317 | >>> import dgl |
| 6318 | >>> import torch |
| 6319 | |
| 6320 | Create a graph of idtype int32. |
| 6321 | |
| 6322 | >>> # (0, 1), (0, 2), (1, 2) |
| 6323 | >>> g = dgl.graph((torch.tensor([0, 0, 1]).int(), torch.tensor([1, 2, 2]).int())) |
| 6324 | >>> g.ndata['feat'] = torch.ones(3, 1) |
| 6325 | >>> g.idtype |
| 6326 | torch.int32 |
| 6327 | |
| 6328 | Cast the graph to one of idtype int64. |
| 6329 | |
| 6330 | >>> # A cloned graph with an idtype of int64 |
| 6331 | >>> g_long = g.long() |
| 6332 | >>> g_long.idtype |
| 6333 | torch.int64 |
| 6334 | >>> # The idtype of the original graph does not change. |
| 6335 | >>> g.idtype |
| 6336 | torch.int32 |
| 6337 | >>> g_long.edges() |
| 6338 | (tensor([0, 0, 1]), tensor([1, 2, 2])) |
| 6339 | >>> g_long.ndata |
| 6340 | {'feat': tensor([[1.], |
| 6341 | [1.], |
| 6342 | [1.]])} |
| 6343 | |
| 6344 | See Also |
| 6345 | -------- |
| 6346 | int |
| 6347 | idtype |
| 6348 | """ |
| 6349 | return self.astype(F.int64) |
| 6350 | |
| 6351 | def int(self): |
| 6352 | """Cast the graph to one with idtype int32 |