Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

move implementations into type overloading (aka. functor) #139

Merged
merged 17 commits into from Aug 15, 2019
Merged

move implementations into type overloading (aka. functor) #139

merged 17 commits into from Aug 15, 2019

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

src/metrics.jl Show resolved Hide resolved
src/wmetrics.jl Outdated Show resolved Hide resolved
src/generic.jl Outdated Show resolved Hide resolved
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}

src/generic.jl Outdated Show resolved Hide resolved
src/generic.jl Outdated Show resolved Hide resolved
src/bregman.jl Outdated Show resolved Hide resolved
src/bregman.jl Outdated Show resolved Hide resolved
src/metrics.jl Show resolved Hide resolved
src/metrics.jl Show resolved Hide resolved
@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?

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.

None yet

3 participants