graph_reindex

paddle.incubate. graph_reindex ( x, neighbors, count, value_buffer=None, index_buffer=None, flag_buffer_hashtable=False, name=None ) [source]

Graph Reindex API.

This API is mainly used in Graph Learning domain, which should be used in conjunction with graph_sample_neighbors API. And the main purpose is to reindex the ids information of the input nodes, and return the corresponding graph edges after reindex.

Take input nodes x = [0, 1, 2] as an example. If we have neighbors = [8, 9, 0, 4, 7, 6, 7], and count = [2, 3, 2], then we know that the neighbors of 0 is [8, 9], the neighbors of 1 is [0, 4, 7], and the neighbors of 2 is [6, 7].

Parameters
  • x (Tensor) – The input nodes which we sample neighbors for. The available data type is int32, int64.

  • neighbors (Tensor) – The neighbors of the input nodes x. The data type should be the same with x.

  • count (Tensor) – The neighbor count of the input nodes x. And the data type should be int32.

  • value_buffer (Tensor|None) – Value buffer for hashtable. The data type should be int32, and should be filled with -1.

  • index_buffer (Tensor|None) – Index buffer for hashtable. The data type should be int32, and should be filled with -1.

  • flag_buffer_hashtable (bool) – Whether to use buffer for hashtable to speed up. Default is False. Only useful for gpu version currently.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

The source node index of graph edges after reindex. reindex_dst (Tensor): The destination node index of graph edges after reindex. out_nodes (Tensor): The index of unique input nodes and neighbors before reindex,

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/incubate/operators/graph_reindex.py:docstring of paddle.incubate.operators.graph_reindex.graph_reindex, line 38)

Unexpected indentation.

where we put the input nodes x in the front, and put neighbor nodes in the back.

Return type

reindex_src (Tensor)

Examples


import paddle

x = [0, 1, 2] neighbors = [8, 9, 0, 4, 7, 6, 7] count = [2, 3, 2] x = paddle.to_tensor(x, dtype=”int64”) neighbors = paddle.to_tensor(neighbors, dtype=”int64”) count = paddle.to_tensor(count, dtype=”int32”)

reindex_src, reindex_dst, out_nodes = paddle.incubate.graph_reindex(x, neighbors, count) # reindex_src: [3, 4, 0, 5, 6, 7, 6] # reindex_dst: [0, 0, 1, 1, 1, 2, 2] # out_nodes: [0, 1, 2, 8, 9, 4, 7, 6]