KristofferC / NearestNeighbors.jl

High performance nearest neighbor data structures (KDTree and BallTree) and algorithms for Julia.
Other
413 stars 65 forks source link

bug: BoundsError when the skip function returns true for all points #149

Closed felipeek closed 2 years ago

felipeek commented 2 years ago

It seems there is a bug with the skip function.

data = rand(3, 10^4)
k = 3
point = rand(3)

kdtree = KDTree(data)
nn(kdtree, point, idx -> return true)

This code throws:

BoundsError: attempt to access 0-element Vector{Int64} at index [1]

I'm using the latest version of the package [0.4.11]

felipeek commented 2 years ago

Complete stack:


Stacktrace:
  [1] getindex
    @ ./array.jl:861 [inlined]
  [2] first
    @ ./abstractarray.jl:398 [inlined]
  [3] |>
    @ ./operators.jl:966 [inlined]
  [4] _broadcast_getindex_evalf
    @ ./broadcast.jl:670 [inlined]
  [5] _broadcast_getindex
    @ ./broadcast.jl:643 [inlined]
  [6] #29
    @ ./broadcast.jl:1075 [inlined]
  [7] ntuple
    @ ./ntuple.jl:49 [inlined]
  [8] copy
    @ ./broadcast.jl:1075 [inlined]
  [9] materialize
    @ ./broadcast.jl:860 [inlined]
 [10] nn(tree::KDTree{StaticArrays.SVector{3, Float64}, Euclidean, Float64}, points::Vector{Float64}, skip::var"#5#6")
    @ NearestNeighbors ~/.julia/packages/NearestNeighbors/VZzTb/src/knn.jl:66
 [11] top-level scope
    @ In[110]:6
 [12] eval
    @ ./boot.jl:373 [inlined]
 [13] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196
felipeek commented 2 years ago

The knn function works fine, so I will use that for now

felipeek commented 2 years ago

closing as this was already reported in https://github.com/KristofferC/NearestNeighbors.jl/issues/127