import torch


def scopes_from_offsets(offsets):
    """Compute scopes (specification used by the segmented operations) from array of offsets

    Parameters
    ----------
    offsets: torch.Tensor
        Tensor of length `n_segments + 1` representing the offsets of each segment

    Returns
    -------
    torch.Tensor
        A tensor of shape `[n_segment, 2]` representing segment specification in the form `(start, length)`.
    """
    return torch.stack((offsets[:-1], offsets[1:] - offsets[:-1]), dim=-1)