code: def feed_ndarray(
      tensor_or_tl, arr, cuda_stream=None, non_blocking=False
  ):
      """
      Copy contents of DALI tensor to PyTorch's Tensor.
  
      Parameters
      ----------
      `tensor_or_tl` : TensorGPU or TensorListGPU
      `arr` : torch.Tensor
              Destination of the copy
      `cuda_stream` : torch.cuda.Stream, cudaStream_t or any value that can be cast to cudaStream_t.
                      CUDA stream to be used for the copy
                      (if not provided, an internal user stream will be selected)
                      In most cases, using pytorch's current stream is expected (for example,
                      if we are copying to a tensor allocated with torch.zeros(...))
      """
      dali_type = to_torch_type[tensor_or_tl.dtype]
      if isinstance(tensor_or_tl, TensorListGPU):
          dali_tensor = tensor_or_tl.as_tensor()
      else:
          dali_tensor = tensor_or_tl
  
      assert dali_type == arr.dtype, (
          f"The element type of DALI Tensor/TensorList "
          f"doesn't match the element type of the target PyTorch Tensor: "
          f"{dali_type} vs {arr.dtype}"
      )
  
      assert dali_tensor.shape() == list(arr.size()), (
          f"Shapes do not match: DALI tensor has size {dali_tensor.shape()}, "
          f"but PyTorch Tensor has size {list(arr.size())}"
      )
      cuda_stream = types._raw_cuda_stream(cuda_stream)
  
      # turn raw int to a c void pointer
      c_type_pointer = ctypes.c_void_p(arr.data_ptr())
      stream = (
          None if cuda_stream is None else ctypes.c_void_p(cuda_stream)
      )
      tensor_or_tl.copy_to_external(
          c_type_pointer, stream, non_blocking
      )
      return arr
  
file_path: DALI/dali/test/python/test_copy_to_external_torch.py
imports: import ctypes
  import numpy
  import nvidia.dali.fn
  import torch
  from nvidia.dali import pipeline_def
  from nvidia.dali import types
  from nvidia.dali.backend import TensorListGPU
label_desc: Use image node_id 2 for calling a global function with example usage: feed_ndarray(tensor_or_tl, arr, cuda_stream, non_blocking) and returns: arr