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

Poor inference for pvalue #263

Open
nalimilan opened this issue Mar 3, 2022 · 4 comments
Open

Poor inference for pvalue #263

nalimilan opened this issue Mar 3, 2022 · 4 comments

Comments

@nalimilan
Copy link
Member

The inferred return type of pvalue is quite imprecise or even weird for some tests. This appears to be a regression from some time ago (as it didn't happen on an old state I had), but the problem doesn't go away when using old versions so I suspect it's related to a change in a dependency.

julia> @code_warntype pvalue(SignedRankTest([1], [1]))
MethodInstance for HypothesisTests.pvalue(::ExactSignedRankTest{Int64})
  from pvalue(x::ExactSignedRankTest; tail) in HypothesisTests at /home/milan/.julia/dev/HypothesisTests/src/wilcoxon.jl:135
Arguments
  #self#::Core.Const(HypothesisTests.pvalue)
  x::ExactSignedRankTest{Int64}
Body::Union{Nothing, Float64, Int64}
1%1 = HypothesisTests.:(var"#pvalue#33")(:both, #self#, x)::Union{Nothing, Float64, Int64}
└──      return %1

julia> @code_warntype pvalue(EqualVarianceTTest([1], [1]))
MethodInstance for HypothesisTests.pvalue(::EqualVarianceTTest)
  from pvalue(x::HypothesisTests.TTest; tail) in HypothesisTests at /home/milan/.julia/dev/HypothesisTests/src/t.jl:31
Arguments
  #self#::Core.Const(HypothesisTests.pvalue)
  x::EqualVarianceTTest
Body::Any
1%1 = HypothesisTests.:(var"#pvalue#29")(:both, #self#, x)::Any
└──      return %1

# But
julia> @code_warntype pvalue(MannWhitneyUTest([1], [1]))
MethodInstance for HypothesisTests.pvalue(::ExactMannWhitneyUTest{Float64})
  from pvalue(x::ExactMannWhitneyUTest; tail) in HypothesisTests at /home/milan/.julia/dev/HypothesisTests/src/mann_whitney.jl:136
Arguments
  #self#::Core.Const(HypothesisTests.pvalue)
  x::ExactMannWhitneyUTest{Float64}
Body::Float64
1%1 = HypothesisTests.:(var"#pvalue#27")(:both, #self#, x)::Float64
└──      return %1

This is one of the causes of JuliaStats/StatsBase.jl#771, though the error is due to a bug in StatsBase.

@devmotion
Copy link
Member

They are all caused by HypothesisTests. The first one due to some simple type stability issues (checked locally that fixing them fixes the example) and the second one since the struct EqualVarianceTTest contains fields of abstract types (I assume, did not try to fix it).

@nalimilan
Copy link
Member Author

OK, cool. That's funny because originally I didn't get the same inference issues, they only appeared after I updated to the latest version of all packages. But I'm unable to go back to the original state now as I didn't save the versions.

@nalimilan
Copy link
Member Author

Ah, and any idea where the Nothing part for ExactSignedRankTest comes from? :-/

@devmotion
Copy link
Member

Yes. There was no else branch. I fixed it in the PR, it was the main reason for the check_tail function and replacing the last elseif with else.

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

No branches or pull requests

2 participants