mindspore_gl.graph.batch_graph_csr_data

View Source On Gitee
mindspore_gl.graph.batch_graph_csr_data(src_idx, dst_idx, n_nodes, n_edges, node_map_idx, node_feat=None, rerank=False)[source]

Convert the batched graph in the COO format to the CSR format.

Parameters
  • src_idx (Union[Tensor, numpy.ndarray]) – tensor with shape \((N\_EDGES)\), with int dtype, represents the source node index of COO edge matrix.

  • dst_idx (Union[Tensor, numpy.ndarray]) – tensor with shape \((N\_EDGES)\), with int dtype, represents the destination node index of COO edge matrix.

  • n_nodes (int) – integer, represent the nodes count of the graph.

  • n_edges (int) – integer, represent the edges count of the graph.

  • node_map_idx (numpy.ndarray) – ID of the subgraph to each node belongs to.

  • node_feat (Union[Tensor, numpy.ndarray, optional]) – node feature. Default: None.

  • rerank (bool, optional) – whether to reorder node features, node labels, and masks. Default: False.

Returns

  • csr_g (tuple) - info of csr graph, it contains indices of csr graph, indptr of csr graph, node numbers of csr graph, edges numbers of csr graph, pre-stored backward indices of csr graph, pre-stored backward indptr of csr graph.

  • node_map_idx (numpy.ndarray) - reordered start map index.

  • node_feat (Union[Tensor, numpy.ndarray, optional]) - reorder node features.

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindspore_gl.graph import batch_graph_csr_data
>>> node_feat = np.array([[1, 2, 3, 4], [2, 4, 1, 3], [1, 3, 2, 4],
...                       [9, 7, 5, 8], [8, 7, 6, 5], [8, 6, 4, 6], [1, 2, 1, 1]], np.float32)
>>> n_nodes = 7
>>> n_edges = 8
>>> edge_feat_size = 7
>>> src_idx = np.array([0, 2, 2, 3, 4, 5, 5, 6], np.int32)
>>> dst_idx = np.array([1, 0, 1, 5, 3, 4, 6, 4], np.int32)
>>> node_map_idx = np.array([0, 0, 0, 0, 1, 1, 1])
>>> g, node_map_idx, node_feat = batch_graph_csr_data(src_idx, dst_idx,\
...                                                   n_nodes, n_edges, node_map_idx, node_feat, rerank=True)
>>> print(g[0], g[1], node_map_idx)
[2 3 5 6 3 4 0 6] [0 2 4 5 6 7 8 8] [1 0 1 1 0 0 0]
>>> print(node_feat)
[[8. 7. 6. 5.]
 [2. 4. 1. 3.]
 [1. 2. 1. 1.]
 [8. 6. 4. 6.]
 [9. 7. 5. 8.]
 [1. 2. 3. 4.]
 [1. 3. 2. 4.]]