KristofferC / NearestNeighbors.jl

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

Is it possible to use integers instead of floats? #13

Open tlnagy opened 8 years ago

tlnagy commented 8 years ago

I would like to use NearestNeighbors.jl to find the nearest string in Hamming distance from a given input string. Do I have to convert them to floats to use the NearestNeighbors library? I would prefer to avoid this because of precision issues and memory use. For example, I can't use ints with BallTree:

data = rand(1:4, (10, 10^4))
balltree = BallTree(data, Hamming())

gives the following error:

LoadError: MethodError: `convert` has no method matching convert(::Type{NearestNeighbors.BallTree{T<:AbstractFloat,M<:Distances.Metric}}, ::Array{Int64,2}, ::Distances.Hamming)
This may have arisen from a call to the constructor NearestNeighbors.BallTree{T<:AbstractFloat,M<:Distances.Metric}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  NearestNeighbors.BallTree{T<:AbstractFloat,M<:Distances.Metric}(!Matched::Array{T<:AbstractFloat,2}, ::M<:Distances.Metric)
  call{T}(::Type{T}, ::Any)
  convert{T}(::Type{T}, !Matched::T)
  ...
while loading In[53], in expression starting on line 2

 in call at essentials.jl:57

Is there a specific reason that AbstractFloat is the parent type? Distances.jl can handle other types just fine:

evaluate(Hamming(), ["A","B","C"], ["A","B","D"])

I'm using Julia v0.4.1 and the masters of both NearestNeighbors and Distances

KristofferC commented 8 years ago

This should be possible, might just need to relax some of the parameters. I will look into it.