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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A very weird method dispatch bug #6161

Closed
lindahua opened this issue Mar 14, 2014 · 2 comments
Closed

A very weird method dispatch bug #6161

lindahua opened this issue Mar 14, 2014 · 2 comments
Assignees
Labels
kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version

Comments

@lindahua
Copy link
Contributor

This bug is due to a recent Base update, and it causes the test failure of Distributions.jl

Related code: (https://github.com/JuliaStats/Distributions.jl/blob/master/src/univariate/categorical.jl#L225)

function fit_mle{T<:Integer}(::Type{Categorical}, k::Integer, x::Array{T}) 
    Categorical(normalize!(add_categorical_counts!(zeros(k), x), 1), NoArgCheck())
end

fit_mle{T<:Integer}(::Type{Categorical}, data::(Int, Array{T})) = 
      fit_mle(Categorical, data...)

Then in Julia:

julia> using Distributions

julia> x = rand(1:3, 10);

julia> fit_mle(Categorical, 3, x)
Categorical( K=3 prob=[0.7000000000000001, 0.30000000000000004, 0.0] )

julia> fit_mle(Categorical, (3, x))
Binomial( size=3 prob=0.43333333333333335 )

However, it I change the last fit_mle method to

fit_mle{T<:Integer}(::Type{Categorical}, data::(Int, Array{T})) = 
      fit_mle(Categorical, data[1], data[2])

Then it works correctly.

It is very weird why fit_mle(Categorical, data...) calls a wrong method, while fit_mle(Categorical, data[1], data[2]) is correct.

Related to JuliaStats/Distributions.jl#198

cc: @JeffBezanson @StefanKarpinski

@JeffBezanson JeffBezanson self-assigned this Mar 14, 2014
@lindahua
Copy link
Contributor Author

Using git bisect, I figured the commit that causes this bug: 9718fcf

@JeffBezanson
Copy link
Sponsor Member

Thanks for doing the bisect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

2 participants