How to calculate the norms of nodes considering weights of edges in an efficient way

If i have a weight on each edge, how do i implement a weighted norm for each node with edata[‘weight’] as input in a fast way. Now i implement a very slow version:

time_norm = torch.ones(g.number_of_nodes())
for node in node_id:
     u, v, eid = g.in_edges(node.squeeze(), form='all')
     in_deg = torch.sum(g.edata['weight'][eid])
     if in_deg.cpu().item():
         time_norm[node.squeeze()] = 1.0 / in_deg

You can sum the edata weight as g.update_all(fn.copy_e('weight', 'e'), fn.sum('e', 'out)) and g.ndata['out'] is the result. And then you can do g.ndata['out2'] = 1 / g.ndata['out']
You can follow our tutorials to find more details Chapter 2: Message Passing — DGL 0.7.1 documentation

Thanks for your reply!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.