mindspore_gl.graph.graph_csr_data

mindspore_gl.graph.graph_csr_data(src_idx, dst_idx, n_nodes, n_edges, node_feat=None, node_label=None, train_mask=None, val_mask=None, test_mask=None, rerank=False)[source]

Convert the entire 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_feat (Union[Tensor, numpy.ndarray, optional]) – node feature.

  • node_label (Union[Tensor, numpy.ndarray, optional]) – node labels.

  • train_mask (Union[Tensor, numpy.ndarray, optional]) – mask of train index.

  • val_mask (Union[Tensor, numpy.ndarray, optional]) – msk of train index.

  • test_mask (Union[Tensor, numpy.ndarray, optional]) – mask of train index.

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

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.

  • in_deg - in degree of each node.

  • out_deg - out degree of each node.

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

  • node_label (Union[Tensor, numpy.ndarray, optional]) - reorder node labels.

  • train_mask (Union[Tensor, numpy.ndarray, optional]) - reorder train index mask.

  • val_mask (Union[Tensor, numpy.ndarray, optional]) - reorder val index mask.

  • test_mask (Union[Tensor, numpy.ndarray, optional]) - reorder test index mask.

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindspore_gl.graph import 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_label = np.array([0, 1, 0, 1, 0, 1, 0])
>>> train_mask = np.array([True, True, True, True, False, False, False])
>>> val_mask = np.array([False, False, False, False, True, True, True])
>>> g, in_deg, out_deg, node_feat, node_label, train_mask, val_mask,\
>>> test_mask = graph_csr_data(src_idx,dst_idx, n_nodes, n_edges, node_feat, node_label,
...                            train_mask, val_mask, test_mask=None, rerank=True)
>>> print(g[0], g[1])
[2 3 5 6 3 4 0 6] [0 2 4 5 6 7 8 8]
>>> print(node_feat, node_label)
[[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.]] [0 1 0 1 1 0 0]
>>> print(train_mask, val_mask)
[False  True False False  True  True  True] [ True False  True  True False False False]