import torch


def rel2abs_traj(rel_pose):
    """Convert a given relative pose sequences to absolute pose sequences.

    Args:
        rel_pose (torch.Tensor): Relative pose sequence in the form of homogenous transformation matrix. Shape: [N,4,4]

    Returns:
        torch.Tensor: Absolute pose sequence in the form of homogenous transformation matrix. Shape: [N,4,4]
    """

    global_pose = torch.eye(4, dtype=rel_pose.dtype, device=rel_pose.device)
    abs_pose = torch.zeros_like(rel_pose)
    for i in range(rel_pose.shape[0]):
        global_pose = global_pose @ rel_pose[i]
        abs_pose[i] = global_pose

    return abs_pose