code: def distance2bbox(
      points: Tensor,
      distance: Tensor,
      max_shape: Optional[
          Union[Sequence[int], Tensor, Sequence[Sequence[int]]]
      ] = None,
  ) -> Tensor:
      """Decode distance prediction to bounding box.
  
      Args:
          points (Tensor): Shape (B, N, 2) or (N, 2).
          distance (Tensor): Distance from the given point to 4
              boundaries (left, top, right, bottom). Shape (B, N, 4) or (N, 4)
          max_shape (Union[Sequence[int], Tensor, Sequence[Sequence[int]]],
              optional): Maximum bounds for boxes, specifies
              (H, W, C) or (H, W). If priors shape is (B, N, 4), then
              the max_shape should be a Sequence[Sequence[int]]
              and the length of max_shape should also be B.
  
      Returns:
          Tensor: Boxes with shape (N, 4) or (B, N, 4)
      """
  
      x1 = points[..., 0] - distance[..., 0]
      y1 = points[..., 1] - distance[..., 1]
      x2 = points[..., 0] + distance[..., 2]
      y2 = points[..., 1] + distance[..., 3]
  
      bboxes = torch.stack([x1, y1, x2, y2], -1)
  
      if max_shape is not None:
          if bboxes.dim() == 2 and not torch.onnx.is_in_onnx_export():
              # speed up
              bboxes[:, 0::2].clamp_(min=0, max=max_shape[1])
              bboxes[:, 1::2].clamp_(min=0, max=max_shape[0])
              return bboxes
  
          # clip bboxes with dynamic `min` and `max` for onnx
          if torch.onnx.is_in_onnx_export():
              # TODO: delete
              from mmdet.core.export import dynamic_clip_for_onnx
  
              x1, y1, x2, y2 = dynamic_clip_for_onnx(
                  x1, y1, x2, y2, max_shape
              )
              bboxes = torch.stack([x1, y1, x2, y2], dim=-1)
              return bboxes
          if not isinstance(max_shape, torch.Tensor):
              max_shape = x1.new_tensor(max_shape)
          max_shape = max_shape[..., :2].type_as(x1)
          if max_shape.ndim == 2:
              assert bboxes.ndim == 3
              assert max_shape.size(0) == bboxes.size(0)
  
          min_xy = x1.new_tensor(0)
          max_xy = (
              torch.cat([max_shape, max_shape], dim=-1)
              .flip(-1)
              .unsqueeze(-2)
          )
          bboxes = torch.where(bboxes < min_xy, min_xy, bboxes)
          bboxes = torch.where(bboxes > max_xy, max_xy, bboxes)
  
      return bboxes
  
imports: from typing import List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  from torch import Tensor
  from mmdet.structures.bbox import BaseBoxes
label_desc: Use image node_id 8 for calling a global function with example usage: distance2bbox(points, distance, max_shape) and returns: bboxes, bboxes, bboxes