Inconsistent edge feature order between G.edata and G.edges[s,d].data

When using large graphs, I’ve noticed that the source and target of my edge features is flipped when accessing them via G.edata and G.edges[source, target].data.

Prior to submitting an issue on Github wanted to double check that I’m not messing something up.

Minimal example bellow:

import dgl
import torch

NUM_NODES = 5

sources = torch.arange(NUM_NODES).repeat(NUM_NODES)
targets = torch.arange(NUM_NODES).repeat_interleave(NUM_NODES)
G = dgl.DGLGraph((sources, targets))

G.edata['test'] = torch.zeros(G.num_edges()).to(torch.long)
source = 0
target = 1

G.edges[source, target].data['test'] = torch.tensor([1])

print(G.edges[source, target].data['test'])
>> tensor([1])

print(G.edges[target, source].data['test'])
>> tensor([0])

print(G.edata['test'].reshape(G.num_nodes(), G.num_nodes())[source, target])
>> tensor(0)

print(G.edata['test'].reshape(G.num_nodes(), G.num_nodes())[target, source])
>> tensor(1)

Since 0.5 DGL no longer supports indexing edges with G.edges[src_id, dst_id]. We instead recommend you to index by edge ID:

G.edata['test'][edge_id]
1 Like

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