The inrange function is super useful, yet some applications only need a subset of at most k indices inside the range. This is particularly useful in hot loops because then it is possible to pre-allocate a buffer of length k once, and populate this buffer with a set of random indices inside the range.
How hard would it be to add a new knninrange function that achieves this goal? From what I understand, the following core function is responsible for adding indices to the final result of inrange:
|
@inline function add_points_inrange!(idx_in_ball::Union{Nothing, AbstractVector{<:Integer}}, tree::NNTree, |
|
index::Int, point::AbstractVector, r::Number) |
|
count = 0 |
|
for z in get_leaf_range(tree.tree_data, index) |
|
idx = tree.reordered ? z : tree.indices[z] |
|
if check_in_range(tree.metric, tree.data[idx], point, r) |
|
count += 1 |
|
idx_in_ball !== nothing && push!(idx_in_ball, idx) |
|
end |
|
end |
|
return count |
|
end |
Could we adjust the code to consider custom criteria besides check_in_range ̇?
The
inrangefunction is super useful, yet some applications only need a subset of at mostkindices inside the range. This is particularly useful in hot loops because then it is possible to pre-allocate a buffer of lengthkonce, and populate this buffer with a set of random indices inside the range.How hard would it be to add a new
knninrangefunction that achieves this goal? From what I understand, the following core function is responsible for adding indices to the final result ofinrange:NearestNeighbors.jl/src/tree_ops.jl
Lines 117 to 128 in 8867613
Could we adjust the code to consider custom criteria besides
check_in_rangė?