def matched_sampling(sample, secondary_sample, background, samples, float_sampling_method='exact'):
    '\n    The general random sampling strategy that sample sets of the same size and shape as primary\n    and secondary sample set and, if they are weighted, try to match the random sample weights\n    according to the\n\n\n    :param sample: primary sample set\n    :param secondary_sample: secondary sample_set\n    :param background: background of ids (and potentially weights) from which to sample\n    :param samples: random samples wanted\n    :param sampling_mode: exact/distro/logdistro. the sampling parametrization method ingesting\n    all the parameters in a single string argument in the general case, here, a pass- through\n    parameter for the _sample_floats function if samples are weighted and the distribution of\n    weights is being matched.\n    :return:\n    '
    if _is_int(background[0]):
        background_ids = np.array(background)
        background_whg = np.ones_like(background_ids).astype(np.float)
    else:
        background_ids = np.array(background)[:, 0]
        background_whg = np.array(background)[:, 1]
    log.debug(('debug sum %s, type: %s, all:%s' % (np.sum(background_whg), type(background_whg), background_whg)))
    background_whg /= np.sum(background_whg)
    if (secondary_sample is None):
        if _is_int(sample[0]):
            for i in range(0, samples):
                selected = np.random.choice(background_ids, len(sample), p=background_whg, replace=False)
                (yield (i, selected, None))
        else:
            for i in range(0, samples):
                id_loads = np.random.choice(background_ids, len(sample), p=background_whg, replace=False)
                float_part = _sample_floats(np.array(sample)[:, 1], float_sampling_method)
                ids_and_floats = [(_id, _float) for (_id, _float) in zip(id_loads, float_part)]
                (yield (i, ids_and_floats, None))
    elif _is_int(sample[0]):
        for i in range(0, samples):
            selected = np.random.choice(background_ids, (len(sample) + len(secondary_sample)), p=background_whg, replace=False)
            np.random.shuffle(selected)
            (yield (i, selected[:len(sample)], selected[(- len(secondary_sample)):]))
    else:
        for i in range(0, samples):
            selected = np.random.choice(background_ids, (len(sample) + len(secondary_sample)), p=background_whg, replace=False)
            np.random.shuffle(selected)
            id_loads = selected[:len(sample)]
            float_part = _sample_floats(np.array(sample)[:, 1], float_sampling_method)
            ids_and_floats = [(_id, _float) for (_id, _float) in zip(id_loads, float_part)]
            sec_id_loads = selected[(- len(secondary_sample)):]
            sec_float_part = _sample_floats(np.array(secondary_sample)[:, 1], float_sampling_method)
            sec_ids_and_floats = [(_id, _float) for (_id, _float) in zip(sec_id_loads, sec_float_part)]
            (yield (i, ids_and_floats, sec_ids_and_floats))
The general random sampling strategy that sample sets of the same size and shape as primary
and secondary sample set and, if they are weighted, try to match the random sample weights
according to the


:param sample: primary sample set
:param secondary_sample: secondary sample_set
:param background: background of ids (and potentially weights) from which to sample
:param samples: random samples wanted
:param sampling_mode: exact/distro/logdistro. the sampling parametrization method ingesting
all the parameters in a single string argument in the general case, here, a pass- through
parameter for the _sample_floats function if samples are weighted and the distribution of
weights is being matched.
:return:
def matched_sampling(sample, secondary_sample, background, samples, float_sampling_method='exact'):
    '\n    The general random sampling strategy that sample sets of the same size and shape as primary\n    and secondary sample set and, if they are weighted, try to match the random sample weights\n    according to the\n\n\n    :param sample: primary sample set\n    :param secondary_sample: secondary sample_set\n    :param background: background of ids (and potentially weights) from which to sample\n    :param samples: random samples wanted\n    :param sampling_mode: exact/distro/logdistro. the sampling parametrization method ingesting\n    all the parameters in a single string argument in the general case, here, a pass- through\n    parameter for the _sample_floats function if samples are weighted and the distribution of\n    weights is being matched.\n    :return:\n    '
    if _is_int(background[0]):
        background_ids = np.array(background)
        background_whg = np.ones_like(background_ids).astype(np.float)
    else:
        background_ids = np.array(background)[:, 0]
        background_whg = np.array(background)[:, 1]
    log.debug(('debug sum %s, type: %s, all:%s' % (np.sum(background_whg), type(background_whg), background_whg)))
    background_whg /= np.sum(background_whg)
    if (secondary_sample is None):
        if _is_int(sample[0]):
            for i in range(0, samples):
                selected = np.random.choice(background_ids, len(sample), p=background_whg, replace=False)
                (yield (i, selected, None))
        else:
            for i in range(0, samples):
                id_loads = np.random.choice(background_ids, len(sample), p=background_whg, replace=False)
                float_part = _sample_floats(np.array(sample)[:, 1], float_sampling_method)
                ids_and_floats = [(_id, _float) for (_id, _float) in zip(id_loads, float_part)]
                (yield (i, ids_and_floats, None))
    elif _is_int(sample[0]):
        for i in range(0, samples):
            selected = np.random.choice(background_ids, (len(sample) + len(secondary_sample)), p=background_whg, replace=False)
            np.random.shuffle(selected)
            (yield (i, selected[:len(sample)], selected[(- len(secondary_sample)):]))
    else:
        for i in range(0, samples):
            selected = np.random.choice(background_ids, (len(sample) + len(secondary_sample)), p=background_whg, replace=False)
            np.random.shuffle(selected)
            id_loads = selected[:len(sample)]
            float_part = _sample_floats(np.array(sample)[:, 1], float_sampling_method)
            ids_and_floats = [(_id, _float) for (_id, _float) in zip(id_loads, float_part)]
            sec_id_loads = selected[(- len(secondary_sample)):]
            sec_float_part = _sample_floats(np.array(secondary_sample)[:, 1], float_sampling_method)
            sec_ids_and_floats = [(_id, _float) for (_id, _float) in zip(sec_id_loads, sec_float_part)]
            (yield (i, ids_and_floats, sec_ids_and_floats))