def _control_input(devices, control_inputs, idx):
  """Returns the `idx`-th item in control_inputs to be used in ops.control_dependencies.

  This is a helper function for building collective ops.

  Args:
    devices: a list of device strings the collective run on.
    control_inputs: a list or None.
    idx: the index into `inputs` and `control_inputs`.

  Returns:
    A one item list of the `idx`-th element of `control_inputs`, or an empty
    list if `control_inputs` is None.
  """
  if control_inputs is None:
    return []
  if len(control_inputs) != len(devices):
    raise ValueError(
        'control_inputs must match the length of the devices, %s != %s' %
        (len(control_inputs), len(devices)))
  return [control_inputs[idx]]