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

from .new import new


rusty1s's avatar
rusty1s committed
6
7
8
def node_degree(index, n, out=None):
    zero = torch.zeros(n) if out is None else out.resize_(n).fill_(0)
    one = new(zero, index.size(0)).fill_(1)
rusty1s's avatar
rusty1s committed
9
    return zero.scatter_add_(0, index, one)