KristofferC / NearestNeighbors.jl

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

Can't do `knn` on `AbstractVector{SVector}` #176

Closed BenCurran98 closed 2 months ago

BenCurran98 commented 7 months ago

Hi, I've been trying to run knn on views of an array of points where my points are SVectors and noticed that knn doesn't allow this? E.g.

using NearestNeighbors
using StaticArrays

points = rand(SVector{3, Float64}, 100)
kdtree = KDTree(points)
idxs, dists = knn(kdtree, view(points, 1:10), 3)

The error from this (in Julia 1.10) is:

ERROR: MethodError: no method matching knn(::KDTree{SVector{…}, Euclidean, Float64, SVector{…}}, ::SubArray{SVector{…}, 1, Vector{…}, Tuple{…}, true}, ::Int64)

Closest candidates are:
  knn(::NNTree{V}, ::Vector{T}, ::Int64, ::Any, ::F) where {V, T<:(AbstractVector), F<:Function}
   @ NearestNeighbors ~/.julia/packages/NearestNeighbors/dZqbT/src/knn.jl:17
  knn(::NNTree{V}, ::Vector{T}, ::Int64, ::Any) where {V, T<:(AbstractVector)}
   @ NearestNeighbors ~/.julia/packages/NearestNeighbors/dZqbT/src/knn.jl:17
  knn(::NNTree{V}, ::Vector{T}, ::Int64) where {V, T<:(AbstractVector)}
   @ NearestNeighbors ~/.julia/packages/NearestNeighbors/dZqbT/src/knn.jl:17
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[24]:1
Some type information was truncated. Use `show(err)` to see complete types.

Any help would be much appreciated! :slightly_smiling_face:

KristofferC commented 2 months ago

Hi and thanks for the report. Sorry for the late reply but this should be fixed and be in a release soon.

BenCurran98 commented 2 months ago

Thanks for that! :slightly_smiling_face: