import torch


def calc_string_acc(y, y_hat, pad_value):
  """
  Ignores first symbol (SOS) and returns 0 or 1 for full sequence match.
  y_hat has to also predict the EOS symbol.
  :param y: single target sequence
  :param y_hat: single predicted sequence
  :param eos_idx: EOS idx
  :return: 1 if all sequence elements match else 0
  """
  # single sample
  # print("calc_string_acc: y.shape=", y.shape, ", y_hat.shape=", y_hat.shape)

  y_shifted = y[1:]              # drop the SOS from y
  exact_match = (torch.eq(y_shifted,y_hat) | (y_shifted==pad_value)).all().item()
  return exact_match