import torch


def rel_to_abs(rel, start):
    """
    Transform relative location into abs location.
    :param rel: Tensor[..., length, 2]
    :param start: the last step of observation seq. [..., 1, 2]
    :return: trajectory -> Tensor[..., length, 2]
    """
    if start is None:
        start = torch.zeros((rel.shape[0], 2), device=rel.device)

    trajectory = torch.zeros_like(rel)
    trajectory[..., 0, :] = rel[..., 0, :] + start
    for i in range(1, trajectory.shape[-2]):
        trajectory[..., i, :] = rel[..., i, :] + trajectory[..., i - 1, :]
    return trajectory