It also seems unnecessary to restrict it to Float64 and Array: function myjaccard2{T}(A::AbstractArray{T,1}, B::AbstractArray{T, 1}) num = zero(T) den = zero(T) for (a,b) in zip(A,B) num += min(a,b) den += max(a,b) end return 1.0 - num/den end
Maybe also use T1, T2 and then promote to a common type ;) Best, Simon Am Montag, 13. Juni 2016 03:53:14 UTC+2 schrieb jean-pierre both: > > > > I encountered in my application with Distances.Jaccard compared with > Distances.Euclidean > It was very slow. > > For example with 2 vecteurs Float64 of size 11520 > > I get the following > julia> D=Euclidean() > Distances.Euclidean() > julia> @time for i in 1:500 > evaluate(D,v1,v2) > end > 0.002553 seconds (500 allocations: 7.813 KB) > > and with Jaccard > > julia> D=Jaccard() > Distances.Jaccard() > @time for i in 1:500 > evaluate(D,v1,v2) > end > 1.995046 seconds (40.32 M allocations: 703.156 MB, 9.68% gc time) > > With a simple loop for computing jaccard : > > > function myjaccard2(a::Array{Float64,1}, b::Array{Float64,1}) > num = 0 > den = 0 > for i in 1:length(a) > num = num + min(a[i],b[i]) > den = den + max(a[i],b[i]) > end > 1. - num/den > end > myjaccard2 (generic function with 1 method) > > julia> @time for i in 1:500 > myjaccard2(v1,v2) > end > 0.451582 seconds (23.04 M allocations: 351.592 MB, 20.04% gc time) > > I do not see the problem in jaccard distance implementation in the > Distances packages >