code: def _default_collate(batch):
      r"""Puts each data field into a tensor with outer dimension batch size"""
  
      elem = batch[0]
      elem_type = type(elem)
      if isinstance(elem, pt.Tensor):
          out = None
          if pt.utils.data.get_worker_info() is not None:
              # If we're in a background process, concatenate directly into a
              # shared memory tensor to avoid an extra copy
              numel = sum([x.numel() for x in batch])
              storage = elem.storage()._new_shared(numel)
              out = elem.new(storage)
          return pt.stack(batch, 0, out=out)
      elif (
          elem_type.__module__ == "numpy"
          and elem_type.__name__ != "str_"
          and elem_type.__name__ != "string_"
      ):
          elem = batch[0]
          if elem_type.__name__ == "ndarray":
              # array of string classes and object
              if (
                  np_str_obj_array_pattern.search(elem.dtype.str)
                  is not None
              ):
                  raise TypeError(
                      _default_collate_err_msg_format.format(elem.dtype)
                  )
              return _default_collate([pt.as_tensor(b) for b in batch])
          elif elem.shape == ():  # scalars
              return pt.as_tensor(batch)
      elif isinstance(elem, float):
          return pt.tensor(batch, dtype=pt.float)
      elif isinstance(elem, int_classes):
          return pt.tensor(batch, dtype=pt.long)
      elif isinstance(elem, string_classes):
          return batch
      elif isinstance(elem, container_abcs.Mapping):
          return {
              key: _default_collate([d[key] for d in batch])
              for key in elem
          }
      elif isinstance(elem, tuple) and hasattr(
          elem, "_fields"
      ):  # namedtuple
          return elem_type(
              *(_default_collate(samples) for samples in zip(*batch))
          )
      elif isinstance(elem, container_abcs.Sequence):
          transposed = zip(*batch)
          return [_default_collate(samples) for samples in transposed]
      elif elem is None:
          return None
  
      raise TypeError(_default_collate_err_msg_format.format(elem_type))
  
file_path: gluonts/src/gluonts/nursery/daf/tslib/dataset/loader.py
imports: from typing import NamedTuple, Callable, Optional, Iterator
  import re
  from torch import Tensor
  from torch._six import container_abcs, int_classes, string_classes
  from torch.utils.data import Dataset, DataLoader, DistributedSampler
  import torch
  from ..engine.distributed import is_distributed, get_world_size
label_desc: Use image node_id 1 for calling a global function with example usage: _default_collate(batch) and returns: pt, _default_collate, pt, pt, pt, batch, unknown, elem_type, unknown, None