NearestNeighbors.jl icon indicating copy to clipboard operation
NearestNeighbors.jl copied to clipboard

`KDTree` inference failure causes results to fail to infer

Open BioTurboNick opened this issue 8 months ago • 0 comments

function foo(data, point)
       b = KDTree(data)
       return knn(b, point, 1)
end

foo([1.0 3.4; 4.5 3.4], [4.5; 3.4])
Image

The root cause is that obviously the static vector size isn't knowable at compile time.

I suggest adding a variant interface allowing the dimension to be specified by the user, such as:

function KDTree(data::AbstractVecOrMat{T}, ::Val{D}, metric::M = Euclidean(); ...) where {T <: AbstractFloat, M <: MinkowskiMetric, D}
    ...
end

BioTurboNick avatar Apr 19 '25 02:04 BioTurboNick