dgl.DGLGraph.int¶
-
DGLGraph.
int
()¶ Cast the graph to one with idtype int32
If the graph already has idtype int32, the function directly returns it. Otherwise, it returns a cloned graph of idtype int32 with features copied (shallow copy).
- Returns
The graph of idtype int32.
- Return type
Examples
The following example uses PyTorch backend.
Create a graph of idtype int64.
Cast the graph to one of idtype int32.
>>> # A cloned graph with an idtype of int32 >>> g_int = g.int() >>> g_int.idtype torch.int32 >>> # The idtype of the original graph does not change. >>> g.idtype torch.int64 >>> g_int.edges() (tensor([0, 0, 1], dtype=torch.int32), tensor([1, 2, 2], dtype=torch.int32)) >>> g_int.ndata {'feat': tensor([[1.], [1.], [1.]])}