(*xss, **kwargs)
Iterate over subsets of lists of examples.

  Yields batches of the form `[xs[indices] for xs in xss]` where at each
  iteration `indices` selects a subset. Each index is only selected once.
  **kwards could be one of the following:
    size: number of elements per batch
    discard_remainder: if true, discard final short batch
    shuffle: if true, yield examples in randomly determined order
    shuffle_rng: seed or rng to determine random order

  Args:
    *xss: lists of elements to batch
    **kwargs: kwargs could be one of the above.


  Yields:
    A batch of the same structure as `xss`, but with `size` examples.
Iterate over subsets of lists of examples.
Iterate over subsets of lists of examples .
def batches(*xss, **kwargs):
  """Iterate over subsets of lists of examples.

  Yields batches of the form `[xs[indices] for xs in xss]` where at each
  iteration `indices` selects a subset. Each index is only selected once.
  **kwards could be one of the following:
    size: number of elements per batch
    discard_remainder: if true, discard final short batch
    shuffle: if true, yield examples in randomly determined order
    shuffle_rng: seed or rng to determine random order

  Args:
    *xss: lists of elements to batch
    **kwargs: kwargs could be one of the above.


  Yields:
    A batch of the same structure as `xss`, but with `size` examples.
  """
  size = kwargs.get("size", 1)
  discard_remainder = kwargs.get("discard_remainder", True)
  shuffle = kwargs.get("shuffle", False)
  shuffle_rng = kwargs.get("shuffle_rng", None)

  shuffle_rng = get_rng(shuffle_rng)
  n = int(np.unique(list(map(len, xss))))
  assert all(len(xs) == len(xss[0]) for xs in xss)
  indices = np.arange(len(xss[0]))
  if shuffle:
    np.random.shuffle(indices)
  for start in range(0, n, size):
    batch_indices = indices[start:start + size]
    if len(batch_indices) < size and discard_remainder:
      break
    batch_xss = [xs[batch_indices] for xs in xss]
    yield batch_xss
def batches ( * xss , * * kwargs ) : size = kwargs . get ( "size" , 1 ) discard_remainder = kwargs . get ( "discard_remainder" , True ) shuffle = kwargs . get ( "shuffle" , False ) shuffle_rng = kwargs . get ( "shuffle_rng" , None ) shuffle_rng = get_rng ( shuffle_rng ) n = int ( np . unique ( list ( map ( len , xss ) ) ) ) assert all ( len ( xs ) == len ( xss [ 0 ] ) for xs in xss ) indices = np . arange ( len ( xss [ 0 ] ) ) if shuffle : np . random . shuffle ( indices ) for start in range ( 0 , n , size ) : batch_indices = indices [ start : start + size ] if len ( batch_indices ) < size and discard_remainder : break batch_xss = [ xs [ batch_indices ] for xs in xss ] yield batch_xss