MCPcopy
hub / github.com/dmlc/dgl / graph

Function graph

python/dgl/convert.py:32–184  ·  view source on GitHub ↗

Create a graph and return. Parameters ---------- data : graph data The data for constructing a graph, which takes the form of :math:`(U, V)`. :math:`(U[i], V[i])` forms the edge with ID :math:`i` in the graph. The allowed data formats are: - ``(Tensor, T

(
    data,
    *,
    num_nodes=None,
    idtype=None,
    device=None,
    row_sorted=False,
    col_sorted=False,
)

Source from the content-addressed store, hash-verified

30
31
32def graph(
33 data,
34 *,
35 num_nodes=None,
36 idtype=None,
37 device=None,
38 row_sorted=False,
39 col_sorted=False,
40):
41 """Create a graph and return.
42
43 Parameters
44 ----------
45 data : graph data
46 The data for constructing a graph, which takes the form of :math:`(U, V)`.
47 :math:`(U[i], V[i])` forms the edge with ID :math:`i` in the graph.
48 The allowed data formats are:
49
50 - ``(Tensor, Tensor)``: Each tensor must be a 1D tensor containing node IDs.
51 DGL calls this format "tuple of node-tensors". The tensors should have the same
52 data type of int32/int64 and device context (see below the descriptions of
53 :attr:`idtype` and :attr:`device`).
54 - ``('coo', (Tensor, Tensor))``: Same as ``(Tensor, Tensor)``.
55 - ``('csr', (Tensor, Tensor, Tensor))``: The three tensors form the CSR representation
56 of the graph's adjacency matrix. The first one is the row index pointer. The
57 second one is the column indices. The third one is the edge IDs, which can be empty
58 to represent consecutive integer IDs starting from 0.
59 - ``('csc', (Tensor, Tensor, Tensor))``: The three tensors form the CSC representation
60 of the graph's adjacency matrix. The first one is the column index pointer. The
61 second one is the row indices. The third one is the edge IDs, which can be empty
62 to represent consecutive integer IDs starting from 0.
63
64 The tensors can be replaced with any iterable of integers (e.g. list, tuple,
65 numpy.ndarray).
66 num_nodes : int, optional
67 The number of nodes in the graph. If not given, this will be the largest node ID
68 plus 1 from the :attr:`data` argument. If given and the value is no greater than
69 the largest node ID from the :attr:`data` argument, DGL will raise an error.
70 idtype : int32 or int64, optional
71 The data type for storing the structure-related graph information such as node and
72 edge IDs. It should be a framework-specific data type object (e.g., ``torch.int32``).
73 If ``None`` (default), DGL infers the ID type from the :attr:`data` argument.
74 See "Notes" for more details.
75 device : device context, optional
76 The device of the returned graph, which should be a framework-specific device object
77 (e.g., ``torch.device``). If ``None`` (default), DGL uses the device of the tensors of
78 the :attr:`data` argument. If :attr:`data` is not a tuple of node-tensors, the
79 returned graph is on CPU. If the specified :attr:`device` differs from that of the
80 provided tensors, it casts the given tensors to the specified device first.
81 row_sorted : bool, optional
82 Whether or not the rows of the COO are in ascending order.
83 col_sorted : bool, optional
84 Whether or not the columns of the COO are in ascending order within
85 each row. This only has an effect when ``row_sorted`` is True.
86
87 Returns
88 -------
89 DGLGraph

Callers 12

to_homogeneousFunction · 0.85
from_cugraphFunction · 0.85
merge_graphsFunction · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85

Calls 5

DGLErrorClass · 0.85
create_from_edgesFunction · 0.85
formatMethod · 0.80
maxFunction · 0.50
toMethod · 0.45

Tested by

no test coverage detected