n, e, K = x.size(0), row.size(0), weight.size(0)
if edge_attr is None:
edge_attr = x.data.new(e).fill_(1)
// Compute degree.
degree = x.data.new(n).fill_(0).scatter_add_(0, row, edge_attr)
degree = degree.pow_(-0.5)
// Compute normalized and rescaled Laplacian.
edge_attr *= degree[row]edge_attr *= degree[col]
lap = SparseTensor(edge_index, -edge_attr, torch.Size([n, n]))
// Convolution.
Tx_0 = x
After Change
row, col = edge_index
n, e, K = x.size(0), row.size(0), weight.size(0)
edge_attr = x.new_full((e, ), 1) if edge_attr is None else edge_attr
deg = degree(row, n, dtype=edge_attr.dtype, device=edge_attr.device)
// Compute normalized and rescaled Laplacian.
deg.pow_(-0.5)
lap = -deg[row] * edge_attr * deg[col]
// Convolution.
Tx_0 = x
out = torch.mm(Tx_0, weight[0])
if K > 1:
Tx_1 = matmul(edge_index, lap, x)
out += torch.mm(Tx_1, weight[1])
for k in range(2, K):
Tx_2 = 2 * matmul(edge_index, lap, Tx_1) - Tx_0
out += torch.mm(Tx_2, weight[k])
Tx_0, Tx_1 = Tx_1, Tx_2