在看DGL中GraphSAGE实现源码的时候,发现里面出现多次srcdata,dstdata。一开始以为是图中边的所有源节点和目标节点,但是后来发现不是,因为在有向图上测试可以得到srcdata和dstdata完全是一样的,这就有点蛋疼了。
后来追踪DGLGraph.num_src_nodes()函数看到下面的注释后才明白,简单来说只有当图是二分图,且节点可以分成A、B两种类型,所有的边都是从A指向B的时候,A就是source,B就是destination。其他时候src和dst都是指全部的结点。官方代码注释如下:
def num_src_nodes(self, ntype=None):
"""Return the number of source nodes in the graph.
If the graph can further divide its node types into two subsets A and B where
all the edeges are from nodes of types in A to nodes of types in B, we call
this graph a *uni-bipartite* graph and the nodes in A being the *source*
nodes and the ones in B being the *destination* nodes. If the graph is not
uni-bipartite, the source and destination nodes are just the entire set of
nodes in the graph.
"""
在GraphSA