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

Function to_simple

python/dgl/transforms/functional.py:2371–2549  ·  view source on GitHub ↗

r"""Convert a graph to a simple graph without parallel edges and return. For a heterogeneous graph with multiple edge types, DGL treats edges with the same edge type and endpoints as parallel edges and removes them. Optionally, one can get the the number of parallel edges by specifying

(
    g,
    return_counts="count",
    writeback_mapping=False,
    copy_ndata=True,
    copy_edata=False,
    aggregator="arbitrary",
)

Source from the content-addressed store, hash-verified

2369
2370
2371def to_simple(
2372 g,
2373 return_counts="count",
2374 writeback_mapping=False,
2375 copy_ndata=True,
2376 copy_edata=False,
2377 aggregator="arbitrary",
2378):
2379 r"""Convert a graph to a simple graph without parallel edges and return.
2380
2381 For a heterogeneous graph with multiple edge types, DGL treats edges with the same
2382 edge type and endpoints as parallel edges and removes them.
2383 Optionally, one can get the the number of parallel edges by specifying the
2384 :attr:`return_counts` argument. To get the a mapping from the edge IDs in the
2385 input graph to the edge IDs in the resulting graph, set :attr:`writeback_mapping`
2386 to true.
2387
2388 Parameters
2389 ----------
2390 g : DGLGraph
2391 The input graph. Must be on CPU.
2392 return_counts : str, optional
2393 If given, the count of each edge in the original graph
2394 will be stored as edge features under the name
2395 ``return_counts``. The old features with the same name will be replaced.
2396
2397 (Default: "count")
2398 writeback_mapping: bool, optional
2399 If True, return an extra write-back mapping for each edge
2400 type. The write-back mapping is a tensor recording
2401 the mapping from the edge IDs in the input graph to
2402 the edge IDs in the result graph. If the graph is
2403 heterogeneous, DGL returns a dictionary of edge types and such
2404 tensors.
2405
2406 If False, only the simple graph is returned.
2407
2408 (Default: False)
2409 copy_ndata: bool, optional
2410 If True, the node features of the simple graph are copied
2411 from the original graph.
2412
2413 If False, the simple graph will not have any node features.
2414
2415 (Default: True)
2416 copy_edata: bool, optional
2417 If True, the edge features of the simple graph are copied
2418 from the original graph. If there exists duplicate edges between
2419 two nodes (u, v), the feature of the edge is the aggregation
2420 of edge feature of duplicate edges.
2421
2422 If False, the simple graph will not have any edge features.
2423
2424 (Default: False)
2425 aggregator: str, optional
2426 Indicate how to coalesce edge feature of duplicate edges.
2427 If ``arbitrary``, select one of the duplicate edges' feature.
2428 If ``sum``, compute the summation of duplicate edges' feature.

Callers 2

to_bidirectedFunction · 0.85
to_simple_graphFunction · 0.85

Calls 4

DGLErrorClass · 0.85
DGLGraphClass · 0.85
_coalesce_edge_frameFunction · 0.85
cpuMethod · 0.45

Tested by

no test coverage detected