Skip to content

Conversation

@johnnychen94
Copy link
Contributor

@johnnychen94 johnnychen94 commented Aug 6, 2019

This PR is related to #22, one can easily rename evaluate later if we reach a consensus.

By moving implementations into functor, evaluate now is simply a really thin wrapper here; evaluate is limited only in generic.jl now (line 24).

This reduces the possibility of meeting method ambiguity introduced by inconsistent type specification. For example, the implementation of CorrDist is cleaner.

Another change is the new usage dist(x, y), e.g., Euclidean()(x, y).

P.S.
[1] Vscode auto-formats some codes here and I commit it as well.
[2] For ImageDistances.jl, it will be much easier to extend to Colorant elements without getting lost in method ambiguity and dispatch orders 😄

cc: @andreasnoack @KristofferC @ararslan

changed parts:

* spaces after type annotation, e.g, `b::AbstractMatrix = a`

not changed parts:

* additional spaces at the end of line
* spaces between operations and comma, e.g., `a + b` and `(a, b)`
@johnnychen94
Copy link
Contributor Author

johnnychen94 commented Aug 8, 2019

This PR also solves the potential ambiguities

Before this PR:

julia> foreach(enumerate(detect_ambiguities(Distances))) do (i, item)
           println("Methods $i:")
           println(item[1])
           println(item[2])
       end
Methods 1:
evaluate(d::Union{BrayCurtis, Chebyshev, ChiSqDist, Cityblock, CorrDist, CosineDist, GenKLDivergence, Hamming, JSDivergence, Jaccard, KLDivergence, RogersTanimoto, SpanNormDist, TotalVariation, Euclidean, SqEuclidean, Minkowski, RenyiDivergence}, a::Union{SubArray{T,1,Array{T,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true} where T, Array}, b::Union{SubArray{T,1,Array{T,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true} where T, Array}) in Distances at /Users/jc/.julia/packages/Distances/HOWRG/src/metrics.jl:153
evaluate(::CorrDist, a::AbstractArray, b::AbstractArray) in Distances at /Users/jc/.julia/packages/Distances/HOWRG/src/metrics.jl:269

After this PR:

julia> detect_ambiguities(Distances)
0-element Array{Tuple{Method,Method},1}

@KristofferC
Copy link
Member

FYI, shoving a code formatting commit into a PR that also does non-formatting changes makes it pretty annoying to review. Is it possible to leave out the formatting stuff to its own PR?

@KristofferC
Copy link
Member

But I like the change :). Makes the code simpler in many places.

@johnnychen94
Copy link
Contributor Author

Ah, I thought you guys would review the codes with the non-whitespace feature provided by github 😂 I can rollback the formatting part if you insist.

@KristofferC
Copy link
Member

Well, I also want to review the whitespace changes separately to see if they make sense :)

This PR fixes all the ambiguities as a good start, future PRs may not
break this.
@johnnychen94
Copy link
Contributor Author

Fortunately, all the format changes are rolled back, and I've added a detect_ambiguities test here since this PR solves all the ambiguities.

Since I need changes from this and #140 to continue my work in ImageDistances.jl, could you please tag a release after merging this?

@KristofferC KristofferC merged commit e03f7d6 into JuliaStats:master Aug 15, 2019
@johnnychen94 johnnychen94 deleted the dispatch branch January 2, 2020 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants