(seq, sample_size, randomize)
Samples a seq if `sample_size` is provided and less than seq size.
Samples a seq if `sample_size` is provided and less than seq size.
Samples a seq if sample_size is provided and less than seq size .
def maybe_sample_items(seq, sample_size, randomize):
  """Samples a seq if `sample_size` is provided and less than seq size."""
  if not sample_size or len(seq) <= sample_size:
    return seq
  if randomize:
    indices = set(np.random.choice(len(seq), size=sample_size, replace=False))
    return [seq[i] for i in indices]
  else:
    return seq[:sample_size]
def maybe_sample_items ( seq , sample_size , randomize ) : if not sample_size or len ( seq ) <= sample_size : return seq if randomize : indices = set ( np . random . choice ( len ( seq ) , size = sample_size , replace = False ) ) return [ seq [ i ] for i in indices ] else : return seq [ : sample_size ]