import torch


def adj_to_seq(adj, device='cpu'):
    """
    Convert a dense adjacency matrix into a sequence.

    Parameters
    ----------
    adj : torch.Tensor
        The dense adjacency tensor.
    device : str, optional
        The device onto which to put the data. The default is 'cpu'.

    Returns
    -------
    adj_seq : torch.Tensor
        The sequence representing the input adjacency tensor.
    """
    B, N = adj.shape[0], adj.shape[1]
    adj_seq = torch.zeros(B,int(((N-1)*N)/2)).to(device)
    for b in range(B):
        for i in range(1,N):
            for j in range(i):
                adj_seq[b,i+j] = adj[b,i,j]
    return adj_seq