mindspore_gl.graph.PadHomoGraph
- class mindspore_gl.graph.PadHomoGraph(n_node=None, mode=PadMode.AUTO, n_edge=None)[源代码]
Pad MindHomoGraph,通过在这些节点之间添加额外的节点和边来填充图形。简言之,PadHomoGraph(graph1) = BatchHomoGraph(graph1, fake_graph) 虚构图中的节点计数和边计数由用户特定的参数决定。
- 参数:
n_node (Union(int, None)) - 目标图的节点计数。默认值:None。
n_edge (Union(int, None)) - 目标图的边计数。默认值:None。
mode (PadMode) - Pad模式,如果选择PadMode.CONST,虚构图将具有n_node数量的节点和n_edge数量的边。如果为PadMode.AUTO,虚构图的node_count和edge_count是根据输入图的大小通过 \(n\_node = 2^{ceil(log2(input\_graph.node\_count))}, n\_edge = 2^{ceil(log2(input\_graph.edge\_count))}\) 计算的。默认值:PadMode.AUTO。
- 输入:
graph (MindHomoGraph) - 输入图。
- 输出:
MindHomoGraph,填充图。
- 支持平台:
Ascend
GPU
样例:
>>> 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