Generate a random uni-directional bipartite graph and return. It uniformly chooses ``num_edges`` from all possible node pairs and form a graph. The random choice is without replacement, which means there will be no multi-edge in the resulting graph. To control the randomness, set t
(
utype,
etype,
vtype,
num_src_nodes,
num_dst_nodes,
num_edges,
idtype=F.int64,
device=F.cpu(),
)
| 58 | |
| 59 | |
| 60 | def rand_bipartite( |
| 61 | utype, |
| 62 | etype, |
| 63 | vtype, |
| 64 | num_src_nodes, |
| 65 | num_dst_nodes, |
| 66 | num_edges, |
| 67 | idtype=F.int64, |
| 68 | device=F.cpu(), |
| 69 | ): |
| 70 | """Generate a random uni-directional bipartite graph and return. |
| 71 | |
| 72 | It uniformly chooses ``num_edges`` from all possible node pairs and form a graph. |
| 73 | The random choice is without replacement, which means there will be no multi-edge |
| 74 | in the resulting graph. |
| 75 | |
| 76 | To control the randomness, set the random seed via :func:`dgl.seed`. |
| 77 | |
| 78 | Parameters |
| 79 | ---------- |
| 80 | utype : str, optional |
| 81 | The name of the source node type. |
| 82 | etype : str, optional |
| 83 | The name of the edge type. |
| 84 | vtype : str, optional |
| 85 | The name of the destination node type. |
| 86 | num_src_nodes : int |
| 87 | The number of source nodes. |
| 88 | num_dst_nodes : int |
| 89 | The number of destination nodes. |
| 90 | num_edges : int |
| 91 | The number of edges |
| 92 | idtype : int32, int64, optional |
| 93 | The data type for storing the structure-related graph information |
| 94 | such as node and edge IDs. It should be a framework-specific data type object |
| 95 | (e.g., torch.int32). By default, DGL uses int64. |
| 96 | device : Device context, optional |
| 97 | The device of the resulting graph. It should be a framework-specific device |
| 98 | object (e.g., torch.device). By default, DGL stores the graph on CPU. |
| 99 | |
| 100 | Returns |
| 101 | ------- |
| 102 | DGLGraph |
| 103 | The generated random bipartite graph. |
| 104 | |
| 105 | See Also |
| 106 | -------- |
| 107 | rand_graph |
| 108 | |
| 109 | Examples |
| 110 | -------- |
| 111 | >>> import dgl |
| 112 | >>> dgl.rand_bipartite('user', 'buys', 'game', 50, 100, 10) |
| 113 | Graph(num_nodes={'game': 100, 'user': 50}, |
| 114 | num_edges={('user', 'buys', 'game'): 10}, |
| 115 | metagraph=[('user', 'game', 'buys')]) |
| 116 | """ |
| 117 | # TODO(minjie): support RNG as one of the arguments. |