code: def to_bidirected_with_reverse_mapping(g):
      """Makes a graph bidirectional, and returns a mapping array ``mapping`` where ``mapping[i]``
      is the reverse edge of edge ID ``i``. Does not work with graphs that have self-loops.
      """
      g_simple, mapping = dgl.to_simple(
          dgl.add_reverse_edges(g),
          return_counts="count",
          writeback_mapping=True,
      )
      c = g_simple.edata["count"]
      num_edges = g.num_edges()
      mapping_offset = torch.zeros(
          g_simple.num_edges() + 1, dtype=g_simple.idtype
      )
      mapping_offset[1:] = c.cumsum(0)
      idx = mapping.argsort()
      idx_uniq = idx[mapping_offset[:-1]]
      reverse_idx = torch.where(
          idx_uniq >= num_edges,
          idx_uniq - num_edges,
          idx_uniq + num_edges,
      )
      reverse_mapping = mapping[reverse_idx]
      # sanity check
      src1, dst1 = g_simple.edges()
      src2, dst2 = g_simple.find_edges(reverse_mapping)
      assert torch.equal(src1, dst2)
      assert torch.equal(src2, dst1)
      return g_simple, reverse_mapping
  
file_path: dgl/examples/pytorch/graphsage/link_pred.py
imports: import argparse
  import dgl
  import dgl.nn
  import torch
  import torch.nn
  import torch.nn.functional
  import tqdm
  from dgl.dataloading import as_edge_prediction_sampler, DataLoader, MultiLayerFullNeighborSampler, negative_sampler, NeighborSampler
  from ogb.linkproppred import DglLinkPropPredDataset, Evaluator
label_desc: Use image node_id 1 for calling a global function with example usage: to_bidirected_with_reverse_mapping(g) and returns: g_simple,  reverse_mapping