mindspore_gl.graph.PadHomoGraph
- class mindspore_gl.graph.PadHomoGraph(n_node=None, mode=PadMode.AUTO, n_edge=None, csr=False)[source]
Pad MindHomoGraph, We pad graph by adding additional nodes and edges between these nodes. In short, \(\text{PadHomoGraph}(graph1) = \text{BatchHomoGraph}(graph1, fake\_graph)\) node count and edge count in fake_graph is determined by user-specific parameters.
- Parameters
n_node (int, optional) – target graph’s node count. Default:
None
.n_edge (int, optional) – target graph’s edge count. Default:
None
.mode (PadMode, optional) – Pad mode, if
PadMode.CONST
, target graph will have n_node nodes and n_edge edges. IfPadMode.AUTO
target graph’s node_count and edge_count is calculated according to input graph’s size by \(n\_node = 2^{\text{ceil}(\log_{2}(input\_graph.node\_count))}\) , \(n\_edge = 2^{\text{ceil}(\log_{2}(input\_graph.edge\_count))}\) . Default:mindspore_gl.graph.PadMode.AUTO
.csr (bool, optional) – Is the csr graph. Default:
False
.
- Inputs:
graph (MindHomoGraph) - input graph.
- Outputs:
MindHomoGraph, padded graph.
- Supported Platforms:
Ascend
GPU
Examples
>>> from mindspore_gl.graph.ops import BatchHomoGraph, PadHomoGraph, PadMode >>> import numpy as np >>> from mindspore_gl.graph.graph import MindHomoGraph >>> graph_list = [] >>> for _ in range(1): ... graph = MindHomoGraph() ... edges = np.array([[0, 2, 2, 3, 4, 5, 5, 6], [1, 0, 1, 5, 3, 4, 6, 4]]) ... graph.set_topo_coo(edges) ... graph.node_count = 7 ... graph.edge_count = 8 ... graph_list.append(graph) >>> batch_fn = BatchHomoGraph() >>> batch_graph = batch_fn(graph_list) >>> n_node = graph.node_count + 1 >>> n_edge = graph.edge_count + 30 >>> pad_graph_op = PadHomoGraph(mode=PadMode.CONST, n_node=n_node, n_edge=n_edge) >>> pad_res = pad_graph_op(batch_graph) >>> print(pad_res[0].edge_count, pad_res[1].edge_count) 8 30 >>> print(pad_res[0].node_count, pad_res[1].node_count) 7 1