trax/tf_numpy/jax_tests/lax_numpy_indexing_test.py
def _ReplaceSlicesWithTuples(self, idx):
    """Helper method to replace slices with tuples for dynamic indexing args."""
    if isinstance(idx, slice):
      triple = idx.start, idx.stop, idx.step
      isnone = [i for i, elt in enumerate(triple) if elt is None]
      zeros = itertools.repeat(0)
      nones = itertools.repeat(None)
      out = subvals(triple, zip(isnone, zeros))
      return out, lambda out: slice(*subvals(out, zip(isnone, nones)))
    elif isinstance(idx, (tuple, list)) and idx:
      t = type(idx)
      elts, packs = zip(*map(self._ReplaceSlicesWithTuples, idx))
      return elts, lambda elts: t((pack(i) for pack, i in zip(packs, elts)))
    else:
      return idx, lambda x: x
Helper method to replace slices with tuples for dynamic indexing args.
Helper method to replace slices with tuples for dynamic indexing args.
Helper method to replace slices with tuples for dynamic indexing args .
def _ReplaceSlicesWithTuples(self, idx):
    if isinstance(idx, slice):
      triple = idx.start, idx.stop, idx.step
      isnone = [i for i, elt in enumerate(triple) if elt is None]
      zeros = itertools.repeat(0)
      nones = itertools.repeat(None)
      out = subvals(triple, zip(isnone, zeros))
      return out, lambda out: slice(*subvals(out, zip(isnone, nones)))
    elif isinstance(idx, (tuple, list)) and idx:
      t = type(idx)
      elts, packs = zip(*map(self._ReplaceSlicesWithTuples, idx))
      return elts, lambda elts: t((pack(i) for pack, i in zip(packs, elts)))
    else:
      return idx, lambda x: x
def _ReplaceSlicesWithTuples ( self , idx ) : if isinstance ( idx , slice ) : triple = idx . start , idx . stop , idx . step isnone = [ i for i , elt in enumerate ( triple ) if elt is None ] zeros = itertools . repeat ( 0 ) nones = itertools . repeat ( None ) out = subvals ( triple , zip ( isnone , zeros ) ) return out , lambda out : slice ( * subvals ( out , zip ( isnone , nones ) ) ) elif isinstance ( idx , ( tuple , list ) ) and idx : t = type ( idx ) elts , packs = zip ( * map ( self . _ReplaceSlicesWithTuples , idx ) ) return elts , lambda elts : t ( ( pack ( i ) for pack , i in zip ( packs , elts ) ) ) else : return idx , lambda x : x
Helper method to replace slices with tuples for dynamic indexing args.
Helper method to replace slices with tuples for dynamic indexing args .
"""Helper method to replace slices with tuples for dynamic indexing args."""
self
idx