mindspore_gl.graph.MindHomoGraph
- class mindspore_gl.graph.MindHomoGraph[source]
Build in-memory homo graph.
- Supported Platforms:
Ascend
GPU
Examples
>>> 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.zeros(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 adj matrix
- Returns
numpy.ndarray, coo graph
Examples
>>> #dataset is an instance object of Dataset >>> adj_coo = graph.adj_coo
- property adj_csr
csr adj matrix
- Returns
mindspore_gl.graph.csr_adj, csr graph
Examples
>>> #dataset is an instance object of Dataset >>> adj_csr = graph.adj_csr
- property batch_meta: mindspore_gl.graph.graph.BatchMeta
If the graph be batched
- Returns
mindspore_gl.graph.BatchMeta, bathc meta info
Examples
>>> #dataset is an instance object of Dataset >>> batch_meta = graph.batch_meta
- degree(node)[source]
Query With Lazy Computation node degree.
- Parameters
node (int) – node idx
- Returns
int, degree of node
- property edge_count
Edge count of graph
- Returns
int, edge numbers
Examples
>>> #dataset is an instance object of Dataset >>> edge_count = graph.edge_count
- property is_batched: bool
If the graph be batched
- Returns
bool, the graph be batched
Examples
>>> #dataset is an instance object of Dataset >>> is_batched = graph.is_batched
- neighbors(node)[source]
Query With Lazy Computation
- Parameters
node (int) – node idx
- Returns
numpy.ndarray, sampled node
- property node_count
Node count of graph
- Returns
int, nodes numbers
Examples
>>> #dataset is an instance object of Dataset >>> node_count = graph.node_count
- set_topo(adj_csr: np.ndarray, node_dict, edge_ids: np.ndarray)[source]
initialize CSR Graph
- Parameters
adj_csr (mindspore_gl.graph.csr_adj) – adj of graph, csr type
node_dict (dict) – node id dict
edge_ids (numpy.ndarray) – array of edges
- set_topo_coo(adj_coo, node_dict=None, edge_ids: np.ndarray = None)[source]
initialize COO Graph
- Parameters
adj_coo (numpy.ndarray) – adj of graph, coo type
node_dict (dict) – node id dict
edge_ids (numpy.ndarray) – array of edges