예제 #1
0
def test_bitmap_no_collisions():
    # Test init for slabs of points in x
    left_edge = np.array([0.0, 0.0, 0.0])
    right_edge = np.array([1.0, 1.0, 1.0])
    periodicity = np.array([0, 0, 0], "bool")
    npart = 100
    nfiles = 2
    file_hash = 12345
    order1 = 2
    order2 = 2
    reg = ParticleBitmap(
        left_edge, right_edge, periodicity, file_hash, nfiles, order1, order2
    )
    # Coarse index
    posgen = yield_fake_decomp("sliced", npart, nfiles, left_edge, right_edge)
    max_npart = 0
    for i, (pos, hsml) in enumerate(posgen):
        reg._coarse_index_data_file(pos, hsml, i)
        max_npart = max(max_npart, pos.shape[0])
        reg._set_coarse_index_data_file(i)
        assert_equal(reg.count_total(i), np.sum(reg.masks[:, i]))
    mask = reg.masks.sum(axis=1).astype("uint8")
    ncoll = np.sum(mask > 1)
    nc, nm = reg.find_collisions_coarse()
    assert_equal(nc, 0, "%d coarse collisions" % nc)
    assert_equal(ncoll, nc, "%d in mask, %d in bitmap" % (ncoll, nc))
    # Refined index
    sub_mi1 = np.zeros(max_npart, "uint64")
    sub_mi2 = np.zeros(max_npart, "uint64")
    posgen = yield_fake_decomp("sliced", npart, nfiles, left_edge, right_edge)
    coll = None
    for i, (pos, hsml) in enumerate(posgen):
        nsub_mi, coll = reg._refined_index_data_file(
            coll,
            pos,
            hsml,
            mask,
            sub_mi1,
            sub_mi2,
            i,
            0,
            count_threshold=1,
            mask_threshold=2,
        )
        reg.bitmasks.append(i, coll)
        assert_equal(reg.count_refined(i), 0)
    nr, nm = reg.find_collisions_refined()
    assert_equal(nr, 0, "%d collisions" % nr)
예제 #2
0
def test_bitmap_collisions():
    # Test init for slabs of points in x
    left_edge = np.array([0.0, 0.0, 0.0])
    right_edge = np.array([1.0, 1.0, 1.0])
    periodicity = np.array([0, 0, 0], "bool")
    nfiles = 2
    file_hash = 12345
    order1 = 2
    order2 = 2
    reg = ParticleBitmap(
        left_edge, right_edge, periodicity, file_hash, nfiles, order1, order2
    )
    # Use same points for all files to force collisions
    pos = cell_centers(order1 + order2, left_edge, right_edge)
    hsml = None
    # Coarse index
    max_npart = 0
    for i in range(nfiles):
        reg._coarse_index_data_file(pos, hsml, i)
        max_npart = max(max_npart, pos.shape[0])
        reg._set_coarse_index_data_file(i)
        assert_equal(reg.count_total(i), np.sum(reg.masks[:, i]))
    mask = reg.masks.sum(axis=1).astype("uint8")
    ncoll = np.sum(mask > 1)
    nc, nm = reg.find_collisions_coarse()
    assert_equal(ncoll, nc, "%d in mask, %d in bitmap" % (ncoll, nc))
    assert_equal(nc, 2 ** (3 * order1), "%d coarse collisions" % nc)
    # Refined index
    sub_mi1 = np.zeros(max_npart, "uint64")
    sub_mi2 = np.zeros(max_npart, "uint64")
    for i in range(nfiles):
        nsub_mi, coll = reg._refined_index_data_file(
            None,
            pos,
            hsml,
            mask,
            sub_mi1,
            sub_mi2,
            i,
            0,
            count_threshold=1,
            mask_threshold=2,
        )
        reg.bitmasks.append(i, coll)
        assert_equal(reg.count_refined(i), ncoll)
    nr, nm = reg.find_collisions_refined()
    assert_equal(nr, 2 ** (3 * (order1 + order2)), "%d collisions" % nr)