code: def check_pad_to_square(
      device="cpu", batch_size=3, ndim=2, num_iter=3
  ):
      pipe = Pipeline(
          batch_size=batch_size, num_threads=3, device_id=0, seed=1234
      )
      with pipe:
          in_shape = fn.cast(
              fn.random.uniform(range=(10, 20), shape=(ndim,)),
              dtype=types.INT32,
          )
          in_data = fn.reshape(
              fn.random.uniform(range=(0.0, 1.0), shape=in_shape),
              layout="HW",
          )
          shape = fn.shapes(in_data, dtype=types.INT32)
          h = fn.slice(shape, 0, 1, axes=[0])
          w = fn.slice(shape, 1, 1, axes=[0])
          side = math.max(h, w)
          if device == "gpu":
              in_data = in_data.gpu()
          out_data = fn.pad(
              in_data, axis_names="HW", shape=fn.cat(side, side, axis=0)
          )
          pipe.set_outputs(in_data, out_data)
      pipe.build()
      for _ in range(num_iter):
          outs = [
              out.as_cpu() if isinstance(out, TensorListGPU) else out
              for out in pipe.run()
          ]
          for i in range(batch_size):
              in_data, out_data = [
                  outs[out_idx].at(i) for out_idx in range(len(outs))
              ]
              in_shape = in_data.shape
              max_side = max(in_shape)
              for s in out_data.shape:
                  assert s == max_side
              np.testing.assert_equal(
                  out_data[: in_shape[0], : in_shape[1]], in_data
              )
              np.testing.assert_equal(out_data[in_shape[0] :, :], 0)
              np.testing.assert_equal(out_data[:, in_shape[1] :], 0)
  
imports: import numpy
  import nvidia.dali
  import nvidia.dali.fn
  import nvidia.dali.math
  import nvidia.dali.ops
  import nvidia.dali.types
  from nvidia.dali import Pipeline, pipeline_def
  from nvidia.dali.backend_impl import TensorListGPU
  from nose_utils import assert_raises
  from test_utils import RandomlyShapedDataIterator, generator_random_axes_for_3d_input, generator_random_data, as_array
label_desc: Use image node_id 7 for calling a global function with example usage: check_pad_to_square(device, batch_size, ndim, num_iter) without return types