def flattened_dimensions(space):
    """
    Computes the number of dimensions a flattened equivalent of the given space would have.
    """

    space_dim = 0
    for prop in space.properties:
        prop_dim = 0
        if prop.WhichOneof("definition") == "discrete":
            prop_dim = max(len(prop.discrete.labels), prop.discrete.num)
        else:
            # box
            if len(prop.box.shape) > 0:
                prop_dim = 1
                for dim in prop.box.shape:
                    prop_dim *= dim
        space_dim += prop_dim

    return space_dim