code: def check_pad_per_sample_shapes_and_alignment(
      device="cpu", batch_size=3, ndim=2, num_iter=3
  ):
      pipe = Pipeline(
          batch_size=batch_size, num_threads=3, device_id=0, seed=1234
      )
      axes = (0, 1)
      with pipe:
          in_shape = fn.cast(
              fn.random.uniform(range=(10, 20), shape=(ndim,)),
              dtype=types.INT32,
          )
          in_data = fn.random.uniform(range=(0.0, 1.0), shape=in_shape)
          if device == "gpu":
              in_data = in_data.gpu()
          req_shape = fn.cast(
              fn.random.uniform(range=(21, 30), shape=(ndim,)),
              dtype=types.INT32,
          )
          req_align = fn.cast(
              fn.random.uniform(range=(3, 5), shape=(ndim,)),
              dtype=types.INT32,
          )
          out_pad_shape = fn.pad(
              in_data, axes=axes, align=None, shape=req_shape
          )
          out_pad_align = fn.pad(
              in_data, axes=axes, align=req_align, shape=None
          )
          out_pad_both = fn.pad(
              in_data, axes=axes, align=req_align, shape=req_shape
          )
          pipe.set_outputs(
              in_shape,
              in_data,
              req_shape,
              req_align,
              out_pad_shape,
              out_pad_align,
              out_pad_both,
          )
      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_shape,
                  in_data,
                  req_shape,
                  req_align,
                  out_pad_shape,
                  out_pad_align,
                  out_pad_both,
              ) = [outs[out_idx].at(i) for out_idx in range(len(outs))]
              assert (in_shape == in_data.shape).all()
              # Pad to explicit shape
              assert (out_pad_shape.shape >= in_shape).all()
              assert (req_shape == out_pad_shape.shape).all()
  
              # Alignment only
              assert (out_pad_align.shape >= in_shape).all()
              assert is_aligned(out_pad_align.shape, req_align, axes)
  
              # Explicit shape + alignment
              assert (out_pad_both.shape >= in_shape).all()
              assert (req_shape <= out_pad_both.shape).all()
              assert is_aligned(out_pad_both.shape, req_align, axes)
  
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 5 for calling a global function with example usage: check_pad_per_sample_shapes_and_alignment(device, batch_size, ndim, num_iter) without return types