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

Fix type inference of Bisection method #245

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

devmotion
Copy link
Member

Currently, the example in the README can't be inferred:

julia> using Roots

julia> f(x) = exp(x) - x^4;

julia> α₀,α₁,α₂ = -0.8155534188089607, 1.4296118247255556, 8.6131694564414;

julia> @code_warntype find_zero(f, (8,9), Bisection())
Variables
  #self#::Core.Const(Roots.find_zero)
  fs::Core.Const(f)
  x0::Tuple{Int64, Int64}
  method::Core.Const(Bisection())

Body::Any
1%1 = Roots.NullTracks()::Core.Const(Roots.NullTracks())
│   %2 = Core.NamedTuple()::Core.Const(NamedTuple())
│   %3 = Base.pairs(%2)::Core.Const(Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}())
│   %4 = Roots.:(var"#find_zero#23")(Roots.nothing, %1, false, %3, #self#, fs, x0, method)::Any
└──      return %4

The PR fixes this issue, also for brackets with mixed types (Base.extrema and hence also Roots._extrema are not type stable for tuples of different types).

@codecov
Copy link

codecov bot commented Sep 14, 2021

Codecov Report

Merging #245 (7eeae0c) into master (a77396c) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #245      +/-   ##
==========================================
+ Coverage   83.38%   83.46%   +0.08%     
==========================================
  Files          12       12              
  Lines        1950     1954       +4     
==========================================
+ Hits         1626     1631       +5     
+ Misses        324      323       -1     
Impacted Files Coverage Δ
src/bracketing.jl 86.54% <100.00%> (ø)
src/find_zeros.jl 95.90% <100.00%> (ø)
src/utils.jl 73.25% <100.00%> (+2.52%) ⬆️
src/find_zero.jl 71.55% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a77396c...7eeae0c. Read the comment docs.

@jverzani
Copy link
Member

Nice! Thanks again!

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.

2 participants