mindspore_gl.graph.MindHomoGraph
- class mindspore_gl.graph.MindHomoGraph[源代码]
构建同构图。
- 支持平台:
Ascend
GPU
样例:
>>> import numpy as np >>> import networkx >>> from scipy.sparse import csr_matrix >>> from mindspore_gl.graph import MindHomoGraph, CsrAdj >>> node_count = 20 >>> edge_prob = 0.1 >>> graph = networkx.generators.random_graphs.fast_gnp_random_graph(node_count, edge_prob) >>> edge_array = np.transpose(np.array(list(graph.edges))) >>> row = edge_array[0] >>> col = edge_array[1] >>> data = np.ones(row.shape) >>> csr_mat = csr_matrix((data, (row, col)), shape=(node_count, node_count)) >>> generated_graph = MindHomoGraph() >>> node_dict = {idx: idx for idx in range(node_count)} >>> edge_count = col.shape[0] >>> edge_ids = np.array(list(range(edge_count))).astype(np.int32) >>> generated_graph.set_topo(CsrAdj(csr_mat.indptr.astype(np.int32), csr_mat.indices.astype(np.int32)), ... node_dict, edge_ids) >>> print(generated_graph.neighbors(0)) # results will be random for suffle [10 14]
- property adj_coo
COO调整矩阵。
- 返回:
numpy.ndarray,COO图。
样例:
>>> #dataset is an instance object of Dataset >>> adj_coo = graph.adj_coo
- property adj_csr
CSR调整矩阵。
- 返回:
mindspore_gl.graph.csr_adj,csr图。
样例:
>>> #dataset is an instance object of Dataset >>> adj_csr = graph.adj_csr
- property batch_meta
如果图形被批处理。
- 返回:
mindspore_gl.graph.BatchMeta,batch meta信息。
样例:
>>> #dataset is an instance object of Dataset >>> batch_meta = graph.batch_meta
- property edge_count
图的边数。
- 返回:
int,边数。
样例:
>>> #dataset is an instance object of Dataset >>> edge_count = graph.edge_count
- property is_batched
图是否被批处理。
- 返回:
bool,图被批处理了返回True,否则返回False。
样例:
>>> #dataset is an instance object of Dataset >>> is_batched = graph.is_batched
- property node_count
图的节点数。
- 返回:
int,节点数。
样例:
>>> #dataset is an instance object of Dataset >>> node_count = graph.node_count