class_docstr: Dataset to create indexes from `Sampler` or `Iterable`
code: def __init__(self, sampler: Union[Sampler, Iterable]) -> None:
      if not isinstance(sampler, Sized):
          raise TypeError(
              "You seem to have configured a sampler in your DataLoader which"
              " does not provide `__len__` method. The sampler was about to be"
              " replaced by `DistributedSamplerWrapper` since `use_distributed_sampler`"
              " is True and you are using distributed training. Either provide `__len__`"
              " method in your sampler, remove it from DataLoader or set `use_distributed_sampler=False`"
              " if you want to handle distributed sampling yourself."
          )
      if len(sampler) == float("inf"):
          raise TypeError(
              "You seem to have configured a sampler in your DataLoader which"
              " does not provide finite `__len__` method. The sampler was about to be"
              " replaced by `DistributedSamplerWrapper` since `use_distributed_sampler`"
              " is True and you are using distributed training. Either provide `__len__`"
              " method in your sampler which returns a finite number, remove it from DataLoader"
              " or set `use_distributed_sampler=False` if you want to handle distributed sampling yourself."
          )
      self._sampler = sampler
      # defer materializing an iterator until it is necessary
      self._sampler_list: Optional[List[Any]] = None
  
imports: import contextlib
  import logging
  import os
  import time
  from contextlib import nullcontext
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Iterable, Iterator, List, Optional, Sized, Union
  import torch
  import torch.nn.functional
  from lightning_utilities.core.imports import package_available
  from torch import Tensor
  from torch.utils.data import Dataset, DistributedSampler, Sampler
  from typing_extensions import override
  from lightning.fabric.utilities.cloud_io import _is_local_file_protocol
  from lightning.fabric.utilities.data import _num_cpus_available
  from lightning.fabric.utilities.rank_zero import rank_zero_info
  from lightning.fabric.utilities.types import _PATH, ReduceOp
label_desc: Use image node_id 1 to create a new _DatasetSamplerWrapper object from inherited base classes: Dataset with example: obj = _DatasetSamplerWrapper(sampler)