code: def coordinate_to_encoding(
      coord_tensor: Tensor,
      num_feats: int = 128,
      temperature: int = 10000,
      scale: float = 2 * math.pi,
  ):
      """Convert coordinate tensor to positional encoding.
  
      Args:
          coord_tensor (Tensor): Coordinate tensor to be converted to
              positional encoding. With the last dimension as 2 or 4.
          num_feats (int, optional): The feature dimension for each position
              along x-axis or y-axis. Note the final returned dimension
              for each position is 2 times of this value. Defaults to 128.
          temperature (int, optional): The temperature used for scaling
              the position embedding. Defaults to 10000.
          scale (float, optional): A scale factor that scales the position
              embedding. The scale will be used only when `normalize` is True.
              Defaults to 2*pi.
      Returns:
          Tensor: Returned encoded positional tensor.
      """
      dim_t = torch.arange(
          num_feats, dtype=torch.float32, device=coord_tensor.device
      )
      dim_t = temperature ** (2 * (dim_t // 2) / num_feats)
      x_embed = coord_tensor[..., 0] * scale
      y_embed = coord_tensor[..., 1] * scale
      pos_x = x_embed[..., None] / dim_t
      pos_y = y_embed[..., None] / dim_t
      pos_x = torch.stack(
          (pos_x[..., 0::2].sin(), pos_x[..., 1::2].cos()), dim=-1
      ).flatten(2)
      pos_y = torch.stack(
          (pos_y[..., 0::2].sin(), pos_y[..., 1::2].cos()), dim=-1
      ).flatten(2)
      if coord_tensor.size(-1) == 2:
          pos = torch.cat((pos_y, pos_x), dim=-1)
      elif coord_tensor.size(-1) == 4:
          w_embed = coord_tensor[..., 2] * scale
          pos_w = w_embed[..., None] / dim_t
          pos_w = torch.stack(
              (pos_w[..., 0::2].sin(), pos_w[..., 1::2].cos()), dim=-1
          ).flatten(2)
  
          h_embed = coord_tensor[..., 3] * scale
          pos_h = h_embed[..., None] / dim_t
          pos_h = torch.stack(
              (pos_h[..., 0::2].sin(), pos_h[..., 1::2].cos()), dim=-1
          ).flatten(2)
  
          pos = torch.cat((pos_y, pos_x, pos_w, pos_h), dim=-1)
      else:
          raise ValueError(
              "Unknown pos_tensor shape(-1):{}".format(
                  coord_tensor.size(-1)
              )
          )
      return pos
  
imports: import math
  import warnings
  from typing import Optional, Sequence, Tuple, Union
  import torch
  import torch.nn.functional
  from mmcv.cnn import Linear, build_activation_layer, build_conv_layer, build_norm_layer
  from mmcv.cnn.bricks.drop import Dropout
  from mmengine.model import BaseModule, ModuleList
  from mmengine.utils import to_2tuple
  from torch import Tensor, nn
  from mmdet.registry import MODELS
  from mmdet.utils import OptConfigType, OptMultiConfig
label_desc: Use image node_id 3 for calling a global function with example usage: coordinate_to_encoding(coord_tensor, num_feats, temperature, scale) and returns: pos