Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
6 changes: 4 additions & 2 deletions src/knn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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`.
Expand Down