def check_tuple_size(tuples, tuple_size, context):
    """Helper function to check that the number of points in each tuple is
  equal to tuple_size (e.g. 2 for pairs), and raise a `ValueError` otherwise"""
    if tuple_size is not None and tuples.shape[1] != tuple_size:
        msg_t = (
            """Tuples of {} element(s) expected{}. Got tuples of {} element(s) instead (shape={}):
input={}.
"""
            .format(tuple_size, context, tuples.shape[1], tuples.shape, tuples)
            )
        raise ValueError(msg_t)
