mindspore_gl.graph.sampling_csr_data
- mindspore_gl.graph.sampling_csr_data(src_idx, dst_idx, n_nodes, n_edges, seeds_idx=None, node_feat=None, rerank=False)[source]
Convert the sampling 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.
seeds_idx (numpy.ndarray) – start nodes for neighbor sampling. Default:
None
.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.
seeds_idx (numpy.ndarray) - reordered start nodes.
node_feat (numpy.ndarray) - reorder node features.
- Supported Platforms:
Ascend
GPU
Examples
>>> import numpy as np >>> from mindspore_gl.graph import sampling_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) >>> seeds_idx = np.array([0, 3, 5]) >>> g, seeds_idx, node_feat = sampling_csr_data(src_idx, dst_idx, n_nodes, n_edges,\ ... seeds_idx, node_feat, rerank=True) >>> print(g[0], g[1], seeds_idx) [2 3 5 6 3 4 0 6] [0 2 4 5 6 7 8 8] [5, 4, 3] >>> 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.]]