# Path: recordlinkage/measures.py
# def full_index_size(*args):
#     """Compute the number of records in a full index.
# 
#     Compute the number of records in a full index without building the index
#     itself. The result is the maximum number of record pairs possible. This
#     function is especially useful in measures like the `reduction_ratio`.
# 
#     Deduplication: Given a DataFrame A with length N, the full index size is
#     N*(N-1)/2. Linking: Given a DataFrame A with length N and a DataFrame B
#     with length M, the full index size is N*M.
# 
#     Parameters
#     ----------
#     *args: int, pandas.MultiIndex, pandas.Series, pandas.DataFrame
#         A pandas object or a int representing the length of a dataset to link.
#         When there is one argument, it is assumed that the record linkage is
#         a deduplication process.
# 
#     Examples
#     --------
# 
#     Use integers:
#     >>> full_index_size(10)  # deduplication: 45 pairs
#     >>> full_index_size(10, 10)  # linking: 100 pairs
# 
#     or pandas objects
#     >>> full_index_size(DF)  # deduplication: len(DF)*(len(DF)-1)/2 pairs
#     >>> full_index_size(DF, DF)  # linking: len(DF)*len(DF) pairs
# 
#     """
# 
#     # check if a list or tuple is passed as argument
#     if len(args) == 1 and isinstance(args[0], (list, tuple)):
#         args = tuple(args[0])
# 
#     if len(args) == 1:
#         n = get_length(args[0])
#         size = int(n * (n - 1) / 2)
#     else:
#         size = numpy.prod([get_length(arg) for arg in args])
# 
#     return size


import numpy as np
from recordlinkage.measures import full_index_size

def random_pairs_with_replacement(n, shape, random_state=None):
    """make random record pairs"""

    if not isinstance(random_state, np.random.RandomState):
        random_state = np.random.RandomState(random_state)

    n_max = full_index_size(shape)

    if n_max <= 0:
        raise ValueError('n_max must be larger than 0')

    # make random pairs
    indices = random_state.randint(0, n_max, n)

    if len(shape) == 1:
        return _map_tril_1d_on_2d(indices, shape[0])
    else:
        return np.array(np.unravel_index(indices, shape))


def random_pairs_without_replacement(
        n, shape, random_state=None):
    """Return record pairs for dense sample.

    Sample random record pairs without replacement bounded by the
    maximum number of record pairs (based on shape). This algorithm is
    efficient and fast for relative small samples.
    """


# Path: recordlinkage/measures.py
# def full_index_size(*args):
#     """Compute the number of records in a full index.
# 
#     Compute the number of records in a full index without building the index
#     itself. The result is the maximum number of record pairs possible. This
#     function is especially useful in measures like the `reduction_ratio`.
# 
#     Deduplication: Given a DataFrame A with length N, the full index size is
#     N*(N-1)/2. Linking: Given a DataFrame A with length N and a DataFrame B
#     with length M, the full index size is N*M.
# 
#     Parameters
#     ----------
#     *args: int, pandas.MultiIndex, pandas.Series, pandas.DataFrame
#         A pandas object or a int representing the length of a dataset to link.
#         When there is one argument, it is assumed that the record linkage is
#         a deduplication process.
# 
#     Examples
#     --------
# 
#     Use integers:
#     >>> full_index_size(10)  # deduplication: 45 pairs
#     >>> full_index_size(10, 10)  # linking: 100 pairs
# 
#     or pandas objects
#     >>> full_index_size(DF)  # deduplication: len(DF)*(len(DF)-1)/2 pairs
#     >>> full_index_size(DF, DF)  # linking: len(DF)*len(DF) pairs
# 
#     """
# 
#     # check if a list or tuple is passed as argument
#     if len(args) == 1 and isinstance(args[0], (list, tuple)):
#         args = tuple(args[0])
# 
#     if len(args) == 1:
#         n = get_length(args[0])
#         size = int(n * (n - 1) / 2)
#     else:
#         size = numpy.prod([get_length(arg) for arg in args])
# 
#     return size


# Path: recordlinkage/algorithms/indexing.py
import numpy as np
from recordlinkage.measures import full_index_size


def random_pairs_with_replacement(n, shape, random_state=None):
    """make random record pairs"""

    if not isinstance(random_state, np.random.RandomState):
        random_state = np.random.RandomState(random_state)

    n_max = full_index_size(shape)

    if n_max <= 0:
        raise ValueError('n_max must be larger than 0')

    # make random pairs
    indices = random_state.randint(0, n_max, n)

    if len(shape) == 1:
        return _map_tril_1d_on_2d(indices, shape[0])
    else:
        return np.array(np.unravel_index(indices, shape))


def random_pairs_without_replacement(
        n, shape, random_state=None):
    """Return record pairs for dense sample.

    Sample random record pairs without replacement bounded by the
    maximum number of record pairs (based on shape). This algorithm is
    efficient and fast for relative small samples.
    """


    n_max = full_index_size(shape)