Esempio n. 1
0
def test_random_item():
    import string

    r = RandomDict()
    for k in string.ascii_lowercase:
        r[k] = 1
    keyset = set(string.ascii_lowercase)

    while len(r) > 0:
        k, v = r.random_item()
        assert k in keyset
        assert v == 1
        del r[k]
############################## ESTABLISH MATCHES AND NON-MATCHES
matches_file_name = os.path.join(output_folder, 'm50_000000_000000_0.txt')
mfile = open(matches_file_name, 'a+')
# establish matches
assert (len(matches) + len(invalid_points3D_id) == len(loader.point3D_ids))
matches_list = {}
max_n_try = 500000
n = 0

count_match = 0
while (n < min(max_n_try, possible_n_matches)):
    if len(matches_list) >= N_matches:
        break

    rand_point3D_id, rand_pair_choices = matches.random_item()
    assert (rand_point3D_id not in invalid_points3D_id)
    assert (len(rand_pair_choices) > 0)
    rand_pair_key, rand_pair = rand_pair_choices.random_item()
    rand_pair_choices.pop(rand_pair_key)
    if len(rand_pair_choices) == 0:
        matches.pop(rand_point3D_id)
    n += 1
    image_id1 = rand_pair[0]
    image_id2 = rand_pair[1]
    patch_id1 = point3D_id_image_id_to_patch_id[(rand_point3D_id, image_id1)]
    patch_id2 = point3D_id_image_id_to_patch_id[(rand_point3D_id, image_id2)]
    print('%d/%d %d (img:%d[patch:%d] img:%d[patch:%d])' %
          (n, possible_n_matches, rand_point3D_id, image_id1, patch_id1,
           image_id2, patch_id2))
Esempio n. 3
0
def test_empty_random_item():
    r = RandomDict()
    r.random_item()