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

Method add_edges

python/dgl/heterograph.py:435–627  ·  view source on GitHub ↗

r"""Add multiple new edges for the specified edge type The i-th new edge will be from ``u[i]`` to ``v[i]``. Parameters ---------- u : int, tensor, numpy.ndarray, list Source node IDs, ``u[i]`` gives the source node for the i-th new edge. v : int,

(self, u, v, data=None, etype=None)

Source from the content-addressed store, hash-verified

433 self._reset_cached_info()
434
435 def add_edges(self, u, v, data=None, etype=None):
436 r"""Add multiple new edges for the specified edge type
437
438 The i-th new edge will be from ``u[i]`` to ``v[i]``.
439
440 Parameters
441 ----------
442 u : int, tensor, numpy.ndarray, list
443 Source node IDs, ``u[i]`` gives the source node for the i-th new edge.
444 v : int, tensor, numpy.ndarray, list
445 Destination node IDs, ``v[i]`` gives the destination node for the i-th new edge.
446 data : dict, optional
447 Feature data of the added edges. The i-th row of the feature data
448 corresponds to the i-th new edge.
449 etype : str or tuple of str, optional
450 The type of the new edges. Can be omitted if there is
451 only one edge type in the graph.
452
453 Notes
454 -----
455
456 * Inplace update is applied to the current graph.
457 * If end nodes of adding edges does not exists, add_nodes is invoked
458 to add new nodes. The node features of the new nodes will be created
459 by initializers defined with :func:`set_n_initializer` (default
460 initializer fills zeros). In certain cases, it is recommanded to
461 add_nodes first and then add_edges.
462 * If the key of ``data`` does not contain some existing feature fields,
463 those features for the new edges will be created by initializers
464 defined with :func:`set_n_initializer` (default initializer fills zeros).
465 * If the key of ``data`` contains new feature fields, those features for
466 the old edges will be created by initializers defined with
467 :func:`set_n_initializer` (default initializer fills zeros).
468 * This function discards the batch information. Please use
469 :func:`dgl.DGLGraph.set_batch_num_nodes`
470 and :func:`dgl.DGLGraph.set_batch_num_edges` on the transformed graph
471 to maintain the information.
472
473 Examples
474 --------
475
476 The following example uses PyTorch backend.
477
478 >>> import dgl
479 >>> import torch
480
481 **Homogeneous Graphs or Heterogeneous Graphs with A Single Edge Type**
482
483 >>> g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2])))
484 >>> g.num_edges()
485 2
486 >>> g.add_edges(torch.tensor([1, 3]), torch.tensor([0, 1]))
487 >>> g.num_edges()
488 4
489
490 Since ``u`` or ``v`` contains a non-existing node ID, the nodes are
491 added implicitly.
492 >>> g.num_nodes()

Callers 15

proteins_mtx2dglFunction · 0.95
build_graph_trainFunction · 0.95
__getitem__Method · 0.95
build_graphMethod · 0.95
mergeFunction · 0.45
processMethod · 0.45
processMethod · 0.45
processMethod · 0.45

Calls 14

to_canonical_etypeMethod · 0.95
num_nodesMethod · 0.95
add_nodesMethod · 0.95
edgesMethod · 0.95
get_etype_idMethod · 0.95
_reset_cached_infoMethod · 0.95
DGLErrorClass · 0.85
number_of_etypesMethod · 0.80
contextMethod · 0.80
appendMethod · 0.80
get_relation_graphMethod · 0.80
add_rowsMethod · 0.80

Tested by 15

test_sequentialFunction · 0.36
test_prop_nodes_topoFunction · 0.36
_testFunction · 0.36
test_all_binary_builtinsFunction · 0.36
generate_graphFunction · 0.36
_test_map_to_subgraphFunction · 0.36
generate_graphFunction · 0.36
test_pull_multi_fallbackFunction · 0.36
test_empty_queryFunction · 0.36
test_cloneFunction · 0.36