degree.py 201 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
import torch


rusty1s's avatar
rusty1s committed
4
5
6
7
def node_degree(edge_index, n, out=None):
    zero = torch.zeros(n, out=out)
    one = torch.ones(edge_index.size(1), out=zero.new())
    return zero.scatter_add_(0, edge_index[0], one)