code: def test_simple_batch_permute(batch_size, permute_prefix):
      """
      Permute `permute_prefix` of the batch and leave the remaining part untouched
      """
  
      @pipeline_def(
          batch_size=batch_size,
          device_id=0,
          num_threads=4,
          enable_conditionals=True,
      )
      def pipeline():
          sample_idx = fn.external_source(
              lambda sample_info: np.array(
                  sample_info.idx_in_batch, dtype=np.int32
              ),
              batch=False,
          )
          if sample_idx < permute_prefix:
              sample_idx = fn.batch_permutation()
          return sample_idx
  
      p = pipeline()
      p.build()
  
      for _ in range(3):
          (sample_indices,) = p.run()
          sample_indices = [
              np.array(sample).item() for sample in sample_indices
          ]
          permuted_prefix = sample_indices[:permute_prefix]
          expected_prefix = list(range(permute_prefix))
          untouched_suffix = sample_indices[permute_prefix:]
          expected_suffix = list(range(permute_prefix, batch_size))
          assert sorted(permuted_prefix) == expected_prefix, (
              f"expected permuted prefix `{permuted_prefix}` to contain the "
              f"following samples {expected_prefix}"
          )
          assert untouched_suffix == expected_suffix, (
              f"expected untouched suffix `{untouched_suffix}` to be exactly "
              f"{expected_suffix}"
          )
  
imports: from nvidia.dali.pipeline import pipeline_def, experimental
  import nvidia.dali.fn
  import nvidia.dali.types
  from nvidia.dali.types import SampleInfo
  from nvidia.dali import _conditionals
  from nvidia.dali.data_node import DataNode
  import numpy
  import os
  from test_utils import check_batch, compare_pipelines
  from nose_utils import assert_raises
  from test_utils import get_dali_extra_path
  from nose2.tools import params
  import itertools
label_desc: Use image node_id 39 for calling a global function with example usage: test_simple_batch_permute(batch_size, permute_prefix) and returns: sample_idx