Skip to content

Getting indices of nearest neighbor in one go #63

@Datseris

Description

@Datseris

Hi Kristoffer

Let's say that I have a tree:

using NearestNeighbors, StaticArrays
data = [rand(SVector{3}) for i in 1:1000]
tree = KDTree(data, Euclidean())

I found that I am implementing an algorithm where I want the nearest neighbor of a point very frequently. Sometimes I am also quering about it multiple times. I was wondering whether there is some way I can get the indices of nearest neighbors from the tree structure.

Of course I know I can do:

nind = [knn(tree, data[j], 1, false, i -> i == j)[1][1] for j in 1:length(data)]

but is there some "faster way" ?

edit: the tree is not an argument to my high-level function but created inside. so if there is a way to do what I want even during construction, then it will still be super useful

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