Skip to content

Instantly share code, notes, and snippets.

@llSourcell
Created January 19, 2020 18:14
Show Gist options
  • Select an option

  • Save llSourcell/f9832052bf908d072bf6b978c4620176 to your computer and use it in GitHub Desktop.

Select an option

Save llSourcell/f9832052bf908d072bf6b978c4620176 to your computer and use it in GitHub Desktop.
import dgl
import torch as th
g = dgl.DGLGraph()
g.add_nodes(10)
# A couple edges one-by-one
for i in range(1, 4):
g.add_edge(i, 0)
# A few more with a paired list
src = list(range(5, 8)); dst = [0]*3
g.add_edges(src, dst)
# finish with a pair of tensors
src = th.tensor([8, 9]); dst = th.tensor([0, 0])
g.add_edges(src, dst)
# Edge broadcasting will do star graph in one go!
g.clear(); g.add_nodes(10)
src = th.tensor(list(range(1, 10)));
g.add_edges(src, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment