class_docstr: Bucket batch sampler
  
  Adapted from https://github.com/PetrochukM/PyTorch-NLP
  
  Args:
      sampler (torch.data.utils.sampler.Sampler):
      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`.
      data (list): List of data samples.
      sort_key (callable, optional): Callable to specify a comparison key for sorting.
      bucket_size_multiplier (int, optional): Buckets are of size
          `batch_size * bucket_size_multiplier`.
  
  Example:
      >>> sampler = WeightedRandomSampler(weights, len(weights))
      >>> sampler = BucketBatchSampler(sampler, data=data_items, batch_size=32, drop_last=True)
class_docstr_tok: ["Bucket","batch","sampler","Adapted","from","https",":","\/\/github.com\/PetrochukM\/PyTorch-NLP","Args",":","sampler","(","torch.data.utils.sampler.Sampler",")",":","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","`",".","data","(","list",")",":","List","of","data","samples",".","sort_key","(","callable",",","optional",")",":","Callable","to","specify","a","comparison","key","for","sorting",".","bucket_size_multiplier","(","int",",","optional",")",":","Buckets","are","of","size","`","batch_size","*","bucket_size_multiplier","`",".","Example",":",">",">",">","sampler","=","WeightedRandomSampler","(","weights",",","len","(","weights",")",")",">",">",">","sampler","=","BucketBatchSampler","(","sampler",",","data=data_items",",","batch_size=32",",","drop_last=True",")"]
code: def __iter__(self):
      for idxs in self.bucket_sampler:
          bucket_data = [self.data[idx] for idx in idxs]
          sorted_sampler = SortedSampler(bucket_data, self.sort_key)
          for batch_idx in SubsetRandomSampler(
              list(
                  BatchSampler(
                      sorted_sampler, self.batch_size, self.drop_last
                  )
              )
          ):
              sorted_idxs = [idxs[i] for i in batch_idx]
              yield sorted_idxs
  
imports: import math
  import random
  from typing import Callable, List, Union
  from torch.utils.data.sampler import BatchSampler, Sampler, SubsetRandomSampler
label_desc: Use image node_id 2 for calling the BucketBatchSampler obj's underlying member method code with example usage: obj.__iter__() without return types