Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add let block around call to partialsort! to avoid overhead from captured variable #76

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions src/kd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ function diameter(bounds::Matrix)
euclidean(vec(bounds[1,:]), vec(bounds[2,:]))
end


"""
build_kdtree(xs, perm, bounds, leaf_size_cutoff, leaf_diameter_cutoff, verts)

Expand Down Expand Up @@ -185,7 +184,11 @@ function build_kdtree(xs::AbstractMatrix{T},
offset = -offset + (offset <= 0)
continue
end
p12 = partialsort!(perm, mid1:mid2, by = i -> xs[i, j])
# Use a let block to avoid overhead from captured variable in closure
# Ref https://github.com/JuliaLang/julia/issues/15276
p12 = let j = j
andreasnoack marked this conversation as resolved.
Show resolved Hide resolved
partialsort!(perm, mid1:mid2, by = i -> xs[i, j])
end
if xs[p12[1], j] == xs[p12[2], j]
@debug "tie! Adjusting offset" xs[p12[1], j] xs[p12[2], j] offset
# This makes the offset 0, 1, -1, 2, -2, ...
Expand Down