code: def calc_rel_pos(n):
      pos = torch.meshgrid(torch.arange(n), torch.arange(n))
      pos = rearrange(
          torch.stack(pos), "n i j -> (i j) n"
      )  # [n*n, 2] pos[n] = (i, j)
      rel_pos = (
          pos[None, :] - pos[:, None]
      )  # [n*n, n*n, 2] rel_pos[n, m] = (rel_i, rel_j)
      rel_pos += (
          n - 1
      )  # shift value range from [-n+1, n-1] to [0, 2n-2]
      return rel_pos
  
file_path: lambda-networks/lambda_networks/lambda_networks.py
imports: import torch
  from torch import nn, einsum
  from einops import rearrange
label_desc: Use image node_id 3 for calling a global function with example usage: calc_rel_pos(n) and returns: rel_pos