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

Method edges

python/dgl/udf.py:146–186  ·  view source on GitHub ↗

Return the edges in the batch. Returns ------- (U, V, EID) : (Tensor, Tensor, Tensor) The edges in the batch. For each :math:`i`, :math:`(U[i], V[i])` is an edge from :math:`U[i]` to :math:`V[i]` with ID :math:`EID[i]`. Examples -----

(self)

Source from the content-addressed store, hash-verified

144 return self._edge_data
145
146 def edges(self):
147 """Return the edges in the batch.
148
149 Returns
150 -------
151 (U, V, EID) : (Tensor, Tensor, Tensor)
152 The edges in the batch. For each :math:`i`, :math:`(U[i], V[i])` is
153 an edge from :math:`U[i]` to :math:`V[i]` with ID :math:`EID[i]`.
154
155 Examples
156 --------
157 The following example uses PyTorch backend.
158
159 >>> import dgl
160 >>> import torch
161
162 >>> # Instantiate a graph.
163 >>> g = dgl.graph((torch.tensor([0, 1, 1]), torch.tensor([1, 1, 0])))
164
165 >>> # Define a UDF that retrieves and concatenates the end nodes of the
166 >>> # edges.
167 >>> def edge_udf(edges):
168 >>> src, dst, _ = edges.edges()
169 >>> return {'uv': torch.stack([src, dst], dim=1).float()}
170
171 >>> # Create a feature 'uv' with the end nodes of the edges.
172 >>> g.apply_edges(edge_udf)
173 >>> g.edata['uv']
174 tensor([[0., 1.],
175 [1., 1.],
176 [1., 0.]])
177
178 >>> # Use edge UDF in message passing.
179 >>> import dgl.function as fn
180 >>> g.update_all(edge_udf, fn.sum('uv', 'h'))
181 >>> g.ndata['h']
182 tensor([[1., 0.],
183 [1., 2.]])
184 """
185 u, v = self._graph.find_edges(self._eid, etype=self.canonical_etype)
186 return u, v, self._eid
187
188 def batch_size(self):
189 """Return the number of edges in the batch.

Callers 15

_chunk_graphFunction · 0.45
mergeFunction · 0.45
invoke_edge_udfFunction · 0.45
unbatchFunction · 0.45
get_long_edgesFunction · 0.45
to_heterogeneousFunction · 0.45
from_networkxFunction · 0.45
bipartite_from_networkxFunction · 0.45
_to_networkx_homogeneousFunction · 0.45
to_cugraphFunction · 0.45

Calls 1

find_edgesMethod · 0.45

Tested by 15

_chunk_graphFunction · 0.36
test_redditFunction · 0.36
test_hetero_convFunction · 0.36
test_csrmm_backwardFunction · 0.36
test_csrsum_backwardFunction · 0.36
test_csrmaskFunction · 0.36
test_csrmask_backwardFunction · 0.36
test_prop_nodes_topoFunction · 0.36
test_heterograph_mergeFunction · 0.36
test_rand_graphFunction · 0.36