Expand_as_pair explanation

Explain it a bit about the usage.
How it works for undirected homogeneous graph and heterogeneous graph.

Hi @kyawlin, expand_as_pair function is called in NN modules to tear apart the input feature into source nodes’ feature and destination nodes’ feature. Modules like GraphSAGE need to use src_feat and dst_feat differently.
For undirected homogeneous graph, we can consider source node set and destination node set are the same, since any nodes with edge will send out messages and receive messages. In expand_as_pair function (https://github.com/dmlc/dgl/blob/master/python/dgl/utils/internal.py#L583), we just return the input tensor.
For heterogeneous graph, we will use heterographconv to call nn modules. For heterographconv, input feature is a dictionary of tensors, the keys are the node type for heterograph. Then in the forward call, we will get the src feat and dst feat for each {src_type, dst_type, e_type} bipartite graph to make it a tuple. Then expand_as_pair will just expand the tuple into two elements as written in: https://github.com/dmlc/dgl/blob/master/python/dgl/utils/internal.py#L573

1 Like