import torch
import math


def attack(grad_honests, f_real, **kwargs):
  """ Generate non-finite gradients.
  Args:
    grad_honests Non-empty list of honest gradients
    f_real       Number of Byzantine gradients to generate
    ...          Ignored keyword-arguments
  Returns:
    Generated Byzantine gradients
  """
  # Fast path
  if f_real == 0:
    return list()
  # Generate the non-finite Byzantine gradient
  byz_grad = torch.empty_like(grad_honests[0])
  byz_grad.copy_(torch.tensor((math.nan,), dtype=byz_grad.dtype))
  # Return this Byzantine gradient 'f_real' times
  return [byz_grad] * f_real