Validate that the matrix has equal number of entities and categories.

def validate_categories_equal_entities(categories, entities, message=None,
                                       exception=MatrixError):
    """Validate that the matrix has equal number of entities and categories."""
    nb_categories = len(categories)
    nb_entities = len(entities)
    if message is None:
        message = 'Number of categories: %s != number of entities: %s' % (
            nb_categories, nb_entities)
    if categories and nb_categories != nb_entities:
        raise exception(message)