diff --git a/README.md b/README.md index 9fae275..a9c7dbd 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,14 @@ kdtree_seq = KDTree(data; parallel=false) A kNN search finds the `k` nearest neighbors to a given point or points. This is done with the methods: ```julia -knn(tree, point[s], k [, skip=always_false]) -> idxs, dists -knn!(idxs, dists, tree, point, k [, skip=always_false]) +knn(tree, point[s], k [, sortres=false, skip=always_false]) -> idxs, dists +knn!(idxs, dists, tree, point, k [, sortres=false, skip=always_false]) ``` * `tree`: The tree instance. * `point[s]`: A vector or matrix of points to find the `k` nearest neighbors for. A vector of numbers represents a single point; a matrix means the `k` nearest neighbors for each point (column) will be computed. `points` can also be a vector of vectors. * `k`: Number of nearest neighbors to find. +* `sortres`: Whether to sort the returned values by their `distances` (`true`) or not (default: `false`). * `skip` (optional): A predicate function to skip certain points, e.g., points already visited. diff --git a/src/knn.jl b/src/knn.jl index 7e13659..2d1905e 100644 --- a/src/knn.jl +++ b/src/knn.jl @@ -5,7 +5,7 @@ function check_k(tree, k) end """ - knn(tree::NNTree, points, k [, skip=always_false]) -> indices, distances + knn(tree::NNTree, points, k [, sortres=false, skip=always_false]) -> indices, distances Performs a lookup of the `k` nearest neighbors to the `points` from the data in the `tree`. @@ -14,6 +14,7 @@ in the `tree`. - `tree`: The tree instance - `points`: Query point(s) - can be a vector (single point), matrix (multiple points), or vector of vectors - `k`: Number of nearest neighbors to find +- `sortres`: Whether to sort the returned values by their `distances` (`true`) or not (default: `false`) - `skip`: Optional predicate function to skip points based on their index (default: `always_false`) # Returns @@ -53,7 +54,7 @@ function knn_point!(tree::NNTree{V}, point::AbstractVector{T}, sortres, dist, id end """ - knn!(idxs, dists, tree, point, k [, skip=always_false]) + knn!(idxs, dists, tree, point, k [, sortres=false, skip=always_false]) Same functionality as `knn` but stores the results in the input vectors `idxs` and `dists`. Useful to avoid allocations or specify the element type of the output vectors. @@ -64,6 +65,7 @@ Useful to avoid allocations or specify the element type of the output vectors. - `tree`: The tree instance - `point`: Query point - `k`: Number of nearest neighbors to find +- `sortres`: Whether to sort the returned values by their `distances` (`true`) or not (default: `false`) - `skip`: Optional predicate function to skip points based on their index (default: `always_false`) See also: `knn`, `nn`.