Open
Conversation
Author
|
friendly bump |
|
I like the idea, I wish we could have a faster Knn in the package and leverage it in other packages, such as Clustering.jl. For reference I ended up doing something similar https://github.com/JuliaStats/Clustering.jl/pulls |
Author
|
Similar to NearestNeighbours, or Multithreaded Nearest Neighbours? |
|
I would say both make sense to have in the NearestNeighbors Package. KNN single threaded by default, and one version that does not store all pairwise distances (which is what Clustering.jl is doing at the moment) and maybe with a keyword argument to allow multithreaded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR has added a function
knn_threaded. I am able to achieve several X speedup from multithreading, but a several X slowdown for small problems. This is an acceptable tradeoff IMO, and possibly some smart heuristic can be implemented to only multithread when beneficial.An internal
_batch_indsfunction accomplishes the batching for separating the task into as few partitions as possible, based on the following quote from the readme:"It is generally better for performance to query once with a large number of points than to query multiple times with one point per query."
I have been using the following function for timing:
which on my computer
with 4 physical and 8 logical cores, gives the following results:
This PR probably requires some cleaning, especially in determining a good API and possibly heuristics for when to use multithreading. I do not think that there should be a separate knn_threaded function, but I implemented it like this for now for easy comparison. If it is confirmed to be overall faster, then I think it should be the default option.
PS - this is my first attempt at multithreading, so please doublecheck things thoroughly before merging anything.