import torch


def timeseries_interpolate_single_times(times, values, t):
  """
    Interpolate the time series defined by X to the times defined by t

    Args:
      times     input time series as a `(ntime,)` array
      values    input value series as a `(ntime,nbatch)` array
      t         times as a scalar

    Returns:
      Interpolated values as a `(nbatch,)` array
  """
  gi = torch.remainder(torch.sum((times - t) <= 0,dim = 0), times.shape[0])
  slopes = (values[gi] - values[gi-1])/(times[gi,None] - times[gi-1,None])
  return values[gi-1] + slopes * (t - times[gi-1])