code: def degree(
      index,
      num_nodes: _typing.Optional[int] = None,
      dtype: _typing.Optional[torch.dtype] = None,
  ):
      r"""Computes the (unweighted) degree of a given one-dimensional index
      tensor.
  
      Args:
          index (LongTensor): Index tensor.
          num_nodes (int, optional): The number of nodes, *i.e.*
              :obj:`max_val + 1` of :attr:`index`. (default: :obj:`None`)
          dtype (:obj:`torch.dtype`, optional): The desired data type of the
              returned tensor.
  
      :rtype: :class:`Tensor`
      """
  
      def maybe_num_nodes(edge_index, __num_nodes=None):
          if __num_nodes is not None:
              return __num_nodes
          elif isinstance(edge_index, torch.Tensor):
              return (
                  int(edge_index.max()) + 1
                  if edge_index.numel() > 0
                  else 0
              )
          else:
              return max(edge_index.size(0), edge_index.size(1))
  
      N = maybe_num_nodes(index, num_nodes)
      out = torch.zeros((N,), dtype=dtype, device=index.device)
      one = torch.ones(
          (index.size(0),), dtype=out.dtype, device=out.device
      )
      return out.scatter_add_(0, index, one)
  
file_path: AutoGL/autogl/module/feature/_generators/_pyg_impl.py
imports: import torch
  import typing
  from typing import Optional, Tuple
label_desc: Use image node_id 1 for calling a global function with example usage: degree(index, num_nodes, dtype) and returns: out, __num_nodes, unknown, max