dgl.DGLGraph.to

DGLGraph.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.

Examples

The following example uses PyTorch backend.

>>> import torch
>>> G = dgl.DGLGraph()
>>> G.add_nodes(5, {'h': torch.ones((5, 2))})
>>> G.add_edges([0, 1], [1, 2], {'m' : torch.ones((2, 2))})
>>> G.add_edges([0, 1], [1, 2], {'m' : torch.ones((2, 2))})
>>> G.to(torch.device('cuda:0'))