Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Commit

Permalink
Removed unnecessary k+1 in knn heap
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Feb 23, 2015
1 parent 4946f75 commit 1d0f4b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/KDTrees.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module KDTrees

import Base.show
using Base.Collections

using Compat
using Devectorize
Expand Down
11 changes: 4 additions & 7 deletions src/kd_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,11 @@ function k_nearest_neighbour{T <: FloatingPoint}(tree::KDTree, point::Vector{T},
end

# Heaps to store indices and distances
best_idxs = [-1 for i in 1:k+1]
best_dists = [typemax(T) for i in 1:k+1]
best_idxs = [-1 for i in 1:k]
best_dists = [typemax(T) for i in 1:k]

_k_nearest_neighbour(tree, point, k, best_idxs, best_dists, 1)

pop!(best_idxs)
pop!(best_dists)

# Sqrt here because distances are stored in reduced format.
@devec best_dists[:] = sqrt(best_dists)

Expand Down Expand Up @@ -381,8 +378,8 @@ function _k_nearest_neighbour{T <: FloatingPoint}(tree::KDTree{T},
idx = tree.data_reordered ? z : tree.indices[z]
dist_d = euclidean_distance_red(tree, idx, point)
if dist_d <= best_dists[1]
best_dists[end] = dist_d
best_idxs[end] = idx
best_dists[1] = dist_d
best_idxs[1] = idx
percolate_down!(best_dists, best_idxs, dist_d, idx)
end
end
Expand Down

0 comments on commit 1d0f4b5

Please sign in to comment.