code: def test_grid_sample():
      def verify_grid_sample(
          data_shape,
          grid_shape,
          method="bilinear",
          layout="NCHW",
          padding_mode="zeros",
          align_corners=True,
      ):
          dtype = "float32"
          data = te.placeholder(data_shape, dtype=dtype)
          grid = te.placeholder(grid_shape, dtype=dtype)
          out = topi.image.grid_sample(
              data, grid, method, layout, padding_mode, align_corners
          )
  
          @memoize("topi.tests.test_grid_sample.verify_grid_sample")
          def get_ref_data():
              data_np = np.random.uniform(size=data_shape).astype(dtype)
              # allow grid values to be out-of-bound
              grid_np = np.random.uniform(
                  size=grid_shape, low=-1.5, high=1.5
              ).astype(dtype)
              out_np = tvm.topi.testing.grid_sample_python(
                  data_np,
                  grid_np,
                  method,
                  layout,
                  padding_mode,
                  align_corners,
              )
              return data_np, grid_np, out_np
  
          data_np, grid_np, out_np = get_ref_data()
  
          def check_target(target, dev):
              print("Running on target: %s" % target)
              with tvm.target.Target(target):
                  s = tvm.topi.testing.get_injective_schedule(target)(
                      out
                  )
              tvm_data = tvm.nd.array(data_np, dev)
              tvm_grid = tvm.nd.array(grid_np, dev)
              tvm_out = tvm.nd.empty(out_np.shape, dtype, dev)
              f = tvm.build(s, [data, grid, out], target)
              f(tvm_data, tvm_grid, tvm_out)
  
              tvm.testing.assert_allclose(
                  tvm_out.numpy(), out_np, rtol=1e-5, atol=1e-5
              )
  
          for target, dev in tvm.testing.enabled_targets():
              check_target(target, dev)
  
      methods = ["nearest", "bilinear", "bicubic"]
      padding_modes = ["zeros", "border", "reflection"]
      align_corners = [True, False]
      data_2D_shape = (4, 4, 8, 8)
      grid_2D_shape = (4, 2, 16, 16)
      layout_2D = "NCHW"
      # choosing smaller sizes to be testable on weaker GPUs
      data_3D_shape = (4, 4, 4, 4, 4)
      grid_3D_shape = (4, 3, 8, 8, 8)
      layout_3D = "NCDHW"
  
      for _method in methods:
          for _padding in padding_modes:
              for _align in align_corners:
                  verify_grid_sample(
                      data_2D_shape,
                      grid_2D_shape,
                      _method,
                      layout_2D,
                      _padding,
                      _align,
                  )
  
                  # 3D "bicubic"(tricubic) is not supported in pytorch
                  if _method != "bicubic":
                      verify_grid_sample(
                          data_3D_shape,
                          grid_3D_shape,
                          _method,
                          layout_3D,
                          _padding,
                          _align,
                      )
  
file_path: tvm/tests/python/topi/test_topi_image.py
imports: import numpy
  import tvm
  from tvm import te
  from tvm import topi
  import tvm.testing
  import tvm.topi.testing
  from tvm.contrib.pickle_memoize import memoize
label_desc: Use image node_id 7 for calling a global function with example usage: test_grid_sample() and returns: data_np,  grid_np,  out_np