import torch


def bulyan(grad_stck, grad_avg, target_idx=-1, **kwargs):
  """ Compute the attack vector adapted from "The Hidden Vulnerability".
  Args:
    target_idx Index of the targeted coordinate, "all" for all
  See:
    make_attack
  """
  if target_idx == "all":
    return torch.ones_like(grad_avg)
  else:
    assert isinstance(target_idx, int), "Expected an integer or \"all\" for 'target_idx', got %r" % (target_idx,)
    grad_att = torch.zeros_like(grad_avg)
    grad_att[target_idx] = 1
    return grad_att