class_docstr: Wraps another sampler to yield a mini-batch of indices.
  
  Args:
      sampler (Sampler or Iterable): Base sampler. Can be any iterable object
      batch_size (int): Size of mini-batch.
      drop_last (bool): If ``True``, the sampler will drop the last batch if
          its size would be less than ``batch_size``
  
  Example:
      >>> list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=False))
      [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
      >>> list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=True))
      [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
class_docstr_tok: ["Wraps","another","sampler","to","yield","a","mini-batch","of","indices",".","Args",":","sampler","(","Sampler","or","Iterable",")",":","Base","sampler",".","Can","be","any","iterable","object","batch_size","(","int",")",":","Size","of","mini-batch",".","drop_last","(","bool",")",":","If","``","True","``",",","the","sampler","will","drop","the","last","batch","if","its","size","would","be","less","than","``","batch_size","``","Example",":",">",">",">","list","(","BatchSampler","(","SequentialSampler","(","range","(","10",")",")",",","batch_size=3",",","drop_last=False",")",")","[","[","0",",","1",",","2","]",",","[","3",",","4",",","5","]",",","[","6",",","7",",","8","]",",","[","9","]","]",">",">",">","list","(","BatchSampler","(","SequentialSampler","(","range","(","10",")",")",",","batch_size=3",",","drop_last=True",")",")","[","[","0",",","1",",","2","]",",","[","3",",","4",",","5","]",",","[","6",",","7",",","8","]","]"]
code: def __iter__(self) -> Iterator[List[int]]:
      # Implemented based on the benchmarking in https://github.com/pytorch/pytorch/pull/76951
      if self.drop_last:
          sampler_iter = iter(self.sampler)
          while True:
              try:
                  batch = [
                      next(sampler_iter) for _ in range(self.batch_size)
                  ]
                  yield batch
              except StopIteration:
                  break
      else:
          batch = [0] * self.batch_size
          idx_in_batch = 0
          for idx in self.sampler:
              batch[idx_in_batch] = idx
              idx_in_batch += 1
              if idx_in_batch == self.batch_size:
                  yield batch
                  idx_in_batch = 0
                  batch = [0] * self.batch_size
          if idx_in_batch > 0:
              yield batch[:idx_in_batch]
  
imports: import torch
  from torch import Tensor
  from typing import Iterator, Iterable, Optional, Sequence, List, TypeVar, Generic, Sized, Union
label_desc: Use image node_id 2 for calling the BatchSampler obj's underlying member method code with example usage: obj.__iter__() without return types