Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
LeavesToBallsLookupBuilder, SpaceInvaderQueryBuilder)
siqb = SpaceInvaderQueryBuilder(ctx)
# 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)
# }}}
# $ python test_tree.py 'test_routine(cl.create_some_context)'