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

Method long

python/dgl/heterograph.py:6301–6349  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

get_long_edgesFunction · 0.45
test_dtype_castFunction · 0.45
test_topologyFunction · 0.45
test_gather_mm_idx_bFunction · 0.45
test_module_signFunction · 0.45
rand_cooFunction · 0.45
rand_csrFunction · 0.45
rand_cscFunction · 0.45
test_coo_to_csrFunction · 0.45
test_csc_to_csrFunction · 0.45

Calls 1

astypeMethod · 0.95

Tested by 15

test_dtype_castFunction · 0.36
test_topologyFunction · 0.36
test_gather_mm_idx_bFunction · 0.36
test_module_signFunction · 0.36
test_coo_to_csrFunction · 0.36
test_csc_to_csrFunction · 0.36
test_coo_to_cscFunction · 0.36
test_csr_to_cscFunction · 0.36
run_clientFunction · 0.36
test_sparse_adamFunction · 0.36
test_sparse_adam_uvaFunction · 0.36
test_sparse_adam_dtypeFunction · 0.36