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

Is it possible to use integers instead of floats?

Open tlnagy opened this issue 10 years ago • 1 comments

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

tlnagy avatar Dec 21 '15 01:12 tlnagy

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

KristofferC avatar Dec 21 '15 12:12 KristofferC