add knninrange to uniformly sample k points in range within a given range#223
add knninrange to uniformly sample k points in range within a given range#223KristofferC wants to merge 1 commit intomasterfrom
knninrange to uniformly sample k points in range within a given range#223Conversation
|
Tested locally and it works as expected. Thank you! Looking forward to the next release. |
|
I just want to say that it won't save you much time, because it still checks all points in range; it is just that it only store a random subset of size |
|
I guess the main benefit would be the pre-allocation of k indices and |
Note that there is also an
So I am actually not sure how useful this is in practice vs just allocating an output idx vector an calling |
|
You are probably right. What is your recommendation for the fastest method to retrieve up to My current implementation looks like the following: inds, dists = knn(tree, x, k, true)
inds[dists .≤ r] |
|
You won't get a uniformly random sample from the points inside that range with that code but I don't know if you care about that. For uniformity you could do something like: (which would be just a version of Also, in your code you allocate |
Thank you. I believe |
9bbf42f to
c792651
Compare
c792651 to
c4c1ff2
Compare
|
@KristofferC what is the plan regarding this PR? Is it ready? |
|
Kind of, but I am a little bit uncertain how useful it is... When it comes to allocations, creating the |
I will investigate this after the break and report results back here. |
|
@KristofferC I started looking into this. Did some benchmarks by replacing inds, dists = knn(tree, x, k, true)
keep = dists .≤ rwith inds = knninrange(tree, x, r, k)
dists = zeros(length(inds)) # currently knninrange doesn't return distances
keep = trues(length(inds)) # keep all indices as they are inside range alreadyand calling the function multiple times inside a hot loop. The original version is 4x faster. I wonder if an in-place |
Fixes #210.
@juliohm, mind trying this out?