Create a unidirectional bipartite graph from a NetworkX graph and return. The created graph will have two types of nodes ``utype`` and ``vtype`` as well as one edge type ``etype`` whose edges are from ``utype`` to ``vtype``. .. note:: Creating a DGLGraph from a NetworkX graph i
(
nx_graph,
utype,
etype,
vtype,
u_attrs=None,
e_attrs=None,
v_attrs=None,
edge_id_attr_name=None,
idtype=None,
device=None,
)
| 1433 | |
| 1434 | |
| 1435 | def bipartite_from_networkx( |
| 1436 | nx_graph, |
| 1437 | utype, |
| 1438 | etype, |
| 1439 | vtype, |
| 1440 | u_attrs=None, |
| 1441 | e_attrs=None, |
| 1442 | v_attrs=None, |
| 1443 | edge_id_attr_name=None, |
| 1444 | idtype=None, |
| 1445 | device=None, |
| 1446 | ): |
| 1447 | """Create a unidirectional bipartite graph from a NetworkX graph and return. |
| 1448 | |
| 1449 | The created graph will have two types of nodes ``utype`` and ``vtype`` as well as one |
| 1450 | edge type ``etype`` whose edges are from ``utype`` to ``vtype``. |
| 1451 | |
| 1452 | .. note:: |
| 1453 | Creating a DGLGraph from a NetworkX graph is not fast especially for large scales. |
| 1454 | It is recommended to first convert a NetworkX graph into a tuple of node-tensors |
| 1455 | and then construct a DGLGraph with :func:`dgl.heterograph`. |
| 1456 | |
| 1457 | Parameters |
| 1458 | ---------- |
| 1459 | nx_graph : networkx.DiGraph |
| 1460 | The NetworkX graph holding the graph structure and the node/edge attributes. |
| 1461 | DGL will relabel the nodes using consecutive integers starting from zero if it is |
| 1462 | not the case. The graph must follow `NetworkX's bipartite graph convention |
| 1463 | <https://networkx.github.io/documentation/stable/reference/algorithms/bipartite.html>`_, |
| 1464 | and furthermore the edges must be from nodes with attribute ``bipartite=0`` to nodes |
| 1465 | with attribute ``bipartite=1``. |
| 1466 | utype : str, optional |
| 1467 | The name of the source node type. |
| 1468 | etype : str, optional |
| 1469 | The name of the edge type. |
| 1470 | vtype : str, optional |
| 1471 | The name of the destination node type. |
| 1472 | u_attrs : list[str], optional |
| 1473 | The names of the node attributes for node type :attr:`utype` to retrieve from the |
| 1474 | NetworkX graph. If given, DGL stores the retrieved node attributes in |
| 1475 | ``nodes[utype].data`` of the returned graph using their original names. The attribute |
| 1476 | data must be convertible to Tensor type (e.g., scalar, ``numpy.ndarray``, list, etc.). |
| 1477 | e_attrs : list[str], optional |
| 1478 | The names of the edge attributes to retrieve from the NetworkX graph. If given, DGL |
| 1479 | stores the retrieved edge attributes in ``edata`` of the returned graph using their |
| 1480 | original names. The attribute data must be convertible to Tensor type (e.g., scalar, |
| 1481 | numpy.ndarray, list, etc.). |
| 1482 | v_attrs : list[str], optional |
| 1483 | The names of the node attributes for node type :attr:`vtype` to retrieve from the |
| 1484 | NetworkX graph. If given, DGL stores the retrieved node attributes in |
| 1485 | ``nodes[vtype].data`` of the returned graph using their original names. The attribute |
| 1486 | data must be convertible to Tensor type (e.g., scalar, numpy.array, list, etc.). |
| 1487 | edge_id_attr_name : str, optional |
| 1488 | The name of the edge attribute that stores the edge IDs. If given, DGL will assign edge |
| 1489 | IDs accordingly when creating the graph, so the attribute must be valid IDs, i.e. |
| 1490 | consecutive integers starting from zero. By default, the edge IDs of the returned graph |
| 1491 | can be arbitrary. |
| 1492 | idtype : int32 or int64, optional |
nothing calls this directly
no test coverage detected