code: def test_multibox_prior(executor_kind):
      def get_ref_result(
          dshape,
          sizes=(1.0,),
          ratios=(1.0,),
          steps=(-1.0, -1.0),
          offsets=(0.5, 0.5),
          clip=True,
      ):
          in_height = dshape[2]
          in_width = dshape[3]
          num_sizes = len(sizes)
          num_ratios = len(ratios)
          size_ratio_concat = sizes + ratios
          steps_h = steps[0] if steps[0] > 0 else 1.0 / in_height
          steps_w = steps[1] if steps[1] > 0 else 1.0 / in_width
          offset_h = offsets[0]
          offset_w = offsets[1]
  
          oshape = (
              1,
              in_height * in_width * (num_sizes + num_ratios - 1),
              4,
          )
          dtype = "float32"
          np_out = np.zeros(oshape).astype(dtype)
  
          for i in range(in_height):
              center_h = (i + offset_h) * steps_h
              for j in range(in_width):
                  center_w = (j + offset_w) * steps_w
                  for k in range(num_sizes + num_ratios - 1):
                      w = (
                          size_ratio_concat[k]
                          * in_height
                          / in_width
                          / 2.0
                          if k < num_sizes
                          else size_ratio_concat[0]
                          * in_height
                          / in_width
                          * math.sqrt(size_ratio_concat[k + 1])
                          / 2.0
                      )
                      h = (
                          size_ratio_concat[k] / 2.0
                          if k < num_sizes
                          else size_ratio_concat[0]
                          / math.sqrt(size_ratio_concat[k + 1])
                          / 2.0
                      )
                      count = (
                          i * in_width * (num_sizes + num_ratios - 1)
                          + j * (num_sizes + num_ratios - 1)
                          + k
                      )
                      np_out[0][count][0] = center_w - w
                      np_out[0][count][1] = center_h - h
                      np_out[0][count][2] = center_w + w
                      np_out[0][count][3] = center_h + h
          if clip:
              np_out = np.clip(np_out, 0, 1)
  
          return np_out
  
      def verify_multibox_prior(
          x,
          dshape,
          ref_res,
          sizes=(1.0,),
          ratios=(1.0,),
          steps=(-1.0, -1.0),
          offsets=(0.5, 0.5),
          clip=True,
          check_size=False,
          check_type_only=False,
      ):
          z = relay.vision.multibox_prior(
              x, sizes, ratios, steps, offsets, clip
          )
          zz = run_infer_type(z)
          if check_size:
              assert "sizes=" in z.astext()
          assert zz.checked_type == relay.TensorType(
              (
                  1,
                  dshape[2]
                  * dshape[3]
                  * (len(sizes) + len(ratios) - 1),
                  4,
              ),
              "float32",
          )
  
          if check_type_only:
              return
  
          data = np.random.uniform(low=-1, high=1, size=dshape).astype(
              "float32"
          )
          func = relay.Function([x], z)
          func = run_infer_type(func)
          for target, dev in tvm.testing.enabled_targets():
              op_res = relay.create_executor(
                  executor_kind, device=dev, target=target
              ).evaluate(func)(data)
              tvm.testing.assert_allclose(
                  op_res.numpy(), ref_res, rtol=1e-5
              )
  
      sizes = (0.3, 1.5, 0.7)
      ratios = (1.3, 2.4)
      steps = (2.0, 1.5)
      offsets = (0.2, 0.3)
      dshape = (1, 3, 56, 56)
      ref_res = get_ref_result(dshape, sizes, ratios, steps, offsets)
      x = relay.var("x", relay.TensorType(dshape, "float32"))
      verify_multibox_prior(
          x,
          dshape,
          ref_res,
          sizes,
          ratios,
          steps,
          offsets,
          check_size=True,
      )
      y = relay.var(
          "y",
          relay.TensorType((te.size_var("n"), 3, 56, 56), "float32"),
      )
      verify_multibox_prior(
          x,
          dshape,
          ref_res,
          sizes,
          ratios,
          steps,
          offsets,
          check_size=True,
          check_type_only=True,
      )
  
      dshape = (1, 24, 32, 32)
      ref_res = get_ref_result(dshape, clip=False)
      x = relay.var("x", relay.TensorType(dshape, "float32"))
      verify_multibox_prior(x, dshape, ref_res, clip=False)
      y = relay.var(
          "y",
          relay.TensorType((te.size_var("n"), 24, 32, 32), "float32"),
      )
      verify_multibox_prior(
          x, dshape, ref_res, clip=False, check_type_only=True
      )
  
imports: import math
  import platform
  import sys
  import numpy
  import pytest
  import tvm
  import tvm.testing
  import tvm.topi.testing
  from tvm import relay, te
  from tvm.relay.testing import run_infer_type
label_desc: Use image node_id 4 for calling a global function with example usage: test_multibox_prior(executor_kind) and returns: np_out