class_docstr: TimeSeriesLoader DataLoader.
  [Source code](https://github.com/Nixtla/neuralforecast1/blob/main/neuralforecast/tsdataset.py).
  
  Small change to PyTorch's Data loader.
  Combines a dataset and a sampler, and provides an iterable over the given dataset.
  
  The class `~torch.utils.data.DataLoader` supports both map-style and
  iterable-style datasets with single- or multi-process loading, customizing
  loading order and optional automatic batching (collation) and memory pinning.
  
  **Parameters:**<br>
  `batch_size`: (int, optional): how many samples per batch to load (default: 1).<br>
  `shuffle`: (bool, optional): set to `True` to have the data reshuffled at every epoch (default: `False`).<br>
  `sampler`: (Sampler or Iterable, optional): defines the strategy to draw samples from the dataset.<br>
              Can be any `Iterable` with `__len__` implemented. If specified, `shuffle` must not be specified.<br>
class_docstr_tok: ["TimeSeriesLoader","DataLoader",".","[","Source","code","]","(","https",":","\/\/github.com\/Nixtla\/neuralforecast1\/blob\/main\/neuralforecast\/tsdataset.py",")",".","Small","change","to","PyTorch","'s","Data","loader",".","Combines","a","dataset","and","a","sampler",",","and","provides","an","iterable","over","the","given","dataset",".","The","class","`","~torch.utils.data.DataLoader","`","supports","both","map-style","and","iterable-style","datasets","with","single-","or","multi-process","loading",",","customizing","loading","order","and","optional","automatic","batching","(","collation",")","and","memory","pinning",".","*","*","Parameters",":","*","*","<","br",">","`","batch_size","`",":","(","int",",","optional",")",":","how","many","samples","per","batch","to","load","(","default",":","1",")",".","<","br",">","`","shuffle","`",":","(","bool",",","optional",")",":","set","to","`","True","`","to","have","the","data","reshuffled","at","every","epoch","(","default",":","`","False","`",")",".","<","br",">","`","sampler","`",":","(","Sampler","or","Iterable",",","optional",")",":","defines","the","strategy","to","draw","samples","from","the","dataset.","<","br",">","Can","be","any","`","Iterable","`","with","`","__len__","`","implemented",".","If","specified",",","`","shuffle","`","must","not","be","specified.","<","br",">"]
code: def _collate_fn(self, batch):
      elem = batch[0]
      elem_type = type(elem)
  
      if isinstance(elem, torch.Tensor):
          out = None
          if torch.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, device=elem.device
              )
              out = elem.new(storage).resize_(
                  len(batch), *list(elem.size())
              )
          return torch.stack(batch, 0, out=out)
  
      elif isinstance(elem, Mapping):
          if elem["static"] is None:
              return dict(
                  temporal=self.collate_fn(
                      [d["temporal"] for d in batch]
                  ),
                  temporal_cols=elem["temporal_cols"],
                  y_idx=elem["y_idx"],
              )
  
          return dict(
              static=self.collate_fn([d["static"] for d in batch]),
              static_cols=elem["static_cols"],
              temporal=self.collate_fn([d["temporal"] for d in batch]),
              temporal_cols=elem["temporal_cols"],
              y_idx=elem["y_idx"],
          )
  
      raise TypeError(f"Unknown {elem_type}")
  
imports: import warnings
  from collections.abc import Mapping
  import numpy
  import pandas
  import pytorch_lightning
  import torch
  import utilsforecast.processing
  from torch.utils.data import Dataset, DataLoader
  from utilsforecast.compat import DataFrame, pl_Series
label_desc: Use image node_id 2 for calling the TimeSeriesLoader obj's underlying member method code with example usage: obj._collate_fn(batch) and returns: torch, dict, dict