code: def degree_as_feature(dataset: LegacyTUDataset, save=True):
      """
      Description
      -----------
      Use node degree (in one-hot format) as node feature
  
      Parameters
      ----------
      dataset : LegacyTUDataset
          The dataset object
  
      save : bool, optional
          Save the result dataset.
          Default: :obj:`True`
      """
      # first check if already have such feature
      check_mark_name = "degree_as_feat"
      feat_name = "feat"
      check_mark_path = os.path.join(
          dataset.save_path,
          "info_{}_{}.json".format(dataset.name, dataset.hash),
      )
      check_mark = _load_check_mark(check_mark_path)
  
      if (
          check_mark_name in check_mark
          and check_mark[check_mark_name]
          and not dataset._force_reload
      ):
          logging.warning("Using cached value in 'degree_as_feature'")
          return dataset
  
      logging.warning("Adding node degree into node features...")
      min_degree = sys.maxsize
      max_degree = 0
      for i in range(len(dataset)):
          degrees = dataset.graph_lists[i].in_degrees()
          min_degree = min(min_degree, degrees.min().item())
          max_degree = max(max_degree, degrees.max().item())
  
      vec_len = max_degree - min_degree + 1
      for i in range(len(dataset)):
          num_nodes = dataset.graph_lists[i].num_nodes()
          node_feat = torch.zeros((num_nodes, vec_len))
          degrees = dataset.graph_lists[i].in_degrees()
          node_feat[torch.arange(num_nodes), degrees - min_degree] = 1.0
          dataset.graph_lists[i].ndata[feat_name] = node_feat
  
      if save:
          check_mark[check_mark_name] = True
          dataset.save()
          _save_check_mark(check_mark_path, check_mark)
      return dataset
  
file_path: dgl/examples/pytorch/gxn/data_preprocess.py
imports: import json
  import logging
  import os
  import sys
  import numpy
  import torch
  from dgl.data import LegacyTUDataset
label_desc: Use image node_id 4 for calling a global function with example usage: degree_as_feature(dataset, save) and returns: dataset, dataset