code: def test_select_impls():
      # Test recursive select that returns tuple of outputs (due to the ops having 2 outputs).
      # Without supporting nested structures it encountered a ((DataNode, DataNode),) branch output
      # and crashed.
  
      def _select_fwd(
          op_range_lo,
          op_range_hi,
          ops,
          selected_op_idx,
          op_args,
          op_kwargs,
      ):
          assert op_range_lo <= op_range_hi
          if op_range_lo == op_range_hi:
              return ops[op_range_lo](*op_args, **op_kwargs)
          mid = (op_range_lo + op_range_hi) // 2
          if selected_op_idx <= mid:
              ret = _select_fwd(
                  op_range_lo,
                  mid,
                  ops,
                  selected_op_idx,
                  op_args,
                  op_kwargs,
              )
          else:
              ret = _select_fwd(
                  mid + 1,
                  op_range_hi,
                  ops,
                  selected_op_idx,
                  op_args,
                  op_kwargs,
              )
          return ret
  
      def _select_unpack(
          op_range_lo,
          op_range_hi,
          ops,
          selected_op_idx,
          op_args,
          op_kwargs,
      ):
          assert op_range_lo <= op_range_hi
          if op_range_lo == op_range_hi:
              return ops[op_range_lo](*op_args, **op_kwargs)
          mid = (op_range_lo + op_range_hi) // 2
          if selected_op_idx <= mid:
              a, b = _select_unpack(
                  op_range_lo,
                  mid,
                  ops,
                  selected_op_idx,
                  op_args,
                  op_kwargs,
              )
          else:
              a, b = _select_unpack(
                  mid + 1,
                  op_range_hi,
                  ops,
                  selected_op_idx,
                  op_args,
                  op_kwargs,
              )
          return a, b
  
      def select(
          ops,
          selected_op_idx,
          *op_args,
          unpacking_select=False,
          **op_kwargs,
      ):
          if unpacking_select:
              return _select_unpack(
                  0,
                  len(ops) - 1,
                  ops,
                  selected_op_idx,
                  op_args,
                  op_kwargs,
              )
          else:
              return _select_fwd(
                  0,
                  len(ops) - 1,
                  ops,
                  selected_op_idx,
                  op_args,
                  op_kwargs,
              )
  
      def rotate(image, label):
          image = fn.rotate(image, angle=42)
          return image, label
  
      def color(image, label):
          image = fn.color_twist(image, saturation=0)
          return image, label
  
      @pipeline_def(
          enable_conditionals=True,
          num_threads=4,
          batch_size=8,
          device_id=0,
      )
      def pipeline(unpacking_select):
          image = types.Constant(
              np.full((200, 300, 3), 42, dtype=np.uint8), device="cpu"
          )
          label = types.Constant(np.array(1), device="cpu")
          ops = [rotate, color]
          op_idx = fn.random.uniform(values=list(range(len(ops))))
          image, label = select(
              ops,
              op_idx,
              image=image,
              label=label,
              unpacking_select=unpacking_select,
          )
          return image, label
  
      pipe_unpacking = pipeline(unpacking_select=True)
      pipe_unpacking.build()
      pipe_unpacking.run()
  
      pipe_forwarding = pipeline(unpacking_select=False)
      pipe_forwarding.build()
      pipe_forwarding.run()
  
imports: from nvidia.dali import fn, pipeline_def, types
  import numpy
  from test_utils import check_batch
  from nose_utils import assert_raises
label_desc: Use image node_id 1 for calling a global function with example usage: test_select_impls() and returns: ret, a,  b, image,  label, image,  label, image,  label, ops, ops, _select_unpack, _select_fwd