Skip to content

Retrieve up to k random indices inrange #210

@juliohm

Description

@juliohm

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 ̇?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions