code: def _downsample(xs, k):
      """Downsample `xs` to at most `k` elements.
  
      If `k` is larger than `xs`, then the contents of `xs` itself will be
      returned. If `k` is smaller than `xs`, the last element of `xs` will
      always be included (unless `k` is `0`) and the preceding elements
      will be selected uniformly at random.
  
      This differs from `random.sample` in that it returns a subsequence
      (i.e., order is preserved) and that it permits `k > len(xs)`.
  
      The random number generator will always be `random.Random(0)`, so
      this function is deterministic (within a Python process).
  
      Args:
        xs: A sequence (`collections.abc.Sequence`).
        k: A non-negative integer.
  
      Returns:
        A new list whose elements are a subsequence of `xs` of length
        `min(k, len(xs))` and that is guaranteed to include the last
        element of `xs`, uniformly selected among such subsequences.
      """
  
      if k > len(xs):
          return list(xs)
      if k == 0:
          return []
      indices = random.Random(0).sample(range(len(xs) - 1), k - 1)
      indices.sort()
      indices += [len(xs) - 1]
      return [xs[i] for i in indices]
  
imports: import base64
  import collections
  import json
  import random
  from tensorboard import errors
  from tensorboard.compat.proto import summary_pb2
  from tensorboard.data import provider
  from tensorboard.util import tb_logging
  from tensorboard.util import tensor_util
label_desc: Use image node_id 7 for calling a global function with example usage: _downsample(xs, k) and returns: unknown, list, list