Skip to content
test_tree.py 33.5 KiB
Newer Older
Matt Wala's avatar
Matt Wala committed
    # We can use leaves-to-balls lookup to get the set of overlapping balls for
    # each box, and from there to compute the outer space invader distance.
    lblb = LeavesToBallsLookupBuilder(ctx)

    siq, _ = siqb(queue, tree, ball_centers, ball_radii)
    lbl, _ = lblb(queue, tree, ball_centers, ball_radii)

    # get data to host for test
    tree = tree.get(queue=queue)
    siq = siq.get(queue=queue)
    lbl = lbl.get(queue=queue)

    ball_centers = np.array([x.get() for x in ball_centers])
    ball_radii = ball_radii.get()

    # Find leaf boxes.
    from boxtree import box_flags_enum

    outer_space_invader_dist = np.zeros(tree.nboxes)

    for ibox in range(tree.nboxes):
        # We only want leaves here.
        if tree.box_flags[ibox] & box_flags_enum.HAS_CHILDREN:
            continue

        start, end = lbl.balls_near_box_starts[ibox:ibox + 2]
        space_invaders = lbl.balls_near_box_lists[start:end]
        if len(space_invaders) > 0:
            outer_space_invader_dist[ibox] = np.max(np.abs(
                    tree.box_centers[:, ibox].reshape((-1, 1))
                    - ball_centers[:, space_invaders]))

    assert np.allclose(siq, outer_space_invader_dist)

# }}}


Andreas Klöckner's avatar
Andreas Klöckner committed
# You can test individual routines by typing
Andreas Klöckner's avatar
Andreas Klöckner committed
# $ python test_tree.py 'test_routine(cl.create_some_context)'
Andreas Klöckner's avatar
Andreas Klöckner committed

if __name__ == "__main__":
    if len(sys.argv) > 1:
        exec(sys.argv[1])
    else:
        from py.test.cmdline import main
        main([__file__])

# vim: fdm=marker