dgl.DGLHeteroGraph.to

DGLHeteroGraph.to(ctx)[source]

Move both ndata and edata to the targeted mode (cpu/gpu) Framework agnostic

Parameters:ctx (framework-specific context object) – The context to move data to.
Returns:g – Moved DGLHeteroGraph of the targeted mode.
Return type:DGLHeteroGraph

Examples

The following example uses PyTorch backend.

>>> import torch
>>> g = dgl.bipartite([(0, 0), (1, 0), (1, 2), (2, 1)], 'user', 'plays', 'game')
>>> g.nodes['user'].data['h'] = torch.tensor([[0.], [1.], [2.]])
>>> g.edges['plays'].data['h'] = torch.tensor([[0.], [1.], [2.], [3.]])
>>> g = g.to(torch.device('cuda:0'))