class_docstr: A random shuffling buffer implementation. Items can be added to the buffer and retrieved in a random order.
docstr: Initializes a new BatchedRandomShufflingBuffer instance.
  
  Items may be retrieved from the buffer once ``min_after_retrieve`` items were added to the queue
  (indicated by ``can_retrieve``).
  
  Items may be added to the buffer as long as the number of items in the buffer (not including the items
  passed to :func:`add_many`) does not exceed ``shuffling_queue_capacity``.
  
  The amount of items in the buffer may actually become more than ``shuffling_buffer_capacity`` since
  :func:`add_many` is passed a list of items. The *hard limit* on the number of items in the buffer is
  ``shuffling_buffer_capacity + extra_capacity``.
  
  Explanation:
  This batch loader performs some non-conventional operations:
  
  Let's say we enqueued several samples:
  
  [1, 2, 3, 4, 5, 6, 7]
  
  Now during a retrieve() we sample the order these samples will be retrieved:
  
  [2, 4, 5, 1, 3, 0, 6]
  
  Once an order has been sampled, we slice the order into batches of ``batch_size`` samples.
  And index 1 batch at a time:
  
  [1, 2, X, 4, X, 6, 7] -> [3, 5] (batch 1)
  [1, X, X, 4, X, X, 7] -> [6 ,2] (batch 2)
  
  We could compress the buffer after every retrieve(), but that would require custom ops.
  
  When we call add_many we first rearrange the remaining elements:
  
  [1, 4, 7]
  
  Then append new elements:
  [1, 4, 7, 8, 9, 10]
  
  After add_many we have to resample a permutation for the buffer.
  
  :param shuffling_buffer_capacity: Items may be added to the buffer as long as the amount of items in the
    buffer does not exceed the value of ``shuffling_queue_capacity`` (not including the items
    passed to :func:`add_many`).
  :param min_after_retrieve: Minimal amount of items in the buffer that allows retrieval. This is needed to
    guarantee good random shuffling of elements. Once :func:`finish` is called, items can be retrieved even if
    the condition does not hold.
  :param extra_capacity: The amount of items in the buffer may grow above ``shuffling_buffer_capacity``
    (due to a call to :func:`add_many` with a list of items), but must remain under ``extra_capacity``. Should be
    set to the upper bound of the number of items that can be added in a single call to :func:`add_many` (can be a
    loose bound).
  :param batch_size: The number of items to be retrieved for each self.retrieve() call.
  This also affects the can_add and can can_retrieve accordingly.
docstr_tok: ["Initializes","a","new","BatchedRandomShufflingBuffer","instance",".","Items","may","be","retrieved","from","the","buffer","once","``","min_after_retrieve","``","items","were","added","to","the","queue","(","indicated","by","``","can_retrieve","``",")",".","Items","may","be","added","to","the","buffer","as","long","as","the","number","of","items","in","the","buffer","(","not","including","the","items","passed","to",":","func",":","`","add_many","`",")","does","not","exceed","``","shuffling_queue_capacity","``",".","The","amount","of","items","in","the","buffer","may","actually","become","more","than","``","shuffling_buffer_capacity","``","since",":","func",":","`","add_many","`","is","passed","a","list","of","items",".","The","*","hard","limit","*","on","the","number","of","items","in","the","buffer","is","``","shuffling_buffer_capacity","+","extra_capacity","``",".","Explanation",":","This","batch","loader","performs","some","non-conventional","operations",":","Let","'s","say","we","enqueued","several","samples",":","[","1",",","2",",","3",",","4",",","5",",","6",",","7","]","Now","during","a","retrieve","(",")","we","sample","the","order","these","samples","will","be","retrieved",":","[","2",",","4",",","5",",","1",",","3",",","0",",","6","]","Once","an","order","has","been","sampled",",","we","slice","the","order","into","batches","of","``","batch_size","``","samples",".","And","index","1","batch","at","a","time",":","[","1",",","2",",","X",",","4",",","X",",","6",",","7","]","-",">","[","3",",","5","]","(","batch","1",")","[","1",",","X",",","X",",","4",",","X",",","X",",","7","]","-",">","[","6",",2","]","(","batch","2",")","We","could","compress","the","buffer","after","every","retrieve","(",")",",","but","that","would","require","custom","ops",".","When","we","call","add_many","we","first","rearrange","the","remaining","elements",":","[","1",",","4",",","7","]","Then","append","new","elements",":","[","1",",","4",",","7",",","8",",","9",",","10","]","After","add_many","we","have","to","resample","a","permutation","for","the","buffer",".",":","param","shuffling_buffer_capacity",":","Items","may","be","added","to","the","buffer","as","long","as","the","amount","of","items","in","the","buffer","does","not","exceed","the","value","of","``","shuffling_queue_capacity","``","(","not","including","the","items","passed","to",":","func",":","`","add_many","`",")",".",":","param","min_after_retrieve",":","Minimal","amount","of","items","in","the","buffer","that","allows","retrieval",".","This","is","needed","to","guarantee","good","random","shuffling","of","elements",".","Once",":","func",":","`","finish","`","is","called",",","items","can","be","retrieved","even","if","the","condition","does","not","hold",".",":","param","extra_capacity",":","The","amount","of","items","in","the","buffer","may","grow","above","``","shuffling_buffer_capacity","``","(","due","to","a","call","to",":","func",":","`","add_many","`","with","a","list","of","items",")",",","but","must","remain","under","``","extra_capacity","``",".","Should","be","set","to","the","upper","bound","of","the","number","of","items","that","can","be","added","in","a","single","call","to",":","func",":","`","add_many","`","(","can","be","a","loose","bound",")",".",":","param","batch_size",":","The","number","of","items","to","be","retrieved","for","each","self.retrieve","(",")","call",".","This","also","affects","the","can_add","and","can","can_retrieve","accordingly","."]
code: def __init__(
      self,
      shuffling_buffer_capacity,
      min_after_retrieve,
      extra_capacity=1000,
      batch_size=1,
  ):
      """Initializes a new BatchedRandomShufflingBuffer instance.
  
      Items may be retrieved from the buffer once ``min_after_retrieve`` items were added to the queue
      (indicated by ``can_retrieve``).
  
      Items may be added to the buffer as long as the number of items in the buffer (not including the items
      passed to :func:`add_many`) does not exceed ``shuffling_queue_capacity``.
  
      The amount of items in the buffer may actually become more than ``shuffling_buffer_capacity`` since
      :func:`add_many` is passed a list of items. The *hard limit* on the number of items in the buffer is
      ``shuffling_buffer_capacity + extra_capacity``.
  
      Explanation:
      This batch loader performs some non-conventional operations:
  
      Let's say we enqueued several samples:
  
      [1, 2, 3, 4, 5, 6, 7]
  
      Now during a retrieve() we sample the order these samples will be retrieved:
  
      [2, 4, 5, 1, 3, 0, 6]
  
      Once an order has been sampled, we slice the order into batches of ``batch_size`` samples.
      And index 1 batch at a time:
  
      [1, 2, X, 4, X, 6, 7] -> [3, 5] (batch 1)
      [1, X, X, 4, X, X, 7] -> [6 ,2] (batch 2)
  
      We could compress the buffer after every retrieve(), but that would require custom ops.
  
      When we call add_many we first rearrange the remaining elements:
  
      [1, 4, 7]
  
      Then append new elements:
      [1, 4, 7, 8, 9, 10]
  
      After add_many we have to resample a permutation for the buffer.
  
      :param shuffling_buffer_capacity: Items may be added to the buffer as long as the amount of items in the
        buffer does not exceed the value of ``shuffling_queue_capacity`` (not including the items
        passed to :func:`add_many`).
      :param min_after_retrieve: Minimal amount of items in the buffer that allows retrieval. This is needed to
        guarantee good random shuffling of elements. Once :func:`finish` is called, items can be retrieved even if
        the condition does not hold.
      :param extra_capacity: The amount of items in the buffer may grow above ``shuffling_buffer_capacity``
        (due to a call to :func:`add_many` with a list of items), but must remain under ``extra_capacity``. Should be
        set to the upper bound of the number of items that can be added in a single call to :func:`add_many` (can be a
        loose bound).
      :param batch_size: The number of items to be retrieved for each self.retrieve() call.
      This also affects the can_add and can can_retrieve accordingly.
      """
      super(BatchedRandomShufflingBuffer, self).__init__(
          batch_size=batch_size
      )
      self._extra_capacity = extra_capacity
      # Preallocate the shuffling buffer.
      self._items = None
      self._shuffling_queue_capacity = shuffling_buffer_capacity
      self._min_after_dequeue = min_after_retrieve
      self._size = 0
      self._done_adding = False
  
      self._random_indices = None
      self.next_sample_head = 0
  
imports: import abc
  import six
  import torch
label_desc: Use image node_id 1 to create a new BatchedRandomShufflingBuffer object from inherited base classes: BatchedShufflingBufferBase with example: obj = BatchedRandomShufflingBuffer(shuffling_buffer_capacity, min_after_retrieve, extra_capacity, batch_size)