Update the features of the specified edges by the provided function. Parameters ---------- func : dgl.function.BuiltinFunction or callable The function to generate new edge features. It must be either a :ref:`api-built-in` or a :ref:`apiudf`.
(self, func, edges=ALL, etype=None)
| 4595 | self._set_n_repr(ntid, v, ndata) |
| 4596 | |
| 4597 | def apply_edges(self, func, edges=ALL, etype=None): |
| 4598 | """Update the features of the specified edges by the provided function. |
| 4599 | |
| 4600 | Parameters |
| 4601 | ---------- |
| 4602 | func : dgl.function.BuiltinFunction or callable |
| 4603 | The function to generate new edge features. It must be either |
| 4604 | a :ref:`api-built-in` or a :ref:`apiudf`. |
| 4605 | edges : edges |
| 4606 | The edges to update features on. The allowed input formats are: |
| 4607 | |
| 4608 | * ``int``: A single edge ID. |
| 4609 | * Int Tensor: Each element is an edge ID. The tensor must have the same device type |
| 4610 | and ID data type as the graph's. |
| 4611 | * iterable[int]: Each element is an edge ID. |
| 4612 | * (Tensor, Tensor): The node-tensors format where the i-th elements |
| 4613 | of the two tensors specify an edge. |
| 4614 | * (iterable[int], iterable[int]): Similar to the node-tensors format but |
| 4615 | stores edge endpoints in python iterables. |
| 4616 | |
| 4617 | Default value specifies all the edges in the graph. |
| 4618 | |
| 4619 | etype : str or (str, str, str), optional |
| 4620 | The type name of the edges. The allowed type name formats are: |
| 4621 | |
| 4622 | * ``(str, str, str)`` for source node type, edge type and destination node type. |
| 4623 | * or one ``str`` edge type name if the name can uniquely identify a |
| 4624 | triplet format in the graph. |
| 4625 | |
| 4626 | Can be omitted if the graph has only one type of edges. |
| 4627 | |
| 4628 | Notes |
| 4629 | ----- |
| 4630 | DGL recommends using DGL's bulit-in function for the :attr:`func` argument, |
| 4631 | because DGL will invoke efficient kernels that avoids copying node features to |
| 4632 | edge features in this case. |
| 4633 | |
| 4634 | Examples |
| 4635 | -------- |
| 4636 | |
| 4637 | The following example uses PyTorch backend. |
| 4638 | |
| 4639 | >>> import dgl |
| 4640 | >>> import torch |
| 4641 | |
| 4642 | **Homogeneous graph** |
| 4643 | |
| 4644 | >>> g = dgl.graph(([0, 1, 2, 3], [1, 2, 3, 4])) |
| 4645 | >>> g.ndata['h'] = torch.ones(5, 2) |
| 4646 | >>> g.apply_edges(lambda edges: {'x' : edges.src['h'] + edges.dst['h']}) |
| 4647 | >>> g.edata['x'] |
| 4648 | tensor([[2., 2.], |
| 4649 | [2., 2.], |
| 4650 | [2., 2.], |
| 4651 | [2., 2.]]) |
| 4652 | |
| 4653 | Use built-in function |
| 4654 |
no test coverage detected