class_docstr: Base class for standard and DataParallel Sampler.
  
  Every subclass should implement `__iter__` method, providing a way to iterate
  over indices of dataset elements.
  
  Args:
      opts: command line argument
      n_data_samples: Number of samples in the dataset
      is_training: Training mode or not. Default: False
class_docstr_tok: ["Base","class","for","standard","and","DataParallel","Sampler",".","Every","subclass","should","implement","`","__iter__","`","method",",","providing","a","way","to","iterate","over","indices","of","dataset","elements",".","Args",":","opts",":","command","line","argument","n_data_samples",":","Number","of","samples","in","the","dataset","is_training",":","Training","mode","or","not",".","Default",":","False"]
code: def __init__(
      self,
      opts: argparse.Namespace,
      n_data_samples: int,
      is_training: bool = False,
      *args,
      **kwargs,
  ) -> None:
      # max between 1 and number of available GPUs. 1 because for supporting CPUs
      n_gpus: int = max(1, torch.cuda.device_count())
      batch_size_gpu0: int = get_batch_size_from_opts(
          opts, is_training=is_training
      )
  
      n_samples_per_gpu = int(math.ceil(n_data_samples * 1.0 / n_gpus))
      total_size = n_samples_per_gpu * n_gpus
  
      indexes = [idx for idx in range(n_data_samples)]
      # This ensures that we can divide the batches evenly across GPUs
      indexes += indexes[: (total_size - n_data_samples)]
      assert total_size == len(indexes)
  
      self.img_indices = indexes
      self.n_samples = total_size
      self.batch_size_gpu0 = batch_size_gpu0
      self.n_gpus = n_gpus
      self.shuffle = True if is_training else False
      self.epoch = 0
  
      self.num_repeats = 1
      self.trunc_rep_aug = False
      if is_training:
          # enable these arguments for repeated data augmentation
          # https://openaccess.thecvf.com/content_CVPR_2020/papers/Hoffer_Augment_Your_Batch_Improving_Generalization_Through_Instance_Repetition_CVPR_2020_paper.pdf
          self.num_repeats = getattr(opts, "sampler.num_repeats")
          self.trunc_rep_aug = getattr(
              opts, "sampler.truncated_repeat_aug_sampler"
          )
  
imports: import argparse
  import copy
  import math
  import random
  from typing import Any, Iterator, List, Tuple
  import numpy
  import torch
  import torch.distributed
  from torch.utils.data.sampler import Sampler
label_desc: Use image node_id 1 to create a new BaseSampler object from inherited base classes: Sampler with example: obj = BaseSampler(opts, n_data_samples, is_training)