import torch


def concat_entities(entities):
    """
    Concat multiple graphs via concatenation of their entities tensors.

    Parameters
    ----------
    entities: a list of graph tuples.
        Either [(v,e,c),...] or [(v,e),...] when the graph has no global attribute.
    Returns v,e,c - concatenated entities tensors, None for c if no global in the graph.
    -------

    """


    has_global = len(entities[0]) == 3 and entities[0][2] is not None

    v = torch.cat([el[0] for el in entities], dim=1)

    e = {}
    for k in entities[0][1].keys():
        e[k] = torch.cat([el[1][k] for el in entities], dim=1)

    c = None
    if has_global:
        c = torch.cat([el[2] for el in entities], dim=1)

    return v, e, c