Skip to content

Commit

Permalink
use the maximum distance to hyper rectangle to add all points in the …
Browse files Browse the repository at this point in the history
…subtree

TODO: This should be done by only looking at the change in the split_dim from the parent
  • Loading branch information
KristofferC committed Jun 29, 2024
1 parent 1a5c45f commit 46b9aee
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/kd_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,24 @@ function inrange_kernel!(tree::KDTree,
return 0
end

M = tree.metric

# At a leaf node. Go through all points in node and add those in range
if isleaf(tree.tree_data.n_internal_nodes, index)
return add_points_inrange!(idx_in_ball, tree, index, point, r)
end

max_dist = get_max_distance_no_end(M, hyper_rec, point)
if max_dist < r
return addall(tree, index, idx_in_ball)
end

split_val = tree.split_vals[index]
split_dim = tree.split_dims[index]
lo = hyper_rec.mins[split_dim]
hi = hyper_rec.maxes[split_dim]
p_dim = point[split_dim]
split_diff = p_dim - split_val
M = tree.metric

count = 0

Expand All @@ -257,11 +263,6 @@ function inrange_kernel!(tree::KDTree,
# Call closer sub tree
count += inrange_kernel!(tree, close, point, r, idx_in_ball, hyper_rec_close, min_dist)

# TODO: We could potentially also keep track of the max distance
# between the point and the hyper rectangle and add the whole sub tree
# in case of the max distance being <= r similarly to the BallTree inrange method.
# It would be interesting to benchmark this on some different data sets.

# Call further sub tree with the new min distance
split_diff_pow = eval_pow(M, split_diff)
ddiff_pow = eval_pow(M, ddiff)
Expand Down

0 comments on commit 46b9aee

Please sign in to comment.