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)[源代码]

将COO类型的采样图转为CSR类型。

参数:
  • src_idx (Union[Tensor, numpy.ndarray]) - shape为 \((N\_EDGES)\) 的int类型Tensor,表示COO边矩阵的源节点索引。

  • dst_idx (Union[Tensor, numpy.ndarray]) - shape为 \((N\_EDGES)\) 的int类型Tensor,表示COO边矩阵的目标节点索引。

  • n_nodes (int) - 图中节点数量。

  • n_edges (int) - 图中边数量。

  • seeds_idx (numpy.ndarray) - 初始邻居采样节点。默认值:None

  • node_feat (Union[Tensor, numpy.ndarray], 可选) - 节点特征。默认值:None

  • rerank (bool, 可选) - 是否对节点特征、标签、掩码进行重排序。默认值:False

返回:
  • csr_g (tuple) - CSR图的信息,它包含CSR图的indices,CSR图的indptr,CSR图的节点数、CSR图的边数、CSR图的预存的反向indices、CSR图的预存储反向indptr。

  • seeds_idx (numpy.ndarray) - 重排序的初始采样节点。

  • node_feat (numpy.ndarray) - 重排序的节点特征。

支持平台:

Ascend GPU

样例:

>>> 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.]]