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

Method int

python/dgl/heterograph.py:6351–6399  ·  view source on GitHub ↗

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 ------- DGLGraph The graph of idtyp

(self)

Source from the content-addressed store, hash-verified

6349 return self.astype(F.int64)
6350
6351 def int(self):
6352 """Cast the graph to one with idtype int32
6353
6354 If the graph already has idtype int32, the function directly returns it. Otherwise,
6355 it returns a cloned graph of idtype int32 with features copied (shallow copy).
6356
6357 Returns
6358 -------
6359 DGLGraph
6360 The graph of idtype int32.
6361
6362 Examples
6363 --------
6364
6365 The following example uses PyTorch backend.
6366
6367 >>> import dgl
6368 >>> import torch
6369
6370 Create a graph of idtype int64.
6371
6372 >>> # (0, 1), (0, 2), (1, 2)
6373 >>> g = dgl.graph((torch.tensor([0, 0, 1]), torch.tensor([1, 2, 2])))
6374 >>> g.ndata['feat'] = torch.ones(3, 1)
6375 >>> g.idtype
6376 torch.int64
6377
6378 Cast the graph to one of idtype int32.
6379
6380 >>> # A cloned graph with an idtype of int32
6381 >>> g_int = g.int()
6382 >>> g_int.idtype
6383 torch.int32
6384 >>> # The idtype of the original graph does not change.
6385 >>> g.idtype
6386 torch.int64
6387 >>> g_int.edges()
6388 (tensor([0, 0, 1], dtype=torch.int32), tensor([1, 2, 2], dtype=torch.int32))
6389 >>> g_int.ndata
6390 {'feat': tensor([[1.],
6391 [1.],
6392 [1.]])}
6393
6394 See Also
6395 --------
6396 long
6397 idtype
6398 """
6399 return self.astype(F.int32)
6400
6401
6402############################################################

Callers 15

test_dtype_castFunction · 0.45
test_topologyFunction · 0.45
test_index_select_cscFunction · 0.45
test_gatconv_equalityFunction · 0.45
test_SAGEConv_equalityFunction · 0.45
forwardMethod · 0.45
train.pyFile · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 1

astypeMethod · 0.95

Tested by 7

test_dtype_castFunction · 0.36
test_topologyFunction · 0.36
test_index_select_cscFunction · 0.36
test_gatconv_equalityFunction · 0.36
test_SAGEConv_equalityFunction · 0.36