class_docstr: General DALI iterator for MXNet with Gluon API. It can return any number of
  outputs from the DALI pipeline in the form of per GPU tuples. These tuples consisting of
  NDArrays (for outputs marked as DALIGluonIterator.DENSE_TAG) and list of NDArrays (for
  output marked as DALIGluonIterator.SPARSE_TAG).
  
  Parameters
  ----------
  pipelines : list of nvidia.dali.Pipeline
              List of pipelines to use
  size : int, default = -1
              Number of samples in the shard for the wrapped pipeline (if there is more than
              one it is a sum)
              Providing -1 means that the iterator will work until StopIteration is raised
              from the inside of iter_setup(). The options `last_batch_policy` and
              `last_batch_padded` don't work in such case. It works with only one pipeline inside
              the iterator.
              Mutually exclusive with `reader_name` argument
  reader_name : str, default = None
              Name of the reader which will be queried for the shard size, number of shards and
              all other properties necessary to count properly the number of relevant and padded
              samples that iterator needs to deal with. It automatically sets
              `last_batch_padded` accordingly to match the reader's configuration.
  output_types : list of str, optional, default = None
              List of tags indicating whether the pipeline(s) output batch is
              uniform (all the samples have the same size) or not. Batch output marked
              as the former will be returned as a single NDArray, the latter
              will be returned as a list of NDArray.
              Must be either DALIGluonIterator.DENSE_TAG
              or DALIGluonIterator.SPARSE_TAG.
              Length of output_types must match the number of output of the pipeline(s).
              If not set, all outputs are considered to be marked with
              DALIGluonIterator.DENSE_TAG.
  auto_reset : string or bool, optional, default = False
              Whether the iterator resets itself for the next epoch or it requires reset() to be
              called explicitly.
  
              It can be one of the following values:
  
              * ``"no"``, ``False`` or ``None`` - at the end of epoch StopIteration is raised
                and reset() needs to be called
              * ``"yes"`` or ``"True"``- at the end of epoch StopIteration is raised but reset()
                is called internally automatically
  
  fill_last_batch : bool, optional, default = None
              **Deprecated** Please use ``last_batch_policy`` instead
  
              Whether to fill the last batch with data up to 'self.batch_size'.
              The iterator would return the first integer multiple
              of self._num_gpus * self.batch_size entries which exceeds 'size'.
              Setting this flag to False will cause the iterator to return
              exactly 'size' entries.
  last_batch_policy: optional, default = LastBatchPolicy.FILL
              What to do with the last batch when there are not enough samples in the epoch
              to fully fill it. See :meth:`nvidia.dali.plugin.base_iterator.LastBatchPolicy`
  last_batch_padded : bool, optional, default = False
              Whether the last batch provided by DALI is padded with the last sample
              or it just wraps up. In the conjunction with ``last_batch_policy`` it tells
              if the iterator returning last batch with data only partially filled with
              data from the current epoch is dropping padding samples or samples from
              the next epoch (it doesn't literally drop but sets ``pad`` field of ndarray
              so the following code could use it to drop the data). If set to ``False`` next
              epoch will end sooner as data from it was consumed but dropped. If set to
              True next epoch would be the same length as the first one. For this to happen,
              the option `pad_last_batch` in the reader needs to be set to True as well.
              It is overwritten when `reader_name` argument is provided
  prepare_first_batch : bool, optional, default = True
              Whether DALI should buffer the first batch right after the creation of the iterator,
              so one batch is already prepared when the iterator is prompted for the data
  
  Example
  -------
  With the data set ``[1,2,3,4,5,6,7]`` and the batch size 2:
  
  last_batch_policy = LastBatchPolicy.PARTIAL, last_batch_padded = True  ->
  last batch = ``[7]``, next iteration will return ``[1, 2]``
  
  last_batch_policy = LastBatchPolicy.PARTIAL, last_batch_padded = False ->
  last batch = ``[7]``, next iteration will return ``[2, 3]``
  
  last_batch_policy = LastBatchPolicy.FILL, last_batch_padded = True   ->
  last batch = ``[7, 7]``, next iteration will return ``[1, 2]``
  
  last_batch_policy = LastBatchPolicy.FILL, last_batch_padded = False  ->
  last batch = ``[7, 1]``, next iteration will return ``[2, 3]``
  
  last_batch_policy = LastBatchPolicy.DROP, last_batch_padded = True   ->
  last batch = ``[5, 6]``, next iteration will return ``[1, 2]``
  
  last_batch_policy = LastBatchPolicy.DROP, last_batch_padded = False  ->
  last batch = ``[5, 6]``, next iteration will return ``[2, 3]``
class_docstr_tok: ["General","DALI","iterator","for","MXNet","with","Gluon","API",".","It","can","return","any","number","of","outputs","from","the","DALI","pipeline","in","the","form","of","per","GPU","tuples",".","These","tuples","consisting","of","NDArrays","(","for","outputs","marked","as","DALIGluonIterator.DENSE_TAG",")","and","list","of","NDArrays","(","for","output","marked","as","DALIGluonIterator.SPARSE_TAG",")",".","Parameters","--","--","--","--","--","pipelines",":","list","of","nvidia.dali.Pipeline","List","of","pipelines","to","use","size",":","int",",","default","=","-1","Number","of","samples","in","the","shard","for","the","wrapped","pipeline","(","if","there","is","more","than","one","it","is","a","sum",")","Providing","-1","means","that","the","iterator","will","work","until","StopIteration","is","raised","from","the","inside","of","iter_setup","(",")",".","The","options","`","last_batch_policy","`","and","`","last_batch_padded","`","do","n't","work","in","such","case",".","It","works","with","only","one","pipeline","inside","the","iterator",".","Mutually","exclusive","with","`","reader_name","`","argument","reader_name",":","str",",","default","=","None","Name","of","the","reader","which","will","be","queried","for","the","shard","size",",","number","of","shards","and","all","other","properties","necessary","to","count","properly","the","number","of","relevant","and","padded","samples","that","iterator","needs","to","deal","with",".","It","automatically","sets","`","last_batch_padded","`","accordingly","to","match","the","reader","'s","configuration",".","output_types",":","list","of","str",",","optional",",","default","=","None","List","of","tags","indicating","whether","the","pipeline","(","s",")","output","batch","is","uniform","(","all","the","samples","have","the","same","size",")","or","not",".","Batch","output","marked","as","the","former","will","be","returned","as","a","single","NDArray",",","the","latter","will","be","returned","as","a","list","of","NDArray",".","Must","be","either","DALIGluonIterator.DENSE_TAG","or","DALIGluonIterator.SPARSE_TAG",".","Length","of","output_types","must","match","the","number","of","output","of","the","pipeline","(","s",")",".","If","not","set",",","all","outputs","are","considered","to","be","marked","with","DALIGluonIterator.DENSE_TAG",".","auto_reset",":","string","or","bool",",","optional",",","default","=","False","Whether","the","iterator","resets","itself","for","the","next","epoch","or","it","requires","reset","(",")","to","be","called","explicitly",".","It","can","be","one","of","the","following","values",":","*","``","``","no","''","``",",","``","False","``","or","``","None","``","-","at","the","end","of","epoch","StopIteration","is","raised","and","reset","(",")","needs","to","be","called","*","``","``","yes","''","``","or","``","``","True","''","``","-","at","the","end","of","epoch","StopIteration","is","raised","but","reset","(",")","is","called","internally","automatically","fill_last_batch",":","bool",",","optional",",","default","=","None","*","*","Deprecated","*","*","Please","use","``","last_batch_policy","``","instead","Whether","to","fill","the","last","batch","with","data","up","to","'self.batch_size","'",".","The","iterator","would","return","the","first","integer","multiple","of","self._num_gpus","*","self.batch_size","entries","which","exceeds","'size","'",".","Setting","this","flag","to","False","will","cause","the","iterator","to","return","exactly","'size","'","entries",".","last_batch_policy",":","optional",",","default","=","LastBatchPolicy.FILL","What","to","do","with","the","last","batch","when","there","are","not","enough","samples","in","the","epoch","to","fully","fill","it",".","See",":","meth",":","`","nvidia.dali.plugin.base_iterator.LastBatchPolicy","`","last_batch_padded",":","bool",",","optional",",","default","=","False","Whether","the","last","batch","provided","by","DALI","is","padded","with","the","last","sample","or","it","just","wraps","up",".","In","the","conjunction","with","``","last_batch_policy","``","it","tells","if","the","iterator","returning","last","batch","with","data","only","partially","filled","with","data","from","the","current","epoch","is","dropping","padding","samples","or","samples","from","the","next","epoch","(","it","does","n't","literally","drop","but","sets","``","pad","``","field","of","ndarray","so","the","following","code","could","use","it","to","drop","the","data",")",".","If","set","to","``","False","``","next","epoch","will","end","sooner","as","data","from","it","was","consumed","but","dropped",".","If","set","to","True","next","epoch","would","be","the","same","length","as","the","first","one",".","For","this","to","happen",",","the","option","`","pad_last_batch","`","in","the","reader","needs","to","be","set","to","True","as","well",".","It","is","overwritten","when","`","reader_name","`","argument","is","provided","prepare_first_batch",":","bool",",","optional",",","default","=","True","Whether","DALI","should","buffer","the","first","batch","right","after","the","creation","of","the","iterator",",","so","one","batch","is","already","prepared","when","the","iterator","is","prompted","for","the","data","Example","--","--","--","-","With","the","data","set","``","[","1,2,3,4,5,6,7","]","``","and","the","batch","size","2",":","last_batch_policy","=","LastBatchPolicy.PARTIAL",",","last_batch_padded","=","True","-",">","last","batch","=","``","[","7","]","``",",","next","iteration","will","return","``","[","1",",","2","]","``","last_batch_policy","=","LastBatchPolicy.PARTIAL",",","last_batch_padded","=","False","-",">","last","batch","=","``","[","7","]","``",",","next","iteration","will","return","``","[","2",",","3","]","``","last_batch_policy","=","LastBatchPolicy.FILL",",","last_batch_padded","=","True","-",">","last","batch","=","``","[","7",",","7","]","``",",","next","iteration","will","return","``","[","1",",","2","]","``","last_batch_policy","=","LastBatchPolicy.FILL",",","last_batch_padded","=","False","-",">","last","batch","=","``","[","7",",","1","]","``",",","next","iteration","will","return","``","[","2",",","3","]","``","last_batch_policy","=","LastBatchPolicy.DROP",",","last_batch_padded","=","True","-",">","last","batch","=","``","[","5",",","6","]","``",",","next","iteration","will","return","``","[","1",",","2","]","``","last_batch_policy","=","LastBatchPolicy.DROP",",","last_batch_padded","=","False","-",">","last","batch","=","``","[","5",",","6","]","``",",","next","iteration","will","return","``","[","2",",","3","]","``"]
code: def __next__(self):
      self._ever_consumed = True
      if self._first_batch is not None:
          batch = self._first_batch
          self._first_batch = None
          return batch
  
      # Gather outputs
      dali_outputs = self._get_outputs()
  
      data_batches = [None for i in range(self._num_gpus)]
      for i in range(self._num_gpus):
          output_elements = []
          shapes = []
          for j, out in enumerate(dali_outputs[i]):
              if (
                  self._outputs_types is None
                  or self._outputs_types[j]
                  == DALIGluonIterator.DENSE_TAG
              ):
                  output_elements.append(out.as_tensor())
                  shapes.append(output_elements[-1].shape())
              else:
                  output_elements.append(
                      [
                          out[sample_idx]
                          for sample_idx in range(self.batch_size)
                      ]
                  )
                  s = [t.shape() for t in output_elements[-1]]
                  shapes.append(s)
  
          data_batches[i] = self._create_data_batch(
              output_elements, shapes, self._pipes[i].device_id
          )
  
          batch = data_batches[i]
          # Copy data from DALI Tensors to MXNet NDArrays
          for j, output_el in enumerate(output_elements):
              if (
                  self._outputs_types is None
                  or self._outputs_types[j]
                  == DALIGluonIterator.DENSE_TAG
              ):
                  feed_ndarray(output_el, batch[j])
              else:
                  for sample_idx in range(self.batch_size):
                      feed_ndarray(
                          output_el[sample_idx], batch[j][sample_idx]
                      )
  
      batches = [
          [
              (
                  [sample for sample in output_el]
                  if isinstance(output_el, list)
                  else output_el
              )
              for output_el in batch
          ]
          for batch in data_batches
      ]
  
      self._schedule_runs()
  
      self._advance_and_check_drop_last()
  
      if self._reader_name:
          if_drop, left = self._remove_padded()
          if np.any(if_drop):
              output = []
              for batch, to_copy in zip(batches, left):
                  batch = batch.copy()
                  for element_idx in range(len(batch)):
                      batch[element_idx] = batch[element_idx][0:to_copy]
                  output.append(batch)
              return output
  
      else:
          if (
              self._last_batch_policy == LastBatchPolicy.PARTIAL
              and (self._counter > self._size)
              and self._size > 0
          ):
              # First calculate how much data is required to return exactly self._size entries.
              diff = self._num_gpus * self.batch_size - (
                  self._counter - self._size
              )
              # Figure out how many GPUs to grab from.
              numGPUs_tograb = int(np.ceil(diff / self.batch_size))
              # Figure out how many results to grab from the last GPU (as a fractional GPU
              # batch may be required to bring us right up to self._size).
              mod_diff = diff % self.batch_size
              data_fromlastGPU = (
                  mod_diff if mod_diff else self.batch_size
              )
  
              # Grab the relevant data.
              # 1) Grab everything from the relevant GPUs.
              # 2) Grab the right data from the last GPU.
              # 3) Append data together correctly and return.
              output = batches[0:numGPUs_tograb]
              output[-1] = output[-1].copy()
              for element_idx in range(len(output[-1])):
                  output[-1][element_idx] = output[-1][element_idx][
                      0:data_fromlastGPU
                  ]
              return output
  
      return batches
  
imports: from nvidia.dali.backend import TensorGPU, TensorListGPU
  from nvidia.dali import types
  from nvidia.dali.plugin.base_iterator import _DaliBaseIterator
  from nvidia.dali.plugin.base_iterator import LastBatchPolicy
  import mxnet
  import ctypes
  import numpy
  from collections.abc import Iterable
label_desc: Use image node_id 2 for calling the DALIGluonIterator obj's underlying member method code with example usage: obj.__next__() and returns: batches, batch, output, output