code: def normalize_adj_tensor(adj, sparse=False):
      """Normalize adjacency tensor matrix."""
      device = torch.device("cuda" if adj.is_cuda else "cpu")
      if sparse:
          # warnings.warn('If you find the training process is too slow, you can uncomment line 207 in deeprobust/graph/utils.py. Note that you need to install torch_sparse')
          # TODO if this is too slow, uncomment the following code,
          # but you need to install torch_scatter
          # return normalize_sparse_tensor(adj)
          adj = to_scipy(adj)
          mx = normalize_adj(adj)
          return sparse_mx_to_torch_sparse_tensor(mx).to(device)
      else:
          mx = adj + torch.eye(adj.shape[0]).to(device)
          rowsum = mx.sum(1)
          r_inv = rowsum.pow(-1 / 2).flatten()
          r_inv[torch.isinf(r_inv)] = 0.0
          r_mat_inv = torch.diag(r_inv)
          mx = r_mat_inv @ mx
          mx = mx @ r_mat_inv
      return mx
  
file_path: AutoGL/autogl/module/model/pyg/robust/utils.py
imports: import numpy
  import scipy.sparse
  import torch
label_desc: Use image node_id 4 for calling a global function with example usage: normalize_adj_tensor(adj, sparse) and returns: mx, sparse_mx_to_torch_sparse_tensor