code: def _collate(
      key: str,
      values: List[Any],
      data_list: List[BaseData],
      stores: List[BaseStorage],
      increment: bool,
  ) -> Tuple[Any, Any, Any]:
      elem = values[0]
  
      if isinstance(elem, Tensor) and not is_sparse(elem):
          # Concatenate a list of `torch.Tensor` along the `cat_dim`.
          # NOTE: We need to take care of incrementing elements appropriately.
          key = str(key)
          cat_dim = data_list[0].__cat_dim__(key, elem, stores[0])
          if cat_dim is None or elem.dim() == 0:
              values = [value.unsqueeze(0) for value in values]
          sizes = torch.tensor(
              [value.size(cat_dim or 0) for value in values]
          )
          slices = cumsum(sizes)
          if increment:
              incs = get_incs(key, values, data_list, stores)
              if incs.dim() > 1 or int(incs[-1]) != 0:
                  values = [
                      value + inc.to(value.device)
                      for value, inc in zip(values, incs)
                  ]
          else:
              incs = None
  
          if getattr(elem, "is_nested", False):
              tensors = []
              for nested_tensor in values:
                  tensors.extend(nested_tensor.unbind())
              value = torch.nested.nested_tensor(tensors)
  
              return value, slices, incs
  
          out = None
          if torch.utils.data.get_worker_info() is not None:
              # Write directly into shared memory to avoid an extra copy:
              numel = sum(value.numel() for value in values)
              if torch_geometric.typing.WITH_PT20:
                  storage = elem.untyped_storage()._new_shared(
                      numel * elem.element_size(), device=elem.device
                  )
              elif torch_geometric.typing.WITH_PT112:
                  storage = elem.storage()._new_shared(
                      numel, device=elem.device
                  )
              else:
                  storage = elem.storage()._new_shared(numel)
              shape = list(elem.size())
              if cat_dim is None or elem.dim() == 0:
                  shape = [len(values)] + shape
              else:
                  shape[cat_dim] = int(slices[-1])
              out = elem.new(storage).resize_(*shape)
  
          value = torch.cat(values, dim=cat_dim or 0, out=out)
  
          if (
              increment
              and isinstance(value, EdgeIndex)
              and values[0].is_sorted
          ):
              # Check whether the whole `EdgeIndex` is sorted by row:
              if (
                  values[0].is_sorted_by_row
                  and (value[0].diff() >= 0).all()
              ):
                  value._sort_order = SortOrder.ROW
              # Check whether the whole `EdgeIndex` is sorted by column:
              elif (
                  values[0].is_sorted_by_col
                  and (value[1].diff() >= 0).all()
              ):
                  value._sort_order = SortOrder.COL
  
          return value, slices, incs
  
      elif isinstance(elem, TensorFrame):
          key = str(key)
          sizes = torch.tensor([value.num_rows for value in values])
          slices = cumsum(sizes)
          value = torch_frame.cat(values, dim=0)
          return value, slices, None
  
      elif is_sparse(elem) and increment:
          # Concatenate a list of `SparseTensor` along the `cat_dim`.
          # NOTE: `cat_dim` may return a tuple to allow for diagonal stacking.
          key = str(key)
          cat_dim = data_list[0].__cat_dim__(key, elem, stores[0])
          cat_dims = (cat_dim,) if isinstance(cat_dim, int) else cat_dim
          repeats = [
              [value.size(dim) for dim in cat_dims] for value in values
          ]
          slices = cumsum(torch.tensor(repeats))
          if is_torch_sparse_tensor(elem):
              value = cat(values, dim=cat_dim)
          else:
              value = torch_sparse.cat(values, dim=cat_dim)
          return value, slices, None
  
      elif isinstance(elem, (int, float)):
          # Convert a list of numerical values to a `torch.Tensor`.
          value = torch.tensor(values)
          if increment:
              incs = get_incs(key, values, data_list, stores)
              if int(incs[-1]) != 0:
                  value.add_(incs)
          else:
              incs = None
          slices = torch.arange(len(values) + 1)
          return value, slices, incs
  
      elif isinstance(elem, Mapping):
          # Recursively collate elements of dictionaries.
          value_dict, slice_dict, inc_dict = {}, {}, {}
          for key in elem.keys():
              (
                  value_dict[key],
                  slice_dict[key],
                  inc_dict[key],
              ) = _collate(
                  key,
                  [v[key] for v in values],
                  data_list,
                  stores,
                  increment,
              )
          return value_dict, slice_dict, inc_dict
  
      elif (
          isinstance(elem, Sequence)
          and not isinstance(elem, str)
          and len(elem) > 0
          and isinstance(elem[0], (Tensor, SparseTensor))
      ):
          # Recursively collate elements of lists.
          value_list, slice_list, inc_list = [], [], []
          for i in range(len(elem)):
              value, slices, incs = _collate(
                  key,
                  [v[i] for v in values],
                  data_list,
                  stores,
                  increment,
              )
              value_list.append(value)
              slice_list.append(slices)
              inc_list.append(incs)
          return value_list, slice_list, inc_list
  
      else:
          # Other-wise, just return the list of values as it is.
          slices = torch.arange(len(values) + 1)
          return values, slices, None
  
file_path: pytorch_geometric/torch_geometric/data/collate.py
imports: from collections import defaultdict
  from collections.abc import Mapping, Sequence
  from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, TypeVar, Union
  import torch
  from torch import Tensor
  import torch_geometric.typing
  from torch_geometric import EdgeIndex
  from torch_geometric.data.data import BaseData
  from torch_geometric.data.storage import BaseStorage, NodeStorage
  from torch_geometric.edge_index import SortOrder
  from torch_geometric.typing import SparseTensor, TensorFrame, torch_frame, torch_sparse
  from torch_geometric.utils import cumsum, is_sparse, is_torch_sparse_tensor
  from torch_geometric.utils.sparse import cat
label_desc: Use image node_id 2 for calling a global function with example usage: _collate(key, values, data_list, stores, increment) and returns: value,  slices,  incs, value,  slices,  incs, value,  slices,  None, value,  slices,  None, value,  slices,  incs, value_dict,  slice_dict,  inc_dict, value_list,  slice_list,  inc_list, values,  slices,  None