class_docstr: Dataset as a stacking of multiple datasets.
  
  This class is useful to assemble different parts of complex input data, given as datasets.
  
  Example:
      >>> # xdoctest: +SKIP
      >>> images = ImageDataset()
      >>> texts = TextDataset()
      >>> tuple_stack = StackDataset(images, texts)
      >>> tuple_stack[0] == (images[0], texts[0])
      >>> dict_stack = StackDataset(image=images, text=texts)
      >>> dict_stack[0] == {'image': images[0], 'text': texts[0]}
  
  Args:
      *args (Dataset): Datasets for stacking returned as tuple.
      **kwargs (Dataset): Datasets for stacking returned as dict.
class_docstr_tok: ["Dataset","as","a","stacking","of","multiple","datasets",".","This","class","is","useful","to","assemble","different","parts","of","complex","input","data",",","given","as","datasets",".","Example",":",">",">",">","#","xdoctest",":","+SKIP",">",">",">","images","=","ImageDataset","(",")",">",">",">","texts","=","TextDataset","(",")",">",">",">","tuple_stack","=","StackDataset","(","images",",","texts",")",">",">",">","tuple_stack","[","0","]","==","(","images","[","0","]",",","texts","[","0","]",")",">",">",">","dict_stack","=","StackDataset","(","image=images",",","text=texts",")",">",">",">","dict_stack","[","0","]","==","{","'image","'",":","images","[","0","]",",","'text","'",":","texts","[","0","]","}","Args",":","*","args","(","Dataset",")",":","Datasets","for","stacking","returned","as","tuple",".","*","*","kwargs","(","Dataset",")",":","Datasets","for","stacking","returned","as","dict","."]
code: def __init__(
      self, *args: Dataset[T_co], **kwargs: Dataset[T_co]
  ) -> None:
      if args:
          if kwargs:
              raise ValueError(
                  "Supported either ``tuple``- (via ``args``) or"
                  "``dict``- (via ``kwargs``) like input/output, but both types are given."
              )
          self._length = len(args[0])  # type: ignore[arg-type]
          if any(self._length != len(dataset) for dataset in args):  # type: ignore[arg-type]
              raise ValueError("Size mismatch between datasets")
          self.datasets = args
      elif kwargs:
          tmp = list(kwargs.values())
          self._length = len(tmp[0])  # type: ignore[arg-type]
          if any(self._length != len(dataset) for dataset in tmp):  # type: ignore[arg-type]
              raise ValueError("Size mismatch between datasets")
          self.datasets = kwargs
      else:
          raise ValueError("At least one dataset should be passed")
  
imports: import bisect
  import itertools
  import math
  import warnings
  from typing import cast, Dict, Generic, Iterable, List, Optional, Sequence, Tuple, TypeVar, Union
  from torch import default_generator, randperm
  from ...None import Generator, Tensor
label_desc: Use image node_id 1 to create a new StackDataset object from inherited base classes: Dataset with example: obj = StackDataset()