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

Method out_degrees

python/dgl/heterograph.py:3679–3757  ·  view source on GitHub ↗

Return the out-degree(s) of the given nodes. It computes the out-degree(s) w.r.t. to the edges of the given edge type. Parameters ---------- u : node IDs The node IDs. The allowed formats are: * ``int``: A single node. * Int Tens

(self, u=ALL, etype=None)

Source from the content-addressed store, hash-verified

3677 return deg
3678
3679 def out_degrees(self, u=ALL, etype=None):
3680 """Return the out-degree(s) of the given nodes.
3681
3682 It computes the out-degree(s) w.r.t. to the edges of the given edge type.
3683
3684 Parameters
3685 ----------
3686 u : node IDs
3687 The node IDs. The allowed formats are:
3688
3689 * ``int``: A single node.
3690 * Int Tensor: Each element is a node ID. The tensor must have the same device type
3691 and ID data type as the graph's.
3692 * iterable[int]: Each element is a node ID.
3693
3694 If not given, return the in-degrees of all the nodes.
3695 etype : str or (str, str, str), optional
3696 The type names of the edges. The allowed type name formats are:
3697
3698 * ``(str, str, str)`` for source node type, edge type and destination node type.
3699 * or one ``str`` edge type name if the name can uniquely identify a
3700 triplet format in the graph.
3701
3702 Can be omitted if the graph has only one type of edges.
3703
3704 Returns
3705 -------
3706 int or Tensor
3707 The out-degree(s) of the node(s) in a Tensor. The i-th element is the out-degree
3708 of the i-th input node. If :attr:`v` is an ``int``, return an ``int`` too.
3709
3710 Examples
3711 --------
3712 The following example uses PyTorch backend.
3713
3714 >>> import dgl
3715 >>> import torch
3716
3717 Create a homogeneous graph.
3718
3719 >>> g = dgl.graph((torch.tensor([0, 0, 1, 1]), torch.tensor([1, 1, 2, 3])))
3720
3721 Query for all nodes.
3722
3723 >>> g.out_degrees()
3724 tensor([2, 2, 0, 0])
3725
3726 Query for nodes 1 and 2.
3727
3728 >>> g.out_degrees(torch.tensor([1, 2]))
3729 tensor([2, 0])
3730
3731 For a graph of multiple edge types, it is required to specify the edge type in query.
3732
3733 >>> hg = dgl.heterograph({
3734 ... ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
3735 ... ('user', 'plays', 'game'): (torch.tensor([3, 4]), torch.tensor([5, 6]))
3736 ... })

Callers 15

_testFunction · 0.45
test_empty_queryFunction · 0.45
_test_hypersparseFunction · 0.45
_test_queryFunction · 0.45
_test_oneFunction · 0.45
_test_csr_oneFunction · 0.45
test_hypersparse_queryFunction · 0.45
test_formatsFunction · 0.45
test_partition_with_haloFunction · 0.45
test_reorder_nodesFunction · 0.45
test_degree_encoderFunction · 0.45

Calls 6

to_canonical_etypeMethod · 0.95
get_etype_idMethod · 0.95
srcnodesMethod · 0.95
has_nodesMethod · 0.95
is_allFunction · 0.85
DGLErrorClass · 0.85

Tested by 13

_testFunction · 0.36
test_empty_queryFunction · 0.36
_test_hypersparseFunction · 0.36
_test_queryFunction · 0.36
_test_oneFunction · 0.36
_test_csr_oneFunction · 0.36
test_hypersparse_queryFunction · 0.36
test_formatsFunction · 0.36
test_partition_with_haloFunction · 0.36
test_reorder_nodesFunction · 0.36
test_degree_encoderFunction · 0.36